summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2019-08-22 16:06:02 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2019-08-23 14:29:05 +0000
commitd310cd447850d8451b9b51b0e3b6243734cddaef (patch)
tree645fde1b601db3bddf45e03af217876f35ca8643 /addons/web/static/tests/fields/relational_fields_tests.js
parentf01c325e9a42ca56cf9e7825a6251739410cc2f9 (diff)
[FIX] web: selection: required, option present but disabled
Before this commit, a field selection which was required did not have an empty option ref: 4dfabb8f7adde06a7936502af61534c9958ed4f7 This is fine, but overlooked the fact that modules can modify the required attribute, or even views can do it So, we may end up in a situation where the field is required but set to false This configuration is problematic, at least for the timezone selection field (see OPW) After this commit, the empty option is just not visible note that `disabled = True` would not work because val is not accessible Because of commits: - 4dfabb8f7adde06a7936502af61534c9958ed4f7 for the selection feature - d77ce4c2a92c1da48150e4e84b714dd93f64847d overriding the required attribute of tz in res.user form OPW 2057913 closes odoo/odoo#35989 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js39
1 files changed, 31 insertions, 8 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 9c60f7f5ca1..7aacbafc259 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -1189,7 +1189,7 @@ QUnit.module('relational_fields', {
});
QUnit.test('required selection widget should not have blank option', async function (assert) {
- assert.expect(3);
+ assert.expect(12);
this.data.partner.fields.feedback_value = {
type: "selection",
@@ -1210,15 +1210,38 @@ QUnit.module('relational_fields', {
});
await testUtils.form.clickEdit(form);
- assert.strictEqual(form.$('.o_field_widget[name=color]')[0].options.length, 3,
- "non required selection field must have 3 options 1 blank option and 2 value options");
- assert.strictEqual(form.$('.o_field_widget[name=feedback_value]')[0].options.length, 2,
- "should have only 2 options without blank option");
+
+ var $colorField = form.$('.o_field_widget[name=color]');
+ assert.containsN($colorField, 'option', 3, "Three options in non required field");
+
+ assert.hasAttrValue($colorField.find('option:first()'), 'style', "",
+ "Should not have display=none");
+ assert.hasAttrValue($colorField.find('option:eq(1)'), 'style', "",
+ "Should not have display=none");
+ assert.hasAttrValue($colorField.find('option:eq(2)'), 'style', "",
+ "Should not have display=none");
+
+ const $requiredSelect = form.$('.o_field_widget[name=feedback_value]');
+
+ assert.containsN($requiredSelect, 'option', 3, "Three options in required field");
+ assert.hasAttrValue($requiredSelect.find('option:first()'), 'style', "display: none",
+ "Should have display=none");
+ assert.hasAttrValue($requiredSelect.find('option:eq(1)'), 'style', "",
+ "Should not have display=none");
+ assert.hasAttrValue($requiredSelect.find('option:eq(2)'), 'style', "",
+ "Should not have display=none");
// change value to update widget modifier values
- await testUtils.fields.editSelect(form.$('.o_field_widget[name=feedback_value]'), '"bad"');
- assert.strictEqual(form.$('.o_field_widget[name=color]')[0].options.length, 2,
- "should have only 2 options");
+ await testUtils.fields.editSelect($requiredSelect, '"bad"');
+ $colorField = form.$('.o_field_widget[name=color]');
+
+ assert.containsN($colorField, 'option', 3, "Three options in required field");
+ assert.hasAttrValue($colorField.find('option:first()'), 'style', "display: none",
+ "Should have display=none");
+ assert.hasAttrValue($colorField.find('option:eq(1)'), 'style', "",
+ "Should not have display=none");
+ assert.hasAttrValue($colorField.find('option:eq(2)'), 'style', "",
+ "Should not have display=none");
form.destroy();
});