[ADD] web: add label_selection widget tests and documentation

This commit is contained in:
David Monjoie
2017-04-11 19:44:38 +02:00
committed by Aaron Bohy
parent fbb0450d51
commit 1b08fa43ab
2 changed files with 138 additions and 2 deletions
@@ -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) {