diff options
Diffstat (limited to 'addons/web/static/tests/views/form_tests.js')
| -rw-r--r-- | addons/web/static/tests/views/form_tests.js | 1893 |
1 files changed, 974 insertions, 919 deletions
diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index b1df6260359..96d36d8eec9 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -16,7 +16,6 @@ var Widget = require('web.Widget'); var _t = core._t; var createView = testUtils.createView; -var createAsyncView = testUtils.createAsyncView; var createActionManager = testUtils.createActionManager; QUnit.module('Views', { @@ -105,7 +104,6 @@ QUnit.module('Views', { ] }, }; - this.actions = [{ id: 1, name: 'Partners Action 1', @@ -113,15 +111,15 @@ QUnit.module('Views', { type: 'ir.actions.act_window', views: [[false, 'kanban'], [false, 'form']], }]; - } + }, }, function () { QUnit.module('FormView'); - QUnit.test('simple form rendering', function (assert) { + QUnit.test('simple form rendering', async function (assert) { assert.expect(12); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -174,10 +172,11 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('attributes are transferred on async widgets', function (assert) { + QUnit.test('attributes are transferred on async widgets', async function (assert) { assert.expect(1); + var done = assert.async(); - var def = $.Deferred(); + var def = testUtils.makeTestPromise(); var FieldChar = fieldRegistry.get('char'); fieldRegistry.add('asyncwidget', FieldChar.extend({ @@ -186,7 +185,7 @@ QUnit.module('Views', { }, })); - createAsyncView({ + createView({ View: FormView, model: 'partner', data: this.data, @@ -201,14 +200,16 @@ QUnit.module('Views', { "should apply style attribute on fields"); form.destroy(); delete fieldRegistry.map.asyncwidget; + done(); }); def.resolve(); + await testUtils.nextTick(); }); - QUnit.test('decoration works on widgets', function (assert) { + QUnit.test('decoration works on widgets', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -224,10 +225,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('decoration on widgets are reevaluated if necessary', function (assert) { + QUnit.test('decoration on widgets are reevaluated if necessary', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -239,15 +240,15 @@ QUnit.module('Views', { viewOptions: {mode: 'edit'}, }); assert.doesNotHaveClass(form.$('input[name="display_name"]'), 'text-danger'); - testUtils.fields.editInput(form.$('input[name=int_field]'), 3); + await testUtils.fields.editInput(form.$('input[name=int_field]'), 3); assert.hasClass(form.$('input[name="display_name"]'), 'text-danger'); form.destroy(); }); - QUnit.test('decoration on widgets works on same widget', function (assert) { + QUnit.test('decoration on widgets works on same widget', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -258,15 +259,15 @@ QUnit.module('Views', { viewOptions: {mode: 'edit'}, }); assert.doesNotHaveClass(form.$('input[name="int_field"]'), 'text-danger'); - testUtils.fields.editInput(form.$('input[name=int_field]'), 3); + await testUtils.fields.editInput(form.$('input[name=int_field]'), 3); assert.hasClass(form.$('input[name="int_field"]'), 'text-danger'); form.destroy(); }); - QUnit.test('only necessary fields are fetched with correct context', function (assert) { + QUnit.test('only necessary fields are fetched with correct context', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -287,10 +288,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('group rendering', function (assert) { + QUnit.test('group rendering', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -308,14 +309,14 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('Form and subview with _view_ref contexts', function (assert) { + QUnit.test('Form and subview with _view_ref contexts', async function (assert) { assert.expect(2); this.data.product.fields.partner_type_ids = {string: "one2many field", type: "one2many", relation: "partner_type"}, this.data.product.records = [{id: 1, name: 'Tromblon', partner_type_ids: [12,14]}]; this.data.partner.records[0].product_id = 1; - var actionManager = createActionManager({ + var actionManager = await createActionManager({ data: this.data, archs: { 'product,false,form': '<form>'+ @@ -344,7 +345,7 @@ QUnit.module('Views', { }, }); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -356,7 +357,7 @@ QUnit.module('Views', { mockRPC: function(route, args) { if (args.method === 'get_formview_action') { - return $.when({ + return Promise.resolve({ res_id: 1, type: 'ir.actions.act_window', target: 'current', @@ -376,14 +377,14 @@ QUnit.module('Views', { }, }, }); - form.$('.o_field_widget[name="product_id"]').click(); + await testUtils.dom.click(form.$('.o_field_widget[name="product_id"]')); form.destroy(); actionManager.destroy(); }); - QUnit.test('invisible fields are properly hidden', function (assert) { + QUnit.test('invisible fields are properly hidden', async function (assert) { assert.expect(4); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -410,10 +411,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('invisible elements are properly hidden', function (assert) { + QUnit.test('invisible elements are properly hidden', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -446,7 +447,8 @@ QUnit.module('Views', { // we set the value bar to simulate a falsy boolean value. this.data.partner.records[0].bar = false; - var form = createView({ + + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -459,9 +461,11 @@ QUnit.module('Views', { '</group></sheet>' + '</form>', res_id: 1, + viewOptions: { + mode:'edit' + }, }); - testUtils.form.clickEdit(form); assert.hasClass(form.$('.foo_field'), 'o_invisible_modifier'); assert.hasClass(form.$('.bar_field'), 'o_invisible_modifier'); @@ -472,10 +476,11 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('asynchronous fields can be set invisible', function (assert) { + QUnit.test('asynchronous fields can be set invisible', async function (assert) { assert.expect(1); + var done = assert.async(); - var def = $.Deferred(); + var def = testUtils.makeTestPromise(); // we choose this widget because it is a quite simple widget with a non // empty qweb template @@ -486,7 +491,7 @@ QUnit.module('Views', { }, })); - createAsyncView({ + createView({ View: FormView, model: 'partner', data: this.data, @@ -501,15 +506,15 @@ QUnit.module('Views', { assert.hasClass(form.$('.o_field_widget[name="int_field"]'), 'o_invisible_modifier'); form.destroy(); delete fieldRegistry.map.asyncwidget; + done(); }); def.resolve(); }); - - QUnit.test('properly handle modifiers and attributes on notebook tags', function (assert) { + QUnit.test('properly handle modifiers and attributes on notebook tags', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -531,10 +536,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('invisible attrs on first notebook page', function (assert) { + QUnit.test('invisible attrs on first notebook page', async function (assert) { assert.expect(6); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -554,12 +559,12 @@ QUnit.module('Views', { res_id: 1, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.hasClass(form.$('.o_notebook .nav .nav-link:first()'), 'active'); assert.doesNotHaveClass(form.$('.o_notebook .nav .nav-item:first()'), 'o_invisible_modifier'); // set a value on the m2o - testUtils.fields.many2one.searchAndClickItem('product_id'); + await testUtils.fields.many2one.searchAndClickItem('product_id'); assert.doesNotHaveClass(form.$('.o_notebook .nav .nav-link:first()'), 'active'); assert.hasClass(form.$('.o_notebook .nav .nav-item:first()'), 'o_invisible_modifier'); assert.hasClass(form.$('.o_notebook .nav .nav-link:nth(1)'), 'active'); @@ -567,10 +572,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('first notebook page invisible', function (assert) { + QUnit.test('first notebook page invisible', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -597,10 +602,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('autofocus on second notebook page', function (assert) { + QUnit.test('autofocus on second notebook page', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -626,10 +631,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('invisible attrs on group are re-evaluated on field change', function (assert) { + QUnit.test('invisible attrs on group are re-evaluated on field change', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -643,22 +648,24 @@ QUnit.module('Views', { '</group>' + '</sheet>' + '</form>', - res_id: 1 + res_id: 1, + viewOptions: { + mode: 'edit' + }, }); assert.containsOnce(form, 'div.o_group:visible'); - testUtils.form.clickEdit(form); - testUtils.dom.click('.o_field_boolean input', form); + await testUtils.dom.click('.o_field_boolean input', form); assert.containsOnce(form, 'div.o_group:hidden'); form.destroy(); }); - QUnit.test('invisible attrs with zero value in domain and unset value in data', function (assert) { + QUnit.test('invisible attrs with zero value in domain and unset value in data', async function (assert) { assert.expect(1); this.data.partner.fields.int_field.type = 'monetary'; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -677,10 +684,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('rendering stat buttons', function (assert) { + QUnit.test('rendering stat buttons', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -706,18 +713,18 @@ QUnit.module('Views', { assert.containsOnce(form, 'button.oe_stat_button.o_invisible_modifier'); var count = 0; - testUtils.mock.intercept(form, "execute_action", function () { + await testUtils.mock.intercept(form, "execute_action", function () { count++; }); - testUtils.dom.click('.oe_stat_button'); + await testUtils.dom.click('.oe_stat_button'); assert.strictEqual(count, 1, "should have triggered a execute action"); form.destroy(); }); - QUnit.test('label uses the string attribute', function (assert) { + QUnit.test('label uses the string attribute', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -736,10 +743,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('readonly attrs on fields are re-evaluated on field change', function (assert) { + QUnit.test('readonly attrs on fields are re-evaluated on field change', async function (assert) { assert.expect(4); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -753,24 +760,24 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.containsOnce(form, 'span[name="foo"]', "the foo field widget should be readonly"); - testUtils.dom.click(form.$('.o_field_boolean input')); + await testUtils.dom.click(form.$('.o_field_boolean input')); assert.containsOnce(form, 'input[name="foo"]', "the foo field widget should have been rerendered to now be editable"); - testUtils.dom.click(form.$('.o_field_boolean input')); + await testUtils.dom.click(form.$('.o_field_boolean input')); assert.containsOnce(form, 'span[name="foo"]', "the foo field widget should have been rerendered to now be readonly again"); - testUtils.dom.click(form.$('.o_field_boolean input')); + await testUtils.dom.click(form.$('.o_field_boolean input')); assert.containsOnce(form, 'input[name="foo"]', "the foo field widget should have been rerendered to now be editable again"); form.destroy(); }); - QUnit.test('empty fields have o_form_empty class in readonly mode', function (assert) { + QUnit.test('empty fields have o_form_empty class in readonly mode', async function (assert) { assert.expect(8); this.data.partner.fields.foo.default = false; // no default value for this test @@ -783,7 +790,7 @@ QUnit.module('Views', { } }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -804,21 +811,21 @@ QUnit.module('Views', { assert.containsN(form, '.o_form_label_empty', 2, "should have 2 muted labels (for the empty fieds) in readonly"); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.containsOnce(form, '.o_field_empty', "in edit mode, only empty readonly fields should have the o_field_empty class"); assert.containsOnce(form, '.o_form_label_empty', "in edit mode, only labels associated to empty readonly fields should have the o_form_label_empty class"); - testUtils.fields.editInput(form.$('input[name=foo]'), 'test'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'test'); assert.containsNone(form, '.o_field_empty', "after readonly modifier change, the o_field_empty class should have been removed"); assert.containsNone(form, '.o_form_label_empty', "after readonly modifier change, the o_form_label_empty class should have been removed"); - testUtils.fields.editInput(form.$('input[name=foo]'), 'hello'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'hello'); assert.containsOnce(form, '.o_field_empty', "after value changed to false for a readonly field, the o_field_empty class should have been added"); @@ -828,14 +835,14 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('empty fields\' labels still get the empty class after widget rerender', function (assert) { + QUnit.test('empty fields\' labels still get the empty class after widget rerender', async function (assert) { assert.expect(6); this.data.partner.fields.foo.default = false; // no default value for this test this.data.partner.records[1].foo = false; // 1 is record with id=2 this.data.partner.records[1].display_name = false; // 1 is record with id=2 - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -848,21 +855,21 @@ QUnit.module('Views', { res_id: 2, }); - assert.containsN(form, '.o_field_widget.o_field_empty', 2) + assert.containsN(form, '.o_field_widget.o_field_empty', 2); assert.containsN(form, '.o_form_label_empty', 2, "should have 1 muted label (for the empty fied) in readonly"); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.containsNone(form, '.o_field_empty', "in edit mode, only empty readonly fields should have the o_field_empty class"); assert.containsNone(form, '.o_form_label_empty', "in edit mode, only labels associated to empty readonly fields should have the o_form_label_empty class"); - testUtils.fields.editInput(form.$('input[name=foo]'), 'readonly'); - testUtils.fields.editInput(form.$('input[name=foo]'), 'edit'); - testUtils.fields.editInput(form.$('input[name=display_name]'), 'some name'); - testUtils.fields.editInput(form.$('input[name=foo]'), 'readonly'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'readonly'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'edit'); + await testUtils.fields.editInput(form.$('input[name=display_name]'), 'some name'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'readonly'); assert.containsNone(form, '.o_field_empty', "there still should not be any empty class on fields as the readonly one is now set"); @@ -872,11 +879,11 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('empty inner readonly fields don\'t have o_form_empty class in "create" mode', function (assert) { + QUnit.test('empty inner readonly fields don\'t have o_form_empty class in "create" mode', async function (assert) { assert.expect(2); this.data.partner.fields.product_id.readonly = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -897,10 +904,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('form view can switch to edit mode', function (assert) { + QUnit.test('form view can switch to edit mode', async function (assert) { assert.expect(9); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -915,7 +922,7 @@ QUnit.module('Views', { assert.isVisible(form.$buttons.find('.o_form_buttons_view')); assert.isNotVisible(form.$buttons.find('.o_form_buttons_edit')); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.mode, 'edit', 'form view should be in edit mode'); assert.hasClass(form.$('.o_form_view'), 'o_form_editable'); @@ -925,10 +932,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('required attrs on fields are re-evaluated on field change', function (assert) { + QUnit.test('required attrs on fields are re-evaluated on field change', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -942,25 +949,25 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.containsOnce(form, 'input[name="foo"].o_required_modifier', "the foo field widget should be required"); - testUtils.dom.click('.o_field_boolean input'); + await testUtils.dom.click('.o_field_boolean input'); assert.containsOnce(form, 'input[name="foo"]:not(.o_required_modifier)', "the foo field widget should now have been marked as non-required"); - testUtils.dom.click('.o_field_boolean input'); + await testUtils.dom.click('.o_field_boolean input'); assert.containsOnce(form, 'input[name="foo"].o_required_modifier', "the foo field widget should now have been marked as required again"); form.destroy(); }); - QUnit.test('required fields should have o_required_modifier in readonly mode', function (assert) { + QUnit.test('required fields should have o_required_modifier in readonly mode', async function (assert) { assert.expect(2); this.data.partner.fields.foo.required = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -976,17 +983,17 @@ QUnit.module('Views', { assert.containsOnce(form, 'span.o_required_modifier', form); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.containsOnce(form, 'input.o_required_modifier', "in edit mode, should have 1 input with o_required_modifier"); form.destroy(); }); - QUnit.test('required float fields works as expected', function (assert) { + QUnit.test('required float fields works as expected', async function (assert) { assert.expect(10); this.data.partner.fields.qux.required = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1007,29 +1014,29 @@ QUnit.module('Views', { assert.strictEqual(form.$('input[name="qux"]').val(), "0.0", "qux input is 0 by default (float field)"); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.containsNone(form.$('input[name="qux"]'), "should have switched to readonly"); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=qux]'), '1'); + await testUtils.fields.editInput(form.$('input[name=qux]'), '1'); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); - assert.strictEqual(form.$('input[name="qux"]').val(), "1.0", + assert.strictEqual(form.$('input[name="qux"]').val(), "1.0", "qux input is properly formatted"); assert.verifySteps(['default_get', 'create', 'read', 'write', 'read']); form.destroy(); }); - QUnit.test('separators', function (assert) { + QUnit.test('separators', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1048,10 +1055,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('invisible attrs on separators', function (assert) { + QUnit.test('invisible attrs on separators', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1071,12 +1078,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('buttons in form view', function (assert) { + QUnit.test('buttons in form view', async function (assert) { assert.expect(8); var rpcCount = 0; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1104,7 +1111,7 @@ QUnit.module('Views', { assert.containsOnce(form, 'button.p[name="post"]:contains(Confirm)'); assert.containsN(form, '.o_form_statusbar button:visible', 2); - testUtils.mock.intercept(form, 'execute_action', function (ev) { + await testUtils.mock.intercept(form, 'execute_action', function (ev) { assert.strictEqual(ev.data.action_data.name, 'post', "should trigger execute_action with correct method name"); assert.deepEqual(ev.data.env.currentID, 2, "should have correct id in ev data"); @@ -1112,14 +1119,14 @@ QUnit.module('Views', { ev.data.on_closed(); }); rpcCount = 0; - testUtils.dom.click('.o_form_statusbar button.p', form); + await testUtils.dom.click('.o_form_statusbar button.p', form); assert.strictEqual(rpcCount, 1, "should have done 1 rpcs to reload"); - testUtils.mock.intercept(form, 'execute_action', function (ev) { + await testUtils.mock.intercept(form, 'execute_action', function (ev) { ev.data.on_fail(); }); - testUtils.dom.click('.o_form_statusbar button.s', form); + await testUtils.dom.click('.o_form_statusbar button.s', form); assert.strictEqual(rpcCount, 1, "should have done 1 rpc, because we do not reload anymore if the server action fails"); @@ -1127,10 +1134,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('buttons classes in form view', function (assert) { + QUnit.test('buttons classes in form view', async function (assert) { assert.expect(16); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1180,13 +1187,13 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('buttons in form view, new record', function (assert) { + QUnit.test('buttons in form view, new record', async function (assert) { // this simulates a situation similar to the settings forms. assert.expect(7); var resID; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1213,20 +1220,20 @@ QUnit.module('Views', { }, }); - testUtils.mock.intercept(form, 'execute_action', function (event) { + await testUtils.mock.intercept(form, 'execute_action', function (event) { assert.step('execute_action'); assert.deepEqual(event.data.env.currentID, resID, "execute action should be done on correct record id"); event.data.on_success(); event.data.on_closed(); }); - testUtils.dom.click('.o_form_statusbar button.p', form); + await testUtils.dom.click('.o_form_statusbar button.p', form); assert.verifySteps(['default_get', 'create', 'read', 'execute_action', 'read']); form.destroy(); }); - QUnit.test('buttons in form view, new record, with field id in view', function (assert) { + QUnit.test('buttons in form view, new record, with field id in view', async function (assert) { assert.expect(7); // buttons in form view are one of the rare example of situation when we // save a record without reloading it immediately, because we only care @@ -1236,7 +1243,7 @@ QUnit.module('Views', { var resID; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1263,22 +1270,22 @@ QUnit.module('Views', { }, }); - testUtils.mock.intercept(form, 'execute_action', function (event) { + await testUtils.mock.intercept(form, 'execute_action', function (event) { assert.step('execute_action'); assert.deepEqual(event.data.env.currentID, resID, "execute action should be done on correct record id"); event.data.on_success(); event.data.on_closed(); }); - testUtils.dom.click('.o_form_statusbar button.p', form); + await testUtils.dom.click('.o_form_statusbar button.p', form); assert.verifySteps(['default_get', 'create', 'read', 'execute_action', 'read']); form.destroy(); }); - QUnit.test('change and save char', function (assert) { + QUnit.test('change and save char', async function (assert) { assert.expect(6); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1298,11 +1305,11 @@ QUnit.module('Views', { assert.containsOnce(form, 'span:contains(blip)', "should contain span with field value"); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.mode, 'edit', 'form view should be in edit mode'); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); - testUtils.form.clickSave(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.form.clickSave(form); assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); assert.containsOnce(form, 'span:contains(tralala)', @@ -1310,10 +1317,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('properly reload data from server', function (assert) { + QUnit.test('properly reload data from server', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1329,18 +1336,18 @@ QUnit.module('Views', { res_id: 2, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); - testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.form.clickSave(form); assert.containsOnce(form, 'span:contains(apple)', "should contain span with field value"); form.destroy(); }); - QUnit.test('disable buttons until reload data from server', function (assert) { + QUnit.test('disable buttons until reload data from server', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1353,22 +1360,23 @@ QUnit.module('Views', { } else if (args.method === 'read') { // Block the 'read' call var result = this._super.apply(this, arguments); - return $.when(def).then(_.constant(result)); + return Promise.resolve(def).then(result); } return this._super(route, args); }, res_id: 2, }); - var def = $.Deferred(); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); - testUtils.form.clickSave(form); + var def = testUtils.makeTestPromise(); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.form.clickSave(form); // Save button should be disabled assert.hasAttrValue(form.$buttons.find('.o_form_button_save'), 'disabled', 'disabled'); // Release the 'read' call - def.resolve(); + await def.resolve(); + await testUtils.nextTick(); // Edit button should be enabled after the reload assert.hasAttrValue(form.$buttons.find('.o_form_button_edit'), 'disabled', undefined); @@ -1376,7 +1384,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('properly apply onchange in simple case', function (assert) { + QUnit.test('properly apply onchange in simple case', async function (assert) { assert.expect(2); this.data.partner.onchanges = { @@ -1384,7 +1392,7 @@ QUnit.module('Views', { obj.int_field = obj.foo.length + 1000; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1394,19 +1402,19 @@ QUnit.module('Views', { res_id: 2, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name=int_field]').val(), "9", "should contain input with initial value"); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); assert.strictEqual(form.$('input[name=int_field]').val(), "1007", "should contain input with onchange applied"); form.destroy(); }); - QUnit.test('properly apply onchange when changed field is active field', function (assert) { + QUnit.test('properly apply onchange when changed field is active field', async function (assert) { assert.expect(3); this.data.partner.onchanges = { @@ -1414,7 +1422,7 @@ QUnit.module('Views', { obj.int_field = 14; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1429,27 +1437,27 @@ QUnit.module('Views', { assert.strictEqual(form.$('input[name=int_field]').val(), "9", "should contain input with initial value"); - testUtils.fields.editInput(form.$('input[name=int_field]'), '666'); + await testUtils.fields.editInput(form.$('input[name=int_field]'), '666'); assert.strictEqual(form.$('input[name=int_field]').val(), "14", "value should have been set to 14 by onchange"); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); - assert.strictEqual(form.$('.o_field_widget[name=int_field]').text(), "14", + assert.strictEqual(form.$('.o_field_widget[name=int_field]').text(), "14", "value should still be 14"); form.destroy(); }); - QUnit.test('onchange send only the present fields to the server', function (assert) { + QUnit.test('onchange send only the present fields to the server', async function (assert) { assert.expect(1); this.data.partner.records[0].product_id = false; this.data.partner.onchanges.foo = function (obj) { obj.foo = obj.foo + " alligator"; }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1477,17 +1485,17 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); form.destroy(); }); - QUnit.test('onchange only send present fields value', function (assert) { + QUnit.test('onchange only send present fields value', async function (assert) { assert.expect(1); this.data.partner.onchanges.foo = function (obj) {}; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1515,22 +1523,24 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); // add a o2m row - testUtils.dom.click('.o_field_x2many_list_row_add a'); + await testUtils.dom.click('.o_field_x2many_list_row_add a'); form.$('.o_field_one2many input:first').focus(); - testUtils.fields.editInput(form.$('.o_field_one2many input[name=display_name]'), 'valid line'); + await testUtils.nextTick(); + await testUtils.fields.editInput(form.$('.o_field_one2many input[name=display_name]'), 'valid line'); form.$('.o_field_one2many input:last').focus(); - testUtils.fields.editInput(form.$('.o_field_one2many input[name=qux]'), '12.4'); + await testUtils.nextTick(); + await testUtils.fields.editInput(form.$('.o_field_one2many input[name=qux]'), '12.4'); // trigger an onchange by modifying foo - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); form.destroy(); }); - QUnit.test('evaluate in python field options', function (assert) { + QUnit.test('evaluate in python field options', async function (assert) { assert.expect(1); var isOk = false; @@ -1541,7 +1551,7 @@ QUnit.module('Views', { } return tmp.apply(tmp, arguments); }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1557,10 +1567,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('can create a record with default values', function (assert) { + QUnit.test('can create a record with default values', async function (assert) { assert.expect(5); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1586,23 +1596,23 @@ QUnit.module('Views', { }); var n = this.data.partner.records.length; - testUtils.form.clickCreate(form); + await testUtils.form.clickCreate(form); assert.strictEqual(form.mode, 'edit', 'form view should be in edit mode'); - assert.strictEqual(form.$('input[name=foo]').val(), "My little Foo Value", + assert.strictEqual(form.$('input:first').val(), "My little Foo Value", "should have correct default_get value"); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); assert.strictEqual(this.data.partner.records.length, n + 1, "should have created a record"); form.destroy(); }); - QUnit.test('default record with a one2many and an onchange on sub field', function (assert) { + QUnit.test('default record with a one2many and an onchange on sub field', async function (assert) { assert.expect(4); this.data.partner.onchanges.foo = function () {}; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1628,10 +1638,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('sidebar is hidden when switching to edit mode', function (assert) { + QUnit.test('sidebar is hidden when switching to edit mode', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1645,21 +1655,21 @@ QUnit.module('Views', { }); assert.isVisible(form.sidebar); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.isNotVisible(form.sidebar); - testUtils.form.clickDiscard(form); + await testUtils.form.clickDiscard(form); assert.isVisible(form.sidebar); form.destroy(); }); - QUnit.test('basic default record', function (assert) { + QUnit.test('basic default record', async function (assert) { assert.expect(2); this.data.partner.fields.foo.default = "default foo value"; var count = 0; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1677,7 +1687,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('make default record with non empty one2many', function (assert) { + QUnit.test('make default record with non empty one2many', async function (assert) { assert.expect(4); this.data.partner.fields.p.default = [ @@ -1688,7 +1698,7 @@ QUnit.module('Views', { var nameGetCount = 0; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1717,7 +1727,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('make default record with non empty many2one', function (assert) { + QUnit.test('make default record with non empty many2one', async function (assert) { var done = assert.async(); assert.expect(2); @@ -1725,7 +1735,7 @@ QUnit.module('Views', { var nameGetCount = 0; - createAsyncView({ + createView({ View: FormView, model: 'partner', data: this.data, @@ -1749,10 +1759,10 @@ QUnit.module('Views', { }); }); - QUnit.test('form view properly change its title', function (assert) { + QUnit.test('form view properly change its title', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1765,17 +1775,17 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_control_panel .breadcrumb').text(), 'first record', "should have the display name of the record as title"); - testUtils.form.clickCreate(form); + await testUtils.form.clickCreate(form); assert.strictEqual(form.$('.o_control_panel .breadcrumb').text(), _t("New"), "should have the display name of the record as title"); form.destroy(); }); - QUnit.test('can duplicate a record', function (assert) { + QUnit.test('can duplicate a record', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1789,8 +1799,8 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_control_panel .breadcrumb').text(), 'first record', "should have the display name of the record as title"); - testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); - testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); + await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + await testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); assert.strictEqual(form.$('.o_control_panel .breadcrumb').text(), 'first record (copy)', "should have duplicated the record"); @@ -1799,10 +1809,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('duplicating a record preserve the context', function (assert) { + QUnit.test('duplicating a record preserve the context', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1822,16 +1832,16 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); - testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); + await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + await testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); form.destroy(); }); - QUnit.test('cannot duplicate a record', function (assert) { + QUnit.test('cannot duplicate a record', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1849,10 +1859,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('clicking on stat buttons in edit mode', function (assert) { + QUnit.test('clicking on stat buttons in edit mode', async function (assert) { assert.expect(9); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1878,30 +1888,30 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); var count = 0; - testUtils.mock.intercept(form, "execute_action", function (event) { + await testUtils.mock.intercept(form, "execute_action", function (event) { event.stopPropagation(); count++; }); - testUtils.dom.click('.oe_stat_button'); + await testUtils.dom.click('.oe_stat_button'); assert.strictEqual(count, 1, "should have triggered a execute action"); assert.strictEqual(form.mode, "edit", "form view should be in edit mode"); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); - testUtils.dom.click('.oe_stat_button:first'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.dom.click('.oe_stat_button:first'); - assert.strictEqual(form.mode, "edit", "form view should be in edit mode"); + assert.strictEqual(form.mode, "edit", "form view should be in edit mode"); assert.strictEqual(count, 2, "should have triggered a execute action"); assert.verifySteps(['read', 'write', 'read']); form.destroy(); }); - QUnit.test('clicking on stat buttons save and reload in edit mode', function (assert) { + QUnit.test('clicking on stat buttons save and reload in edit mode', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1930,23 +1940,23 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_control_panel .breadcrumb').text(), 'second record', "should have correct display_name"); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=name]'), 'some other name'); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=name]'), 'some other name'); - testUtils.dom.click('.oe_stat_button'); + await testUtils.dom.click('.oe_stat_button'); assert.strictEqual(form.$('.o_control_panel .breadcrumb').text(), 'GOLDORAK', "should have correct display_name"); form.destroy(); }); - QUnit.test('buttons with attr "special" do not trigger a save', function (assert) { + QUnit.test('buttons with attr "special" do not trigger a save', async function (assert) { assert.expect(4); var executeActionCount = 0; var writeCount = 0; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1961,34 +1971,35 @@ QUnit.module('Views', { writeCount++; } return this._super(route, args); - } + }, }); - testUtils.mock.intercept(form, "execute_action", function () { + await testUtils.mock.intercept(form, "execute_action", function () { executeActionCount++; }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); // make the record dirty - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); - testUtils.dom.click(form.$('button:contains(Do something)')); + await testUtils.dom.click(form.$('button:contains(Do something)')); + //TODO: VSC: add a next tick ? assert.strictEqual(writeCount, 1, "should have triggered a write"); assert.strictEqual(executeActionCount, 1, "should have triggered a execute action"); - testUtils.fields.editInput(form.$('input[name=foo]'), 'abcdef'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'abcdef'); - testUtils.dom.click(form.$('button:contains(Or discard)')); + await testUtils.dom.click(form.$('button:contains(Or discard)')); assert.strictEqual(writeCount, 1, "should not have triggered a write"); assert.strictEqual(executeActionCount, 2, "should have triggered a execute action"); form.destroy(); }); - QUnit.test('buttons with attr "special=save" save', function (assert) { + QUnit.test('buttons with attr "special=save" save', async function (assert) { assert.expect(5); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2011,18 +2022,18 @@ QUnit.module('Views', { }, }); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); - testUtils.dom.click(form.$('.o_form_view button')); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.dom.click(form.$('button[special="save"]')); assert.verifySteps(['read', 'write', 'read', 'execute_action']); form.destroy(); }); - QUnit.test('missing widgets do not crash', function (assert) { + QUnit.test('missing widgets do not crash', async function (assert) { assert.expect(1); this.data.partner.fields.foo.type = 'new field type without widget'; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2035,10 +2046,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('nolabel', function (assert) { + QUnit.test('nolabel', async function (assert) { assert.expect(6); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2073,13 +2084,13 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('many2one in a one2many', function (assert) { + QUnit.test('many2one in a one2many', async function (assert) { assert.expect(1); this.data.partner.records[0].p = [2]; this.data.partner.records[1].product_id = 37; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2096,13 +2107,13 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('circular many2many\'s', function (assert) { + QUnit.test('circular many2many\'s', async function (assert) { assert.expect(4); - this.data.partner_type.fields.partner_ids = {string: "partners", type: "many2many", relation: 'partner'} + this.data.partner_type.fields.partner_ids = {string: "partners", type: "many2many", relation: 'partner'}; this.data.partner.records[0].timmy = [12]; this.data.partner_type.records[0].partner_ids = [1]; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2128,24 +2139,24 @@ QUnit.module('Views', { assert.containsOnce(form, 'td:contains(gold)', "should display the name of the many2many on the original form"); - testUtils.dom.click(form.$('td:contains(gold)')); + await testUtils.dom.click(form.$('td:contains(gold)')); assert.containsOnce(document.body, '.modal'); assert.containsOnce($('.modal'), 'td:contains(first record)', "should display the name of the many2many on the modal form"); - testUtils.dom.click('.modal td:contains(first record)'); + await testUtils.dom.click('.modal td:contains(first record)'); assert.containsN(document.body, '.modal', 2, "there should be 2 modals (partner on top of partner_type) opened"); form.destroy(); }); - QUnit.test('discard changes on a non dirty form view', function (assert) { + QUnit.test('discard changes on a non dirty form view', async function (assert) { assert.expect(4); var nbWrite = 0; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2160,25 +2171,24 @@ QUnit.module('Views', { }); // switch to edit mode - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name=foo]').val(), 'yop', "input should contain yop"); // click on discard - testUtils.form.clickDiscard(form); - assert.containsNone(document.body, '.modal', "no confirm modal should be displayed"); - assert.strictEqual(form.$('.o_field_widget').text(), 'yop', - "field in readonly should display yop"); + await testUtils.form.clickDiscard(form); + assert.containsNone(document.body, '.modal', 'no confirm modal should be displayed'); + assert.strictEqual(form.$('.o_field_widget').text(), 'yop', 'field in readonly should display yop'); assert.strictEqual(nbWrite, 0, "no write RPC should have been done"); form.destroy(); }); - QUnit.test('discard changes on a dirty form view', function (assert) { + QUnit.test('discard changes on a dirty form view', async function (assert) { assert.expect(7); var nbWrite = 0; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2193,31 +2203,29 @@ QUnit.module('Views', { }); // switch to edit mode and edit the foo field - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name=foo]').val(), 'yop', "input should contain yop"); - testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); assert.strictEqual(form.$('input[name=foo]').val(), 'new value', "input should contain new value"); // click on discard and cancel the confirm request - testUtils.form.clickDiscard(form); + await testUtils.form.clickDiscard(form); assert.containsOnce(document.body, '.modal', "a confirm modal should be displayed"); - testUtils.dom.click('.modal-footer .btn-secondary'); - assert.strictEqual(form.$('input[name=foo]').val(), 'new value', - "input should still contain new value"); + await testUtils.dom.click('.modal-footer .btn-secondary'); + assert.strictEqual(form.$('input').val(), 'new value', 'input should still contain new value'); // click on discard and confirm - testUtils.form.clickDiscard(form); + await testUtils.form.clickDiscard(form); assert.containsOnce(document.body, '.modal', "a confirm modal should be displayed"); - testUtils.dom.click('.modal-footer .btn-primary'); - assert.strictEqual(form.$('.o_field_widget').text(), 'yop', - "field in readonly should display yop"); + await testUtils.dom.click('.modal-footer .btn-primary'); + assert.strictEqual(form.$('.o_field_widget').text(), 'yop', 'field in readonly should display yop'); assert.strictEqual(nbWrite, 0, "no write RPC should have been done"); form.destroy(); }); - QUnit.test('discard changes on a dirty form view (for date field)', function (assert) { + QUnit.test('discard changes on a dirty form view (for date field)', async function (assert) { assert.expect(1); // this test checks that the basic model properly handles date object @@ -2226,7 +2234,7 @@ QUnit.module('Views', { // then parsed into string, which is wrong. this.data.partner.fields.date.default = "2017-01-25"; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2243,18 +2251,18 @@ QUnit.module('Views', { // event to properly focusout the input, otherwise it crashes later on // when the 'blur' event is triggered by the re-rendering) form.$buttons.find('.o_form_button_cancel').focus(); - testUtils.dom.click('.o_form_button_cancel'); + await testUtils.dom.click('.o_form_button_cancel'); form.$buttons.find('.o_form_button_save').focus(); - testUtils.dom.click('.o_form_button_save'); + await testUtils.dom.click('.o_form_button_save'); assert.containsOnce(form, 'span:contains(2017)'); form.destroy(); }); - QUnit.test('discard changes on relational data on new record', function (assert) { + QUnit.test('discard changes on relational data on new record', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2278,28 +2286,28 @@ QUnit.module('Views', { }); // edit the p field - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - testUtils.fields.many2one.clickOpenDropdown('product_id'); - testUtils.fields.many2one.clickHighlightedItem('product_id'); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.fields.many2one.clickOpenDropdown('product_id'); + await testUtils.fields.many2one.clickHighlightedItem('product_id'); assert.strictEqual(form.$('.o_field_widget[name=product_id] input').val(), 'xphone', "input should contain xphone"); // click on discard and confirm - testUtils.form.clickDiscard(form); - testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm + await testUtils.form.clickDiscard(form); + await testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm assert.notOk(form.$el.prop('outerHTML').match('xphone'), "the string xphone should not be present after discarding"); form.destroy(); }); - QUnit.test('discard changes on a new (non dirty, except for defaults) form view', function (assert) { + QUnit.test('discard changes on a new (non dirty, except for defaults) form view', async function (assert) { assert.expect(3); this.data.partner.fields.foo.default = "ABC"; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2315,7 +2323,7 @@ QUnit.module('Views', { assert.strictEqual(form.$('input[name=foo]').val(), 'ABC', "input should contain ABC"); - testUtils.form.clickDiscard(form); + await testUtils.form.clickDiscard(form); assert.containsNone(document.body, '.modal', "there should not be a confirm modal"); @@ -2323,12 +2331,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('discard changes on a new (dirty) form view', function (assert) { + QUnit.test('discard changes on a new (dirty) form view', async function (assert) { assert.expect(8); this.data.partner.fields.foo.default = "ABC"; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2346,35 +2354,30 @@ QUnit.module('Views', { }); // edit the foo field - assert.strictEqual(form.$('input[name=foo]').val(), 'ABC', - "input should contain ABC"); - testUtils.fields.editInput(form.$('input[name=foo]'), 'DEF'); + assert.strictEqual(form.$('input').val(), 'ABC', 'input should contain ABC'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'DEF'); // discard the changes and check it has properly been discarded - testUtils.form.clickDiscard(form); - assert.containsOnce(document.body, '.modal', "there should be a confirm modal"); - assert.strictEqual(form.$('input[name=foo]').val(), 'DEF', - "input should be DEF"); - testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm - assert.strictEqual(form.$('input[name=foo]').val(), 'ABC', - "input should now be ABC"); + await testUtils.form.clickDiscard(form); + assert.containsOnce(document.body, '.modal', 'there should be a confirm modal'); + assert.strictEqual(form.$('input').val(), 'DEF', 'input should be DEF'); + await testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm + assert.strictEqual(form.$('input').val(), 'ABC', 'input should now be ABC'); // redirty and discard the field foo (to make sure initial changes haven't been lost) - testUtils.fields.editInput(form.$('input[name=foo]'), 'GHI'); - testUtils.form.clickDiscard(form); - assert.strictEqual(form.$('input[name=foo]').val(), 'GHI', - "input should be GHI"); - testUtils.dom.click('.modal-footer .btn-primary') // click on confirm - assert.strictEqual(form.$('input[name=foo]').val(), 'ABC', - "input should now be ABC"); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'GHI'); + await testUtils.form.clickDiscard(form); + assert.strictEqual(form.$('input').val(), 'GHI', 'input should be GHI'); + await testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm + assert.strictEqual(form.$('input').val(), 'ABC', 'input should now be ABC'); form.destroy(); }); - QUnit.test('discard changes on a duplicated record', function (assert) { + QUnit.test('discard changes on a duplicated record', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2382,28 +2385,27 @@ QUnit.module('Views', { res_id: 1, viewOptions: {hasSidebar: true}, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); - testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.form.clickSave(form); - testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); - testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); + await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + await testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); - assert.strictEqual(form.$('input[name=foo]').val(), 'tralala', - "input should contain ABC"); + assert.strictEqual(form.$('input[name=foo]').val(), 'tralala', 'input should contain ABC'); - testUtils.form.clickDiscard(form); + await testUtils.form.clickDiscard(form); assert.containsNone(document.body, '.modal', "there should not be a confirm modal"); form.destroy(); }); - QUnit.test('switching to another record from a dirty one', function (assert) { + QUnit.test("switching to another record from a dirty one", async function (assert) { assert.expect(11); var nbWrite = 0; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2425,26 +2427,25 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_pager_limit').text(), '2', "pager limit should be 2"); // switch to edit mode - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name=foo]').val(), 'yop', "input should contain yop"); // edit the foo field - testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); - assert.strictEqual(form.$('input[name=foo]').val(), 'new value', - "input should contain new value"); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); + assert.strictEqual(form.$('input').val(), 'new value', 'input should contain new value'); // click on the pager to switch to the next record and cancel the confirm request - testUtils.dom.click('.o_pager_next'); // click on next + await testUtils.dom.click('.o_pager_next'); // click on next assert.containsOnce(document.body, '.modal', "a confirm modal should be displayed"); - testUtils.dom.click('.modal-footer .btn-secondary'); // click on cancel + await testUtils.dom.click('.modal-footer .btn-secondary'); // click on cancel assert.strictEqual(form.$('input[name=foo]').val(), 'new value', "input should still contain new value"); assert.strictEqual(form.$('.o_pager_value').text(), '1', "pager value should still be 1"); // click on the pager to switch to the next record and confirm - testUtils.dom.click('.o_pager_next'); // click on next + await testUtils.dom.click('.o_pager_next'); // click on next assert.containsOnce(document.body, '.modal', "a confirm modal should be displayed"); - testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm + await testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm assert.strictEqual(form.$('input[name=foo]').val(), 'blip', "input should contain blip"); assert.strictEqual(form.$('.o_pager_value').text(), '2', "pager value should be 2"); @@ -2452,10 +2453,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('handling dirty state: switching to another record', function (assert) { + QUnit.test('handling dirty state: switching to another record', async function (assert) { assert.expect(12); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2472,18 +2473,18 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_pager_value').text(), '1', "pager value should be 1"); // switch to edit mode - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name=foo]').val(), 'yop', "input should contain yop"); // edit the foo field - testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); assert.strictEqual(form.$('input[name=foo]').val(), 'new value', "input should contain new value"); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); // click on the pager to switch to the next record and cancel the confirm request - testUtils.dom.click('.o_pager_next'); // click on next + await testUtils.dom.click('.o_pager_next'); // click on next assert.containsNone(document.body, '.modal:visible', "no confirm modal should be displayed"); assert.strictEqual(form.$('.o_pager_value').text(), '2', "pager value should be 2"); @@ -2492,35 +2493,35 @@ QUnit.module('Views', { 'priority widget should have been rendered with correct value'); // edit the value in readonly - testUtils.dom.click(form.$('.o_priority .fa-star-o:first')); // click on the first star + await testUtils.dom.click(form.$('.o_priority .fa-star-o:first')); // click on the first star assert.containsOnce(form, '.o_priority .fa-star', 'priority widget should have been updated'); - testUtils.dom.click('.o_pager_next'); // click on next + await testUtils.dom.click('.o_pager_next'); // click on next assert.containsNone(document.body, '.modal:visible', "no confirm modal should be displayed"); assert.strictEqual(form.$('.o_pager_value').text(), '1', "pager value should be 1"); // switch to edit mode - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name=foo]').val(), 'new value', "input should contain yop"); // edit the foo field - testUtils.fields.editInput(form.$('input[name=foo]'), 'wrong value'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'wrong value'); - testUtils.form.clickDiscard(form); + await testUtils.form.clickDiscard(form); assert.containsOnce(document.body, '.modal', "a confirm modal should be displayed"); - testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm - testUtils.dom.click('.o_pager_next'); // click on next + await testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm + await testUtils.dom.click('.o_pager_next'); // click on next assert.strictEqual(form.$('.o_pager_value').text(), '2', "pager value should be 2"); form.destroy(); }); - QUnit.test('restore local state when switching to another record', function (assert) { + QUnit.test('restore local state when switching to another record', async function (assert) { assert.expect(4); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2542,23 +2543,23 @@ QUnit.module('Views', { }); // click on second page tab - testUtils.dom.click(form.$('.o_notebook .nav-link:eq(1)')); + await testUtils.dom.click(form.$('.o_notebook .nav-link:eq(1)')); assert.doesNotHaveClass(form.$('.o_notebook .nav-link:eq(0)'), 'active'); assert.hasClass(form.$('.o_notebook .nav-link:eq(1)'), 'active'); // click on the pager to switch to the next record - testUtils.dom.click('.o_pager_next'); + await testUtils.dom.click('.o_pager_next'); assert.doesNotHaveClass(form.$('.o_notebook .nav-link:eq(0)'), 'active'); assert.hasClass(form.$('.o_notebook .nav-link:eq(1)'), 'active'); form.destroy(); }); - QUnit.test('pager is hidden in create mode', function (assert) { + QUnit.test('pager is hidden in create mode', async function (assert) { assert.expect(7); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2578,10 +2579,10 @@ QUnit.module('Views', { assert.strictEqual(form.pager.$('.o_pager_limit').text(), "2", "current pager limit should be 1"); - testUtils.form.clickCreate(form); + await testUtils.form.clickCreate(form); assert.isNotVisible(form.pager); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.isVisible(form.pager); assert.strictEqual(form.pager.$('.o_pager_value').text(), "3", "current pager value should be 3"); @@ -2591,12 +2592,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('switching to another record, in readonly mode', function (assert) { + QUnit.test('switching to another record, in readonly mode', async function (assert) { assert.expect(5); var pushStateCount = 0; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2615,7 +2616,7 @@ QUnit.module('Views', { assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1'); - testUtils.dom.click(form.pager.$('.o_pager_next')); + await testUtils.dom.click(form.pager.$('.o_pager_next')); assert.strictEqual(form.pager.$('.o_pager_value').text(), "2", 'pager value should be 2'); assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); @@ -2624,10 +2625,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('modifiers are reevaluated when creating new record', function (assert) { + QUnit.test('modifiers are reevaluated when creating new record', async function (assert) { assert.expect(4); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2643,7 +2644,7 @@ QUnit.module('Views', { assert.containsOnce(form, 'span.foo_field'); assert.isNotVisible(form.$('span.foo_field')); - testUtils.form.clickCreate(form); + await testUtils.form.clickCreate(form); assert.containsOnce(form, 'input.foo_field'); assert.isVisible(form.$('input.foo_field')); @@ -2651,14 +2652,14 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('empty readonly fields are visible on new records', function (assert) { + QUnit.test('empty readonly fields are visible on new records', async function (assert) { assert.expect(2); this.data.partner.fields.foo.readonly = true; this.data.partner.fields.foo.default = undefined; this.data.partner.records[0].foo = undefined; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2672,16 +2673,16 @@ QUnit.module('Views', { assert.containsOnce(form, '.o_field_empty'); - testUtils.form.clickCreate(form); + await testUtils.form.clickCreate(form); assert.containsNone(form, '.o_field_empty'); form.destroy(); }); - QUnit.test('all group children have correct layout classname', function (assert) { + QUnit.test('all group children have correct layout classname', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2703,10 +2704,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('deleting a record', function (assert) { + QUnit.test('deleting a record', async function (assert) { assert.expect(8); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2726,13 +2727,13 @@ QUnit.module('Views', { assert.ok(!$('.modal:visible').length, 'no confirm modal should be displayed'); // open sidebar and delete - testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); - testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); + await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + await testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); assert.ok($('.modal').length, 'a confirm modal should be displayed'); // confirm the delete - testUtils.dom.click($('.modal-footer button.btn-primary')); + await testUtils.dom.click($('.modal-footer button.btn-primary')); assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1'); assert.strictEqual(form.pager.$('.o_pager_limit').text(), "2", 'pager limit should be 2'); @@ -2741,10 +2742,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('deleting the last record', function (assert) { + QUnit.test('deleting the last record', async function (assert) { assert.expect(6); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2762,27 +2763,27 @@ QUnit.module('Views', { }); // open sidebar, click on delete and confirm - testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); - testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); + await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + await testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); - testUtils.mock.intercept(form, 'history_back', function () { + await testUtils.mock.intercept(form, 'history_back', function () { assert.step('history_back'); }); assert.strictEqual($('.modal').length, 1, 'a confirm modal should be displayed'); - testUtils.dom.click($('.modal-footer button.btn-primary')); + await testUtils.dom.click($('.modal-footer button.btn-primary')); assert.strictEqual($('.modal').length, 0, 'no confirm modal should be displayed'); assert.verifySteps(['read', 'unlink', 'history_back']); form.destroy(); }); - QUnit.test('empty required fields cannot be saved', function (assert) { + QUnit.test('empty required fields cannot be saved', async function (assert) { assert.expect(5); this.data.partner.fields.foo.required = true; delete this.data.partner.fields.foo.default; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2804,22 +2805,22 @@ QUnit.module('Views', { }, }); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.hasClass(form.$('label.o_form_label'),'o_field_invalid'); assert.hasClass(form.$('input[name=foo]'),'o_field_invalid'); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); assert.containsNone(form, '.o_field_invalid'); form.destroy(); }); - QUnit.test('changes in a readonly form view are saved directly', function (assert) { + QUnit.test('changes in a readonly form view are saved directly', async function (assert) { assert.expect(10); var nbWrite = 0; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2844,36 +2845,36 @@ QUnit.module('Views', { 'priority widget should have been rendered with correct value'); // edit the value in readonly - testUtils.dom.click(form.$('.o_priority .fa-star-o:first')); + await testUtils.dom.click(form.$('.o_priority .fa-star-o:first')); assert.strictEqual(nbWrite, 1, 'should have saved directly'); assert.containsOnce(form, '.o_priority .fa-star', 'priority widget should have been updated'); // switch to edit mode and edit the value again - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.containsN(form, '.o_priority .o_priority_star', 2, 'priority widget should have been correctly rendered'); assert.containsOnce(form, '.o_priority .fa-star', 'priority widget should have correct value'); - testUtils.dom.click(form.$('.o_priority .fa-star-o:first')); + await testUtils.dom.click(form.$('.o_priority .fa-star-o:first')); assert.strictEqual(nbWrite, 1, 'should not have saved directly'); assert.containsN(form, '.o_priority .fa-star', 2, 'priority widget should have been updated'); // save - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.strictEqual(nbWrite, 2, 'should not have saved directly'); assert.containsN(form, '.o_priority .fa-star', 2, 'priority widget should have correct value'); form.destroy(); }); - QUnit.test('display a dialog if onchange result is a warning', function (assert) { + QUnit.test('display a dialog if onchange result is a warning', async function (assert) { assert.expect(5); this.data.partner.onchanges = { foo: true }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2883,7 +2884,7 @@ QUnit.module('Views', { res_id: 2, mockRPC: function (route, args) { if (args.method === 'onchange') { - return $.when({ + return Promise.resolve({ value: { int_field: 10 }, warning: { title: "Warning", @@ -2905,23 +2906,23 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name=int_field]').val(), '9'); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); assert.strictEqual(form.$('input[name=int_field]').val(), '10'); form.destroy(); }); - QUnit.test('can create record even if onchange returns a warning', function (assert) { + QUnit.test('can create record even if onchange returns a warning', async function (assert) { assert.expect(2); this.data.partner.onchanges = { foo: true }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2930,7 +2931,7 @@ QUnit.module('Views', { '</form>', mockRPC: function (route, args) { if (args.method === 'onchange') { - return $.when({ + return Promise.resolve({ value: { int_field: 10 }, warning: { title: "Warning", @@ -2942,7 +2943,7 @@ QUnit.module('Views', { }, intercepts: { warning: function (event) { - assert.step('warning'); + assert.ok(true, 'should trigger a warning'); }, }, }); @@ -2952,12 +2953,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('do nothing if add a line in one2many result in a onchange with a warning', function (assert) { - assert.expect(2); + QUnit.test('do nothing if add a line in one2many result in a onchange with a warning', async function (assert) { + assert.expect(3); this.data.partner.onchanges = { foo: true }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -2971,7 +2972,7 @@ QUnit.module('Views', { res_id: 2, mockRPC: function (route, args) { if (args.method === 'onchange') { - return $.when({ + return Promise.resolve({ value: {}, warning: { title: "Warning", @@ -2989,19 +2990,20 @@ QUnit.module('Views', { }); // go to edit mode, click to add a record in the o2m - testUtils.form.clickEdit(form); - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.form.clickEdit(form); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.containsNone(form, 'tr.o_data_row', "should not have added a line"); + assert.verifySteps(["should have triggered a warning"]); form.destroy(); }); - QUnit.test('default_get, onchange which fails, should still work', function (assert) { + QUnit.test('default_get, onchange which fails, should still work', async function (assert) { assert.expect(1); this.data.partner.onchanges.foo = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3013,8 +3015,8 @@ QUnit.module('Views', { // we simulate a validation error. In the 'real' web client, // the server error will be used by the session to display // an error dialog. From the point of view of the basic - // model, the deferred is just rejected. - return $.Deferred().reject(); + // model, the promise is just rejected. + return Promise.reject(); } return this._super.apply(this, arguments); }, @@ -3034,7 +3036,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('attrs are properly transmitted to new records', function (assert) { + QUnit.test('attrs are properly transmitted to new records', async function (assert) { assert.expect(2); // this test checks that the fieldsInfo have been transmitted to the @@ -3046,7 +3048,7 @@ QUnit.module('Views', { string_false: "Test Environment", hover_false: "Switch to production environment" }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3062,7 +3064,7 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_stat_text.o_not_hover:contains(Production Environment)').length, 1, "button should contain correct string"); - testUtils.form.clickCreate(form); + await testUtils.form.clickCreate(form); assert.strictEqual(form.$('.o_stat_text.o_not_hover:contains(Test Environment)').length, 1, "button should contain correct string"); @@ -3070,10 +3072,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('button box is rendered in create mode', function (assert) { + QUnit.test('button box is rendered in create mode', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3092,21 +3094,21 @@ QUnit.module('Views', { "button box should be displayed in readonly"); // edit mode - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.containsOnce(form, '.oe_stat_button', "button box should be displayed in edit on an existing record"); // create mode (leave edition first!) - testUtils.form.clickDiscard(form); - testUtils.form.clickCreate(form); + await testUtils.form.clickDiscard(form); + await testUtils.form.clickCreate(form); assert.containsOnce(form, '.oe_stat_button', "button box should be displayed when creating a new record as well"); form.destroy(); }); - QUnit.test('properly apply onchange on one2many fields', function (assert) { + QUnit.test('properly apply onchange on one2many fields', async function (assert) { assert.expect(5); this.data.partner.records[0].p = [4]; @@ -3119,7 +3121,7 @@ QUnit.module('Views', { ]; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3140,8 +3142,8 @@ QUnit.module('Views', { "the 'display_name' of the one2many record should be correct"); // switch to edit mode - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'let us trigger an onchange'); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'let us trigger an onchange'); var $o2m = form.$('.o_field_one2many'); assert.strictEqual($o2m.find('.o_data_row').length, 2, "there should be two linked record"); @@ -3153,7 +3155,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('update many2many value in one2many after onchange', function (assert) { + QUnit.test('update many2many value in one2many after onchange', async function (assert) { assert.expect(2); this.data.partner.records[1].p = [4]; @@ -3168,7 +3170,7 @@ QUnit.module('Views', { ]; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3185,21 +3187,21 @@ QUnit.module('Views', { }); assert.strictEqual($('div[name="p"] .o_data_row td').text().trim(), "aaaNo records", "should have proper initial content"); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); assert.strictEqual($('div[name="p"] .o_data_row td').text().trim(), "goldNo records", "should have proper initial content"); form.destroy(); }); - QUnit.test('delete a line in a one2many while editing another line triggers a warning', function (assert) { + QUnit.test('delete a line in a one2many while editing another line triggers a warning', async function (assert) { assert.expect(3); this.data.partner.records[0].p = [1, 2]; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3213,15 +3215,15 @@ QUnit.module('Views', { res_id: 1, }); - testUtils.form.clickEdit(form); - testUtils.dom.click(form.$('.o_data_cell').first()); - testUtils.fields.editInput(form.$('input[name=display_name]'), ''); - testUtils.dom.click(form.$('.fa-trash-o').eq(1)); + await testUtils.form.clickEdit(form); + await testUtils.dom.click(form.$('.o_data_cell').first()); + await testUtils.fields.editInput(form.$('input[name=display_name]'), ''); + await testUtils.dom.click(form.$('.fa-trash-o').eq(1)); assert.strictEqual($('.modal').find('.modal-title').first().text(), "Warning", "Clicking out of a dirty line while editing should trigger a warning modal."); - testUtils.dom.click($('.modal').find('.btn-primary')); + await testUtils.dom.click($('.modal').find('.btn-primary')); assert.strictEqual(form.$('.o_data_cell').first().text(), "first record", "Value should have been reset to what it was before editing began."); @@ -3230,7 +3232,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('properly apply onchange on many2many fields', function (assert) { + QUnit.test('properly apply onchange on many2many fields', async function (assert) { assert.expect(14); this.data.partner.onchanges = { @@ -3242,7 +3244,7 @@ QUnit.module('Views', { ]; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3274,8 +3276,8 @@ QUnit.module('Views', { "there should be no many2many record linked at first"); // switch to edit mode - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'let us trigger an onchange'); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'let us trigger an onchange'); var $m2m = form.$('.o_field_many2many'); assert.strictEqual($m2m.find('.o_data_row').length, 2, "there should be two linked records"); @@ -3284,14 +3286,14 @@ QUnit.module('Views', { assert.strictEqual($m2m.find('.o_data_row:nth(1) td:first').text(), 'silver', "the 'display_name' of the second m2m record should be correctly displayed"); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.verifySteps(['read', 'onchange', 'read', 'write', 'read', 'read']); form.destroy(); }); - QUnit.test('display_name not sent for onchanges if not in view', function (assert) { + QUnit.test('display_name not sent for onchanges if not in view', async function (assert) { assert.expect(7); this.data.partner.records[0].timmy = [12]; @@ -3302,7 +3304,7 @@ QUnit.module('Views', { name: function () {}, }; var readInModal = false; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3367,17 +3369,17 @@ QUnit.module('Views', { }); // trigger the onchange - testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), "coucou"); + await testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), "coucou"); // open a subrecord and trigger an onchange readInModal = true; - testUtils.dom.click(form.$('.o_data_row .o_data_cell:first')); - testUtils.fields.editInput($('.modal .o_field_widget[name=name]'), "new name"); + await testUtils.dom.click(form.$('.o_data_row .o_data_cell:first')); + await testUtils.fields.editInput($('.modal .o_field_widget[name=name]'), "new name"); form.destroy(); }); - QUnit.test('onchanges on date(time) fields', function (assert) { + QUnit.test('onchanges on date(time) fields', async function (assert) { assert.expect(6); this.data.partner.onchanges = { @@ -3386,7 +3388,7 @@ QUnit.module('Views', { obj.datetime = '2021-12-12 10:55:05'; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3410,7 +3412,7 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_field_widget[name=datetime]').text(), '12/12/2016 12:55:05', "the initial datetime should be correct"); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget[name=date] input').val(), '01/25/2017', "the initial date should be correct in edit"); @@ -3418,7 +3420,7 @@ QUnit.module('Views', { '12/12/2016 12:55:05', "the initial datetime should be correct in edit"); // trigger the onchange - testUtils.fields.editInput(form.$('.o_field_widget[name="foo"]'), "coucou"); + await testUtils.fields.editInput(form.$('.o_field_widget[name="foo"]'), "coucou"); assert.strictEqual(form.$('.o_field_widget[name=date] input').val(), '12/12/2021', "the initial date should be correct in edit"); @@ -3428,7 +3430,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('onchanges are not sent for each keystrokes', function (assert) { + QUnit.test('onchanges are not sent for each keystrokes', async function (assert) { var done = assert.async(); assert.expect(5); @@ -3439,8 +3441,8 @@ QUnit.module('Views', { obj.int_field = obj.foo.length + 1000; }, }; - var def = $.Deferred(); - var form = createView({ + var def = testUtils.makeTestPromise(); + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3462,19 +3464,18 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); testUtils.fields.editInput(form.$('input[name=foo]'), '1'); assert.strictEqual(onchangeNbr, 0, "no onchange has been called yet"); testUtils.fields.editInput(form.$('input[name=foo]'), '12'); assert.strictEqual(onchangeNbr, 0, "no onchange has been called yet"); - return waitForFinishedOnChange().then(function () { + return waitForFinishedOnChange().then(async function () { assert.strictEqual(onchangeNbr, 1, "one onchange has been called"); // add something in the input, then focus another input - testUtils.fields.editInput(form.$('input[name=foo]'), '123'); - form.$('input[name=foo]').change(); + await testUtils.fields.editAndTrigger(form.$('input[name=foo]'), '123', ['change']); assert.strictEqual(onchangeNbr, 2, "one onchange has been called immediately"); return waitForFinishedOnChange(); @@ -3487,13 +3488,13 @@ QUnit.module('Views', { function waitForFinishedOnChange() { return def.then(function () { - def = $.Deferred(); + def = testUtils.makeTestPromise(); return concurrency.delay(0); }); } }); - QUnit.test('onchanges are not sent for invalid values', function (assert) { + QUnit.test('onchanges are not sent for invalid values', async function (assert) { assert.expect(6); this.data.partner.onchanges = { @@ -3501,7 +3502,7 @@ QUnit.module('Views', { obj.foo = String(obj.int_field); }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3515,21 +3516,21 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); // edit int_field, and check that an onchange has been applied - testUtils.fields.editInput(form.$('input[name="int_field"]'), "123"); + await testUtils.fields.editInput(form.$('input[name="int_field"]'), "123"); assert.strictEqual(form.$('input[name="foo"]').val(), "123", "the onchange has been applied"); // enter an invalid value in a float, and check that no onchange has // been applied - testUtils.fields.editInput(form.$('input[name="int_field"]'), "123a"); + await testUtils.fields.editInput(form.$('input[name="int_field"]'), "123a"); assert.strictEqual(form.$('input[name="foo"]').val(), "123", "the onchange has not been applied"); // save, and check that the int_field input is marked as invalid - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.hasClass(form.$('input[name="int_field"]'),'o_field_invalid', "input int_field is marked as invalid"); @@ -3537,10 +3538,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('rpc complete after destroying parent', function (assert) { + QUnit.test('rpc complete after destroying parent', async function (assert) { // We just test that there is no crash in this situation assert.expect(0); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3555,20 +3556,20 @@ QUnit.module('Views', { } } }); - testUtils.dom.click(form.$('.o_form_button_update')); + await testUtils.dom.click(form.$('.o_form_button_update')); }); - QUnit.test('onchanges that complete after discarding', function (assert) { - assert.expect(4); + QUnit.test('onchanges that complete after discarding', async function (assert) { + assert.expect(5); - var def1 = $.Deferred(); + var def1 = testUtils.makeTestPromise(); this.data.partner.onchanges = { foo: function (obj) { obj.int_field = obj.foo.length + 1000; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3591,31 +3592,33 @@ QUnit.module('Views', { // go into edit mode assert.strictEqual(form.$('span[name="foo"]').text(), "blip", "field foo should be displayed to initial value"); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); // edit a value - testUtils.fields.editInput(form.$('input[name=foo]'), '1234'); + await testUtils.fields.editInput(form.$('input[name=foo]'), '1234'); // discard changes - testUtils.form.clickDiscard(form); - testUtils.dom.click($('.modal-footer .btn-primary')); + await testUtils.form.clickDiscard(form); + await testUtils.dom.click($('.modal-footer .btn-primary')); assert.strictEqual(form.$('span[name="foo"]').text(), "blip", "field foo should still be displayed to initial value"); // complete the onchange def1.resolve(); + await testUtils.nextTick(); assert.strictEqual(form.$('span[name="foo"]').text(), "blip", "field foo should still be displayed to initial value"); + assert.verifySteps(['onchange is done']); form.destroy(); }); - QUnit.test('discarding before save returns', function (assert) { + QUnit.test('discarding before save returns', async function (assert) { assert.expect(4); - var def = $.Deferred(); + var def = testUtils.makeTestPromise(); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3635,10 +3638,10 @@ QUnit.module('Views', { }, }); - testUtils.fields.editInput(form.$('input[name=foo]'), '1234'); + await testUtils.fields.editInput(form.$('input[name=foo]'), '1234'); // save the value and discard directly - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); form.discardChanges(); // Simulate click on breadcrumb assert.strictEqual(form.$('.o_field_widget[name="foo"]').val(), "1234", @@ -3648,7 +3651,7 @@ QUnit.module('Views', { // complete the write def.resolve(); - + await testUtils.nextTick(); assert.strictEqual($('.modal').length, 0, "Confirm dialog should not be displayed"); assert.strictEqual(form.$('.o_field_widget[name="foo"]').text(), "1234", @@ -3657,7 +3660,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('unchanged relational data is sent for onchanges', function (assert) { + QUnit.test('unchanged relational data is sent for onchanges', async function (assert) { assert.expect(1); this.data.partner.records[1].p = [4]; @@ -3666,7 +3669,7 @@ QUnit.module('Views', { obj.int_field = obj.foo.length + 1000; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3692,13 +3695,13 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'trigger an onchange'); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'trigger an onchange'); form.destroy(); }); - QUnit.test('onchanges on unknown fields of o2m are ignored', function (assert) { + QUnit.test('onchanges on unknown fields of o2m are ignored', async function (assert) { // many2one fields need to be postprocessed (the onchange returns [id, // display_name]), but if we don't know the field, we can't know it's a // many2one, so it isn't ignored, its value is an array instead of a @@ -3709,7 +3712,7 @@ QUnit.module('Views', { this.data.partner.onchanges = { foo: function () {}, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3732,7 +3735,7 @@ QUnit.module('Views', { res_id: 2, mockRPC: function (route, args) { if (args.method === 'onchange') { - return $.when({ + return Promise.resolve({ value: { p: [ [5], @@ -3753,25 +3756,25 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'trigger an onchange'); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'trigger an onchange'); assert.strictEqual(form.$('.o_data_row td:first').text(), 'foo changed', "onchange should have been correctly applied on field in o2m list"); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); form.destroy(); }); - QUnit.test('onchange value are not discarded on o2m edition', function (assert) { + QUnit.test('onchange value are not discarded on o2m edition', async function (assert) { assert.expect(4); this.data.partner.records[1].p = [4]; this.data.partner.onchanges = { foo: function () {}, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3794,7 +3797,7 @@ QUnit.module('Views', { res_id: 2, mockRPC: function (route, args) { if (args.method === 'onchange') { - return $.when({ + return Promise.resolve({ value: { p: [[5], [1, 4, {foo: 'foo changed'}]], }, @@ -3809,17 +3812,17 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_data_row td:first').text(), 'My little Foo Value', "the initial value should be the default one"); - testUtils.fields.editInput(form.$('input[name=foo]'), 'trigger an onchange'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'trigger an onchange'); assert.strictEqual(form.$('.o_data_row td:first').text(), 'foo changed', "onchange should have been correctly applied on field in o2m list"); - testUtils.dom.click(form.$('.o_data_row')); + await testUtils.dom.click(form.$('.o_data_row')); assert.strictEqual($('.modal .modal-title').text().trim(), 'Open: one2many field', "the field string is displayed in the modal title"); assert.strictEqual($('.modal .o_field_widget').val(), 'foo changed', @@ -3828,7 +3831,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('args of onchanges in o2m fields are correct (inline edition)', function (assert) { + QUnit.test('args of onchanges in o2m fields are correct (inline edition)', async function (assert) { assert.expect(3); this.data.partner.records[1].p = [4]; @@ -3839,7 +3842,7 @@ QUnit.module('Views', { obj.foo = '[' + obj.rel_field.foo + '] ' + obj.int_field; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3857,26 +3860,26 @@ QUnit.module('Views', { res_id: 2, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_data_row td:first').text(), 'My little Foo Value', "the initial value should be the default one"); - testUtils.dom.click(form.$('.o_data_row td:nth(1)')); - testUtils.fields.editInput(form.$('.o_data_row input:nth(1)'), 77); + await testUtils.dom.click(form.$('.o_data_row td:nth(1)')); + await testUtils.fields.editInput(form.$('.o_data_row input:nth(1)'), 77); assert.strictEqual(form.$('.o_data_row input:first').val(), '[blip] 77', "onchange should have been correctly applied"); // create a new o2m record - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('.o_data_row input:first').val(), '[blip] 14', "onchange should have been correctly applied after default get"); form.destroy(); }); - QUnit.test('args of onchanges in o2m fields are correct (dialog edition)', function (assert) { + QUnit.test('args of onchanges in o2m fields are correct (dialog edition)', async function (assert) { assert.expect(6); this.data.partner.records[1].p = [4]; @@ -3887,7 +3890,7 @@ QUnit.module('Views', { obj.foo = '[' + obj.rel_field.foo + '] ' + obj.int_field; }, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3908,39 +3911,41 @@ QUnit.module('Views', { res_id: 2, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_data_row td:first').text(), 'My little Foo Value', "the initial value should be the default one"); - testUtils.dom.click(form.$('.o_data_row td:first')); - testUtils.fields.editInput($('.modal input:nth(1)'), 77); + await testUtils.dom.click(form.$('.o_data_row td:first')); + await testUtils.nextTick(); + await testUtils.fields.editInput($('.modal input:nth(1)'), 77); assert.strictEqual($('.modal input:first').val(), '[blip] 77', "onchange should have been correctly applied"); - testUtils.dom.click($('.modal-footer .btn-primary')); + await testUtils.dom.click($('.modal-footer .btn-primary')); assert.strictEqual(form.$('.o_data_row td:first').text(), '[blip] 77', "onchange should have been correctly applied"); // create a new o2m record - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .modal-title').text().trim(), 'Create custom label', "the custom field label is applied in the modal title"); assert.strictEqual($('.modal input:first').val(), '[blip] 14', "onchange should have been correctly applied after default get"); - testUtils.dom.clickFirst($('.modal-footer .btn-primary')); + await testUtils.dom.clickFirst($('.modal-footer .btn-primary')); + await testUtils.nextTick(); assert.strictEqual(form.$('.o_data_row:nth(1) td:first').text(), '[blip] 14', "onchange should have been correctly applied after default get"); form.destroy(); }); - QUnit.test('context of onchanges contains the context of changed fields', function (assert) { + QUnit.test('context of onchanges contains the context of changed fields', async function (assert) { assert.expect(2); this.data.partner.onchanges = { foo: function () {}, }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3962,16 +3967,16 @@ QUnit.module('Views', { res_id: 2, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name=foo]'), 'coucou'); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'coucou'); form.destroy(); }); - QUnit.test('navigation with tab key in form view', function (assert) { + QUnit.test('navigation with tab key in form view', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -3988,7 +3993,7 @@ QUnit.module('Views', { }); // go to edit mode - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); // focus first input, trigger tab form.$('input[name="foo"]').focus(); @@ -4010,12 +4015,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('navigation with tab key in readonly form view', function (assert) { + QUnit.test('navigation with tab key in readonly form view', async function (assert) { assert.expect(3); this.data.partner.records[1].product_id = 37; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4055,12 +4060,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('skip invisible fields when navigating with TAB', function (assert) { + QUnit.test('skip invisible fields when navigating with TAB', async function (assert) { assert.expect(1); this.data.partner.records[0].bar = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4075,7 +4080,7 @@ QUnit.module('Views', { res_id: 1, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); form.$('input[name="foo"]').focus(); form.$('input[name="foo"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); assert.strictEqual(form.$('input[name="int_field"]')[0], document.activeElement, @@ -4084,10 +4089,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('clicking on a stat button with a context', function (assert) { + QUnit.test('clicking on a stat button with a context', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4114,15 +4119,15 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.$('.oe_stat_button')); + await testUtils.dom.click(form.$('.oe_stat_button')); form.destroy(); }); - QUnit.test('clicking on a stat button with no context', function (assert) { + QUnit.test('clicking on a stat button with no context', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4148,15 +4153,15 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.$('.oe_stat_button')); + await testUtils.dom.click(form.$('.oe_stat_button')); form.destroy(); }); - QUnit.test('diplay a stat button outside a buttonbox', function (assert) { + QUnit.test('diplay a stat button outside a buttonbox', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4180,10 +4185,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('diplay something else than a button in a buttonbox', function (assert) { + QUnit.test('diplay something else than a button in a buttonbox', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4208,10 +4213,41 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('display correctly buttonbox, in large size class', function (assert) { + QUnit.test('invisible fields are not considered as visible in a buttonbox', async function (assert) { + assert.expect(2); + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form>' + + '<div name="button_box" class="oe_button_box">' + + '<field name="foo" invisible="1"/>' + + '<field name="bar" invisible="1"/>' + + '<field name="int_field" invisible="1"/>' + + '<field name="qux" invisible="1"/>' + + '<field name="display_name" invisible="1"/>' + + '<field name="state" invisible="1"/>' + + '<field name="date" invisible="1"/>' + + '<field name="datetime" invisible="1"/>' + + '<button type="object" class="oe_stat_button" icon="fa-check-square"/>' + + '</div>' + + '</form>', + res_id: 2, + }); + + assert.strictEqual(form.$('.oe_button_box').children().length, 9, + "button box should contain nine children"); + assert.hasClass(form.$('.oe_button_box'), 'o_not_full', + "the buttonbox should not be full (only 1 visible child)"); + + form.destroy(); + }); + + QUnit.test('display correctly buttonbox, in large size class', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4237,12 +4273,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('one2many default value creation', function (assert) { + QUnit.test('one2many default value creation', async function (assert) { assert.expect(1); this.data.partner.records[0].product_ids = [37]; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4259,7 +4295,7 @@ QUnit.module('Views', { '</form>', mockRPC: function (route, args) { if (args.method === 'default_get') { - return $.when({ + return Promise.resolve({ product_ids: [[0, 0, { name: 'xdroid', partner_type_id: 12, @@ -4274,14 +4310,14 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, }); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); form.destroy(); }); - QUnit.test('many2manys inside one2manys are saved correctly', function (assert) { + QUnit.test('many2manys inside one2manys are saved correctly', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4306,19 +4342,19 @@ QUnit.module('Views', { }); // add a o2m subrecord with a m2m tag - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - testUtils.fields.many2one.clickOpenDropdown('timmy'); - testUtils.fields.many2one.clickHighlightedItem('timmy'); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.fields.many2one.clickOpenDropdown('timmy'); + await testUtils.fields.many2one.clickHighlightedItem('timmy'); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); form.destroy(); }); - QUnit.test('one2manys (list editable) inside one2manys are saved correctly', function (assert) { + QUnit.test('one2manys (list editable) inside one2manys are saved correctly', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4353,10 +4389,10 @@ QUnit.module('Views', { }); // add a o2m subrecord - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - testUtils.dom.click($('.modal-body .o_field_one2many .o_field_x2many_list_row_add a')); - testUtils.fields.editInput($('.modal-body input'), 'xtv'); - testUtils.dom.click($('.modal-footer button:first')); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.dom.click($('.modal-body .o_field_one2many .o_field_x2many_list_row_add a')); + await testUtils.fields.editInput($('.modal-body input'), 'xtv'); + await testUtils.dom.click($('.modal-footer button:first')); assert.strictEqual($('.modal').length, 0, "dialog should be closed"); @@ -4364,16 +4400,16 @@ QUnit.module('Views', { assert.strictEqual(row.children()[0].textContent, '1 record', "the cell should contains the number of record: 1"); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); form.destroy(); }); - QUnit.test('*_view_ref in context are passed correctly', function (assert) { + QUnit.test('*_view_ref in context are passed correctly', async function (assert) { var done = assert.async(); assert.expect(3); - createAsyncView({ + createView({ View: FormView, model: 'partner', data: this.data, @@ -4401,15 +4437,15 @@ QUnit.module('Views', { } return this._super.apply(this, arguments); }, - }).then(function (form) { + }).then(async function (form) { // reload to check that the record's context hasn't been modified - form.reload(); + await form.reload(); form.destroy(); done(); }); }); - QUnit.test('readonly fields with modifiers may be saved', function (assert) { + QUnit.test('readonly fields with modifiers may be saved', async function (assert) { // the readonly property on the field description only applies on view, // this is not a DB constraint. It should be seen as a default value, // that may be overriden in views, for example with modifiers. So @@ -4417,7 +4453,7 @@ QUnit.module('Views', { assert.expect(3); this.data.partner.fields.foo.readonly = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4439,13 +4475,13 @@ QUnit.module('Views', { // bar being set to true, foo shouldn't be readonly and thus its value // could be saved, even if in its field description it is readonly - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.containsOnce(form, 'input[name="foo"]', "foo field should be editable"); - testUtils.fields.editInput(form.$('input[name="foo"]'), 'New foo value'); + await testUtils.fields.editInput(form.$('input[name="foo"]'), 'New foo value'); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget[name=foo]').text(), 'New foo value', "new value for foo field should have been saved"); @@ -4453,10 +4489,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('check if id and active_id are defined', function (assert) { + QUnit.test('check if id and active_id are defined', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4474,8 +4510,8 @@ QUnit.module('Views', { }, mockRPC: function (route, args) { if (args.method === 'default_get' && args.args[0][0] === 'trululu') { - assert.strictEqual(args.kwargs.context.current_id, false, - "current_id should be false"); + assert.strictEqual(args.kwargs.context.current_id, false, + "current_id should be false"); assert.strictEqual(args.kwargs.context.default_trululu, false, "default_trululu should be false"); } @@ -4483,14 +4519,14 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.destroy(); }); - QUnit.test('modifiers are considered on multiple <footer/> tags', function (assert) { + QUnit.test('modifiers are considered on multiple <footer/> tags', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4515,7 +4551,7 @@ QUnit.module('Views', { assert.deepEqual(getVisibleButtonTexts(), ["Hello", "World"], "only the first button section should be visible"); - testUtils.dom.click(form.$(".o_field_boolean input")); + await testUtils.dom.click(form.$(".o_field_boolean input")); assert.deepEqual(getVisibleButtonTexts(), ["Foo"], "only the second button section should be visible"); @@ -4530,10 +4566,10 @@ QUnit.module('Views', { } }); - QUnit.test('buttons in footer are moved to $buttons if necessary', function (assert) { + QUnit.test('buttons in footer are moved to $buttons if necessary', async function (assert) { assert.expect(4); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4551,7 +4587,7 @@ QUnit.module('Views', { assert.containsNone(form.$('.o_form_view'), 'button.infooter'); // check that this still works after a reload - testUtils.form.reload(form); + await testUtils.form.reload(form); assert.containsOnce(form.$('.o_control_panel'), 'button.infooter'); assert.containsNone(form.$('.o_form_view'), 'button.infooter'); @@ -4559,10 +4595,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('render stat button with string inline', function (assert) { + QUnit.test('render stat button with string inline', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', res_id: 1, @@ -4581,11 +4617,11 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('renderer waits for asynchronous fields rendering', function (assert) { + QUnit.test('renderer waits for asynchronous fields rendering', async function (assert) { assert.expect(1); var done = assert.async(); - testUtils.createAsyncView({ + testUtils.createView({ View: FormView, model: 'partner', data: this.data, @@ -4603,7 +4639,7 @@ QUnit.module('Views', { }); }); - QUnit.test('open one2many form containing one2many', function (assert) { + QUnit.test('open one2many form containing one2many', async function (assert) { assert.expect(9); this.data.partner.records[0].product_ids = [37]; @@ -4612,7 +4648,7 @@ QUnit.module('Views', { }; this.data.product.records[0].partner_type_ids = [12]; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', res_id: 1, @@ -4652,7 +4688,7 @@ QUnit.module('Views', { var row = form.$('.o_field_one2many .o_list_view .o_data_row'); assert.strictEqual(row.children()[1].textContent, '1 record', "the cell should contains the number of record: 1"); - testUtils.dom.click(row); + await testUtils.dom.click(row); var modal_row = $('.modal-body .o_form_sheet .o_field_one2many .o_list_view .o_data_row'); assert.strictEqual(modal_row.children().length, 2, "the row should contains the 2 fields defined in the form view"); @@ -4663,10 +4699,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('in edit mode, first field is focused', function (assert) { + QUnit.test('in edit mode, first field is focused', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4676,7 +4712,7 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(document.activeElement, form.$('input[name="foo"]')[0], "foo field should have focus"); @@ -4686,10 +4722,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('autofocus fields are focused', function (assert) { + QUnit.test('autofocus fields are focused', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4699,17 +4735,17 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(document.activeElement, form.$('input[name="foo"]')[0], "foo field should have focus"); form.destroy(); }); - QUnit.test('in create mode, autofocus fields are focused', function (assert) { + QUnit.test('in create mode, autofocus fields are focused', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4724,9 +4760,9 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('create with false values', function (assert) { + QUnit.test('create with false values', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4742,15 +4778,15 @@ QUnit.module('Views', { }, }); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); form.destroy(); }); - QUnit.test('autofocus first visible field', function (assert) { + QUnit.test('autofocus first visible field', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4765,10 +4801,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('no autofocus with disable_autofocus option [REQUIRE FOCUS]', function (assert) { + QUnit.test('no autofocus with disable_autofocus option [REQUIRE FOCUS]', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4783,7 +4819,7 @@ QUnit.module('Views', { assert.notStrictEqual(document.activeElement, form.$('input[name="int_field"]')[0], "int_field field should not have focus"); - form.update({}); + await form.update({}); assert.notStrictEqual(document.activeElement, form.$('input[name="int_field"]')[0], "int_field field should not have focus"); @@ -4791,7 +4827,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('open one2many form containing many2many_tags', function (assert) { + QUnit.test('open one2many form containing many2many_tags', async function (assert) { assert.expect(4); this.data.partner.records[0].product_ids = [37]; @@ -4800,7 +4836,7 @@ QUnit.module('Views', { }; this.data.product.records[0].partner_type_ids = [12, 14]; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', res_id: 1, @@ -4833,21 +4869,21 @@ QUnit.module('Views', { }, }); var row = form.$('.o_field_one2many .o_list_view .o_data_row'); - testUtils.dom.click(row); + await testUtils.dom.click(row); assert.verifySteps(['read', 'read', 'read'], "there should be 3 read rpcs"); form.destroy(); }); - QUnit.test('onchanges are applied before checking if it can be saved', function (assert) { + QUnit.test('onchanges are applied before checking if it can be saved', async function (assert) { assert.expect(4); this.data.partner.onchanges.foo = function (obj) {}; this.data.partner.fields.foo.required = true; - var def = $.Deferred(); + var def = testUtils.makeTestPromise(); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4876,20 +4912,21 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name="foo"]'), ''); - testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name="foo"]'), ''); + await testUtils.form.clickSave(form); def.resolve(); + await testUtils.nextTick(); assert.verifySteps(['read', 'onchange', 'warning']); form.destroy(); }); - QUnit.test('display toolbar', function (assert) { + QUnit.test('display toolbar', async function (assert) { assert.expect(8); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -4915,7 +4952,7 @@ QUnit.module('Views', { "the active_id shoud be 1."); assert.deepEqual(args.context.active_ids, [1], "the active_ids should be an array with 1 inside."); - return $.when({}); + return Promise.resolve({}); } return this._super.apply(this, arguments); }, @@ -4932,19 +4969,19 @@ QUnit.module('Views', { var $customAction = $actionMenu.find('.dropdown-item:last'); assert.strictEqual($customAction.text().trim(), 'Action partner', "the custom action should have 'Action partner' as name"); - testUtils.mock.intercept(form, 'do_action', function (event) { + await testUtils.mock.intercept(form, 'do_action', function (event) { var context = event.data.action.context.__contexts[1]; assert.strictEqual(context.active_id, 1, "the active_id shoud be 1."); assert.deepEqual(context.active_ids, [1], "the active_ids should be an array with 1 inside."); }); - testUtils.dom.click($customAction); + await testUtils.dom.click($customAction); form.destroy(); }); - QUnit.test('check interactions between multiple FormViewDialogs', function (assert) { + QUnit.test('check interactions between multiple FormViewDialogs', async function (assert) { assert.expect(8); this.data.product.fields.product_ids = { @@ -4953,7 +4990,7 @@ QUnit.module('Views', { this.data.partner.records[0].product_id = 37; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', res_id: 1, @@ -4979,7 +5016,7 @@ QUnit.module('Views', { }, mockRPC: function (route, args) { if (route === '/web/dataset/call_kw/product/get_formview_id') { - return $.when(false); + return Promise.resolve(false); } else if (args.method === 'write') { assert.strictEqual(args.model, 'product', "should write on product model"); @@ -4990,9 +5027,9 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); // Open first dialog - testUtils.dom.click(form.$('.o_external_button')); + await testUtils.dom.click(form.$('.o_external_button')); assert.strictEqual($('.modal').length, 1, "One FormViewDialog should be opened"); var $firstModal = $('.modal'); @@ -5002,27 +5039,27 @@ QUnit.module('Views', { "display_name should be correctly displayed"); // Open second dialog - testUtils.dom.click($firstModal.find('.o_field_x2many_list_row_add a')); + await testUtils.dom.click($firstModal.find('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal').length, 2, "two FormViewDialogs should be opened"); var $secondModal = $('.modal:nth(1)'); // Add new value - testUtils.fields.editInput($secondModal.find('input'), 'xtv'); - testUtils.dom.click($secondModal.find('.modal-footer button:first')); + await testUtils.fields.editInput($secondModal.find('input'), 'xtv'); + await testUtils.dom.click($secondModal.find('.modal-footer button:first')); assert.strictEqual($('.modal').length, 1, "last opened dialog should be closed"); // Check that data in first dialog is correctly updated assert.strictEqual($firstModal.find('tr.o_data_row td').text(), 'xtv', "should have added a line with xtv as new record"); - testUtils.dom.click($firstModal.find('.modal-footer button:first')); + await testUtils.dom.click($firstModal.find('.modal-footer button:first')); form.destroy(); }); - QUnit.test('fields and record contexts are not mixed', function (assert) { + QUnit.test('fields and record contexts are not mixed', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5047,15 +5084,15 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.$('.o_field_widget[name=trululu] input')); + await testUtils.dom.click(form.$('.o_field_widget[name=trululu] input')); form.destroy(); }); - QUnit.test('do not activate an hidden tab when switching between records', function (assert) { + QUnit.test('do not activate an hidden tab when switching between records', async function (assert) { assert.expect(6); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5084,14 +5121,14 @@ QUnit.module('Views', { "first tab should be active"); // click on the pager to switch to the next record - testUtils.dom.click(form.pager.$('.o_pager_next')); + await testUtils.dom.click(form.pager.$('.o_pager_next')); assert.strictEqual(form.$('.o_notebook .nav-item:not(.o_invisible_modifier)').length, 1, "only the second tab should be visible"); assert.hasClass(form.$('.o_notebook .nav-item:not(.o_invisible_modifier) .nav-link'),'active', "the visible tab should be active"); // click on the pager to switch back to the previous record - testUtils.dom.click(form.pager.$('.o_pager_previous')); + await testUtils.dom.click(form.pager.$('.o_pager_previous')); assert.strictEqual(form.$('.o_notebook .nav-item:not(.o_invisible_modifier)').length, 2, "both tabs should be visible again"); assert.hasClass(form.$('.o_notebook .nav-link:nth(1)'),'active', @@ -5100,16 +5137,16 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('support anchor tags with action type', function (assert) { + QUnit.test('support anchor tags with action type', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, arch: '<form string="Partners">' + '<a type="action" name="42"><i class="fa fa-arrow-right"/> Click me !</a>' + - '</form>', + '</form>', res_id: 1, intercepts: { do_action: function (event) { @@ -5118,17 +5155,17 @@ QUnit.module('Views', { } } }); - testUtils.dom.click(form.$('a[type="action"]')); + await testUtils.dom.click(form.$('a[type="action"]')); form.destroy(); }); - QUnit.test('do not perform extra RPC to read invisible many2one fields', function (assert) { + QUnit.test('do not perform extra RPC to read invisible many2one fields', async function (assert) { assert.expect(2); this.data.partner.fields.trululu.default = 2; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5148,14 +5185,14 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('do not perform extra RPC to read invisible x2many fields', function (assert) { + QUnit.test('do not perform extra RPC to read invisible x2many fields', async function (assert) { assert.expect(2); this.data.partner.records[0].p = [2]; // one2many this.data.partner.records[0].product_ids = [37]; // one2many this.data.partner.records[0].timmy = [12]; // many2many - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5180,13 +5217,13 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('default_order on x2many embedded view', function (assert) { + QUnit.test('default_order on x2many embedded view', async function (assert) { assert.expect(11); this.data.partner.fields.display_name.sortable = true; this.data.partner.records[0].p = [1, 4]; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5215,14 +5252,14 @@ QUnit.module('Views', { assert.ok(form.$('.o_field_one2many tbody tr:first td:contains(yop)').length, "record 1 should be first"); - testUtils.form.clickEdit(form); - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.form.clickEdit(form); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal').length, 1, "FormViewDialog should be opened"); - testUtils.fields.editInput($('.modal input[name="foo"]'), 'xop') - testUtils.dom.click($('.modal-footer button:eq(1)')); - testUtils.fields.editInput($('.modal input[name="foo"]'), 'zop') - testUtils.dom.click($('.modal-footer button:first')); + await testUtils.fields.editInput($('.modal input[name="foo"]'), 'xop'); + await testUtils.dom.click($('.modal-footer button:eq(1)')); + await testUtils.fields.editInput($('.modal input[name="foo"]'), 'zop'); + await testUtils.dom.click($('.modal-footer button:first')); // client-side sort assert.ok(form.$('.o_field_one2many tbody tr:eq(0) td:contains(zop)').length, @@ -5233,7 +5270,7 @@ QUnit.module('Views', { "record xop should be third"); // server-side sort - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.ok(form.$('.o_field_one2many tbody tr:eq(0) td:contains(zop)').length, "record zop should be first"); assert.ok(form.$('.o_field_one2many tbody tr:eq(1) td:contains(yop)').length, @@ -5242,10 +5279,10 @@ QUnit.module('Views', { "record xop should be third"); // client-side sort on edit - testUtils.form.clickEdit(form); - testUtils.dom.click(form.$('.o_field_one2many tbody tr:eq(1) td:contains(yop)')); - testUtils.fields.editInput($('.modal input[name="foo"]'), 'zzz'); - testUtils.dom.click($('.modal-footer button:first')); + await testUtils.form.clickEdit(form); + await testUtils.dom.click(form.$('.o_field_one2many tbody tr:eq(1) td:contains(yop)')); + await testUtils.fields.editInput($('.modal input[name="foo"]'), 'zzz'); + await testUtils.dom.click($('.modal-footer button:first')); assert.ok(form.$('.o_field_one2many tbody tr:eq(0) td:contains(zzz)').length, "record zzz should be first"); assert.ok(form.$('.o_field_one2many tbody tr:eq(1) td:contains(zop)').length, @@ -5256,10 +5293,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('action context is used when evaluating domains', function (assert) { + QUnit.test('action context is used when evaluating domains', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5280,16 +5317,16 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, }); - testUtils.form.clickEdit(form); - testUtils.dom.click(form.$('div[name="trululu"] input')); + await testUtils.form.clickEdit(form); + await testUtils.dom.click(form.$('div[name="trululu"] input')); form.destroy(); }); - QUnit.test('form rendering with groups with col/colspan', function (assert) { + QUnit.test('form rendering with groups with col/colspan', async function (assert) { assert.expect(46); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5411,10 +5448,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('outer and inner groups string attribute', function (assert) { + QUnit.test('outer and inner groups string attribute', async function (assert) { assert.expect(5); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5451,10 +5488,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('form group with newline tag inside', function (assert) { + QUnit.test('form group with newline tag inside', async function (assert) { assert.expect(6); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5508,11 +5545,11 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('custom open record dialog title', function (assert) { + QUnit.test('custom open record dialog title', async function (assert) { assert.expect(1); this.data.partner.records[0].p = [2]; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5530,14 +5567,14 @@ QUnit.module('Views', { res_id: 1, }); - testUtils.dom.click(form.$('.o_data_row:first')); + await testUtils.dom.click(form.$('.o_data_row:first')); assert.strictEqual($('.modal .modal-title').first().text().trim(), 'Open: custom label', "modal should use the python field string as title"); form.destroy(); }); - QUnit.test('display translation alert', function (assert) { + QUnit.test('display translation alert', async function (assert) { assert.expect(2); this.data.partner.fields.foo.translate = true; @@ -5546,7 +5583,7 @@ QUnit.module('Views', { var multi_lang = _t.database.multi_lang; _t.database.multi_lang = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5561,15 +5598,15 @@ QUnit.module('Views', { res_id: 1, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name="foo"]'), "test"); - testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name="foo"]'), "test"); + await testUtils.form.clickSave(form); assert.containsOnce(form, '.o_form_view > .alert > div .oe_field_translate', "should have single translation alert"); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name="display_name"]'), "test2"); - testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name="display_name"]'), "test2"); + await testUtils.form.clickSave(form); assert.containsN(form, '.o_form_view > .alert > div .oe_field_translate', 2, "should have two translate fields in translation alert"); @@ -5578,7 +5615,7 @@ QUnit.module('Views', { _t.database.multi_lang = multi_lang; }); - QUnit.test('translation alerts are preserved on pager change', function (assert) { + QUnit.test('translation alerts are preserved on pager change', async function (assert) { assert.expect(5); this.data.partner.fields.foo.translate = true; @@ -5586,7 +5623,7 @@ QUnit.module('Views', { var multi_lang = _t.database.multi_lang; _t.database.multi_lang = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5602,27 +5639,27 @@ QUnit.module('Views', { res_id: 1, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name="foo"]'), "test"); - testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name="foo"]'), "test"); + await testUtils.form.clickSave(form); assert.containsOnce(form, '.o_form_view > .alert > div',"should have a translation alert"); // click on the pager to switch to the next record - form.pager.$('.o_pager_next').click(); + await testUtils.dom.click(form.pager.$('.o_pager_next')); assert.strictEqual(form.$('.o_form_view > .alert > div').length, 0, "should not have a translation alert"); // click on the pager to switch back to the previous record - form.pager.$('.o_pager_previous').click(); + await testUtils.dom.click(form.pager.$('.o_pager_previous')); assert.containsOnce(form, '.o_form_view > .alert > div',"should have a translation alert"); // remove translation alert by click X and check alert even after form reload - form.$('.o_form_view > .alert > .close').click(); + await testUtils.dom.click(form.$('.o_form_view > .alert > .close')); assert.strictEqual(form.$('.o_form_view > .alert > div').length, 0, "should not have a translation alert"); - form.reload(); + await form.reload(); assert.strictEqual(form.$('.o_form_view > .alert > div').length, 0, "should not have a translation alert after reload"); @@ -5630,7 +5667,7 @@ QUnit.module('Views', { _t.database.multi_lang = multi_lang; }); - QUnit.test('translation alerts preseved on reverse breadcrumb', function (assert) { + QUnit.test('translation alerts preseved on reverse breadcrumb', async function (assert) { assert.expect(2); this.data['ir.translation'] = { @@ -5678,23 +5715,21 @@ QUnit.module('Views', { flags: {'search_view': true, 'action_buttons': true}, }]; - var actionManager = createActionManager({ + var actionManager = await createActionManager({ actions: actions, archs: archs, data: this.data, }); - actionManager.doAction(1); - - actionManager.$('.o_form_button_edit').click(); + await actionManager.doAction(1); actionManager.$('input[name="foo"]').val("test").trigger("input"); - actionManager.$('.o_form_button_save').click(); + await testUtils.dom.click(actionManager.$('.o_form_button_save')); assert.strictEqual(actionManager.$('.o_form_view > .alert > div').length, 1, "should have a translation alert"); var currentController = actionManager.getCurrentController().widget; - actionManager.doAction(2, { + await actionManager.doAction(2, { on_reverse_breadcrumb: function () { if (!_.isEmpty(currentController.renderer.alertFields)) { currentController.renderer.displayTranslationAlert(); @@ -5703,7 +5738,7 @@ QUnit.module('Views', { }, }); - $('.o_control_panel .breadcrumb a:first').click(); + await testUtils.dom.click($('.o_control_panel .breadcrumb a:first')); assert.strictEqual(actionManager.$('.o_form_view > .alert > div').length, 1, "should have a translation alert"); @@ -5711,7 +5746,7 @@ QUnit.module('Views', { _t.database.multi_lang = multi_lang; }); - QUnit.test('translate event correctly handled with multiple controllers', function (assert) { + QUnit.test('translate event correctly handled with multiple controllers', async function (assert) { assert.expect(3); this.data.product.fields.name.translate = true; @@ -5721,7 +5756,7 @@ QUnit.module('Views', { var multi_lang = _t.database.multi_lang; _t.database.multi_lang = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5745,23 +5780,23 @@ QUnit.module('Views', { res_id: 1, mockRPC: function (route, args) { if (route === '/web/dataset/call_kw/product/get_formview_id') { - return $.when(false); + return Promise.resolve(false); } else if (route === "/web/dataset/call_button" && args.method === 'translate_fields') { assert.deepEqual(args.args, ["product",37,"name",{}], 'should call "call_button" route'); nbTranslateCalls++; - return $.when(); + return Promise.resolve(); } return this._super.apply(this, arguments); }, }); - testUtils.form.clickEdit(form); - testUtils.dom.click(form.$('[name="product_id"] .o_external_button')); + await testUtils.form.clickEdit(form); + await testUtils.dom.click(form.$('[name="product_id"] .o_external_button')); assert.strictEqual($('.modal-body .o_field_translate').length, 1, "there should be a translate button in the modal"); - testUtils.dom.click($('.modal-body .o_field_translate')); + await testUtils.dom.click($('.modal-body .o_field_translate')); assert.strictEqual(nbTranslateCalls, 1, "should call_button translate once"); @@ -5769,12 +5804,12 @@ QUnit.module('Views', { _t.database.multi_lang = multi_lang; }); - QUnit.test('buttons are disabled until status bar action is resolved', function (assert) { + QUnit.test('buttons are disabled until status bar action is resolved', async function (assert) { assert.expect(9); - var def = $.Deferred(); + var def = testUtils.makeTestPromise(); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5811,9 +5846,9 @@ QUnit.module('Views', { assert.strictEqual(form.$('.oe_button_box button:not(:disabled)').length, 1, "stat buttons should be enabled"); - testUtils.dom.clickFirst(form.$('.o_form_statusbar button')); + await testUtils.dom.clickFirst(form.$('.o_form_statusbar button')); - // The unresolved deferred lets us check the state of the buttons + // The unresolved promise lets us check the state of the buttons assert.strictEqual(form.$buttons.find('button:disabled').length, 4, "control panel buttons should be disabled"); assert.containsN(form, '.o_form_statusbar button:disabled', 2, @@ -5822,7 +5857,7 @@ QUnit.module('Views', { "stat buttons should be disabled"); def.resolve(); - + await testUtils.nextTick(); assert.strictEqual(form.$buttons.find('button:not(:disabled)').length, 4, "control panel buttons should be enabled"); assert.strictEqual(form.$('.o_form_statusbar button:not(:disabled)').length, 2, @@ -5833,12 +5868,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('buttons are disabled until button box action is resolved', function (assert) { + QUnit.test('buttons are disabled until button box action is resolved', async function (assert) { assert.expect(9); - var def = $.Deferred(); + var def = testUtils.makeTestPromise(); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5875,9 +5910,9 @@ QUnit.module('Views', { assert.strictEqual(form.$('.oe_button_box button:not(:disabled)').length, 1, "stat buttons should be enabled"); - testUtils.dom.click(form.$('.oe_button_box button')); + await testUtils.dom.click(form.$('.oe_button_box button')); - // The unresolved deferred lets us check the state of the buttons + // The unresolved promise lets us check the state of the buttons assert.strictEqual(form.$buttons.find('button:disabled').length, 4, "control panel buttons should be disabled"); assert.containsN(form, '.o_form_statusbar button:disabled', 2, @@ -5886,7 +5921,7 @@ QUnit.module('Views', { "stat buttons should be disabled"); def.resolve(); - + await testUtils.nextTick(); assert.strictEqual(form.$buttons.find('button:not(:disabled)').length, 4, "control panel buttons should be enabled"); assert.strictEqual(form.$('.o_form_statusbar button:not(:disabled)').length, 2, @@ -5897,10 +5932,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('buttons with "confirm" attribute save before calling the method', function (assert) { + QUnit.test('buttons with "confirm" attribute save before calling the method', async function (assert) { assert.expect(9); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5920,36 +5955,36 @@ QUnit.module('Views', { intercepts: { execute_action: function (event) { assert.step('execute_action'); + event.data.on_success(); }, }, }); // click on button, and cancel in confirm dialog - testUtils.dom.click(form.$('.o_statusbar_buttons button')); + await testUtils.dom.click(form.$('.o_statusbar_buttons button')); assert.ok(form.$('.o_statusbar_buttons button').prop('disabled'), 'button should be disabled'); - testUtils.dom.click($('.modal-footer button.btn-secondary')); + await testUtils.dom.click($('.modal-footer button.btn-secondary')); assert.ok(!form.$('.o_statusbar_buttons button').prop('disabled'), 'button should no longer be disabled'); assert.verifySteps(['default_get']); // click on button, and click on ok in confirm dialog - testUtils.dom.click(form.$('.o_statusbar_buttons button')); - assert.verifySteps(['default_get']); - testUtils.dom.click($('.modal-footer button.btn-primary')); - - assert.verifySteps(['default_get', 'create', 'read', 'execute_action']); + await testUtils.dom.click(form.$('.o_statusbar_buttons button')); + assert.verifySteps([]); + await testUtils.dom.click($('.modal-footer button.btn-primary')); + assert.verifySteps(['create', 'read', 'execute_action']); form.destroy(); }); - QUnit.test('buttons are disabled until action is resolved (in dialogs)', function (assert) { + QUnit.test('buttons are disabled until action is resolved (in dialogs)', async function (assert) { assert.expect(3); - var def = $.Deferred(); + var def = testUtils.makeTestPromise(); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -5982,7 +6017,7 @@ QUnit.module('Views', { }, mockRPC: function (route, args) { if (args.method === 'get_formview_id') { - return $.when(false); + return Promise.resolve(false); } return this._super.apply(this, arguments); }, @@ -5991,30 +6026,30 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.$('.o_external_button')); + await testUtils.dom.click(form.$('.o_external_button')); assert.notOk($('.modal .oe_button_box button').attr('disabled'), "stat buttons should be enabled"); - testUtils.dom.click($('.modal .oe_button_box button')); + await testUtils.dom.click($('.modal .oe_button_box button')); assert.ok($('.modal .oe_button_box button').attr('disabled'), "stat buttons should be disabled"); def.resolve(); - + await testUtils.nextTick(); assert.notOk($('.modal .oe_button_box button').attr('disabled'), "stat buttons should be enabled"); form.destroy(); }); - QUnit.test('multiple clicks on save should reload only once', function (assert) { + QUnit.test('multiple clicks on save should reload only once', async function (assert) { assert.expect(4); - var def = $.Deferred(); + var def = testUtils.makeTestPromise(); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6039,13 +6074,13 @@ QUnit.module('Views', { }, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name="foo"]'), "test"); - testUtils.form.clickSave(form); - testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name="foo"]'), "test"); + await testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); def.resolve(); - + await testUtils.nextTick(); assert.verifySteps([ 'read', // initial read to render the view 'write', // write on save @@ -6055,10 +6090,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('form view is not broken if save operation fails', function (assert) { + QUnit.test('form view is not broken if save operation fails', async function (assert) { assert.expect(5); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6073,19 +6108,19 @@ QUnit.module('Views', { mockRPC: function (route, args) { assert.step(args.method); if (args.method === 'write' && args.args[1].foo === 'incorrect value') { - return $.Deferred().reject(); + return Promise.reject(); } return this._super.apply(this, arguments); }, }); - testUtils.form.clickEdit(form); - testUtils.fields.editInput(form.$('input[name="foo"]'), "incorrect value"); - testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); + await testUtils.fields.editInput(form.$('input[name="foo"]'), "incorrect value"); + await testUtils.form.clickSave(form); - testUtils.fields.editInput(form.$('input[name="foo"]'), "correct value"); + await testUtils.fields.editInput(form.$('input[name="foo"]'), "correct value"); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.verifySteps([ 'read', // initial read to render the view @@ -6097,10 +6132,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('support password attribute', function (assert) { + QUnit.test('support password attribute', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6112,7 +6147,7 @@ QUnit.module('Views', { assert.strictEqual(form.$('span[name="foo"]').text(), '***', "password should be displayed with stars"); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name="foo"]').val(), 'yop', "input value should be the password"); assert.strictEqual(form.$('input[name="foo"]').prop('type'), 'password', @@ -6120,10 +6155,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('support autocomplete attribute', function (assert) { + QUnit.test('support autocomplete attribute', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6133,16 +6168,16 @@ QUnit.module('Views', { res_id: 1, }); - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); assert.hasAttrValue(form.$('input[name="display_name"]'), 'autocomplete', 'coucou', "attribute autocomplete should be set"); form.destroy(); }); - QUnit.test('context is correctly passed after save & new in FormViewDialog', function (assert) { + QUnit.test('context is correctly passed after save & new in FormViewDialog', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', res_id: 4, @@ -6174,27 +6209,30 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, }); - - testUtils.form.clickEdit(form); - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.form.clickEdit(form); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.nextTick(); assert.strictEqual($('.modal').length, 1, "One FormViewDialog should be opened"); // set a value on the m2o - testUtils.fields.many2one.clickOpenDropdown('partner_type_id'); - testUtils.fields.many2one.clickHighlightedItem('partner_type_id'); + await testUtils.fields.many2one.clickOpenDropdown('partner_type_id'); + await testUtils.fields.many2one.clickHighlightedItem('partner_type_id'); - testUtils.dom.click($('.modal-footer button:eq(1)')); - testUtils.dom.click($('.modal .o_field_many2one input')); - testUtils.dom.click($('.modal-footer button:first')); + await testUtils.dom.click($('.modal-footer button:eq(1)')); + await testUtils.nextTick(); + await testUtils.dom.click($('.modal .o_field_many2one input')); + await testUtils.fields.many2one.clickHighlightedItem('partner_type_id'); + await testUtils.dom.click($('.modal-footer button:first')); + await testUtils.nextTick(); form.destroy(); }); - QUnit.test('render domain field widget without model', function (assert) { + QUnit.test('render domain field widget without model', async function (assert) { assert.expect(3); this.data.partner.fields.model_name = { string: "Model name", type: "char" }; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6209,11 +6247,11 @@ QUnit.module('Views', { assert.strictEqual(args.model, 'test', "should search_count on test"); if (!args.kwargs.domain) { - return $.Deferred().reject({ + return Promise.reject({message:{ code: 200, data: {}, message: "MockServer._getRecords: given domain has to be an array.", - }, $.Event()); + }, event: $.Event()}); } } return this._super.apply(this, arguments); @@ -6222,13 +6260,13 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_field_widget[name="display_name"]').text(), "Select a model to add a filter.", "should contain an error message saying the model is missing"); - testUtils.fields.editInput(form.$('input[name="model_name"]'), "test"); + await testUtils.fields.editInput(form.$('input[name="model_name"]'), "test"); assert.notStrictEqual(form.$('.o_field_widget[name="display_name"]').text(), "Select a model to add a filter.", "should not contain an error message anymore"); form.destroy(); }); - QUnit.test('readonly fields are not sent when saving', function (assert) { + QUnit.test('readonly fields are not sent when saving', async function (assert) { assert.expect(6); // define an onchange on display_name to check that the value of readonly @@ -6239,7 +6277,7 @@ QUnit.module('Views', { }; var checkOnchange = false; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6274,31 +6312,33 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.nextTick(); assert.strictEqual($('.modal input.o_field_widget[name=foo]').length, 1, - 'foo should be editable'); + 'foo should be editable'); checkOnchange = true; - testUtils.fields.editInput($('.modal .o_field_widget[name=foo]'), 'foo value'); - testUtils.fields.editInput($('.modal .o_field_widget[name=display_name]'), 'readonly'); + await testUtils.fields.editInput($('.modal .o_field_widget[name=foo]'), 'foo value'); + await testUtils.fields.editInput($('.modal .o_field_widget[name=display_name]'), 'readonly'); assert.strictEqual($('.modal span.o_field_widget[name=foo]').length, 1, - 'foo should be readonly'); - testUtils.dom.clickFirst($('.modal-footer .btn-primary')); + 'foo should be readonly'); + await testUtils.dom.clickFirst($('.modal-footer .btn-primary')); + await testUtils.nextTick(); checkOnchange = false; - testUtils.dom.click(form.$('.o_data_row')); + await testUtils.dom.click(form.$('.o_data_row')); assert.strictEqual($('.modal .o_field_widget[name=foo]').text(), 'foo value', - "the edited value should have been kept"); - testUtils.dom.clickFirst($('.modal-footer .btn-primary')); - - testUtils.form.clickSave(form); // save the record + "the edited value should have been kept"); + await testUtils.dom.clickFirst($('.modal-footer .btn-primary')); + await testUtils.nextTick(); + await testUtils.form.clickSave(form); // save the record form.destroy(); }); - QUnit.test('id is False in evalContext for new records', function (assert) { + QUnit.test('id is False in evalContext for new records', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6311,8 +6351,8 @@ QUnit.module('Views', { assert.hasClass(form.$('.o_field_widget[name=foo]'),'o_readonly_modifier', "foo should be readonly in 'Create' mode"); - testUtils.form.clickSave(form); - testUtils.form.clickEdit(form); + await testUtils.form.clickSave(form); + await testUtils.form.clickEdit(form); assert.doesNotHaveClass(form.$('.o_field_widget[name=foo]'), 'o_readonly_modifier', "foo should not be readonly anymore"); @@ -6320,11 +6360,11 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('delete a duplicated record', function (assert) { + QUnit.test('delete a duplicated record', async function (assert) { assert.expect(5); var newRecordID; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6350,20 +6390,20 @@ QUnit.module('Views', { }); // duplicate record 1 - testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); - testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); + await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + await testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); assert.containsOnce(form, '.o_form_editable', "form should be in edit mode"); assert.strictEqual(form.$('.o_field_widget').val(), 'first record (copy)', "duplicated record should have correct name"); - testUtils.form.clickSave(form); // save duplicated record + await testUtils.form.clickSave(form); // save duplicated record // delete duplicated record - testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); - testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); + await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + await testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); assert.strictEqual($('.modal').length, 1, "should have opened a confirm dialog"); - testUtils.dom.click($('.modal-footer .btn-primary')); + await testUtils.dom.click($('.modal-footer .btn-primary')); assert.strictEqual(form.$('.o_field_widget').text(), 'first record', "should have come back to previous record"); @@ -6371,13 +6411,13 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('display tooltips for buttons', function (assert) { + QUnit.test('display tooltips for buttons', async function (assert) { assert.expect(2); var initialDebugMode = config.debug; config.debug = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6409,7 +6449,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('reload event is handled only once', function (assert) { + QUnit.test('reload event is handled only once', async function (assert) { // In this test, several form controllers are nested (two of them are // opened in dialogs). When the users clicks on save in the last // opened dialog, a 'reload' event is triggered up to reload the (direct) @@ -6422,7 +6462,7 @@ QUnit.module('Views', { '<field name="display_name"/>' + '<field name="trululu"/>' + '</form>'; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6434,7 +6474,7 @@ QUnit.module('Views', { mockRPC: function (route, args) { assert.step(args.method); if (args.method === 'get_formview_id') { - return $.when(false); + return Promise.resolve(false); } return this._super.apply(this, arguments); }, @@ -6443,11 +6483,11 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.$('.o_external_button')); - testUtils.dom.click($('.modal .o_external_button')); + await testUtils.dom.click(form.$('.o_external_button')); + await testUtils.dom.click($('.modal .o_external_button')); - testUtils.fields.editInput($('.modal:nth(1) .o_field_widget[name=display_name]'), 'new name'); - testUtils.dom.click($('.modal:nth(1) footer .btn-primary').first()); + await testUtils.fields.editInput($('.modal:nth(1) .o_field_widget[name=display_name]'), 'new name'); + await testUtils.dom.click($('.modal:nth(1) footer .btn-primary').first()); assert.strictEqual($('.modal .o_field_widget[name=trululu] input').val(), 'new name', "record should have been reloaded"); @@ -6466,12 +6506,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('process the context for inline subview', function (assert) { + QUnit.test('process the context for inline subview', async function (assert) { assert.expect(1); this.data.partner.records[0].p = [2]; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6493,12 +6533,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('process the context for subview not inline', function (assert) { + QUnit.test('process the context for subview not inline', async function (assert) { assert.expect(1); this.data.partner.records[0].p = [2]; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6521,12 +6561,12 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('can toggle column in x2many in sub form view', function (assert) { + QUnit.test('can toggle column in x2many in sub form view', async function (assert) { assert.expect(2); this.data.partner.records[2].p = [1,2]; this.data.partner.fields.foo.sortable = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6536,7 +6576,7 @@ QUnit.module('Views', { res_id: 1, mockRPC: function (route, args) { if (route === '/web/dataset/call_kw/partner/get_formview_id') { - return $.when(false); + return Promise.resolve(false); } return this._super.apply(this, arguments); }, @@ -6551,20 +6591,20 @@ QUnit.module('Views', { }, viewOptions: {mode: 'edit'}, }); - testUtils.dom.click(form.$('.o_external_button')); + await testUtils.dom.click(form.$('.o_external_button')); assert.strictEqual($('.modal-body .o_form_view .o_list_view .o_data_cell').text(), "yopblip", "table has some initial order"); - testUtils.dom.click($('.modal-body .o_form_view .o_list_view th')); + await testUtils.dom.click($('.modal-body .o_form_view .o_list_view th')); assert.strictEqual($('.modal-body .o_form_view .o_list_view .o_data_cell').text(), "blipyop", "table is now sorted"); form.destroy(); }); - QUnit.test('rainbowman attributes correctly passed on button click', function (assert) { + QUnit.test('rainbowman attributes correctly passed on button click', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6578,14 +6618,14 @@ QUnit.module('Views', { var effectDescription = pyUtils.py_eval(event.data.action_data.effect); assert.deepEqual(effectDescription, {message: 'Congrats!'}, "should have correct effect description"); } - } + }, }); - testUtils.dom.click(form.$('.o_form_statusbar .btn-secondary')); + await testUtils.dom.click(form.$('.o_form_statusbar .btn-secondary')); form.destroy(); }); - QUnit.test('basic support for widgets', function (assert) { + QUnit.test('basic support for widgets', async function (assert) { assert.expect(1); var MyWidget = Widget.extend({ @@ -6598,7 +6638,7 @@ QUnit.module('Views', { }); widgetRegistry.add('test', MyWidget); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6616,10 +6656,10 @@ QUnit.module('Views', { delete widgetRegistry.map.test; }); - QUnit.test('support header button as widgets on form statusbar', function (assert) { + QUnit.test('support header button as widgets on form statusbar', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6638,7 +6678,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('basic support for widgets', function (assert) { + QUnit.test('basic support for widgets', async function (assert) { assert.expect(1); var MyWidget = Widget.extend({ @@ -6654,7 +6694,7 @@ QUnit.module('Views', { }); widgetRegistry.add('test', MyWidget); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6664,7 +6704,7 @@ QUnit.module('Views', { '</form>', }); - testUtils.fields.editInput(form.$('input[name="foo"]'), "I am alive"); + await testUtils.fields.editInput(form.$('input[name="foo"]'), "I am alive"); assert.strictEqual(form.$('.o_widget').text(), 'I am alive!', "widget should have been updated"); @@ -6673,10 +6713,10 @@ QUnit.module('Views', { }); - QUnit.test('bounce edit button in readonly mode', function (assert) { + QUnit.test('bounce edit button in readonly mode', async function (assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6694,24 +6734,24 @@ QUnit.module('Views', { }); // in readonly - testUtils.dom.click(form.$('[name="display_name"]')); + await testUtils.dom.click(form.$('[name="display_name"]')); assert.verifySteps(['bounce']); // in edit - testUtils.form.clickEdit(form); - testUtils.dom.click(form.$('[name="display_name"]')); - assert.verifySteps(['bounce']); + await testUtils.form.clickEdit(form); + await testUtils.dom.click(form.$('[name="display_name"]')); + assert.verifySteps([]); form.destroy(); }); - QUnit.test('proper stringification in debug mode tooltip', function (assert) { + QUnit.test('proper stringification in debug mode tooltip', async function (assert) { assert.expect(4); var initialDebugMode = config.debug; config.debug = true; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6740,14 +6780,14 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('autoresize of text fields is done when switching to edit mode', function (assert) { + QUnit.test('autoresize of text fields is done when switching to edit mode', async function (assert) { assert.expect(4); this.data.partner.fields.text_field = { string: 'Text field', type: 'text' }; this.data.partner.fields.text_field.default = "some\n\nmulti\n\nline\n\ntext\n"; this.data.partner.records[0].text_field = "a\nb\nc\nd\ne\nf"; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6761,7 +6801,7 @@ QUnit.module('Views', { }); // switch to edit mode to ensure that autoresize is correctly done - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); var height = form.$('.o_field_widget[name=text_field]').height(); // focus the field to manually trigger autoresize form.$('.o_field_widget[name=text_field]').trigger('focus'); @@ -6772,8 +6812,8 @@ QUnit.module('Views', { assert.ok(height > 80, "textarea should have an height of at least 80px"); // save and create a new record to ensure that autoresize is correctly done - testUtils.form.clickSave(form); - testUtils.form.clickCreate(form); + await testUtils.form.clickSave(form); + await testUtils.form.clickCreate(form); height = form.$('.o_field_widget[name=text_field]').height(); // focus the field to manually trigger autoresize form.$('.o_field_widget[name=text_field]').trigger('focus'); @@ -6784,11 +6824,11 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('check if the view destroys all widgets and instances', function (assert) { + QUnit.test('check if the view destroys all widgets and instances', async function (assert) { assert.expect(1); var instanceNumber = 0; - testUtils.mock.patch(mixins.ParentedMixin, { + await testUtils.mock.patch(mixins.ParentedMixin, { init: function () { instanceNumber++; return this._super.apply(this, arguments); @@ -6844,13 +6884,13 @@ QUnit.module('Views', { res_id: 1, }; - var form = createView(params); + var form = await createView(params); form.destroy(); var initialInstanceNumber = instanceNumber; instanceNumber = 0; - form = createView(params); + form = await createView(params); // call destroy function of controller to ensure that it correctly destroys everything form.__destroy(); @@ -6861,13 +6901,13 @@ QUnit.module('Views', { form.destroy(); - testUtils.mock.unpatch(mixins.ParentedMixin); + await testUtils.mock.unpatch(mixins.ParentedMixin); }); - QUnit.test('do not change pager when discarding current record', function (assert) { + QUnit.test('do not change pager when discarding current record', async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6884,8 +6924,8 @@ QUnit.module('Views', { assert.strictEqual(form.pager.$('.o_pager_counter').text().trim(), '2 / 2', 'pager should indicate that we are on second record'); - testUtils.form.clickEdit(form); - testUtils.form.clickDiscard(form); + await testUtils.form.clickEdit(form); + await testUtils.form.clickDiscard(form); assert.strictEqual(form.pager.$('.o_pager_counter').text().trim(), '2 / 2', 'pager should not have changed'); @@ -6893,14 +6933,14 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('edition in form view on a "noCache" model', function (assert) { - assert.expect(4); + QUnit.test('edition in form view on a "noCache" model', async function (assert) { + assert.expect(5); - testUtils.mock.patch(BasicModel, { + await testUtils.mock.patch(BasicModel, { noCacheModels: BasicModel.prototype.noCacheModels.concat(['partner']), }); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6922,23 +6962,25 @@ QUnit.module('Views', { }); core.bus.on('clear_cache', form, assert.step.bind(assert, 'clear_cache')); - testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'new value'); - testUtils.form.clickSave(form); + await testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'new value'); + await testUtils.form.clickSave(form); assert.verifySteps(['write', 'clear_cache']); form.destroy(); - testUtils.mock.unpatch(BasicModel); + await testUtils.mock.unpatch(BasicModel); + + assert.verifySteps(['clear_cache']); // triggered by the test environment on destroy }); - QUnit.test('creation in form view on a "noCache" model', function (assert) { - assert.expect(4); + QUnit.test('creation in form view on a "noCache" model', async function (assert) { + assert.expect(5); - testUtils.mock.patch(BasicModel, { + await testUtils.mock.patch(BasicModel, { noCacheModels: BasicModel.prototype.noCacheModels.concat(['partner']), }); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6956,23 +6998,25 @@ QUnit.module('Views', { }); core.bus.on('clear_cache', form, assert.step.bind(assert, 'clear_cache')); - testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'value'); - testUtils.form.clickSave(form); + await testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'value'); + await testUtils.form.clickSave(form); assert.verifySteps(['create', 'clear_cache']); form.destroy(); - testUtils.mock.unpatch(BasicModel); + await testUtils.mock.unpatch(BasicModel); + + assert.verifySteps(['clear_cache']); // triggered by the test environment on destroy }); - QUnit.test('deletion in form view on a "noCache" model', function (assert) { - assert.expect(4); + QUnit.test('deletion in form view on a "noCache" model', async function (assert) { + assert.expect(5); - testUtils.mock.patch(BasicModel, { + await testUtils.mock.patch(BasicModel, { noCacheModels: BasicModel.prototype.noCacheModels.concat(['partner']), }); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -6994,17 +7038,19 @@ QUnit.module('Views', { }); core.bus.on('clear_cache', form, assert.step.bind(assert, 'clear_cache')); - testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); - testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); - testUtils.dom.click($('.modal-footer .btn-primary')); + await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + await testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); + await testUtils.dom.click($('.modal-footer .btn-primary')); assert.verifySteps(['unlink', 'clear_cache']); form.destroy(); - testUtils.mock.unpatch(BasicModel); + await testUtils.mock.unpatch(BasicModel); + + assert.verifySteps(['clear_cache']); // triggered by the test environment on destroy }); - QUnit.test('reload currencies when writing on records of model res.currency', function (assert) { + QUnit.test('reload currencies when writing on records of model res.currency', async function (assert) { assert.expect(5); this.data['res.currency'] = { @@ -7012,7 +7058,7 @@ QUnit.module('Views', { records: [{id: 1, display_name: "some currency"}], }; - var form = createView({ + var form = await createView({ View: FormView, model: 'res.currency', data: this.data, @@ -7032,8 +7078,8 @@ QUnit.module('Views', { }, }); - testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'new value'); - testUtils.form.clickSave(form); + await testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'new value'); + await testUtils.form.clickSave(form); assert.verifySteps([ 'read', @@ -7045,8 +7091,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('a popup window should automatically close after a do_action event', function (assert) { - + QUnit.test('a popup window should automatically close after a do_action event', async function (assert) { // Having clicked on a one2many in a form view and clicked on a many2one // field in the resulting popup window that popup window should automatically close. @@ -7055,7 +7100,7 @@ QUnit.module('Views', { this.data.partner.records[0].product_ids = [37]; this.data.product.records[0].partner_type_id = 12; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7068,7 +7113,7 @@ QUnit.module('Views', { res_id: 1, mockRPC: function (route, args) { if (args.method === 'get_formview_action' && args.model === 'partner_type') { - return $.when(); + return Promise.resolve(); } return this._super(route, args); }, @@ -7079,16 +7124,16 @@ QUnit.module('Views', { }, }); // Open one2many - testUtils.dom.click(form.$('.o_data_row')); + await testUtils.dom.click(form.$('.o_data_row')); assert.strictEqual($('.modal-content').length, 1, "a popup window should have opened"); // Click on many2one and trigger do_action - testUtils.dom.click($('.modal-content a[name="partner_type_id"]')); + await testUtils.dom.click($('.modal-content a[name="partner_type_id"]')); assert.strictEqual($('.modal-content').length, 0, "the popup window should have closed"); form.destroy(); }); - QUnit.test('all popup windows should automatically close after a do_action event', function (assert) { + QUnit.test('all popup windows should automatically close after a do_action event', async function (assert) { // Having clicked successively on two different one2many in form views // and clicked on a many2one in the last popup window all popup @@ -7100,7 +7145,7 @@ QUnit.module('Views', { this.data.partner.records[1].product_ids = [37]; this.data.product.records[0].partner_type_id = 12; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7118,7 +7163,7 @@ QUnit.module('Views', { res_id: 1, mockRPC: function (route, args) { if (args.method === 'get_formview_action' && args.model === 'partner_type') { - return $.when(); + return Promise.resolve(); } return this._super(route, args); }, @@ -7129,21 +7174,21 @@ QUnit.module('Views', { }, }); // Open two one2manys - testUtils.dom.click(form.$('.o_data_row')); - testUtils.dom.click($('.modal-content .o_data_row')); + await testUtils.dom.click(form.$('.o_data_row')); + await testUtils.dom.click($('.modal-content .o_data_row')); assert.strictEqual($('.modal-content').length, 2, "Two popup windows should have opened."); // Click on many2one and trigger do_action - testUtils.dom.click($('.modal-content a[name="partner_type_id"]')); + await testUtils.dom.click($('.modal-content a[name="partner_type_id"]')); assert.strictEqual($('.modal-content').length, 0, "All popup windows should have closed."); form.destroy(); }); - QUnit.test('keep editing after call_button fail', function (assert) { + QUnit.test('keep editing after call_button fail', async function (assert) { assert.expect(4); var values; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7175,21 +7220,20 @@ QUnit.module('Views', { }); // add a row and partially fill it - form.$('.o_field_x2many_list_row_add a').click(); - form.$('input[name=display_name]').val('abc').trigger('input'); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.fields.editInput(form.$('input[name=display_name]'), 'abc'); // click button which will trigger_up 'execute_action' (this will save) values = { display_name: 'abc', product_id: false, }; - form.$('button.p').click(); - + await testUtils.dom.click(form.$('button.p')); // edit the new row again and set a many2one value - form.$('.o_form_view .o_field_one2many .o_data_row .o_data_cell').click(); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').click(); - $dropdown.find('li:first()').click(); + await testUtils.dom.clickLast(form.$('.o_form_view .o_field_one2many .o_data_row .o_data_cell')); + await testUtils.nextTick(); + await testUtils.fields.many2one.clickOpenDropdown('product_id'); + await testUtils.fields.many2one.clickHighlightedItem('product_id'); assert.strictEqual(form.$('.o_field_many2one input').val(), 'xphone', "value of the m2o should have been correctly updated"); @@ -7197,15 +7241,15 @@ QUnit.module('Views', { values = { product_id: 37, }; - form.$buttons.find('.o_form_button_save').click(); + await testUtils.form.clickSave(form); form.destroy(); }); - QUnit.test('asynchronous rendering of a widget tag', function (assert) { + QUnit.test('asynchronous rendering of a widget tag', async function (assert) { assert.expect(1); - var def1 = $.Deferred(); + var def1 = testUtils.makeTestPromise(); var MyWidget = Widget.extend({ willStart: function() { @@ -7215,7 +7259,7 @@ QUnit.module('Views', { widgetRegistry.add('test', MyWidget); - createAsyncView({ + createView({ View: FormView, model: 'partner', data: this.data, @@ -7230,9 +7274,10 @@ QUnit.module('Views', { }); def1.resolve(); + await testUtils.nextTick(); }); - QUnit.test('no deadlock when saving with uncommitted changes', function (assert) { + QUnit.test('no deadlock when saving with uncommitted changes', async function (assert) { // Before saving a record, all field widgets are asked to commit their changes (new values // that they wouldn't have sent to the model yet). This test is added alongside a bug fix // ensuring that we don't end up in a deadlock when a widget actually has some changes to @@ -7245,7 +7290,7 @@ QUnit.module('Views', { // on 'Save'. assert.expect(6); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7254,16 +7299,18 @@ QUnit.module('Views', { assert.step(args.method); return this._super.apply(this, arguments); }, - // we set a fieldDebounce to precisely mock the behavior of the webclient: changes are - // not sent to the model at keystrokes, but when the input is left + // we set a fieldDebounce to precisely mock the behavior of the webclient: changes are + // not sent to the model at keystrokes, but when the input is left fieldDebounce: 5000, }); - testUtils.fields.editInput(form.$('input[name=foo]'), 'some foo value'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'some foo value'); // manually save the record, to prevent the field widget to notify the model of its new // value before being requested to form.saveRecord(); + await testUtils.nextTick(); + assert.containsOnce(form, '.o_form_readonly', "form view should be in readonly"); assert.strictEqual(form.$('.o_form_view').text().trim(), 'some foo value', "foo field should have correct value"); @@ -7272,7 +7319,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('save record with onchange on one2many with required field', function (assert) { + QUnit.test('save record with onchange on one2many with required field', async function (assert) { // in this test, we have a one2many with a required field, whose value is // set by an onchange on another field ; we manually set the value of that // first field, and directly click on Save (before the onchange RPC returns @@ -7287,7 +7334,7 @@ QUnit.module('Views', { }; var onchangeDef; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7302,7 +7349,7 @@ QUnit.module('Views', { mockRPC: function (route, args) { var result = this._super.apply(this, arguments); if (args.method === 'onchange') { - return $.when(onchangeDef).then(_.constant(result)); + return Promise.resolve(onchangeDef).then(_.constant(result)); } if (args.method === 'create') { assert.step('create'); @@ -7313,28 +7360,29 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('.o_field_widget[name=display_name]').val(), '', "display_name should be the empty string by default"); assert.strictEqual(form.$('.o_field_widget[name=foo]').val(), '', "foo should be the empty string by default"); - onchangeDef = $.Deferred(); // delay the onchange + onchangeDef = testUtils.makeTestPromise(); // delay the onchange - testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'some value'); + await testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'some value'); - testUtils.form.clickSave(form); + await testUtils.form.clickSave(form); assert.step('resolve'); onchangeDef.resolve(); + await testUtils.nextTick(); assert.verifySteps(['resolve', 'create']); form.destroy(); }); - QUnit.test('call canBeRemoved while saving', function (assert) { + QUnit.test('call canBeRemoved while saving', async function (assert) { assert.expect(10); this.data.partner.onchanges = { @@ -7344,8 +7392,8 @@ QUnit.module('Views', { }; var onchangeDef; - var createDef = $.Deferred(); - var form = createView({ + var createDef = testUtils.makeTestPromise(); + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7353,41 +7401,43 @@ QUnit.module('Views', { mockRPC: function (route, args) { var result = this._super.apply(this, arguments); if (args.method === 'onchange') { - return $.when(onchangeDef).then(_.constant(result)); + return Promise.resolve(onchangeDef).then(_.constant(result)); } if (args.method === 'create') { - return $.when(createDef).then(_.constant(result)); + return Promise.resolve(createDef).then(_.constant(result)); } return result; }, }); // edit foo to trigger a delayed onchange - onchangeDef = $.Deferred(); - testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), 'trigger onchange'); + onchangeDef = testUtils.makeTestPromise(); + await testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), 'trigger onchange'); assert.strictEqual(form.$('.o_field_widget[name=display_name]').val(), 'default'); // save (will wait for the onchange to return), and will be delayed as well - testUtils.dom.click(form.$buttons.find('.o_form_button_save')); + await testUtils.dom.click(form.$buttons.find('.o_form_button_save')); assert.hasClass(form.$('.o_form_view'), 'o_form_editable'); assert.strictEqual(form.$('.o_field_widget[name=display_name]').val(), 'default'); // simulate a click on the breadcrumbs to leave the form view form.canBeRemoved(); + await testUtils.nextTick(); assert.hasClass(form.$('.o_form_view'), 'o_form_editable'); assert.strictEqual(form.$('.o_field_widget[name=display_name]').val(), 'default'); // unlock the onchange onchangeDef.resolve(); - + await testUtils.nextTick(); assert.hasClass(form.$('.o_form_view'), 'o_form_editable'); assert.strictEqual(form.$('.o_field_widget[name=display_name]').val(), 'changed'); // unlock the create createDef.resolve(); + await testUtils.nextTick(); assert.hasClass(form.$('.o_form_view'), 'o_form_readonly'); assert.strictEqual(form.$('.o_field_widget[name=display_name]').text(), 'changed'); @@ -7397,7 +7447,7 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('domain returned by onchange is cleared on discard', function (assert) { + QUnit.test('domain returned by onchange is cleared on discard', async function (assert) { assert.expect(4); this.data.partner.onchanges = { @@ -7406,7 +7456,7 @@ QUnit.module('Views', { var domain = ['id', '=', 1]; var expectedDomain = domain; - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7414,7 +7464,7 @@ QUnit.module('Views', { mockRPC: function (route, args) { if (args.method === 'onchange' && args.args[0][0] === 1) { // onchange returns a domain only on record 1 - return $.when({ + return Promise.resolve({ domain: { trululu: domain, }, @@ -7435,30 +7485,30 @@ QUnit.module('Views', { assert.strictEqual(form.$('input[name=foo]').val(), 'yop', "should be on record 1"); // change foo to trigger the onchange - testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); + await testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); // open many2one dropdown to check if the domain is applied - testUtils.fields.many2one.clickOpenDropdown('trululu'); + await testUtils.fields.many2one.clickOpenDropdown('trululu'); // switch to another record (should ask to discard changes, and reset the domain) - testUtils.dom.click(form.pager.$('.o_pager_next')); + await testUtils.dom.click(form.pager.$('.o_pager_next')); // discard changes by clicking on confirm in the dialog - testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); + await testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); assert.strictEqual(form.$('input[name=foo]').val(), 'blip', "should be on record 2"); // open many2one dropdown to check if the domain is applied expectedDomain = []; - testUtils.fields.many2one.clickOpenDropdown('trululu'); + await testUtils.fields.many2one.clickOpenDropdown('trululu'); form.destroy(); }); - QUnit.test('discard after a failed save', function (assert) { + QUnit.test('discard after a failed save', async function (assert) { assert.expect(2); - var actionManager = createActionManager({ + var actionManager = await createActionManager({ data: this.data, archs: { 'partner,false,form': '<form>' + @@ -7472,13 +7522,13 @@ QUnit.module('Views', { actions: this.actions, }); - actionManager.doAction(1); + await actionManager.doAction(1); - testUtils.dom.click('.o_control_panel .o-kanban-button-new'); + await testUtils.dom.click('.o_control_panel .o-kanban-button-new'); //cannot save because there is a required field - testUtils.dom.click('.o_control_panel .o_form_button_save'); - testUtils.dom.click('.o_control_panel .o_form_button_cancel'); + await testUtils.dom.click('.o_control_panel .o_form_button_save'); + await testUtils.dom.click('.o_control_panel .o_form_button_cancel'); assert.containsNone(actionManager, '.o_form_view'); assert.containsOnce(actionManager, '.o_kanban_view'); @@ -7486,10 +7536,10 @@ QUnit.module('Views', { actionManager.destroy(); }); - QUnit.test("one2many create record dialog shouldn't have a 'remove' button", function (assert) { + QUnit.test("one2many create record dialog shouldn't have a 'remove' button", async function (assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7510,8 +7560,8 @@ QUnit.module('Views', { res_id: 1, }); - testUtils.form.clickCreate(form); - form.$('.o-kanban-button-new').click(); + await testUtils.form.clickCreate(form); + await testUtils.dom.click(form.$('.o-kanban-button-new')); assert.containsOnce(document.body, '.modal'); assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 0, @@ -7522,10 +7572,10 @@ QUnit.module('Views', { QUnit.module('FormViewTABMainButtons'); - QUnit.test('using tab in an empty required string field should not move to the next field',function(assert) { + QUnit.test('using tab in an empty required string field should not move to the next field', async function(assert) { assert.expect(3); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7539,7 +7589,7 @@ QUnit.module('Views', { '</form>', }); - testUtils.dom.click(form.$('input[name=display_name]')); + await testUtils.dom.click(form.$('input[name=display_name]')); assert.strictEqual(form.$('input[name="display_name"]')[0], document.activeElement, "display_name should be focused"); form.$('input[name="display_name"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); @@ -7550,10 +7600,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('using tab in an empty required date field should not move to the next field',function(assert) { + QUnit.test('using tab in an empty required date field should not move to the next field', async function(assert) { assert.expect(2); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7567,7 +7617,7 @@ QUnit.module('Views', { '</form>', }); - testUtils.dom.click(form.$('input[name=date]')); + await testUtils.dom.click(form.$('input[name=date]')); assert.strictEqual(form.$('input[name="date"]')[0], document.activeElement, "display_name should be focused"); form.$('input[name="date"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); @@ -7577,10 +7627,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('Edit button get the focus when pressing TAB from form', function (assert) { + QUnit.test('Edit button get the focus when pressing TAB from form', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7593,7 +7643,7 @@ QUnit.module('Views', { }); // in edit - testUtils.form.clickEdit(form); + await testUtils.form.clickEdit(form); form.$('input[name="display_name"]').focus().trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); assert.strictEqual(form.$buttons.find('.btn-primary:visible')[0], document.activeElement, "the first primary button (save) should be focused"); @@ -7602,9 +7652,9 @@ QUnit.module('Views', { QUnit.module('FormViewTABFormButtons'); - QUnit.test('In Edition mode, after navigating to the last field, the default button when pressing TAB is SAVE', function (assert) { + QUnit.test('In Edition mode, after navigating to the last field, the default button when pressing TAB is SAVE', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7634,10 +7684,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('In READ mode, the default button with focus is the first primary button of the form', function (assert) { + QUnit.test('In READ mode, the default button with focus is the first primary button of the form', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7662,10 +7712,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('In READ mode, the default button when pressing TAB is EDIT when there is no primary button on the form', function (assert) { + QUnit.test('In READ mode, the default button when pressing TAB is EDIT when there is no primary button on the form', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7690,10 +7740,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('In Edition mode, when an attribute is dynamically required (and not required), TAB should navigate to the next field', function (assert) { + QUnit.test('In Edition mode, when an attribute is dynamically required (and not required), TAB should navigate to the next field', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7718,10 +7768,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('In Edition mode, when an attribute is dynamically required, TAB should stop on the field if it is required', function (assert) { + QUnit.test('In Edition mode, when an attribute is dynamically required, TAB should stop on the field if it is required', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7739,7 +7789,7 @@ QUnit.module('Views', { }, }); - testUtils.dom.click(form.$('div[name="bar"]>input')); + await testUtils.dom.click(form.$('div[name="bar"]>input')); form.$('input[name="foo"]').focus(); $(document.activeElement).trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); @@ -7747,10 +7797,10 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('display tooltips for save and discard buttons', function (assert) { + QUnit.test('display tooltips for save and discard buttons', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7762,12 +7812,13 @@ QUnit.module('Views', { form.$buttons.find('.o_form_buttons_edit').tooltip('show',false); assert.strictEqual($('.tooltip .oe_tooltip_string').length, 1, "should have rendered a tooltip"); + await testUtils.nextTick(); form.destroy(); }); - QUnit.test('if the focus is on the save button, hitting ENTER should save', function (assert) { + QUnit.test('if the focus is on the save button, hitting ENTER should save', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7786,14 +7837,15 @@ QUnit.module('Views', { }); form.$buttons.find('.o_form_button_save') - .focus() - .trigger($.Event('keydown', {which: $.ui.keyCode.ENTER})); + .focus() + .trigger($.Event('keydown', {which: $.ui.keyCode.ENTER})); + await testUtils.nextTick(); form.destroy(); }); - QUnit.test('if the focus is on the discard button, hitting ENTER should save', function (assert) { + QUnit.test('if the focus is on the discard button, hitting ENTER should save', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7812,14 +7864,15 @@ QUnit.module('Views', { }); form.$buttons.find('.o_form_button_cancel') - .focus() - .trigger($.Event('keydown', {which: $.ui.keyCode.ENTER})); + .focus() + .trigger($.Event('keydown', {which: $.ui.keyCode.ENTER})); + await testUtils.nextTick(); form.destroy(); }); - QUnit.test('if the focus is on the save button, hitting ESCAPE should discard', function (assert) { + QUnit.test('if the focus is on the save button, hitting ESCAPE should discard', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7838,14 +7891,15 @@ QUnit.module('Views', { }); form.$buttons.find('.o_form_button_save') - .focus() - .trigger($.Event('keydown', {which: $.ui.keyCode.ESCAPE})); + .focus() + .trigger($.Event('keydown', {which: $.ui.keyCode.ESCAPE})); + await testUtils.nextTick(); form.destroy(); }); - QUnit.test('if the focus is on the discard button, hitting ESCAPE should discard', function (assert) { + QUnit.test('if the focus is on the discard button, hitting ESCAPE should discard', async function (assert) { assert.expect(1); - var form = createView({ + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -7864,18 +7918,19 @@ QUnit.module('Views', { }); form.$buttons.find('.o_form_button_cancel') - .focus() - .trigger($.Event('keydown', {which: $.ui.keyCode.ESCAPE})); + .focus() + .trigger($.Event('keydown', {which: $.ui.keyCode.ESCAPE})); + await testUtils.nextTick(); form.destroy(); }); - QUnit.test('if the focus is on the save button, hitting TAB should not move to the next button', function (assert) { + QUnit.test('if the focus is on the save button, hitting TAB should not move to the next button', async function (assert) { assert.expect(1); /* this test has only one purpose: to say that it is normal that the focus stays within a button primary even after the TAB key has been pressed. It is not possible here to execute the default action of the TAB on a button : https://stackoverflow.com/questions/32428993/why-doesnt-simulating-a-tab-keypress-move-focus-to-the-next-input-field so writing a test that will always succeed is not useful. - */ + */ assert.ok("Behavior can't be tested"); }); }); |
