summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2017-11-02 16:00:58 +0100
committerMartin Geubelle <mge@odoo.com>2017-11-07 14:12:18 +0100
commit255478acbd66f01daf32422636f09f2014ebc9f8 (patch)
tree32603470881197cd67f85efdee8aa37dbd173a18 /addons/web/static/tests/fields
parentf8bf66b6def30b5738d91da564fda0a8eb8eeead (diff)
[FIX] web: clear m2o input at creation cancel
After entering a value in a many2one, if one clicks somewhere else, a popup is opened to suggest the user to create (or not) a new record with the entered value. Before this rev, closing this popup resulted in an unclear situation where the input was still set with the entered value but the new record hadn't been created. This commit fixes this by clearing the input value if the record is not created. See task#36055
Diffstat (limited to 'addons/web/static/tests/fields')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js32
1 files changed, 27 insertions, 5 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 3cdd4b89138..07b58764e30 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -1395,7 +1395,7 @@ QUnit.module('relational_fields', {
});
QUnit.test('slow create on a many2one', function (assert) {
- assert.expect(1);
+ assert.expect(7);
var form = createView({
View: FormView,
@@ -1415,12 +1415,34 @@ QUnit.module('relational_fields', {
},
});
- form.$('.o_field_many2one input').focus();
- form.$('.o_field_many2one input').val('new partner').trigger('keyup').trigger('focusout');
+ // cancel the many2one creation with Cancel button
+ form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur');
+ assert.strictEqual($('.modal').length, 1, "there should be one opened modal");
+ $('.modal .modal-footer .btn:contains(Cancel)').click();
+ assert.strictEqual(form.$('.o_field_many2one input').val(), "",
+ 'the many2one should not set a value as its creation has been cancelled (with Cancel button)');
- $('.modal .modal-footer .btn-primary').first().click();
+ // cancel the many2one creation with Close button
+ form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur');
+ $('.modal .modal-header button').click();
+ assert.strictEqual(form.$('.o_field_many2one input').val(), "",
+ 'the many2one should not set a value as its creation has been cancelled (with Close button)');
- assert.strictEqual($('.modal:visible:last .o_form_view').length, 1,
+ // select a new value then cancel the creation of the new one --> restore the previous
+ form.$('.o_field_many2one input').click();
+ form.$('.o_field_many2one input').autocomplete('widget').find('a').first().click();
+ assert.strictEqual(form.$('input').val(), "xphone", "should have selected xphone");
+ form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur');
+ assert.strictEqual($('.modal').length, 1, "there should be one opened modal");
+ $('.modal .modal-footer .btn:contains(Cancel)').click();
+ assert.strictEqual(form.$('.o_field_many2one input').val(), "xphone",
+ 'should have restored the many2one with its previous selected value (xphone)');
+
+ // confirm the many2one creation
+ form.$('.o_field_many2one input').focus();
+ form.$('.o_field_many2one input').val('new partner').trigger('keyup').trigger('blur');
+ $('.modal .modal-footer .btn-primary').click();
+ assert.strictEqual($('.modal .o_form_view').length, 1,
'a new modal should be opened and contain a form view');
form.destroy();