diff options
| author | David Monjoie <dmo@odoo.com> | 2017-03-24 16:25:37 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 1b08fa43abc046b3952f2c7c636931cdef4f0adf (patch) | |
| tree | e004a06b09ed59c2a7faacf91db0d4aa50148db4 /addons/web/static/test/fields/basic_fields_tests.js | |
| parent | fbb0450d512e97c960de780d772486203529e6c0 (diff) | |
[ADD] web: add label_selection widget tests and documentation
Diffstat (limited to 'addons/web/static/test/fields/basic_fields_tests.js')
| -rw-r--r-- | addons/web/static/test/fields/basic_fields_tests.js | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/addons/web/static/test/fields/basic_fields_tests.js b/addons/web/static/test/fields/basic_fields_tests.js index d489db97572..b57c6246b5f 100644 --- a/addons/web/static/test/fields/basic_fields_tests.js +++ b/addons/web/static/test/fields/basic_fields_tests.js @@ -2081,6 +2081,127 @@ QUnit.module('basic_fields', { }); + QUnit.module('LabelSelectionWidget'); + + QUnit.test('label_selection widget in form view', function (assert) { + assert.expect(12); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<sheet>' + + '<group>' + + '<field name="selection" widget="label_selection" ' + + ' options="{\'classes\': {\'normal\': \'default\', \'blocked\': \'warning\',\'done\': \'success\'}}"/>' + + '</group>' + + '</sheet>' + + '</form>', + res_id: 1, + }); + + assert.strictEqual(form.$('.o_form_field.label.label-warning').length, 1, + "should have a warning status label since selection is the second, blocked state"); + assert.strictEqual(form.$('.o_form_field.label.label-default').length, 0, + "should not have a default status since selection is the second, blocked state"); + assert.strictEqual(form.$('.o_form_field.label.label-success').length, 0, + "should not have a success status since selection is the second, blocked state"); + assert.strictEqual(form.$('.o_form_field.label.label-warning').text(), 'Blocked', + "the label should say 'Blocked' since this is the label value for that state"); + + // // switch to edit mode and check the result + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('.o_form_field.label.label-warning').length, 1, + "should have a warning status label since selection is the second, blocked state"); + assert.strictEqual(form.$('.o_form_field.label.label-default').length, 0, + "should not have a default status since selection is the second, blocked state"); + assert.strictEqual(form.$('.o_form_field.label.label-success').length, 0, + "should not have a success status since selection is the second, blocked state"); + assert.strictEqual(form.$('.o_form_field.label.label-warning').text(), 'Blocked', + "the label should say 'Blocked' since this is the label value for that state"); + + // save + form.$buttons.find('.o_form_button_save').click(); + assert.strictEqual(form.$('.o_form_field.label.label-warning').length, 1, + "should have a warning status label since selection is the second, blocked state"); + assert.strictEqual(form.$('.o_form_field.label.label-default').length, 0, + "should not have a default status since selection is the second, blocked state"); + assert.strictEqual(form.$('.o_form_field.label.label-success').length, 0, + "should not have a success status since selection is the second, blocked state"); + assert.strictEqual(form.$('.o_form_field.label.label-warning').text(), 'Blocked', + "the label should say 'Blocked' since this is the label value for that state"); + + form.destroy(); + }); + + QUnit.test('label_selection widget in editable list view', function(assert) { + assert.expect(21); + + var list = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '<tree editable="bottom">' + + '<field name="foo"/>' + + '<field name="selection" widget="label_selection"' + + ' options="{\'classes\': {\'normal\': \'default\', \'blocked\': \'warning\',\'done\': \'success\'}}"/>' + + '</tree>', + }); + + assert.strictEqual(list.$('.o_field_widget.label:not(:empty)').length, 3, + "should have three visible status labels"); + assert.strictEqual(list.$('.o_field_widget.label.label-warning').length, 1, + "should have one warning status label"); + assert.strictEqual(list.$('.o_field_widget.label.label-warning').text(), 'Blocked', + "the warning label should read 'Blocked'"); + assert.strictEqual(list.$('.o_field_widget.label.label-default').length, 1, + "should have one default status label"); + assert.strictEqual(list.$('.o_field_widget.label.label-default').text(), 'Normal', + "the default label should read 'Normal'"); + assert.strictEqual(list.$('.o_field_widget.label.label-success').length, 1, + "should have one success status label"); + assert.strictEqual(list.$('.o_field_widget.label.label-success').text(), 'Done', + "the success label should read 'Done'"); + + // switch to edit mode and check the result + list.$('tbody td:not(.o_list_record_selector)').first().click(); + assert.strictEqual(list.$('.o_field_widget.label:not(:empty)').length, 3, + "should have three visible status labels"); + assert.strictEqual(list.$('.o_field_widget.label.label-warning').length, 1, + "should have one warning status label"); + assert.strictEqual(list.$('.o_field_widget.label.label-warning').text(), 'Blocked', + "the warning label should read 'Blocked'"); + assert.strictEqual(list.$('.o_field_widget.label.label-default').length, 1, + "should have one default status label"); + assert.strictEqual(list.$('.o_field_widget.label.label-default').text(), 'Normal', + "the default label should read 'Normal'"); + assert.strictEqual(list.$('.o_field_widget.label.label-success').length, 1, + "should have one success status label"); + assert.strictEqual(list.$('.o_field_widget.label.label-success').text(), 'Done', + "the success label should read 'Done'"); + + // save and check the result + list.$buttons.find('.o_list_button_save').click(); + assert.strictEqual(list.$('.o_field_widget.label:not(:empty)').length, 3, + "should have three visible status labels"); + assert.strictEqual(list.$('.o_field_widget.label.label-warning').length, 1, + "should have one warning status label"); + assert.strictEqual(list.$('.o_field_widget.label.label-warning').text(), 'Blocked', + "the warning label should read 'Blocked'"); + assert.strictEqual(list.$('.o_field_widget.label.label-default').length, 1, + "should have one default status label"); + assert.strictEqual(list.$('.o_field_widget.label.label-default').text(), 'Normal', + "the default label should read 'Normal'"); + assert.strictEqual(list.$('.o_field_widget.label.label-success').length, 1, + "should have one success status label"); + assert.strictEqual(list.$('.o_field_widget.label.label-success').text(), 'Done', + "the success label should read 'Done'"); + + list.destroy(); + }); + + QUnit.module('FieldDomain'); QUnit.test('basic domain field usage is ok', function (assert) { |
