diff options
Diffstat (limited to 'addons/web/static/tests/fields')
9 files changed, 1859 insertions, 1964 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_mobile_tests.js b/addons/web/static/tests/fields/basic_fields_mobile_tests.js index acd9cebc989..05f1b93226e 100644 --- a/addons/web/static/tests/fields/basic_fields_mobile_tests.js +++ b/addons/web/static/tests/fields/basic_fields_mobile_tests.js @@ -75,25 +75,25 @@ QUnit.module('basic_fields', { "should have a anchor with correct classes"); assert.strictEqual($phoneLink.text(), 'yop', "value should be displayed properly"); - assert.strictEqual($phoneLink.attr('href'), 'tel:yop', + assert.hasAttrValue($phoneLink, 'href', 'tel:yop', "should have proper tel prefix"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('input[type="text"].o_field_widget').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, 'input[type="text"].o_field_widget', "should have an int for the phone field"); assert.strictEqual(form.$('input[type="text"].o_field_widget').val(), 'yop', "input should contain field value in edit mode"); // change value in edit mode - form.$('input[type="text"].o_field_widget').val('new').trigger('input'); + testUtils.fields.editInput(form.$('input[type="text"].o_field_widget'), 'new'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); $phoneLink = form.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.text(), 'new', "new value should be displayed properly"); - assert.strictEqual($phoneLink.attr('href'), 'tel:new', + assert.hasAttrValue($phoneLink, 'href', 'tel:new', "should still have proper tel prefix"); form.destroy(); @@ -109,7 +109,7 @@ QUnit.module('basic_fields', { arch: '<tree editable="bottom"><field name="foo" widget="phone"/></tree>', }); - assert.strictEqual(list.$('.o_data_row').length, 3, + assert.containsN(list, '.o_data_row', 3, "should have 3 record"); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yop', "value should be displayed properly"); @@ -117,27 +117,27 @@ QUnit.module('basic_fields', { var $phoneLink = list.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.length, 3, "should have anchors with correct classes"); - assert.strictEqual($phoneLink.first().attr('href'), 'tel:yop', + assert.hasAttrValue($phoneLink.first(), 'href', 'tel:yop', "should have proper tel prefix"); // Edit a line and check the result var $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - $cell.click(); - assert.ok($cell.parent().hasClass('o_selected_row'), 'should be set as edit mode'); + testUtils.dom.click($cell); + assert.hasClass($cell.parent(),'o_selected_row', 'should be set as edit mode'); assert.strictEqual($cell.find('input').val(), 'yop', 'should have the corect value in internal input'); - $cell.find('input').val('new').trigger('input'); + testUtils.fields.editInput($cell.find('input'), 'new'); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - assert.ok(!$cell.parent().hasClass('o_selected_row'), 'should not be in edit mode anymore'); + assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore'); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'new', "value should be properly updated"); $phoneLink = list.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.length, 3, "should still have anchors with correct classes"); - assert.strictEqual($phoneLink.first().attr('href'), 'tel:new', + assert.hasAttrValue($phoneLink.first(), 'href', 'tel:new', "should still have proper tel prefix"); list.destroy(); @@ -164,10 +164,10 @@ QUnit.module('basic_fields', { }); var val = '<script>throw Error();</script><script>throw Error();</script>'; - form.$('input').val(val).trigger('input'); + testUtils.fields.editInput(form.$('input'), val); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').text(), val, "value should have been correctly escaped"); diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index f1640b06c82..b4998b01712 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -18,6 +18,9 @@ var DebouncedField = basicFields.DebouncedField; var JournalDashboardGraph = basicFields.JournalDashboardGraph; var _t = core._t; +var DOM = testUtils.DOM; +var mock = testUtils.mock; + QUnit.module('fields', {}, function () { QUnit.module('basic_fields', { @@ -163,11 +166,11 @@ QUnit.module('basic_fields', { }); // change the value - form.$('input').val('new value').trigger('input'); + testUtils.fields.editInput(form.$('input'), 'new value'); assert.verifySteps([], "_setValue shouldn't have been called yet"); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.verifySteps(['_setValue'], "_setValue should have been called once"); // destroy the form view @@ -199,47 +202,47 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 1, + assert.containsOnce(form, '.o_field_boolean input:checked', "checkbox should be checked"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, '.o_field_boolean input:checked', "checkbox should still be checked"); // uncheck the checkbox - form.$('.o_field_boolean input:checked').click(); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 0, + testUtils.dom.click(form.$('.o_field_boolean input:checked')); + assert.containsNone(form, '.o_field_boolean input:checked', "checkbox should no longer be checked"); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 0, + testUtils.form.clickSave(form); + assert.containsNone(form, '.o_field_boolean input:checked', "checkbox should still no longer be checked"); // switch to edit mode and test the opposite change - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 0, + testUtils.form.clickEdit(form); + assert.containsNone(form, '.o_field_boolean input:checked', "checkbox should still be unchecked"); // check the checkbox - form.$('.o_field_boolean input').click(); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 1, + testUtils.dom.click(form.$('.o_field_boolean input')); + assert.containsOnce(form, '.o_field_boolean input:checked', "checkbox should now be checked"); // uncheck it back - form.$('.o_field_boolean input').click(); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 0, + testUtils.dom.click(form.$('.o_field_boolean input')); + assert.containsNone(form, '.o_field_boolean input:checked', "checkbox should now be unchecked"); // check the checkbox by clicking on label - form.$('label:first').click(); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 1, + testUtils.dom.click(form.$('label:first')); + assert.containsOnce(form, '.o_field_boolean input:checked', "checkbox should now be checked"); // uncheck it back - form.$('label:first').click(); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 0, + testUtils.dom.click(form.$('label:first')); + assert.containsNone(form, '.o_field_boolean input:checked', "checkbox should now be unchecked"); // check the checkbox by hitting the "enter" key after focusing it @@ -247,18 +250,18 @@ QUnit.module('basic_fields', { .trigger("focusin") .trigger({type: "keydown", which: $.ui.keyCode.ENTER}) .trigger({type: "keyup", which: $.ui.keyCode.ENTER}); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 1, + assert.containsOnce(form, '.o_field_boolean input:checked', "checkbox should now be checked"); // blindly press enter again, it should uncheck the checkbox $(document.activeElement).trigger({type: "keydown", which: $.ui.keyCode.ENTER}); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 0, + assert.containsNone(form, '.o_field_boolean input:checked', "checkbox should not be checked"); // blindly press enter again, it should check the checkbox back $(document.activeElement).trigger({type: "keydown", which: $.ui.keyCode.ENTER}); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_field_boolean input:checked').length, 1, + testUtils.form.clickSave(form); + assert.containsOnce(form, '.o_field_boolean input:checked', "checkbox should still be checked"); form.destroy(); }); @@ -282,13 +285,13 @@ QUnit.module('basic_fields', { var $cell = list.$('tr.o_data_row:has(.custom-checkbox input:checked) td:not(.o_list_record_selector)').first(); assert.ok($cell.find('.custom-checkbox input:checked').prop('disabled'), "input should be disabled in readonly mode"); - $cell.click(); + testUtils.dom.click($cell); assert.ok(!$cell.find('.custom-checkbox input:checked').prop('disabled'), "input should not have the disabled property in edit mode"); - $cell.find('.custom-checkbox input:checked').click(); + testUtils.dom.click($cell.find('.custom-checkbox input:checked')); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); $cell = list.$('tr.o_data_row:has(.custom-checkbox input:not(:checked)) td:not(.o_list_record_selector)').first(); assert.ok($cell.find('.custom-checkbox input:not(:checked)').prop('disabled'), "input should be disabled again"); @@ -298,12 +301,12 @@ QUnit.module('basic_fields', { "should now have only 3 checked input"); // Re-Edit the line and fake-check the checkbox - $cell.click(); - $cell.find('.custom-checkbox input').click(); // Change the checkbox - $cell.find('.custom-checkbox input').click(); // Undo the change + testUtils.dom.click($cell); + testUtils.dom.click($cell.find('.custom-checkbox input')); + testUtils.dom.click($cell.find('.custom-checkbox input')); // Save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector) .custom-checkbox input').length, 5, "should still have 5 checkboxes"); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector) .custom-checkbox input:checked').length, 3, @@ -312,10 +315,8 @@ QUnit.module('basic_fields', { // Re-Edit the line to check the checkbox back but this time click on // the checkbox directly in readonly mode ! $cell = list.$('tr.o_data_row:has(.custom-checkbox input:not(:checked)) td:not(.o_list_record_selector)').first(); - $cell.find('.custom-checkbox .custom-control-label').click(); + testUtils.dom.click($cell.find('.custom-checkbox .custom-control-label')); - // save - list.$buttons.find('.o_form_button_save').click(); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector) .custom-checkbox input').length, 5, "should still have 5 checkboxes"); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector) .custom-checkbox input:checked').length, 4, @@ -328,7 +329,6 @@ QUnit.module('basic_fields', { QUnit.test('use custom terminology in form view', function (assert) { assert.expect(2); - var terminology = { string_true: "Production Environment", hover_true: "Switch to test environment", @@ -370,7 +370,7 @@ QUnit.module('basic_fields', { res_id: 2, }); - assert.strictEqual(form.$(".custom-checkbox.o_boolean_toggle").length, 1, "Boolean toggle widget applied to boolean field"); + assert.containsOnce(form, ".custom-checkbox.o_boolean_toggle", "Boolean toggle widget applied to boolean field"); form.destroy(); }); @@ -389,23 +389,23 @@ QUnit.module('basic_fields', { '</tree>', }); - assert.strictEqual(list.$('button i.fa.fa-circle.o_toggle_button_success').length, 4, + assert.containsN(list, 'button i.fa.fa-circle.o_toggle_button_success', 4, "should have 4 green buttons"); - assert.strictEqual(list.$('button i.fa.fa-circle.text-muted').length, 1, + assert.containsOnce(list, 'button i.fa.fa-circle.text-muted', "should have 1 muted button"); - assert.strictEqual(list.$('button').first().attr('title'), "Reported in last payslips", + assert.hasAttrValue(list.$('button').first(), 'title', "Reported in last payslips", "active buttons should have proper tooltip"); - assert.strictEqual(list.$('button').last().attr('title'), "To Report in Payslip", + assert.hasAttrValue(list.$('button').last(), 'title', "To Report in Payslip", "inactive buttons should have proper tooltip"); // clicking on first button to check the state is properly changed - list.$('button').first().click(); - assert.strictEqual(list.$('button i.fa.fa-circle.o_toggle_button_success').length, 3, + testUtils.dom.click(list.$('button').first()); + assert.containsN(list, 'button i.fa.fa-circle.o_toggle_button_success', 3, "should have 3 green buttons"); - list.$('button').first().click(); - assert.strictEqual(list.$('button i.fa.fa-circle.o_toggle_button_success').length, 4, + testUtils.dom.click(list.$('button').first()); + assert.containsN(list, 'button i.fa.fa-circle.o_toggle_button_success', 4, "should have 4 green buttons"); list.destroy(); }); @@ -437,14 +437,14 @@ QUnit.module('basic_fields', { 1, "should be green"); // click on the button to toggle the value - form.$('.o_field_widget[name=bar]').click(); + testUtils.dom.click(form.$('.o_field_widget[name=bar]')); assert.strictEqual(form.$('.o_field_widget[name=bar] i.text-muted:not(.o_toggle_button_success)').length, 1, "should be gray"); assert.verifySteps([]); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget[name=bar] i.text-muted:not(.o_toggle_button_success)').length, 1, "should still be gray"); @@ -477,7 +477,7 @@ QUnit.module('basic_fields', { 1, "should be green"); // click on the button to toggle the value - form.$('.o_field_widget[name=bar]').click(); + testUtils.dom.click(form.$('.o_field_widget[name=bar]')); assert.strictEqual(form.$('.o_field_widget[name=bar] i.text-muted:not(.o_toggle_button_success)').length, 1, "should be gray"); @@ -503,7 +503,7 @@ QUnit.module('basic_fields', { res_id: 4, }); - assert.notOk(form.$('.o_field_widget').hasClass('o_field_empty'), + assert.doesNotHaveClass(form.$('.o_field_widget'), 'o_field_empty', 'Non-set float field should be considered as 0.'); assert.strictEqual(form.$('.o_field_widget').text(), "0.000", 'Non-set float field should be considered as 0.'); @@ -547,21 +547,21 @@ QUnit.module('basic_fields', { res_id: 2, }); - assert.ok(!form.$('.o_field_widget').hasClass('o_field_empty'), + assert.doesNotHaveClass(form.$('.o_field_widget'), 'o_field_empty', 'Float field should be considered set for value 0.'); assert.strictEqual(form.$('.o_field_widget').first().text(), '0.000', 'The value should be displayed properly.'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), '0.000', 'The value should be rendered with correct precision.'); - form.$('input').val('108.2458938598598').trigger('input'); + testUtils.fields.editInput(form.$('input'), '108.2458938598598'); assert.strictEqual(form.$('input').val(), '108.2458938598598', 'The value should not be formated yet.'); - form.$('input').val('18.8958938598598').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editInput(form.$('input'), '18.8958938598598'); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').first().text(), '18.896', 'The new value should be rounded properly.'); @@ -586,17 +586,17 @@ QUnit.module('basic_fields', { // switch to edit mode var $cell = list.$('tr.o_data_row td:not(.o_list_record_selector)').first(); - $cell.click(); + testUtils.dom.click($cell); - assert.strictEqual(list.$('input[name="qux"]').length, 1, + assert.containsOnce(list, 'input[name="qux"]', 'The view should have 1 input for editable float.'); - list.$('input[name="qux"]').val('108.2458938598598').trigger('input'); + testUtils.fields.editInput(list.$('input[name="qux"]'), '108.2458938598598'); assert.strictEqual(list.$('input[name="qux"]').val(), '108.2458938598598', 'The value should not be formated yet.'); - list.$('input[name="qux"]').val('18.8958938598598').trigger('input'); - list.$buttons.find('.o_list_button_save').click(); + testUtils.fields.editInput(list.$('input[name="qux"]'), '18.8958938598598'); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('.o_field_widget').first().text(), '18.896', 'The new value should be rounded properly.'); @@ -625,8 +625,8 @@ QUnit.module('basic_fields', { } }); - form.$buttons.find('.o_form_button_edit').click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickEdit(form); + testUtils.form.clickSave(form); assert.verifySteps(['read']); // should not have save as nothing changed @@ -669,7 +669,7 @@ QUnit.module('basic_fields', { id: 1, qux: -8.89859, currency_id: 1, - }] + }]; var form = createView({ View: FormView, model: 'partner', @@ -690,17 +690,17 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0-8.9', 'The value should be displayed properly.'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), '-8.9', 'The input should be rendered without the currency symbol.'); assert.strictEqual(form.$('input').parent().children().first().text(), '$', 'The input should be preceded by a span containing the currency symbol.'); - form.$('input').val('109.2458938598598').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_monetary input'), '109.2458938598598'); assert.strictEqual(form.$('input').val(), '109.2458938598598', 'The value should not be formated yet.'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); // Non-breaking space between the currency and the amount assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0109.2', 'The new value should be rounded properly.'); @@ -725,17 +725,17 @@ QUnit.module('basic_fields', { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(form.$('.o_field_widget')[0].hasAttribute('type'), 'Float field with option type must have a type attribute.'); - assert.strictEqual(form.$('.o_field_widget').attr('type'), 'number', + assert.hasAttrValue(form.$('.o_field_widget'), 'type', 'number', 'Float field with option type must have a type attribute equals to "number".'); - form.$('input').val('123456.7890').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.fields.editInput(form.$('input'), '123456.7890'); + testUtils.form.clickSave(form); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget').val(), '123456.789', 'Float value must be not formatted if input type is number.'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').text(), '123,456.8', 'Float value must be formatted in readonly view even if the input type is number.'); @@ -759,13 +759,13 @@ QUnit.module('basic_fields', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_widget').attr('type'), 'text', + testUtils.form.clickEdit(form); + assert.hasAttrValue(form.$('.o_field_widget'), 'type', 'text', 'Float field with option type must have a text type (default type).'); - form.$('input').val('123456.7890').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.fields.editInput(form.$('input'), '123456.7890'); + testUtils.form.clickSave(form); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget').val(), '123,456.8', 'Float value must be formatted if input type isn\'t number.'); @@ -797,25 +797,25 @@ QUnit.module('basic_fields', { "should have a anchor with correct classes"); assert.strictEqual($mailtoLink.text(), 'yop', "the value should be displayed properly"); - assert.strictEqual($mailtoLink.attr('href'), 'mailto:yop', + assert.hasAttrValue($mailtoLink, 'href', 'mailto:yop', "should have proper mailto prefix"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('input[type="text"].o_field_widget').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, 'input[type="text"].o_field_widget', "should have an input for the email field"); assert.strictEqual(form.$('input[type="text"].o_field_widget').val(), 'yop', "input should contain field value in edit mode"); // change value in edit mode - form.$('input[type="text"].o_field_widget').val('new').trigger('input'); + testUtils.fields.editInput(form.$('input[type="text"].o_field_widget'), 'new'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); $mailtoLink = form.$('a.o_form_uri.o_field_widget.o_text_overflow'); assert.strictEqual($mailtoLink.text(), 'new', "new value should be displayed properly"); - assert.strictEqual($mailtoLink.attr('href'), 'mailto:new', + assert.hasAttrValue($mailtoLink, 'href', 'mailto:new', "should still have proper mailto prefix"); form.destroy(); @@ -839,27 +839,27 @@ QUnit.module('basic_fields', { var $mailtoLink = list.$('a.o_form_uri.o_field_widget.o_text_overflow'); assert.strictEqual($mailtoLink.length, 5, "should have anchors with correct classes"); - assert.strictEqual($mailtoLink.first().attr('href'), 'mailto:yop', + assert.hasAttrValue($mailtoLink.first(), 'href', 'mailto:yop', "should have proper mailto prefix"); // Edit a line and check the result var $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - $cell.click(); - assert.ok($cell.parent().hasClass('o_selected_row'), 'should be set as edit mode'); + testUtils.dom.click($cell); + assert.hasClass($cell.parent(),'o_selected_row', 'should be set as edit mode'); assert.strictEqual($cell.find('input').val(), 'yop', 'should have the corect value in internal input'); - $cell.find('input').val('new').trigger('input'); + testUtils.fields.editInput($cell.find('input'), 'new'); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - assert.ok(!$cell.parent().hasClass('o_selected_row'), 'should not be in edit mode anymore'); + assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore'); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'new', "value should be properly updated"); $mailtoLink = list.$('a.o_form_uri.o_field_widget.o_text_overflow'); assert.strictEqual($mailtoLink.length, 5, "should still have anchors with correct classes"); - assert.strictEqual($mailtoLink.first().attr('href'), 'mailto:new', + assert.hasAttrValue($mailtoLink.first(), 'href', 'mailto:new', "should still have proper mailto prefix"); list.destroy(); @@ -908,17 +908,17 @@ QUnit.module('basic_fields', { "the value should be displayed properly"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('input[type="text"].o_field_widget').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, 'input[type="text"].o_field_widget', "should have an input for the char field"); assert.strictEqual(form.$('input[type="text"].o_field_widget').val(), 'yop', "input should contain field value in edit mode"); // change value in edit mode - form.$('input[type="text"].o_field_widget').val('limbo').trigger('input'); + testUtils.fields.editInput(form.$('input[type="text"].o_field_widget'), 'limbo'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').text(), 'limbo', 'the new value should be displayed'); form.destroy(); @@ -949,10 +949,10 @@ QUnit.module('basic_fields', { } }); - form.$('input[type="text"].o_field_widget').val('').trigger('input'); + testUtils.fields.editInput(form.$('input[type="text"].o_field_widget'), ''); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); @@ -975,7 +975,7 @@ QUnit.module('basic_fields', { }, }); - assert.strictEqual(form.$('input.o_field_widget').attr('maxlength'), '5', + assert.hasAttrValue(form.$('input.o_field_widget'), 'maxlength', '5', "maxlength attribute should have been set correctly on the input"); form.destroy(); @@ -998,16 +998,16 @@ QUnit.module('basic_fields', { // Edit a line and check the result var $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - $cell.click(); - assert.ok($cell.parent().hasClass('o_selected_row'), 'should be set as edit mode'); + testUtils.dom.click($cell); + assert.hasClass($cell.parent(),'o_selected_row', 'should be set as edit mode'); assert.strictEqual($cell.find('input').val(), 'yop', 'should have the corect value in internal input'); - $cell.find('input').val('brolo').trigger('input'); + testUtils.fields.editInput($cell.find('input'), 'brolo'); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - assert.ok(!$cell.parent().hasClass('o_selected_row'), 'should not be in edit mode anymore'); + assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore'); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'brolo', "value should be properly updated"); list.destroy(); @@ -1041,10 +1041,10 @@ QUnit.module('basic_fields', { return this._super.apply(this, arguments); }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var $button = form.$('input[type="text"].o_field_char + .o_field_translate'); assert.strictEqual($button.length, 1, "should have a translate button"); - $button.click(); + testUtils.dom.click($button); form.destroy(); form = createView({ @@ -1086,8 +1086,8 @@ QUnit.module('basic_fields', { }, }); - form.$('input').val('<script>throw Error();</script>').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editInput(form.$('input'), '<script>throw Error();</script>'); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').text(), '<script>throw Error();</script>', 'the value should have been properly escaped'); @@ -1117,13 +1117,13 @@ QUnit.module('basic_fields', { }, }); - form.$('input[name="foo"]').val(' abc ').trigger('input'); - form.$('input[name="foo2"]').val(' def ').trigger('input'); + testUtils.fields.editInput(form.$('input[name="foo"]'), ' abc '); + testUtils.fields.editInput(form.$('input[name="foo2"]'), ' def '); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); // edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name="foo"]').val(), 'abc', 'Foo value should have been trimmed'); assert.strictEqual(form.$('input[name="foo2"]').val(), ' def ', 'Foo2 value should not have been trimmed'); @@ -1169,17 +1169,17 @@ QUnit.module('basic_fields', { }, }); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('input[name="foo"]').val(), 'My little Foo Value', 'should contain the default value'); def = $.Deferred(); - form.$('.o_field_many2one input').click(); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - $dropdown.find('li:first()').click(); + + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickHighlightedItem('product_id'); // set foo before onchange - form.$('input[name="foo"]').val("tralala").trigger('input'); + testUtils.fields.editInput(form.$('input[name="foo"]'), "tralala"); assert.strictEqual(form.$('input[name="foo"]').val(), 'tralala', 'input should contain tralala'); @@ -1230,12 +1230,11 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('input[name="foo"]').val(), 'yop', 'should contain the correct value'); - form.$('.o_field_many2one input').click(); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - $dropdown.find('li:first()').click(); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickHighlightedItem('product_id'); // set foo before onchange - form.$('input[name="foo"]').val("tralala").trigger('input'); + testUtils.fields.editInput(form.$('input[name="foo"]'), "tralala"); assert.strictEqual(form.$('input[name="foo"]').val(), 'tralala', 'input should contain tralala'); @@ -1265,9 +1264,9 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_char').text(), "***", "password field value should be hidden with '*' in read mode"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('input.o_field_char').attr('type'), 'password', + assert.hasAttrValue(form.$('input.o_field_char'), 'type', 'password', "password field input should be with type 'password' in edit mode"); assert.strictEqual(form.$('input.o_field_char').val(), 'yop', "password field input value should be the (non-hidden) password value"); @@ -1293,9 +1292,9 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_char').text(), "", "password field value should be empty in read mode"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('input.o_field_char').attr('type'), 'password', + assert.hasAttrValue(form.$('input.o_field_char'), 'type', 'password', "password field input should be with type 'password' in edit mode"); assert.strictEqual(form.$('input.o_field_char').val(), '', "password field input value should be the (non-hidden, empty) password value"); @@ -1322,30 +1321,30 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.strictEqual(form.$('a.o_form_uri.o_field_widget.o_text_overflow').length, 1, + assert.containsOnce(form, 'a.o_form_uri.o_field_widget.o_text_overflow', "should have a anchor with correct classes"); - assert.strictEqual(form.$('a.o_form_uri.o_field_widget.o_text_overflow').attr('href'), 'yop', + assert.hasAttrValue(form.$('a.o_form_uri.o_field_widget.o_text_overflow'), 'href', 'yop', "should have proper href link"); - assert.strictEqual(form.$('a.o_form_uri.o_field_widget.o_text_overflow').attr('target'), '_blank', + assert.hasAttrValue(form.$('a.o_form_uri.o_field_widget.o_text_overflow'), 'target', '_blank', "should have target attribute set to _blank"); assert.strictEqual(form.$('a.o_form_uri.o_field_widget.o_text_overflow').text(), 'yop', "the value should be displayed properly"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('input[type="text"].o_field_widget').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, 'input[type="text"].o_field_widget', "should have an input for the char field"); assert.strictEqual(form.$('input[type="text"].o_field_widget').val(), 'yop', "input should contain field value in edit mode"); // change value in edit mode - form.$('input[type="text"].o_field_widget').val('limbo').trigger('input'); + testUtils.fields.editInput(form.$('input[type="text"].o_field_widget'), 'limbo'); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('a.o_form_uri.o_field_widget.o_text_overflow').length, 1, + testUtils.form.clickSave(form); + assert.containsOnce(form, 'a.o_form_uri.o_field_widget.o_text_overflow', "should still have a anchor with correct classes"); - assert.strictEqual(form.$('a.o_form_uri.o_field_widget.o_text_overflow').attr('href'), 'limbo', + assert.hasAttrValue(form.$('a.o_form_uri.o_field_widget.o_text_overflow'), 'href', 'limbo', "should have proper new href link"); assert.strictEqual(form.$('a.o_form_uri.o_field_widget.o_text_overflow').text(), 'limbo', 'the new value should be displayed'); @@ -1383,28 +1382,28 @@ QUnit.module('basic_fields', { assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').length, 5, "should have 5 cells"); - assert.strictEqual(list.$('a.o_form_uri.o_field_widget.o_text_overflow').length, 5, + assert.containsN(list, 'a.o_form_uri.o_field_widget.o_text_overflow', 5, "should have 5 anchors with correct classes"); - assert.strictEqual(list.$('a.o_form_uri.o_field_widget.o_text_overflow').first().attr('href'), 'yop', + assert.hasAttrValue(list.$('a.o_form_uri.o_field_widget.o_text_overflow').first(), 'href', 'yop', "should have proper href link"); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yop', "value should be displayed properly as text"); // Edit a line and check the result var $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - $cell.click(); - assert.ok($cell.parent().hasClass('o_selected_row'), 'should be set as edit mode'); + testUtils.dom.click($cell); + assert.hasClass($cell.parent(),'o_selected_row', 'should be set as edit mode'); assert.strictEqual($cell.find('input').val(), 'yop', 'should have the corect value in internal input'); - $cell.find('input').val('brolo').trigger('input'); + testUtils.fields.editInput($cell.find('input'), 'brolo'); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - assert.ok(!$cell.parent().hasClass('o_selected_row'), 'should not be in edit mode anymore'); - assert.strictEqual(list.$('a.o_form_uri.o_field_widget.o_text_overflow').length, 5, + assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore'); + assert.containsN(list, 'a.o_form_uri.o_field_widget.o_text_overflow', 5, "should still have 5 anchors with correct classes"); - assert.strictEqual(list.$('a.o_form_uri.o_field_widget.o_text_overflow').first().attr('href'), 'brolo', + assert.hasAttrValue(list.$('a.o_form_uri.o_field_widget.o_text_overflow').first(), 'href', 'brolo', "should have proper new href link"); assert.strictEqual(list.$('a.o_form_uri.o_field_widget.o_text_overflow').first().text(), 'brolo', "value should be properly updated"); @@ -1446,8 +1445,8 @@ QUnit.module('basic_fields', { '</sheet>' + '</form>', }).then(function (form) { - assert.strictEqual(form.$('.o_clipboard_button.o_btn_text_copy').length, 1,"Should have copy button on text type field"); - assert.strictEqual(form.$('.o_clipboard_button.o_btn_char_copy').length, 1,"Should have copy button on char type field"); + assert.containsOnce(form, '.o_clipboard_button.o_btn_text_copy',"Should have copy button on text type field"); + assert.containsOnce(form, '.o_clipboard_button.o_btn_char_copy',"Should have copy button on char type field"); form.destroy(); done(); }); @@ -1473,19 +1472,19 @@ QUnit.module('basic_fields', { assert.ok(form.$('.o_field_text').length, "should have a text area"); assert.strictEqual(form.$('.o_field_text').text(), 'yop', 'should be "yop" in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var $textarea = form.$('textarea.o_field_text'); assert.ok($textarea.length, "should have a text area"); assert.strictEqual($textarea.val(), 'yop', 'should still be "yop" in edit'); - $textarea.val('hello').trigger('input'); + testUtils.fields.editInput($textarea, 'hello'); assert.strictEqual($textarea.val(), 'hello', 'should be "hello" after first edition'); - $textarea.val('hello world').trigger('input'); + testUtils.fields.editInput($textarea, 'hello world'); assert.strictEqual($textarea.val(), 'hello world', 'should be "hello world" after second edition'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_text').text(), 'hello world', 'should be "hello world" after save'); @@ -1512,7 +1511,7 @@ QUnit.module('basic_fields', { assert.strictEqual($field.outerHeight(), $field[0].scrollHeight, "text field should not have a scroll bar"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var $textarea = form.$('textarea:first'); @@ -1535,7 +1534,7 @@ QUnit.module('basic_fields', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var $textarea = form.$('textarea:first'); @@ -1564,7 +1563,7 @@ QUnit.module('basic_fields', { // the focus on the textarea by clicking on another column. // The main goal is to test the resize is actually triggered in this // particular case. - list.$('.o_data_cell:first').click(); + testUtils.dom.click(list.$('.o_data_cell:first')); var $textarea = list.$('textarea:first'); // make sure the correct data is there @@ -1602,9 +1601,9 @@ QUnit.module('basic_fields', { // edit the form // trigger a textarea reset (through onchange) by clicking the box // then check there is no scroll bar - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('div[name="bar"] input').click(); + testUtils.dom.click(form.$('div[name="bar"] input')); var $textarea = form.$('textarea:first'); assert.strictEqual($textarea.innerHeight(), $textarea[0].scrollHeight, @@ -1641,10 +1640,10 @@ QUnit.module('basic_fields', { return this._super.apply(this, arguments); }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var $button = form.$('textarea + .o_field_translate'); assert.strictEqual($button.length, 1, "should have a translate button"); - $button.click(); + testUtils.dom.click($button); form.destroy(); form = createView({ @@ -1681,7 +1680,7 @@ QUnit.module('basic_fields', { '</list>', }); - list.$('tbody tr:first .o_list_text').click(); + testUtils.dom.click(list.$('tbody tr:first .o_list_text')); var $textarea = list.$('textarea.o_field_text'); assert.strictEqual($textarea.length, 1, "should have a text area"); assert.strictEqual($textarea.val(), 'yop', 'should still be "yop" in edit'); @@ -1755,40 +1754,40 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 1, + assert.containsOnce(form, 'a.o_field_widget[name="document"] > .fa-download', "the binary field should be rendered as a downloadable link in readonly"); assert.strictEqual(form.$('a.o_field_widget[name="document"]').text().trim(), 'coucou.txt', "the binary field should display the name of the file in the link"); assert.strictEqual(form.$('.o_field_char').text(), 'coucou.txt', "the filename field should have the file name as value"); - form.$('a.o_field_widget[name="document"]').click(); + testUtils.dom.click(form.$('a.o_field_widget[name="document"]')); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 0, + assert.containsNone(form, 'a.o_field_widget[name="document"] > .fa-download', "the binary field should not be rendered as a downloadable link in edit"); assert.strictEqual(form.$('div.o_field_binary_file[name="document"] > input').val(), 'coucou.txt', "the binary field should display the file name in the input edit mode"); - assert.strictEqual(form.$('.o_field_binary_file > input').attr('readonly'), 'readonly', + assert.hasAttrValue(form.$('.o_field_binary_file > input'), 'readonly', 'readonly', "the input should be readonly"); - assert.strictEqual(form.$('.o_field_binary_file > .o_clear_file_button').length, 1, + assert.containsOnce(form, '.o_field_binary_file > .o_clear_file_button', "there shoud be a button to clear the file"); assert.strictEqual(form.$('input.o_field_char').val(), 'coucou.txt', "the filename field should have the file name as value"); - form.$('.o_field_binary_file > .o_clear_file_button').click(); + testUtils.dom.click(form.$('.o_field_binary_file > .o_clear_file_button')); - assert.ok(form.$('.o_field_binary_file > input').hasClass('o_hidden'), + assert.isNotVisible(form.$('.o_field_binary_file > input'), "the input should be hidden"); assert.strictEqual(form.$('.o_field_binary_file > .o_select_file_button:not(.o_hidden)').length, 1, "there shoud be a button to upload the file"); assert.strictEqual(form.$('input.o_field_char').val(), '', "the filename field should be empty since we removed the file"); - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 0, + testUtils.form.clickSave(form); + assert.containsNone(form, 'a.o_field_widget[name="document"] > .fa-download', "the binary field should not render as a downloadable link since we removed the file"); assert.strictEqual(form.$('a.o_field_widget[name="document"]').text().trim(), '', "the binary field should not display a filename in the link since we removed the file"); @@ -1830,16 +1829,14 @@ QUnit.module('basic_fields', { res_id: 1, }); - form.$buttons.find('.o_form_button_create').click(); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - - form.$('.o_field_many2one input').click(); - $dropdown.find('li:not(.o_m2o_dropdown_option):contains(xphone)').click(); + testUtils.form.clickCreate(form); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickHighlightedItem('product_id'); - assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 1, + assert.containsOnce(form, 'a.o_field_widget[name="document"] > .fa-download', 'The link to download the binary should be present'); - form.$('a.o_field_widget[name="document"]').click(); + testUtils.dom.click(form.$('a.o_field_widget[name="document"]')); assert.verifySteps([]); // We shoudln't have passed through steps @@ -1862,12 +1859,12 @@ QUnit.module('basic_fields', { '</form>', }); - assert.ok(form.$('.o_field_widget').hasClass('o_field_pdfviewer')); + assert.hasClass(form.$('.o_field_widget'), 'o_field_pdfviewer'); assert.strictEqual(form.$('.o_select_file_button:not(.o_hidden)').length, 1, "there should be a visible 'Upload' button"); - assert.ok(form.$('.o_field_widget iframe.o_pdfview_iframe').hasClass('o_hidden'), + assert.isNotVisible(form.$('.o_field_widget iframe.o_pdfview_iframe'), "there should be an invisible iframe"); - assert.strictEqual(form.$('input[type="file"]').length, 1, + assert.containsOnce(form, 'input[type="file"]', "there should be one input"); form.destroy(); @@ -1893,12 +1890,12 @@ QUnit.module('basic_fields', { } }); - assert.ok(form.$('.o_field_widget').hasClass('o_field_pdfviewer')); + assert.hasClass(form.$('.o_field_widget'), 'o_field_pdfviewer'); assert.strictEqual(form.$('.o_select_file_button:not(.o_hidden)').length, 0, "there should not be a any visible 'Upload' button"); - assert.notOk(form.$('.o_field_widget iframe.o_pdfview_iframe').hasClass('o_hidden'), + assert.isVisible(form.$('.o_field_widget iframe.o_pdfview_iframe'), "there should be an visible iframe"); - assert.strictEqual(form.$('.o_field_widget iframe.o_pdfview_iframe').attr('data-src'), + assert.hasAttrValue(form.$('.o_field_widget iframe.o_pdfview_iframe'), 'data-src', '/web/static/lib/pdfjs/web/viewer.html?file=%2Fweb%2Fimage%3Fmodel%3Dpartner%26field%3Ddocument%26id%3D1#page=1', "the src attribute should be correctly set on the iframe"); @@ -1908,7 +1905,7 @@ QUnit.module('basic_fields', { QUnit.test("pdf_viewer: upload rendering", function (assert) { assert.expect(6); - testUtils.patch(field_registry.map.pdf_viewer, { + testUtils.mock.patch(field_registry.map.pdf_viewer, { on_file_change: function (ev) { ev.target = {files: [new Blob()]}; this._super.apply(this, arguments); @@ -1944,7 +1941,7 @@ QUnit.module('basic_fields', { form.$('input[type="file"]').trigger('change'); assert.verifySteps(['_getURI', 'open']); - testUtils.unpatch(field_registry.map.pdf_viewer); + testUtils.mock.unpatch(field_registry.map.pdf_viewer); form.destroy(); }); @@ -1983,7 +1980,7 @@ QUnit.module('basic_fields', { '</tree>', }); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); assert.strictEqual(list.$('textarea').first().get(0), document.activeElement, "text area should have the focus"); @@ -2016,12 +2013,12 @@ QUnit.module('basic_fields', { def.resolve(); }; - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('textarea').val("1").trigger('input'); + testUtils.fields.editInput(form.$('textarea').first(), "1"); assert.strictEqual(nbNotifyChanges, 0, "no event should have been triggered"); - form.$('textarea').val("12").trigger('input'); + testUtils.fields.editInput(form.$('textarea').first(), "12"); assert.strictEqual(nbNotifyChanges, 0, "no event should have been triggered"); @@ -2030,7 +2027,7 @@ QUnit.module('basic_fields', { "one event should have been triggered"); // add something in the textarea, then focus another input - form.$('textarea').first().val("123").trigger('input'); + testUtils.fields.editInput(form.$('textarea').first(), "123"); form.$('textarea').first().change(); assert.strictEqual(nbNotifyChanges, 2, "one event should have been triggered immediately"); @@ -2080,13 +2077,13 @@ QUnit.module('basic_fields', { }, }); - assert.ok(form.$('div[name="document"]').hasClass('o_field_image'), + assert.hasClass(form.$('div[name="document"]'),'o_field_image', "the widget should have the correct class"); - assert.strictEqual(form.$('div[name="document"] > img').length, 1, + assert.containsOnce(form, 'div[name="document"] > img', "the widget should contain an image"); - assert.ok(form.$('div[name="document"] > img').hasClass('img-fluid'), + assert.hasClass(form.$('div[name="document"] > img'),'img-fluid', "the image should have the correct class"); - assert.strictEqual(form.$('div[name="document"] > img').attr('width'), "90", + assert.hasAttrValue(form.$('div[name="document"] > img'), 'width', "90", "the image should correctly set its attributes"); assert.strictEqual(form.$('div[name="document"] > img').css('max-width'), "90px", "the image should correctly set its attributes"); @@ -2132,11 +2129,11 @@ QUnit.module('basic_fields', { }); assert.verifySteps(["The view's image should have been fetched"]); - assert.strictEqual(form.$('tr.o_data_row').length, 1, + assert.containsOnce(form, 'tr.o_data_row', 'There should be one record in the many2many'); // Actual flow: click on an element of the m2m to get its form view - form.$('tbody td:contains(gold)').click(); + testUtils.dom.click(form.$('tbody td:contains(gold)')); assert.strictEqual($('.modal').length, 1, 'The modal should have opened'); assert.verifySteps([ @@ -2175,7 +2172,7 @@ QUnit.module('basic_fields', { }, }); - assert.strictEqual(form.$('tr.o_data_row').length, 1, + assert.containsOnce(form, 'tr.o_data_row', 'There should be one record in the many2many'); form.destroy(); @@ -2199,11 +2196,11 @@ QUnit.module('basic_fields', { }, }); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); - assert.ok(form.$('.o_form_view').hasClass('o_form_editable'), + assert.hasClass(form.$('.o_form_view'),'o_form_editable', "form view should still be editable"); - assert.ok(form.$('.o_field_widget').hasClass('o_field_invalid'), + assert.hasClass(form.$('.o_field_widget'),'o_field_invalid', "image field should be displayed as invalid"); form.destroy(); @@ -2251,7 +2248,7 @@ QUnit.module('basic_fields', { var done = assert.async(); assert.expect(6); - testUtils.patch(JournalDashboardGraph, { + testUtils.mock.patch(JournalDashboardGraph, { on_attach_callback: function () { assert.step('on_attach_callback'); }, @@ -2289,7 +2286,7 @@ QUnit.module('basic_fields', { ]); kanban.destroy(); - testUtils.unpatch(JournalDashboardGraph); + testUtils.mock.unpatch(JournalDashboardGraph); done(); }); }); @@ -2354,7 +2351,7 @@ QUnit.module('basic_fields', { // when being destroyed before nv has been loaded assert.expect(2); - testUtils.patch(basicFields.JournalDashboardGraph, { + testUtils.mock.patch(basicFields.JournalDashboardGraph, { destroy: function () { assert.step('destroy'); var nv = window.nv; @@ -2380,7 +2377,7 @@ QUnit.module('basic_fields', { }); kanban.destroy(); - testUtils.unpatch(basicFields.JournalDashboardGraph); + testUtils.mock.unpatch(basicFields.JournalDashboardGraph); assert.verifySteps(['destroy']); @@ -2393,7 +2390,7 @@ QUnit.module('basic_fields', { // when being destroyed before nv has been completely loaded assert.expect(2); - testUtils.patch(basicFields.JournalDashboardGraph, { + testUtils.mock.patch(basicFields.JournalDashboardGraph, { destroy: function () { assert.step('destroy'); // nv is fully loaded only when nvd3.js has been loaded @@ -2422,7 +2419,7 @@ QUnit.module('basic_fields', { }); kanban.destroy(); - testUtils.unpatch(basicFields.JournalDashboardGraph); + testUtils.mock.unpatch(basicFields.JournalDashboardGraph); assert.verifySteps(['destroy']); @@ -2452,14 +2449,14 @@ QUnit.module('basic_fields', { concurrency.delay(0).then(function () { return concurrency.delay(0); }).then(function () { - assert.strictEqual(kanban.$('.o_dashboard_graph svg').length, 2, "there should be two graph rendered"); + assert.containsN(kanban, '.o_dashboard_graph svg', 2, "there should be two graph rendered"); return kanban.update({}); }).then(function () { return concurrency.delay(0); // one graph is re-rendered }).then(function () { return concurrency.delay(0); // one graph is re-rendered }).then(function () { - assert.strictEqual(kanban.$('.o_dashboard_graph svg').length, 2, "there should be one graph rendered"); + assert.containsN(kanban, '.o_dashboard_graph svg', 2, "there should be one graph rendered"); kanban.destroy(); done(); }); @@ -2488,12 +2485,12 @@ QUnit.module('basic_fields', { concurrency.delay(0).then(function () { return concurrency.delay(0); }).then(function () { - assert.strictEqual(kanban.$('.o_dashboard_graph svg').length, 2, "there should be two graph rendered"); + assert.containsN(kanban, '.o_dashboard_graph svg', 2, "there should be two graph rendered"); return kanban.update({groupBy: ['selection'], domain: [['int_field', '=', 10]]}); }).then(function () { return concurrency.delay(0); }).then(function () { - assert.strictEqual(kanban.$('.o_dashboard_graph svg').length, 1, "there should be one graph rendered"); + assert.containsOnce(kanban, '.o_dashboard_graph svg', "there should be one graph rendered"); kanban.destroy(); done(); }); @@ -2550,18 +2547,18 @@ QUnit.module('basic_fields', { assert.notOk(form.$('td span.o_row_handle').is(':visible'), "handle should be invisible in readonly mode"); - assert.strictEqual(form.$('span.o_row_handle').length, 2, "should have 2 handles"); + assert.containsN(form, 'span.o_row_handle', 2, "should have 2 handles"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.ok(form.$('td:first').hasClass('o_handle_cell'), + assert.hasClass(form.$('td:first'),'o_handle_cell', "column widget should be displayed in css class"); assert.ok(form.$('td span.o_row_handle').is(':visible'), "handle should be visible in readonly mode"); - form.$('td').eq(1).click(); - assert.strictEqual(form.$('td:first span.o_row_handle').length, 1, + testUtils.dom.click(form.$('td').eq(1)); + assert.containsOnce(form, 'td:first span.o_row_handle', "content of the cell should have been replaced"); form.destroy(); }); @@ -2579,7 +2576,7 @@ QUnit.module('basic_fields', { '</tree>', }); - assert.strictEqual(list.$('.o_row_handle:visible').length, this.data.partner.records.length, + assert.containsN(list, '.o_row_handle:visible', this.data.partner.records.length, 'there should be a visible handle for each record'); list.destroy(); }); @@ -2603,13 +2600,13 @@ QUnit.module('basic_fields', { assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 0, "datepicker should be closed initially"); - testUtils.openDatepicker(form.$('.o_datepicker')); + testUtils.dom.openDatepicker(form.$('.o_datepicker')); assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 1, "datepicker should be opened"); // focus another field - form.$('.o_field_widget[name=foo]').click().focus(); + testUtils.dom.click(form.$('.o_field_widget[name=foo]').focus().mouseenter()); assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 0, "datepicker should close itself when the user clicks outside"); @@ -2644,15 +2641,15 @@ QUnit.module('basic_fields', { res_id: 4, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // open datepicker and select a date - testUtils.openDatepicker(form.$('.o_datepicker')); + testUtils.dom.openDatepicker(form.$('.o_datepicker')); assert.strictEqual(form.$('.o_datepicker_input').val(), '', "date field's input should be empty on first click"); - $('.day:contains(22)').click(); + testUtils.dom.click($('.day:contains(22)')); // re-open datepicker - testUtils.openDatepicker(form.$('.o_datepicker')); + testUtils.dom.openDatepicker(form.$('.o_datepicker')); assert.strictEqual($('.day.active').text(), '22', "datepicker should be highlight with 22nd day of month"); @@ -2688,25 +2685,25 @@ QUnit.module('basic_fields', { 'the date should be correctly displayed in readonly'); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_datepicker_input').val(), '02/03/2017', 'the date should be correct in edit mode'); // open datepicker and select another value - testUtils.openDatepicker(form.$('.o_datepicker')); + testUtils.dom.openDatepicker(form.$('.o_datepicker')); assert.ok($('.bootstrap-datetimepicker-widget').length, 'datepicker should be open'); assert.strictEqual($('.day.active').data('day'), '02/03/2017', 'datepicker should be highlight February 3'); - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Month selection - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Year selection - $('.bootstrap-datetimepicker-widget .year:contains(2017)').click(); - $('.bootstrap-datetimepicker-widget .month').eq(1).click(); // February - $('.day:contains(22)').click(); // select the 22 February + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch').first()); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch:eq(1)').first()); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .year:contains(2017)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .month').eq(1)); + testUtils.dom.click($('.day:contains(22)')); assert.ok(!$('.bootstrap-datetimepicker-widget').length, 'datepicker should be closed'); assert.strictEqual(form.$('.o_datepicker_input').val(), '02/22/2017', 'the selected date should be displayed in the input'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_date').text(), '02/22/2017', 'the selected date should be displayed after saving'); form.destroy(); @@ -2735,7 +2732,7 @@ QUnit.module('basic_fields', { 'the date should be correctly displayed in readonly'); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_datepicker_input').val(), '02/03/2017', 'the date should be correct in edit mode'); @@ -2756,19 +2753,19 @@ QUnit.module('basic_fields', { }); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // open datepicker and select another value - testUtils.openDatepicker(form.$('.o_datepicker')); - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Month selection - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Year selection - $('.bootstrap-datetimepicker-widget .year').eq(11).click(); // last year - $('.bootstrap-datetimepicker-widget .month').eq(11).click(); // December - $('.day:contains(31)').click(); // select the 31 December + testUtils.dom.openDatepicker(form.$('.o_datepicker')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch').first()); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch:eq(1)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .year').eq(11)); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .month').eq(11)); + testUtils.dom.click($('.day:contains(31)')); var $warn = form.$('.o_datepicker_warning:visible'); assert.strictEqual($warn.length, 1, "should have a warning in the form view"); - form.$('.o_field_widget[name=date] input').val('').trigger('change'); // remove the value + testUtils.fields.editSelect(form.$('.o_field_widget[name=date] input'), ''); // remove the value $warn = form.$('.o_datepicker_warning:visible'); assert.strictEqual($warn.length, 0, "the warning in the form view should be hidden"); @@ -2799,9 +2796,9 @@ QUnit.module('basic_fields', { var $cell = list.$('tr.o_data_row td:not(.o_list_record_selector)').first(); assert.strictEqual($cell.text(), '02/03/2017', 'the date should be displayed correctly in readonly'); - $cell.click(); + testUtils.dom.click($cell); - assert.strictEqual(list.$('input.o_datepicker_input').length, 1, + assert.containsOnce(list, 'input.o_datepicker_input', "the view should have a date input for editable mode"); assert.strictEqual(list.$('input.o_datepicker_input').get(0), document.activeElement, @@ -2811,19 +2808,19 @@ QUnit.module('basic_fields', { 'the date should be correct in edit mode'); // open datepicker and select another value - testUtils.openDatepicker(list.$('.o_datepicker')); + testUtils.dom.openDatepicker(list.$('.o_datepicker')); assert.ok($('.bootstrap-datetimepicker-widget').length, 'datepicker should be open'); - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Month selection - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Year selection - $('.bootstrap-datetimepicker-widget .year:contains(2017)').click(); - $('.bootstrap-datetimepicker-widget .month').eq(1).click(); // February - $('.day:contains(22)').click(); // select the 22 February + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch').first()); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch:eq(1)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .year:contains(2017)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .month').eq(1)); + testUtils.dom.click($('.day:contains(22)')); assert.ok(!$('.bootstrap-datetimepicker-widget').length, 'datepicker should be closed'); assert.strictEqual(list.$('.o_datepicker_input').val(), '02/22/2017', 'the selected date should be displayed in the input'); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('tr.o_data_row td:not(.o_list_record_selector)').text(), '02/22/2017', 'the selected date should be displayed after saving'); @@ -2851,16 +2848,16 @@ QUnit.module('basic_fields', { }); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_datepicker_input').val(), '02/03/2017', 'the date should be correct in edit mode'); - form.$('.o_datepicker_input').val('').trigger('input').trigger('change').trigger('focusout'); + testUtils.fields.editAndTrigger(form.$('.o_datepicker_input'), '', ['input', 'change', 'focusout']); assert.strictEqual(form.$('.o_datepicker_input').val(), '', 'should have correctly removed the value'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_date').text(), '', 'the selected date should be displayed after saving'); @@ -2892,9 +2889,8 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_datepicker_input').val(), '02/08/2017', 'the date should be correct'); - form.$('input[name="datetime"]').val('02/08/2017') - .trigger('input').trigger('change').trigger('focusout'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editAndTrigger(form.$('input[name="datetime"]'),'02/08/2017', ['input', 'change', 'focusout']); + testUtils.form.clickSave(form); assert.verifySteps(['read']); // should not have save as nothing changed @@ -2928,24 +2924,23 @@ QUnit.module('basic_fields', { 'the datetime should be correctly displayed in readonly'); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_datepicker_input').val(), expectedDateString, 'the datetime should be correct in edit mode'); // select 22 February at 8:23:33 assert.ok($('.bootstrap-datetimepicker-widget').length, 'datepicker should be open'); - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Month selection - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Year selection - $('.bootstrap-datetimepicker-widget .year:contains(2017)').click(); - $('.bootstrap-datetimepicker-widget .month').eq(3).click(); // April - $('.bootstrap-datetimepicker-widget .day:contains(22)').click(); - $('.bootstrap-datetimepicker-widget .fa-clock-o').click(); - $('.bootstrap-datetimepicker-widget .timepicker-hour').click(); - $('.bootstrap-datetimepicker-widget .hour:contains(08)').click(); - $('.bootstrap-datetimepicker-widget .timepicker-minute').click(); - $('.bootstrap-datetimepicker-widget .minute:contains(25)').click(); - $('.bootstrap-datetimepicker-widget .timepicker-second').click(); - $('.bootstrap-datetimepicker-widget .second:contains(35)').click(); - $('.bootstrap-datetimepicker-widget .fa-times').click(); // close + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch').first()); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch:eq(1)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .year:contains(2017)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .month').eq(3)); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .day:contains(22)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .fa-clock-o')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker-hour')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .hour:contains(08)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker-minute')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .minute:contains(25)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker-second')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .second:contains(35)')); assert.ok(!$('.bootstrap-datetimepicker-widget').length, 'datepicker should be closed'); var newExpectedDateString = "04/22/2017 08:25:35"; @@ -2953,7 +2948,7 @@ QUnit.module('basic_fields', { 'the selected date should be displayed in the input'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_date').text(), newExpectedDateString, 'the selected date should be displayed after saving'); @@ -3006,7 +3001,7 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_date input').val(), expectedDateString, 'the datetime should be correctly displayed in readonly'); - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.form.clickDiscard(form); assert.strictEqual($('.modal').length, 0, "there should not be a Warning dialog"); @@ -3041,8 +3036,8 @@ QUnit.module('basic_fields', { 'the datetime should be correctly displayed in readonly'); // switch to edit mode - $cell.click(); - assert.strictEqual(list.$('input.o_datepicker_input').length, 1, + testUtils.dom.click($cell); + assert.containsOnce(list, 'input.o_datepicker_input', "the view should have a date input for editable mode"); assert.strictEqual(list.$('input.o_datepicker_input').get(0), document.activeElement, @@ -3053,19 +3048,18 @@ QUnit.module('basic_fields', { // select 22 February at 8:23:33 assert.ok($('.bootstrap-datetimepicker-widget').length, 'datepicker should be open'); - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Month selection - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Year selection - $('.bootstrap-datetimepicker-widget .year:contains(2017)').click(); - $('.bootstrap-datetimepicker-widget .month').eq(3).click(); // April - $('.bootstrap-datetimepicker-widget .day:contains(22)').click(); - $('.bootstrap-datetimepicker-widget .fa-clock-o').click(); - $('.bootstrap-datetimepicker-widget .timepicker-hour').click(); - $('.bootstrap-datetimepicker-widget .hour:contains(08)').click(); - $('.bootstrap-datetimepicker-widget .timepicker-minute').click(); - $('.bootstrap-datetimepicker-widget .minute:contains(25)').click(); - $('.bootstrap-datetimepicker-widget .timepicker-second').click(); - $('.bootstrap-datetimepicker-widget .second:contains(35)').click(); - $('.bootstrap-datetimepicker-widget .fa-times').click(); // close + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch').first()); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch:eq(1)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .year:contains(2017)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .month').eq(3)); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .day:contains(22)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .fa-clock-o')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker-hour')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .hour:contains(08)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker-minute')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .minute:contains(25)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker-second')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .second:contains(35)')); assert.ok(!$('.bootstrap-datetimepicker-widget').length, 'datepicker should be closed'); var newExpectedDateString = "04/22/2017 08:25:35"; @@ -3073,7 +3067,7 @@ QUnit.module('basic_fields', { 'the selected datetime should be displayed in the input'); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('tr.o_data_row td:not(.o_list_record_selector)').text(), newExpectedDateString, 'the selected datetime should be displayed after saving'); @@ -3107,16 +3101,16 @@ QUnit.module('basic_fields', { }); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_datepicker_input').val(), '02/08/2017 12:00:00', 'the date time should be correct in edit mode'); - $('.o_datepicker_input').val('').trigger('input').trigger('change').trigger('focusout'); + testUtils.fields.editAndTrigger($('.o_datepicker_input'), '', ['input', 'change', 'focusout']); assert.strictEqual(form.$('.o_datepicker_input').val(), '', "should have an empty input"); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_date').text(), '', 'the selected date should be displayed after saving'); @@ -3160,7 +3154,7 @@ QUnit.module('basic_fields', { 'the datetime (datetime widget) should be correctly displayed in tree view'); // switch to form view - form.$('.o_field_widget[name=p] .o_data_row').click(); + testUtils.dom.click(form.$('.o_field_widget[name=p] .o_data_row')); assert.strictEqual($('.modal .o_field_date[name=datetime]').text(), '02/07/2017', 'the datetime (date widget) should be correctly displayed in form view'); @@ -3204,7 +3198,7 @@ QUnit.module('basic_fields', { 'the datetime (datetime widget) should be correctly displayed in tree view'); // switch to form view - form.$('.o_field_widget[name=p] .o_data_row').click(); + testUtils.dom.click(form.$('.o_field_widget[name=p] .o_data_row')); assert.strictEqual($('.modal .o_field_date[name=datetime]').text(), '02/08/2017', 'the datetime (date widget) should be correctly displayed in form view'); @@ -3212,7 +3206,7 @@ QUnit.module('basic_fields', { }); QUnit.test('datepicker option: daysOfWeekDisabled', function (assert) { - assert.expect(2); + assert.expect(42); this.data.partner.fields.datetime.default = "2017-08-02 12:00:05"; this.data.partner.fields.datetime.required = true; @@ -3228,12 +3222,16 @@ QUnit.module('basic_fields', { res_id: 1, }); - form.$buttons.find('.o_form_button_create').click(); - assert.ok($('.day:last-child(),.day:nth-child(2)').hasClass('disabled'), - 'first and last days must be disabled'); - assert.notOk($('.day:not(:last-child()):not(:nth-child(2))').hasClass('disabled'), - 'other days must stay clickable'); - + testUtils.form.clickCreate(form); + $.each($('.day:last-child(),.day:nth-child(2)'), function (index, value) { + assert.hasClass(value, 'disabled', 'first and last days must be disabled'); + }); + // the assertions below could be replaced by a single hasClass classic on the jQuery set using the idea + // All not <=> not Exists. But we want to be sure that the set is non empty. We don't have an helper + // function for that. + $.each($('.day:not(:last-child()):not(:nth-child(2))'), function (index, value) { + assert.doesNotHaveClass(value, 'disabled', 'other days must stay clickable'); + }); form.destroy(); }); @@ -3262,17 +3260,17 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a09.10', 'The value should be displayed properly.'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), '9.10', 'The input should be rendered without the currency symbol.'); assert.strictEqual(form.$('input').parent().children().first().text(), '$', 'The input should be preceded by a span containing the currency symbol.'); - form.$('input').val('108.2458938598598').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_monetary input'), '108.2458938598598'); assert.strictEqual(form.$('input').val(), '108.2458938598598', 'The value should not be formated yet.'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); // Non-breaking space between the currency and the amount assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0108.25', 'The new value should be rounded properly.'); @@ -3303,17 +3301,17 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_widget').first().text(), '0.00\u00a0€', 'The value should be displayed properly.'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').first().val(), '0.00', 'The input should be rendered without the currency symbol.'); assert.strictEqual(form.$('input').parent().children().eq(1).text(), '€', 'The input should be followed by a span containing the currency symbol.'); - form.$('input').first().val('108.2458938598598').trigger('input'); + testUtils.fields.editInput(form.$('input').first(), '108.2458938598598'); assert.strictEqual(form.$('input').first().val(), '108.2458938598598', 'The value should not be formated yet.'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); // Non-breaking space between the currency and the amount assert.strictEqual(form.$('.o_field_widget').first().text(), '108.25\u00a0€', 'The new value should be rounded properly.'); @@ -3360,17 +3358,17 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_widget').first().text(), '99.1234\u00a0Bs.F', 'The value should be displayed properly.'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').first().val(), '99.1234', 'The input should be rendered without the currency symbol.'); assert.strictEqual(form.$('input').parent().children().eq(1).text(), 'Bs.F', 'The input should be followed by a span containing the currency symbol.'); - form.$('input').first().val('99.111111111').trigger('input'); + testUtils.fields.editInput(form.$('input').first(), '99.111111111'); assert.strictEqual(form.$('input').first().val(), '99.111111111', 'The value should not be formated yet.'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); // Non-breaking space between the currency and the amount assert.strictEqual(form.$('.o_field_widget').first().text(), '99.1111\u00a0Bs.F', 'The new value should be rounded properly.'); @@ -3408,22 +3406,22 @@ QUnit.module('basic_fields', { // switch to edit mode var $cell = list.$('tr.o_data_row td:not(.o_list_record_selector):contains($)'); - $cell.click(); + testUtils.dom.click($cell); assert.strictEqual($cell.children().length, 1, 'The cell td should only contain the special div of monetary widget.'); - assert.strictEqual(list.$('[name="qux"] input').length, 1, + assert.containsOnce(list, '[name="qux"] input', 'The view should have 1 input for editable monetary float.'); assert.strictEqual(list.$('[name="qux"] input').val(), '9.10', 'The input should be rendered without the currency symbol.'); assert.strictEqual(list.$('[name="qux"] input').parent().children().first().text(), '$', 'The input should be preceded by a span containing the currency symbol.'); - list.$('[name="qux"] input').val('108.2458938598598').trigger('input'); + testUtils.fields.editInput(list.$('[name="qux"] input'), '108.2458938598598'); assert.strictEqual(list.$('[name="qux"] input').val(), '108.2458938598598', 'The typed value should be correctly displayed.'); - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('tr.o_data_row td:not(.o_list_record_selector):contains($)').text(), '$\u00a0108.25', 'The new value should be rounded properly.'); @@ -3469,20 +3467,19 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_monetary').first().next().html(), "$ 4.20", "readonly value should contain the currency"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_monetary > input').val(), "9.10", "input value in edition should only contain the value, without the currency"); - form.$('input[type="checkbox"]').click(); // Change the field on which the monetary depends - assert.strictEqual(form.$('.o_field_monetary > input').length, 1, + testUtils.dom.click(form.$('input[type="checkbox"]')); + assert.containsOnce(form, '.o_field_monetary > input', "After the onchange, the monetary <input/> should not have been duplicated"); - assert.strictEqual(form.$('.o_field_monetary[name=quux]').length, 1, + assert.containsOnce(form, '.o_field_monetary[name=quux]', "After the onchange, the monetary readonly field should not have been duplicated"); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').click(); - $dropdown.find('li:not(.o_m2o_dropdown_option):last').mouseenter().click(); + testUtils.fields.many2one.clickOpenDropdown('currency_id'); + testUtils.fields.many2one.clickItem('currency_id','€'); assert.strictEqual(form.$('.o_field_monetary > span').html(), "€", "After currency change, the monetary field currency should have been updated"); assert.strictEqual(form.$('.o_field_monetary').first().next().html(), "4.20 €", @@ -3552,30 +3549,30 @@ QUnit.module('basic_fields', { // test the monetary field inside the one2many var $o2m = form.$('.o_field_widget[name=p]'); - $o2m.find('.o_field_x2many_list_row_add a').click(); - $o2m.find('.o_field_widget input').val("22").trigger('input'); + testUtils.dom.click($o2m.find('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput($o2m.find('.o_field_widget input'), "22"); assert.strictEqual($o2m.find('.o_field_widget input').get(0), document.activeElement, "the focus should still be on the input"); assert.strictEqual($o2m.find('.o_field_widget input').val(), "22", "the value should not have been formatted yet"); - form.$el.click(); // focusout the input + testUtils.dom.click(form.$el); assert.strictEqual($o2m.find('.o_field_widget[name=qux]').html(), "$ 22.00", "the value should have been formatted after losing the focus"); // test the monetary field inside the many2many var $m2m = form.$('.o_field_widget[name=m2m]'); - $m2m.find('.o_data_row td:first').click(); - $m2m.find('.o_field_widget input').val("22").trigger('input'); + testUtils.dom.click($m2m.find('.o_data_row td:first')); + testUtils.fields.editInput($m2m.find('.o_field_widget input'), "22"); assert.strictEqual($m2m.find('.o_field_widget input').get(0), document.activeElement, "the focus should still be on the input"); assert.strictEqual($m2m.find('.o_field_widget input').val(), "22", "the value should not have been formatted yet"); - form.$el.click(); // focusout the input + testUtils.dom.click(form.$el); assert.strictEqual($m2m.find('.o_field_widget[name=qux]').html(), "22.00 €", "the value should have been formatted after losing the focus"); @@ -3583,7 +3580,7 @@ QUnit.module('basic_fields', { form.destroy(); }); - QUnit.test('monetary field with currency set by an onchange', function (assert) { + QUnit.test('monetary field with currency set by an onchange',async function (assert) { // this test ensures that the monetary field can be re-rendered with and // without currency (which can happen as the currency can be set by an // onchange) @@ -3609,31 +3606,33 @@ QUnit.module('basic_fields', { }, }); - list.$buttons.find('.o_list_button_add').click(); - assert.strictEqual(list.$('div.o_field_widget[name=qux] input').length, 1, + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); + assert.containsOnce(list, 'div.o_field_widget[name=qux] input', "monetary field should have been rendered correctly (without currency)"); - assert.strictEqual(list.$('.o_field_widget[name=qux] span').length, 0, + assert.containsNone(list, '.o_field_widget[name=qux] span', "monetary field should have been rendered correctly (without currency)"); // set a value for int_field -> should set the currency and re-render qux - list.$('.o_field_widget[name=int_field]').click().val('7').trigger('input'); - assert.strictEqual(list.$('div.o_field_widget[name=qux] input').length, 1, + testUtils.fields.editInput(list.$('.o_field_widget[name=int_field]'),'7'); + assert.containsOnce(list, 'div.o_field_widget[name=qux] input', "monetary field should have been re-rendered correctly (with currency)"); assert.strictEqual(list.$('.o_field_widget[name=qux] span:contains(€)').length, 1, "monetary field should have been re-rendered correctly (with currency)"); var $quxInput = list.$('.o_field_widget[name=qux] input'); - $quxInput.click(); // check that the field is focusable + testUtils.dom.click($quxInput); assert.strictEqual(document.activeElement, $quxInput[0], "focus should be on the qux field's input"); // unset the value of int_field -> should unset the currency and re-render qux - list.$('.o_field_widget[name=int_field]').click().val('0').trigger('input'); + testUtils.dom.click(list.$('.o_field_widget[name=int_field]')); + testUtils.fields.editInput(list.$('.o_field_widget[name=int_field]'),'0'); $quxInput = list.$('div.o_field_widget[name=qux] input'); assert.strictEqual($quxInput.length, 1, "monetary field should have been re-rendered correctly (without currency)"); - assert.strictEqual(list.$('.o_field_widget[name=qux] span').length, 0, + assert.containsNone(list, '.o_field_widget[name=qux] span', "monetary field should have been re-rendered correctly (without currency)"); - $quxInput.click(); // check that the field is still focusable + await concurrency.delay(0); + testUtils.dom.click($quxInput); assert.strictEqual(document.activeElement, $quxInput[0], "focus should be on the qux field's input"); @@ -3653,7 +3652,7 @@ QUnit.module('basic_fields', { res_id: 4, }); - assert.notOk(form.$('.o_field_widget').hasClass('o_field_empty'), + assert.doesNotHaveClass(form.$('.o_field_widget'), 'o_field_empty', 'Non-set integer field should be recognized as 0.'); assert.strictEqual(form.$('.o_field_widget').text(), "0", 'Non-set integer field should be recognized as 0.'); @@ -3672,18 +3671,18 @@ QUnit.module('basic_fields', { res_id: 2, }); - assert.ok(!form.$('.o_field_widget').hasClass('o_field_empty'), + assert.doesNotHaveClass(form.$('.o_field_widget'), 'o_field_empty', 'Integer field should be considered set for value 0.'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), '0', 'The value should be rendered correctly in edit mode.'); - form.$('input').val('-18').trigger('input'); + testUtils.fields.editInput(form.$('input'), '-18'); assert.strictEqual(form.$('input').val(), '-18', 'The value should be correctly displayed in the input.'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').text(), '-18', 'The new value should be saved and displayed properly.'); @@ -3725,16 +3724,16 @@ QUnit.module('basic_fields', { // switch to edit mode var $cell = list.$('tr.o_data_row td:not(.o_list_record_selector)').first(); - $cell.click(); + testUtils.dom.click($cell); - assert.strictEqual(list.$('input[name="int_field"]').length, 1, + assert.containsOnce(list, 'input[name="int_field"]', 'The view should have 1 input for editable integer.'); - list.$('input[name="int_field"]').val('-28').trigger('input'); + testUtils.fields.editInput(list.$('input[name="int_field"]'), '-28'); assert.strictEqual(list.$('input[name="int_field"]').val(), '-28', 'The value should be displayed properly in the input.'); - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('td:not(.o_list_record_selector)').first().text(), '-28', 'The new value should be saved and displayed properly.'); @@ -3758,18 +3757,18 @@ QUnit.module('basic_fields', { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(form.$('.o_field_widget')[0].hasAttribute('type'), 'Integer field with option type must have a type attribute.'); - assert.strictEqual(form.$('.o_field_widget').attr('type'), 'number', + assert.hasAttrValue(form.$('.o_field_widget'), 'type', 'number', 'Integer field with option type must have a type attribute equals to "number".'); - form.$('input').val('1234567890').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.fields.editInput(form.$('input'), '1234567890'); + testUtils.form.clickSave(form); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget').val(), '1234567890', 'Integer value must be not formatted if input type is number.'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').text(), '1,234,567,890', 'Integer value must be formatted in readonly view even if the input type is number.'); @@ -3793,13 +3792,13 @@ QUnit.module('basic_fields', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_widget').attr('type'), 'text', + testUtils.form.clickEdit(form); + assert.hasAttrValue(form.$('.o_field_widget'), 'type', 'text', 'Integer field without option type must have a text type (default type).'); - form.$('input').val('1234567890').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.fields.editInput(form.$('input'), '1234567890'); + testUtils.form.clickSave(form); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget').val(), '1,234,567,890', 'Integer value must be formatted if input type isn\'t number.'); @@ -3835,15 +3834,15 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_widget').first().text(), '09:06', 'The formatted time value should be displayed properly.'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), '09:06', 'The value should be rendered correctly in the input.'); - form.$('input').val('-11:48').trigger('input'); + testUtils.fields.editInput(form.$('input'), '-11:48'); assert.strictEqual(form.$('input').val(), '-11:48', 'The new value should be displayed properly in the input.'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').first().text(), '-11:48', 'The new value should be saved and displayed properly.'); @@ -3877,13 +3876,13 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_widget').first().text(), '4.55', // 9.1 / 0.5 'The formatted value should be displayed properly.'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), '4.55', 'The value should be rendered correctly in the input.'); - form.$('input').val('2.3').trigger('input'); + testUtils.fields.editInput(form.$('input'), '2.3'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').first().text(), '2.30', 'The new value should be saved and displayed properly.'); @@ -3916,17 +3915,17 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_widget').first().text(), '0.056', 'The formatted time value should be displayed properly.'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('button.o_field_float_toggle').text(), '0.056', 'The value should be rendered correctly on the button.'); - form.$('button.o_field_float_toggle').click(); // clicking will make the next value 1, since 0 was the closest of 0.056 + testUtils.dom.click(form.$('button.o_field_float_toggle')); assert.strictEqual(form.$('button.o_field_float_toggle').text(), '1.000', 'The value should be rendered correctly on the button.'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').first().text(), '1.000', 'The new value should be saved and displayed properly.'); @@ -3966,17 +3965,17 @@ QUnit.module('basic_fields', { "value should be displayed properly"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('input[type="text"].o_field_widget').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, 'input[type="text"].o_field_widget', "should have an input for the phone field"); assert.strictEqual(form.$('input[type="text"].o_field_widget').val(), 'yop', "input should contain field value in edit mode"); // change value in edit mode - form.$('input[type="text"].o_field_widget').val('new').trigger('input'); + testUtils.fields.editInput(form.$('input[type="text"].o_field_widget'), 'new'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('a.o_field_widget.o_form_uri').text(), 'new', "new value should be displayed properly"); @@ -4003,24 +4002,24 @@ QUnit.module('basic_fields', { assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yop', "value should be displayed properly"); - assert.strictEqual(list.$('a.o_field_widget.o_form_uri').length, 5, + assert.containsN(list, 'a.o_field_widget.o_form_uri', 5, "should have the correct classnames"); // Edit a line and check the result var $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - $cell.click(); - assert.ok($cell.parent().hasClass('o_selected_row'), 'should be set as edit mode'); + testUtils.dom.click($cell); + assert.hasClass($cell.parent(),'o_selected_row', 'should be set as edit mode'); assert.strictEqual($cell.find('input').val(), 'yop', 'should have the corect value in internal input'); - $cell.find('input').val('new').trigger('input'); + testUtils.fields.editInput($cell.find('input'), 'new'); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - assert.ok(!$cell.parent().hasClass('o_selected_row'), 'should not be in edit mode anymore'); + assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore'); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'new', "value should be properly updated"); - assert.strictEqual(list.$('a.o_field_widget.o_form_uri').length, 5, + assert.containsN(list, 'a.o_field_widget.o_form_uri', 5, "should still have links with correct classes"); list.destroy(); @@ -4043,7 +4042,7 @@ QUnit.module('basic_fields', { '</form>', }); - form.$('input[name=display_name]').click(); + 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})); @@ -4123,7 +4122,7 @@ QUnit.module('basic_fields', { // occurs in a setTimeout after 200ms so it's not trivial to test it here. // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget.o_priority').find('a.o_priority_star').length, 2, "should still have two stars"); assert.strictEqual(form.$('.o_field_widget.o_priority').find('a.o_priority_star.fa-star').length, 1, @@ -4132,7 +4131,7 @@ QUnit.module('basic_fields', { "should still have one empty star since the value is the second value"); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget.o_priority').find('a.o_priority_star').length, 2, "should still have two stars"); assert.strictEqual(form.$('.o_field_widget.o_priority').find('a.o_priority_star.fa-star').length, 1, @@ -4141,7 +4140,7 @@ QUnit.module('basic_fields', { "should still have one empty star since the value is the second value"); // switch to edit mode to check that the new value was properly written - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget.o_priority').find('a.o_priority_star').length, 2, "should still have two stars"); assert.strictEqual(form.$('.o_field_widget.o_priority').find('a.o_priority_star.fa-star').length, 1, @@ -4150,7 +4149,7 @@ QUnit.module('basic_fields', { "should still have one empty star since the value is the second value"); // click on the second star in edit mode - form.$('.o_field_widget.o_priority a.o_priority_star.fa-star-o').last().click(); + testUtils.dom.click(form.$('.o_field_widget.o_priority a.o_priority_star.fa-star-o').last()); assert.strictEqual(form.$('.o_field_widget.o_priority').find('a.o_priority_star').length, 2, "should still have two stars"); @@ -4160,7 +4159,7 @@ QUnit.module('basic_fields', { "should now have no empty star since the value is the third value"); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget.o_priority').find('a.o_priority_star').length, 2, "should still have two stars"); assert.strictEqual(form.$('.o_field_widget.o_priority').find('a.o_priority_star.fa-star').length, 2, @@ -4195,7 +4194,7 @@ QUnit.module('basic_fields', { // switch to edit mode and check the result var $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - $cell.click(); + testUtils.dom.click($cell); assert.strictEqual(list.$('.o_data_row').first().find('.o_priority a.o_priority_star').length, 2, "should have two stars for representing each possible value: no star, one star and two stars"); assert.strictEqual(list.$('.o_data_row').first().find('.o_priority a.o_priority_star.fa-star').length, 1, @@ -4204,7 +4203,7 @@ QUnit.module('basic_fields', { "should have one empty star since the value is the second value"); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('.o_data_row').first().find('.o_priority a.o_priority_star').length, 2, "should have two stars for representing each possible value: no star, one star and two stars"); assert.strictEqual(list.$('.o_data_row').first().find('.o_priority a.o_priority_star.fa-star').length, 1, @@ -4222,7 +4221,7 @@ QUnit.module('basic_fields', { "should temporary have no empty star since we are hovering the third value"); // click on the first star in readonly mode - list.$('.o_priority a.o_priority_star.fa-star').first().click(); + testUtils.dom.click(list.$('.o_priority a.o_priority_star.fa-star').first()); assert.strictEqual(list.$('.o_data_row').first().find('.o_priority a.o_priority_star').length, 2, "should still have two stars"); @@ -4233,7 +4232,7 @@ QUnit.module('basic_fields', { // re-enter edit mode to force re-rendering the widget to check if the value was correctly saved $cell = list.$('tbody td:not(.o_list_record_selector)').first(); - $cell.click(); + testUtils.dom.click($cell); assert.strictEqual(list.$('.o_data_row').first().find('.o_priority a.o_priority_star').length, 2, "should still have two stars"); @@ -4243,7 +4242,7 @@ QUnit.module('basic_fields', { "should now have two empty stars since the value is the first value"); // Click on second star in edit mode - list.$('.o_priority a.o_priority_star.fa-star-o').last().click(); + testUtils.dom.click(list.$('.o_priority a.o_priority_star.fa-star-o').last()); assert.strictEqual(list.$('.o_data_row').last().find('.o_priority a.o_priority_star').length, 2, "should still have two stars"); @@ -4253,7 +4252,7 @@ QUnit.module('basic_fields', { "should now have no empty star since the value is the third value"); // save - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('.o_data_row').last().find('.o_priority a.o_priority_star').length, 2, "should still have two stars"); assert.strictEqual(list.$('.o_data_row').last().find('.o_priority a.o_priority_star.fa-star').length, 2, @@ -4287,65 +4286,65 @@ QUnit.module('basic_fields', { }, }); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_red').length, 1, + assert.containsOnce(form, '.o_field_widget.o_selection > a span.o_status.o_status_red', "should have one red status since selection is the second, blocked state"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_green').length, 0, + assert.containsNone(form, '.o_field_widget.o_selection > a span.o_status.o_status_green', "should not have one green status since selection is the second, blocked state"); - assert.strictEqual(form.$('.dropdown-menu.state:visible').length, 0, + assert.containsNone(form, '.dropdown-menu.state:visible', "there should not be a dropdown"); // Click on the status button to make the dropdown appear - form.$('.o_field_widget.o_selection .o_status').first().click(); - assert.strictEqual(form.$('.dropdown-menu.state:visible').length, 1, + testUtils.dom.click(form.$('.o_field_widget.o_selection .o_status').first()); + assert.containsOnce(form, '.dropdown-menu.state:visible', "there should be a dropdown"); - assert.strictEqual(form.$('.dropdown-menu.state:visible .dropdown-item').length, 2, + assert.containsN(form, '.dropdown-menu.state:visible .dropdown-item', 2, "there should be two options in the dropdown"); // Click on the first option, "Normal" - form.$('.dropdown-menu.state:visible .dropdown-item').first().click(); - assert.strictEqual(form.$('.dropdown-menu.state:visible').length, 0, + testUtils.dom.click(form.$('.dropdown-menu.state:visible .dropdown-item').first()); + assert.containsNone(form, '.dropdown-menu.state:visible', "there should not be a dropdown anymore"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_red').length, 0, + assert.containsNone(form, '.o_field_widget.o_selection > a span.o_status.o_status_red', "should not have one red status since selection is the first, normal state"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_green').length, 0, + assert.containsNone(form, '.o_field_widget.o_selection > a span.o_status.o_status_green', "should not have one green status since selection is the first, normal state"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status').length, 1, + assert.containsOnce(form, '.o_field_widget.o_selection > a span.o_status', "should have one grey status since selection is the first, normal state"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.dropdown-menu.state:visible').length, 0, + testUtils.form.clickEdit(form); + assert.containsNone(form, '.dropdown-menu.state:visible', "there should still not be a dropdown"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_red').length, 0, + assert.containsNone(form, '.o_field_widget.o_selection > a span.o_status.o_status_red', "should still not have one red status since selection is the first, normal state"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_green').length, 0, + assert.containsNone(form, '.o_field_widget.o_selection > a span.o_status.o_status_green', "should still not have one green status since selection is the first, normal state"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status').length, 1, + assert.containsOnce(form, '.o_field_widget.o_selection > a span.o_status', "should still have one grey status since selection is the first, normal state"); // Click on the status button to make the dropdown appear - form.$('.o_field_widget.o_selection .o_status').first().click(); - assert.strictEqual(form.$('.dropdown-menu.state:visible').length, 1, + testUtils.dom.click(form.$('.o_field_widget.o_selection .o_status').first()); + assert.containsOnce(form, '.dropdown-menu.state:visible', "there should be a dropdown"); - assert.strictEqual(form.$('.dropdown-menu.state:visible .dropdown-item').length, 2, + assert.containsN(form, '.dropdown-menu.state:visible .dropdown-item', 2, "there should be two options in the dropdown"); // Click on the last option, "Done" - form.$('.dropdown-menu.state:visible .dropdown-item').last().click(); - assert.strictEqual(form.$('.dropdown-menu.state:visible').length, 0, + testUtils.dom.click(form.$('.dropdown-menu.state:visible .dropdown-item').last()); + assert.containsNone(form, '.dropdown-menu.state:visible', "there should not be a dropdown anymore"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_red').length, 0, + assert.containsNone(form, '.o_field_widget.o_selection > a span.o_status.o_status_red', "should not have one red status since selection is the third, done state"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_green').length, 1, + assert.containsOnce(form, '.o_field_widget.o_selection > a span.o_status.o_status_green', "should have one green status since selection is the third, done state"); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.dropdown-menu.state:visible').length, 0, + testUtils.form.clickSave(form); + assert.containsNone(form, '.dropdown-menu.state:visible', "there should still not be a dropdown anymore"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_red').length, 0, + assert.containsNone(form, '.o_field_widget.o_selection > a span.o_status.o_status_red', "should still not have one red status since selection is the third, done state"); - assert.strictEqual(form.$('.o_field_widget.o_selection > a span.o_status.o_status_green').length, 1, + assert.containsOnce(form, '.o_field_widget.o_selection > a span.o_status.o_status_green', "should still have one green status since selection is the third, done state"); form.destroy(); @@ -4364,97 +4363,97 @@ QUnit.module('basic_fields', { '</tree>', }); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5, + assert.containsN(list, '.o_state_selection_cell .o_selection > a span.o_status', 5, "should have five status selection widgets"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 1, + assert.containsOnce(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_red', "should have one red status"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 1, + assert.containsOnce(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_green', "should have one green status"); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 0, + assert.containsNone(list, '.dropdown-menu.state:visible', "there should not be a dropdown"); // Click on the status button to make the dropdown appear var $cell = list.$('tbody td.o_state_selection_cell').first(); - list.$('.o_state_selection_cell .o_selection > a span.o_status').first().click(); - assert.ok(!$cell.parent().hasClass('o_selected_row'), + testUtils.dom.click(list.$('.o_state_selection_cell .o_selection > a span.o_status').first()); + assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode since we clicked on the state selection widget'); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 1, + assert.containsOnce(list, '.dropdown-menu.state:visible', "there should be a dropdown"); - assert.strictEqual(list.$('.dropdown-menu.state:visible .dropdown-item').length, 2, + assert.containsN(list, '.dropdown-menu.state:visible .dropdown-item', 2, "there should be two options in the dropdown"); // Click on the first option, "Normal" - list.$('.dropdown-menu.state:visible .dropdown-item').first().click(); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5, + testUtils.dom.click(list.$('.dropdown-menu.state:visible .dropdown-item').first()); + assert.containsN(list, '.o_state_selection_cell .o_selection > a span.o_status', 5, "should still have five status selection widgets"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 0, + assert.containsNone(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_red', "should now have no red status"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 1, + assert.containsOnce(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_green', "should still have one green status"); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 0, + assert.containsNone(list, '.dropdown-menu.state:visible', "there should not be a dropdown"); // switch to edit mode and check the result $cell = list.$('tbody td.o_state_selection_cell').first(); - $cell.click(); - assert.ok($cell.parent().hasClass('o_selected_row'), + testUtils.dom.click($cell); + assert.hasClass($cell.parent(),'o_selected_row', 'should now be in edit mode'); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5, + assert.containsN(list, '.o_state_selection_cell .o_selection > a span.o_status', 5, "should still have five status selection widgets"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 0, + assert.containsNone(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_red', "should now have no red status"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 1, + assert.containsOnce(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_green', "should still have one green status"); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 0, + assert.containsNone(list, '.dropdown-menu.state:visible', "there should not be a dropdown"); // Click on the status button to make the dropdown appear - list.$('.o_state_selection_cell .o_selection > a span.o_status').first().click(); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 1, + testUtils.dom.click(list.$('.o_state_selection_cell .o_selection > a span.o_status').first()); + assert.containsOnce(list, '.dropdown-menu.state:visible', "there should be a dropdown"); - assert.strictEqual(list.$('.dropdown-menu.state:visible .dropdown-item').length, 2, + assert.containsN(list, '.dropdown-menu.state:visible .dropdown-item', 2, "there should be two options in the dropdown"); // Click on another row - var $firstCell = list.$('tbody td.o_state_selection_cell').first(); var $lastCell = list.$('tbody td.o_state_selection_cell').last(); - $lastCell.click(); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 0, + testUtils.dom.click($lastCell); + assert.containsNone(list, '.dropdown-menu.state:visible', "there should not be a dropdown anymore"); - assert.ok(!$firstCell.parent().hasClass('o_selected_row'), + var $firstCell = list.$('tbody td.o_state_selection_cell').first(); + assert.doesNotHaveClass($firstCell.parent(), 'o_selected_row', 'first row should not be in edit mode anymore'); - assert.ok($lastCell.parent().hasClass('o_selected_row'), + assert.hasClass($lastCell.parent(),'o_selected_row', 'last row should be in edit mode'); // Click on the last status button to make the dropdown appear - list.$('.o_state_selection_cell .o_selection > a span.o_status').last().click(); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 1, + testUtils.dom.click(list.$('.o_state_selection_cell .o_selection > a span.o_status').last()); + assert.containsOnce(list, '.dropdown-menu.state:visible', "there should be a dropdown"); - assert.strictEqual(list.$('.dropdown-menu.state:visible .dropdown-item').length, 2, + assert.containsN(list, '.dropdown-menu.state:visible .dropdown-item', 2, "there should be two options in the dropdown"); // Click on the last option, "Done" - list.$('.dropdown-menu.state:visible .dropdown-item').last().click(); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 0, + testUtils.dom.click(list.$('.dropdown-menu.state:visible .dropdown-item').last()); + assert.containsNone(list, '.dropdown-menu.state:visible', "there should not be a dropdown anymore"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5, + assert.containsN(list, '.o_state_selection_cell .o_selection > a span.o_status', 5, "should still have five status selection widgets"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 0, + assert.containsNone(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_red', "should still have no red status"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 2, + assert.containsN(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_green', 2, "should now have two green status"); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 0, + assert.containsNone(list, '.dropdown-menu.state:visible', "there should not be a dropdown"); // save - list.$buttons.find('.o_list_button_save').click(); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5, + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); + assert.containsN(list, '.o_state_selection_cell .o_selection > a span.o_status', 5, "should have five status selection widgets"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 0, + assert.containsNone(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_red', "should have no red status"); - assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 2, + assert.containsN(list, '.o_state_selection_cell .o_selection > a span.o_status.o_status_green', 2, "should have two green status"); - assert.strictEqual(list.$('.dropdown-menu.state:visible').length, 0, + assert.containsNone(list, '.dropdown-menu.state:visible', "there should not be a dropdown"); list.destroy(); @@ -4482,14 +4481,14 @@ QUnit.module('basic_fields', { domain: [['id', '=', 1]], }); - assert.strictEqual(kanban.$('.o_kanban_record .o_field_widget.o_favorite > a i.fa.fa-star').length, 1, + assert.containsOnce(kanban, '.o_kanban_record .o_field_widget.o_favorite > a i.fa.fa-star', 'should be favorite'); assert.strictEqual(kanban.$('.o_kanban_record .o_field_widget.o_favorite > a').text(), ' Remove from Favorites', 'the label should say "Remove from Favorites"'); // click on favorite - kanban.$('.o_field_widget.o_favorite').click(); - assert.strictEqual(kanban.$('.o_kanban_record .o_field_widget.o_favorite > a i.fa.fa-star').length, 0, + testUtils.dom.click(kanban.$('.o_field_widget.o_favorite')); + assert.containsNone(kanban, '.o_kanban_record .o_field_widget.o_favorite > a i.fa.fa-star', 'should not be favorite'); assert.strictEqual(kanban.$('.o_kanban_record .o_field_widget.o_favorite > a').text(), ' Add to Favorites', 'the label should say "Add to Favorites"'); @@ -4514,35 +4513,35 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star').length, 1, + assert.containsOnce(form, '.o_field_widget.o_favorite > a i.fa.fa-star', 'should be favorite'); assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Remove from Favorites', 'the label should say "Remove from Favorites"'); // click on favorite - form.$('.o_field_widget.o_favorite').click(); - assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star').length, 0, + testUtils.dom.click(form.$('.o_field_widget.o_favorite')); + assert.containsNone(form, '.o_field_widget.o_favorite > a i.fa.fa-star', 'should not be favorite'); assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Add to Favorites', 'the label should say "Add to Favorites"'); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star-o').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, '.o_field_widget.o_favorite > a i.fa.fa-star-o', 'should not be favorite'); assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Add to Favorites', 'the label should say "Add to Favorites"'); // click on favorite - form.$('.o_field_widget.o_favorite').click(); - assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star').length, 1, + testUtils.dom.click(form.$('.o_field_widget.o_favorite')); + assert.containsOnce(form, '.o_field_widget.o_favorite > a i.fa.fa-star', 'should be favorite'); assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Remove from Favorites', 'the label should say "Remove from Favorites"'); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star').length, 1, + testUtils.form.clickSave(form); + assert.containsOnce(form, '.o_field_widget.o_favorite > a i.fa.fa-star', 'should be favorite'); assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Remove from Favorites', 'the label should say "Remove from Favorites"'); @@ -4562,22 +4561,22 @@ QUnit.module('basic_fields', { '</tree>', }); - assert.strictEqual(list.$('.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star').length, 1, + assert.containsOnce(list, '.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star', 'should be favorite'); // switch to edit mode - list.$('tbody td:not(.o_list_record_selector)').first().click(); - assert.strictEqual(list.$('.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star').length, 1, + testUtils.dom.click(list.$('tbody td:not(.o_list_record_selector)').first()); + assert.containsOnce(list, '.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star', 'should be favorite'); // click on favorite - list.$('.o_data_row:first .o_field_widget.o_favorite').click(); - assert.strictEqual(list.$('.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star').length, 0, + testUtils.dom.click(list.$('.o_data_row:first .o_field_widget.o_favorite')); + assert.containsNone(list, '.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star', 'should not be favorite'); // save - list.$buttons.find('.o_list_button_save').click(); - assert.strictEqual(list.$('.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star-o').length, 1, + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); + assert.containsOnce(list, '.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star-o', 'should not be favorite'); list.destroy(); @@ -4604,33 +4603,33 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.strictEqual(form.$('.o_field_widget.badge.badge-warning').length, 1, + assert.containsOnce(form, '.o_field_widget.badge.badge-warning', "should have a warning status label since selection is the second, blocked state"); - assert.strictEqual(form.$('.o_field_widget.badge.badge-secondary').length, 0, + assert.containsNone(form, '.o_field_widget.badge.badge-secondary', "should not have a default status since selection is the second, blocked state"); - assert.strictEqual(form.$('.o_field_widget.badge.badge-success').length, 0, + assert.containsNone(form, '.o_field_widget.badge.badge-success', "should not have a success status since selection is the second, blocked state"); assert.strictEqual(form.$('.o_field_widget.badge.badge-warning').text(), 'Blocked', "the label should say 'Blocked' since this is the label value for that state"); // // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_widget.badge.badge-warning').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, '.o_field_widget.badge.badge-warning', "should have a warning status label since selection is the second, blocked state"); - assert.strictEqual(form.$('.o_field_widget.badge.badge-secondary').length, 0, + assert.containsNone(form, '.o_field_widget.badge.badge-secondary', "should not have a default status since selection is the second, blocked state"); - assert.strictEqual(form.$('.o_field_widget.badge.badge-success').length, 0, + assert.containsNone(form, '.o_field_widget.badge.badge-success', "should not have a success status since selection is the second, blocked state"); assert.strictEqual(form.$('.o_field_widget.badge.badge-warning').text(), 'Blocked', "the label should say 'Blocked' since this is the label value for that state"); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_field_widget.badge.badge-warning').length, 1, + testUtils.form.clickSave(form); + assert.containsOnce(form, '.o_field_widget.badge.badge-warning', "should have a warning status label since selection is the second, blocked state"); - assert.strictEqual(form.$('.o_field_widget.badge.badge-secondary').length, 0, + assert.containsNone(form, '.o_field_widget.badge.badge-secondary', "should not have a default status since selection is the second, blocked state"); - assert.strictEqual(form.$('.o_field_widget.badge.badge-success').length, 0, + assert.containsNone(form, '.o_field_widget.badge.badge-success', "should not have a success status since selection is the second, blocked state"); assert.strictEqual(form.$('.o_field_widget.badge.badge-warning').text(), 'Blocked', "the label should say 'Blocked' since this is the label value for that state"); @@ -4654,49 +4653,49 @@ QUnit.module('basic_fields', { assert.strictEqual(list.$('.o_field_widget.badge:not(:empty)').length, 3, "should have three visible status labels"); - assert.strictEqual(list.$('.o_field_widget.badge.badge-warning').length, 1, + assert.containsOnce(list, '.o_field_widget.badge.badge-warning', "should have one warning status label"); assert.strictEqual(list.$('.o_field_widget.badge.badge-warning').text(), 'Blocked', "the warning label should read 'Blocked'"); - assert.strictEqual(list.$('.o_field_widget.badge.badge-secondary').length, 1, + assert.containsOnce(list, '.o_field_widget.badge.badge-secondary', "should have one default status label"); assert.strictEqual(list.$('.o_field_widget.badge.badge-secondary').text(), 'Normal', "the default label should read 'Normal'"); - assert.strictEqual(list.$('.o_field_widget.badge.badge-success').length, 1, + assert.containsOnce(list, '.o_field_widget.badge.badge-success', "should have one success status label"); assert.strictEqual(list.$('.o_field_widget.badge.badge-success').text(), 'Done', "the success label should read 'Done'"); // switch to edit mode and check the result - list.$('tbody td:not(.o_list_record_selector)').first().click(); + testUtils.dom.click(list.$('tbody td:not(.o_list_record_selector)').first()); assert.strictEqual(list.$('.o_field_widget.badge:not(:empty)').length, 3, "should have three visible status labels"); - assert.strictEqual(list.$('.o_field_widget.badge.badge-warning').length, 1, + assert.containsOnce(list, '.o_field_widget.badge.badge-warning', "should have one warning status label"); assert.strictEqual(list.$('.o_field_widget.badge.badge-warning').text(), 'Blocked', "the warning label should read 'Blocked'"); - assert.strictEqual(list.$('.o_field_widget.badge.badge-secondary').length, 1, + assert.containsOnce(list, '.o_field_widget.badge.badge-secondary', "should have one default status label"); assert.strictEqual(list.$('.o_field_widget.badge.badge-secondary').text(), 'Normal', "the default label should read 'Normal'"); - assert.strictEqual(list.$('.o_field_widget.badge.badge-success').length, 1, + assert.containsOnce(list, '.o_field_widget.badge.badge-success', "should have one success status label"); assert.strictEqual(list.$('.o_field_widget.badge.badge-success').text(), 'Done', "the success label should read 'Done'"); // save and check the result - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('.o_field_widget.badge:not(:empty)').length, 3, "should have three visible status labels"); - assert.strictEqual(list.$('.o_field_widget.badge.badge-warning').length, 1, + assert.containsOnce(list, '.o_field_widget.badge.badge-warning', "should have one warning status label"); assert.strictEqual(list.$('.o_field_widget.badge.badge-warning').text(), 'Blocked', "the warning label should read 'Blocked'"); - assert.strictEqual(list.$('.o_field_widget.badge.badge-secondary').length, 1, + assert.containsOnce(list, '.o_field_widget.badge.badge-secondary', "should have one default status label"); assert.strictEqual(list.$('.o_field_widget.badge.badge-secondary').text(), 'Normal', "the default label should read 'Normal'"); - assert.strictEqual(list.$('.o_field_widget.badge.badge-success').length, 1, + assert.containsOnce(list, '.o_field_widget.badge.badge-success', "should have one success status label"); assert.strictEqual(list.$('.o_field_widget.badge.badge-success').text(), 'Done', "the success label should read 'Done'"); @@ -4763,7 +4762,7 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info').length, 1, + assert.containsOnce(form, '.oe_stat_button .o_field_widget.o_stat_info', "should have one stat button"); assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').text(), '10', "should have 10 as value"); @@ -4771,8 +4770,8 @@ QUnit.module('basic_fields', { 'int_field', "should have 'int_field' as text"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, '.oe_stat_button .o_field_widget.o_stat_info', "should still have one stat button"); assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').text(), '10', "should still have 10 as value"); @@ -4780,8 +4779,8 @@ QUnit.module('basic_fields', { 'int_field', "should have 'int_field' as text"); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info').length, 1, + testUtils.form.clickSave(form); + assert.containsOnce(form, '.oe_stat_button .o_field_widget.o_stat_info', "should have one stat button"); assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').text(), '10', "should have 10 as value"); @@ -4815,7 +4814,7 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info').length, 1, + assert.containsOnce(form, '.oe_stat_button .o_field_widget.o_stat_info', "should have one stat button"); assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').text(), '10', "should have 10 as value"); @@ -4823,8 +4822,8 @@ QUnit.module('basic_fields', { 'yop', "should have 'yop' as text, since it is the value of field foo"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, '.oe_stat_button .o_field_widget.o_stat_info', "should still have one stat button"); assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').text(), '10', "should still have 10 as value"); @@ -4832,8 +4831,8 @@ QUnit.module('basic_fields', { 'yop', "should have 'yop' as text, since it is the value of field foo"); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info').length, 1, + testUtils.form.clickSave(form); + assert.containsOnce(form, '.oe_stat_button .o_field_widget.o_stat_info', "should have one stat button"); assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').text(), '10', "should have 10 as value"); @@ -4866,7 +4865,7 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info').length, 1, + assert.containsOnce(form, '.oe_stat_button .o_field_widget.o_stat_info', "should have one stat button"); assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').text(), '10', "should have 10 as value"); @@ -4874,8 +4873,8 @@ QUnit.module('basic_fields', { '', "should not have any label"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, '.oe_stat_button .o_field_widget.o_stat_info', "should still have one stat button"); assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').text(), '10', "should still have 10 as value"); @@ -4883,8 +4882,8 @@ QUnit.module('basic_fields', { '', "should not have any label"); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info').length, 1, + testUtils.form.clickSave(form); + assert.containsOnce(form, '.oe_stat_button .o_field_widget.o_stat_info', "should have one stat button"); assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').text(), '10', "should have 10 as value"); @@ -4914,7 +4913,7 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie').length, 1, + assert.containsOnce(form, '.o_field_percent_pie.o_field_widget .o_pie', "should have a pie chart"); assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_pie_value').text(), '10%', "should have 10% as pie value since int_field=10"); @@ -4924,8 +4923,8 @@ QUnit.module('basic_fields', { 'transform: rotate(36deg);'), "right mask should be rotated from 360*(10/100) = 36 degrees"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, '.o_field_percent_pie.o_field_widget .o_pie', "should have a pie chart"); assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_pie_value').text(), '10%', "should have 10% as pie value since int_field=10"); @@ -4935,8 +4934,8 @@ QUnit.module('basic_fields', { 'transform: rotate(36deg);'), "right mask should be rotated from 360*(10/100) = 36 degrees"); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie').length, 1, + testUtils.form.clickSave(form); + assert.containsOnce(form, '.o_field_percent_pie.o_field_widget .o_pie', "should have a pie chart"); assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_pie_value').text(), '10%', "should have 10% as pie value since int_field=10"); @@ -4965,35 +4964,35 @@ QUnit.module('basic_fields', { res_id: 3, }); - assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie').length, 1, + assert.containsOnce(form, '.o_field_percent_pie.o_field_widget .o_pie', "should have a pie chart"); assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_pie_value').text(), '80%', "should have 80% as pie value since int_field=80"); assert.ok(_.str.include(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_mask').first().attr('style'), 'transform: rotate(288deg);'), "left mask should be rotated from 360*(80/100) = 288 degrees"); - assert.ok(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_mask').last().hasClass('o_full'), + assert.hasClass(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_mask').last(),'o_full', "right mask should be hidden since the value > 50%"); // switch to edit mode and check the result - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, '.o_field_percent_pie.o_field_widget .o_pie', "should have a pie chart"); assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_pie_value').text(), '80%', "should have 80% as pie value since int_field=80"); assert.ok(_.str.include(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_mask').first().attr('style'), 'transform: rotate(288deg);'), "left mask should be rotated from 360*(80/100) = 288 degrees"); - assert.ok(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_mask').last().hasClass('o_full'), + assert.hasClass(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_mask').last(),'o_full', "right mask should be hidden since the value > 50%"); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie').length, 1, + testUtils.form.clickSave(form); + assert.containsOnce(form, '.o_field_percent_pie.o_field_widget .o_pie', "should have a pie chart"); assert.strictEqual(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_pie_value').text(), '80%', "should have 80% as pie value since int_field=80"); assert.ok(_.str.include(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_mask').first().attr('style'), 'transform: rotate(288deg);'), "left mask should be rotated from 360*(80/100) = 288 degrees"); - assert.ok(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_mask').last().hasClass('o_full'), + assert.hasClass(form.$('.o_field_percent_pie.o_field_widget .o_pie .o_mask').last(),'o_full', "right mask should be hidden since the value > 50%"); form.destroy(); @@ -5018,7 +5017,7 @@ QUnit.module('basic_fields', { // '</tree>', // }); // - // assert.strictEqual(list.$('.o_field_percent_pie .o_pie').length, 5, + // assert.containsN(list, '.o_field_percent_pie .o_pie', 5, // "should have five pie charts"); // assert.strictEqual(list.$('.o_field_percent_pie:first .o_pie .o_pie_value').first().text(), // '10%', "should have 10% as pie value since int_field=10"); @@ -5028,7 +5027,7 @@ QUnit.module('basic_fields', { // 'transform: rotate(36deg);', "right mask should be rotated from 360*(10/100) = 36 degrees"); // // // switch to edit mode and check the result - // list.$('tbody td:not(.o_list_record_selector)').first().click(); +// testUtils.dom.click( list.$('tbody td:not(.o_list_record_selector)').first()); // assert.strictEqual(list.$('.o_field_percent_pie:first .o_pie .o_pie_value').first().text(), // '10%', "should have 10% as pie value since int_field=10"); // assert.strictEqual(list.$('.o_field_percent_pie:first .o_pie .o_mask').first().attr('style'), @@ -5037,7 +5036,7 @@ QUnit.module('basic_fields', { // 'transform: rotate(36deg);', "right mask should be rotated from 360*(10/100) = 36 degrees"); // // // save - // list.$buttons.find('.o_list_button_save').click(); +// testUtils.dom.click( list.$buttons.find('.o_list_button_save')); // assert.strictEqual(list.$('.o_field_percent_pie:first .o_pie .o_pie_value').first().text(), // '10%', "should have 10% as pie value since int_field=10"); // assert.strictEqual(list.$('.o_field_percent_pie:first .o_pie .o_mask').first().attr('style'), @@ -5097,7 +5096,7 @@ QUnit.module('basic_fields', { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // As the domain is empty, there should be a button to add the first // domain part @@ -5108,7 +5107,7 @@ QUnit.module('basic_fields', { // Clicking on the button should add the [["id", "=", "1"]] domain, so // there should be a field selector in the DOM - $domainAddFirstNodeButton.click(); + testUtils.dom.click($domainAddFirstNodeButton); var $fieldSelector = $domain.find(".o_field_selector"); assert.equal($fieldSelector.length, 1, "there should be a field selector"); @@ -5135,14 +5134,14 @@ QUnit.module('basic_fields', { // Clicking on this field should close the popover, then changing the // associated value should reveal one matched record - $colorIndex.click(); + testUtils.dom.click($colorIndex); $domain.find(".o_domain_leaf_value_input").val(2).change(); assert.equal($domain.find(".o_domain_show_selection_button").text().trim().substr(0, 2), "1 ", "changing color value to 2 should reveal only one record"); // Saving the form view should show a readonly domain containing the // "color" field - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); $domain = form.$(".o_field_domain"); assert.ok($domain.html().indexOf("Color index") >= 0, "field selector readonly value should now contain 'Color index'"); @@ -5171,7 +5170,7 @@ QUnit.module('basic_fields', { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // As the domain is equal to [["id", "=", 1]] there should be a field // selector to change this @@ -5202,7 +5201,8 @@ QUnit.module('basic_fields', { "field selector popover should contain 'Product Name' field"); // Now change the value of the "bar" field to "partner_type" - form.$("input.o_field_widget").click().val("partner_type").trigger("input"); + testUtils.dom.click(form.$("input.o_field_widget")); + testUtils.fields.editInput(form.$("input.o_field_widget"), "partner_type"); // Refocusing the field selector input should open the popover again $fieldSelector = form.$(".o_field_selector"); @@ -5256,7 +5256,7 @@ QUnit.module('basic_fields', { "the domain being empty, there should be 5 records"); // update display_name to trigger the onchange and reset foo - form.$('.o_field_widget[name=display_name]').val('new value').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'new value'); assert.equal(form.$('.o_domain_show_selection_button').text().trim(), '1 record(s)', "the domain has changed, there should be only 1 record"); @@ -5296,7 +5296,7 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_field_widget[name=foo]:not(.o_field_empty)').length, 1, "there should be a domain field, not considered empty"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var $warning = form.$('.o_field_widget[name=foo] .text-warning'); assert.strictEqual($warning.length, 0, "should not display that the domain is invalid"); @@ -5332,14 +5332,14 @@ QUnit.module('basic_fields', { "selection should contain 2 records"); // open the selection - form.$(".o_domain_show_selection_button").click(); + testUtils.dom.click(form.$(".o_domain_show_selection_button")); assert.strictEqual($('.modal .o_list_view .o_data_row').length, 2, "should have open a list view with 2 records in a dialog"); // click on a record -> should not open the record // we don't actually check that it doesn't open the record because even // if it tries to, it will crash as we don't define an arch in this test - $('.modal .o_list_view .o_data_row:first .o_data_cell').click(); + testUtils.dom.click($('.modal .o_list_view .o_data_row:first .o_data_cell')); form.destroy(); }); diff --git a/addons/web/static/tests/fields/relational_fields/field_many2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_many2many_tests.js index e782a27cb4a..e6f2c06173f 100644 --- a/addons/web/static/tests/fields/relational_fields/field_many2many_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_many2many_tests.js @@ -178,7 +178,7 @@ QUnit.module('fields', {}, function () { // the SelectCreateDialog requests the session, so intercept its custom // event to specify a fake session to prevent it from crashing - testUtils.intercept(form, 'get_session', function (event) { + testUtils.mock.intercept(form, 'get_session', function (event) { event.data.callback({ user_context: {} }); }); @@ -187,7 +187,7 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o_field_many2many .o-kanban-button-new').length, '"Add" button should not be visible in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 2, 'should contain 2 records'); @@ -201,20 +201,20 @@ QUnit.module('fields', {}, function () { 'Create button should have "Add" label'); // edit existing subrecord - form.$('.oe_kanban_global_click:first()').click(); + testUtils.dom.click(form.$('.oe_kanban_global_click:first()')); - $('.modal .o_form_view input').val('new name').trigger('input'); - $('.modal .modal-footer .btn-primary').click(); // save + testUtils.fields.editInput($('.modal .o_form_view input'), 'new name'); + testUtils.dom.click($('.modal .modal-footer .btn-primary')); assert.strictEqual(form.$('.o_kanban_record:first() span').text(), 'new name', 'value of subrecord should have been updated'); // add subrecords // -> single select - form.$('.o_field_many2many .o-kanban-button-new').click(); + testUtils.dom.click(form.$('.o_field_many2many .o-kanban-button-new')); assert.ok($('.modal .o_list_view').length, "should have opened a list view in a modal"); assert.strictEqual($('.modal .o_list_view tbody .o_list_record_selector').length, 3, "list view should contain 3 records"); - $('.modal .o_list_view tbody tr:contains(red)').click(); // select red + testUtils.dom.click($('.modal .o_list_view tbody tr:contains(red)')); assert.ok(!$('.modal .o_list_view').length, "should have closed the modal"); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 3, 'kanban should now contain 3 records'); @@ -222,23 +222,23 @@ QUnit.module('fields', {}, function () { 'record "red" should be in the kanban'); // -> multiple select - form.$('.o_field_many2many .o-kanban-button-new').click(); + testUtils.dom.click(form.$('.o_field_many2many .o-kanban-button-new')); assert.ok($('.modal .o_select_button').prop('disabled'), "select button should be disabled"); assert.strictEqual($('.modal .o_list_view tbody .o_list_record_selector').length, 2, "list view should contain 2 records"); - $('.modal .o_list_view thead .o_list_record_selector input').click(); // select all - $('.modal .o_select_button').click(); // validate selection + testUtils.dom.click($('.modal .o_list_view thead .o_list_record_selector input')); + testUtils.dom.click($('.modal .o_select_button')); assert.ok(!$('.modal .o_select_button').prop('disabled'), "select button should be enabled"); assert.ok(!$('.modal .o_list_view').length, "should have closed the modal"); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 5, 'kanban should now contain 5 records'); // -> created record - form.$('.o_field_many2many .o-kanban-button-new').click(); - $('.modal .modal-footer .btn-primary:nth(1)').click(); // click on 'Create' + testUtils.dom.click(form.$('.o_field_many2many .o-kanban-button-new')); + testUtils.dom.click($('.modal .modal-footer .btn-primary:nth(1)')); assert.ok($('.modal .o_form_view.o_form_editable').length, "should have opened a form view in edit mode, in a modal"); - $('.modal .o_form_view input').val('A new type').trigger('input'); - $('.modal:nth(1) footer .btn-primary:first()').click(); // click on 'Save & Close' + testUtils.fields.editInput($('.modal .o_form_view input'), 'A new type'); + testUtils.dom.click($('.modal:nth(1) footer .btn-primary:first()')); assert.ok(!$('.modal').length, "should have closed both modals"); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 6, 'kanban should now contain 6 records'); @@ -246,23 +246,23 @@ QUnit.module('fields', {}, function () { 'the newly created type should be in the kanban'); // delete subrecords - form.$('.o_kanban_record:contains(silver)').click(); + testUtils.dom.click(form.$('.o_kanban_record:contains(silver)')); assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 1, 'There should be a modal having Remove Button'); - $('.modal .modal-footer .o_btn_remove').click(); // Click Remove Button of Formview Dialog + testUtils.dom.click($('.modal .modal-footer .o_btn_remove')); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 5, 'should contain 5 records'); assert.ok(!form.$('.o_kanban_record:contains(silver)').length, 'the removed record should not be in kanban anymore'); - form.$('.o_kanban_record:contains(blue) .delete_icon').click(); + testUtils.dom.click(form.$('.o_kanban_record:contains(blue) .delete_icon')); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 4, 'should contain 4 records'); assert.ok(!form.$('.o_kanban_record:contains(blue)').length, 'the removed record should not be in kanban anymore'); // save the record - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -291,7 +291,7 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_many2many[name="timmy"] .o-kanban-button-new').text().trim(), "Add timmy", "In M2M Kanban, Add button should have 'Add timmy' label"); @@ -335,14 +335,14 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o-kanban-button-new').length, '"Add" button should not be available in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(form.$('.o-kanban-button-new').length, '"Add" button should be available in edit'); assert.ok(form.$('.o_kanban_view .delete_icon').length, 'delete icon should be visible in edit'); - form.$('.o-kanban-button-new').click(); // click on 'Add' + testUtils.dom.click(form.$('.o-kanban-button-new')); assert.strictEqual($('.modal .modal-footer .btn-primary').length, 1, // only button 'Select' '"Create" button should not be available in the modal'); @@ -392,9 +392,9 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o_field_x2many_list_row_add').length, '"Add an item" should not be visible in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 2, + assert.containsN(form, '.o_list_view td.o_list_number', 2, 'should contain 2 records'); assert.strictEqual(form.$('.o_list_view tbody td:first()').text(), 'gold', 'display_name of first subrecord should be the one in DB'); @@ -404,35 +404,35 @@ QUnit.module('fields', {}, function () { '"Add an item" should be visible in edit'); // edit existing subrecord - form.$('.o_list_view tbody tr:first()').click(); + testUtils.dom.click(form.$('.o_list_view tbody tr:first()')); - $('.modal .o_form_view input').val('new name').trigger('input'); - $('.modal .modal-footer .btn-primary').click(); // save + testUtils.fields.editInput($('.modal .o_form_view input'), 'new name'); + testUtils.dom.click($('.modal .modal-footer .btn-primary')); assert.strictEqual(form.$('.o_list_view tbody td:first()').text(), 'new name', 'value of subrecord should have been updated'); // add new subrecords - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .o_list_view').length, 1, "a modal should be open"); assert.strictEqual($('.modal .o_list_view .o_data_row').length, 1, "the list should contain one row"); - $('.modal .o_list_view .o_data_row').click(); // select a record + testUtils.dom.click($('.modal .o_list_view .o_data_row')); assert.strictEqual($('.modal .o_list_view').length, 0, "the modal should be closed"); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 3, + assert.containsN(form, '.o_list_view td.o_list_number', 3, 'should contain 3 subrecords'); // remove subrecords - form.$('.o_list_record_remove:nth(1)').click(); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 2, + testUtils.dom.click(form.$('.o_list_record_remove:nth(1)')); + assert.containsN(form, '.o_list_view td.o_list_number', 2, 'should contain 2 subrecords'); assert.strictEqual(form.$('.o_list_view .o_data_row td:first').text(), 'new name', 'the updated row still has the correct values'); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 2, + testUtils.form.clickSave(form);; + assert.containsN(form, '.o_list_view td.o_list_number', 2, 'should contain 2 subrecords'); assert.strictEqual(form.$('.o_list_view .o_data_row td:first').text(), 'new name', 'the updated row still has the correct values'); @@ -494,59 +494,59 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o_field_x2many_list_row_add').length, '"Add an item" should not be visible in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 2, + assert.containsN(form, '.o_list_view td.o_list_number', 2, 'should contain 2 records'); assert.strictEqual(form.$('.o_list_view tbody td:first()').text(), 'gold', 'display_name of first subrecord should be the one in DB'); assert.ok(form.$('.o_list_record_remove').length, 'delete icon should be visible in edit'); - assert.ok(form.$('td.o_list_record_remove button').first().hasClass('fa fa-times'), + assert.hasClass(form.$('td.o_list_record_remove button').first(),'fa fa-times', "should have X icons to remove (unlink) records"); assert.ok(form.$('.o_field_x2many_list_row_add').length, '"Add an item" should not visible in edit'); // edit existing subrecord - form.$('.o_list_view tbody td:first()').click(); + testUtils.dom.click(form.$('.o_list_view tbody td:first()')); assert.ok(!$('.modal').length, 'in edit, clicking on a subrecord should not open a dialog'); - assert.ok(form.$('.o_list_view tbody tr:first()').hasClass('o_selected_row'), + assert.hasClass(form.$('.o_list_view tbody tr:first()'),'o_selected_row', 'first row should be in edition'); - form.$('.o_list_view input:first()').val('new name').trigger('input'); - assert.ok(form.$('.o_list_view .o_data_row:first').hasClass('o_selected_row'), + testUtils.fields.editInput(form.$('.o_list_view input:first()'), 'new name'); + assert.hasClass(form.$('.o_list_view .o_data_row:first'),'o_selected_row', 'first row should still be in edition'); assert.strictEqual(form.$('.o_list_view input[name=display_name]').get(0), document.activeElement, 'edited field should still have the focus'); - form.$el.click(); // click outside the list to validate the row - assert.ok(!form.$('.o_list_view tbody tr:first').hasClass('o_selected_row'), + testUtils.dom.click(form.$el); + assert.doesNotHaveClass(form.$('.o_list_view tbody tr:first'), 'o_selected_row', 'first row should not be in edition anymore'); assert.strictEqual(form.$('.o_list_view tbody td:first()').text(), 'new name', 'value of subrecord should have been updated'); assert.verifySteps(['read', 'read']); // add new subrecords - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .o_list_view').length, 1, "a modal should be open"); assert.strictEqual($('.modal .o_list_view .o_data_row').length, 1, "the list should contain one row"); - $('.modal .o_list_view .o_data_row').click(); // select a record + testUtils.dom.click($('.modal .o_list_view .o_data_row')); assert.strictEqual($('.modal .o_list_view').length, 0, "the modal should be closed"); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 3, + assert.containsN(form, '.o_list_view td.o_list_number', 3, 'should contain 3 subrecords'); // remove subrecords - form.$('.o_list_record_remove:nth(1)').click(); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 2, + testUtils.dom.click(form.$('.o_list_record_remove:nth(1)')); + assert.containsN(form, '.o_list_view td.o_list_number', 2, 'should contain 2 subrecord'); assert.strictEqual(form.$('.o_list_view tbody .o_data_row td:first').text(), 'new name', 'the updated row still has the correct values'); // save - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 2, + testUtils.form.clickSave(form);; + assert.containsN(form, '.o_list_view td.o_list_number', 2, 'should contain 2 subrecords'); assert.strictEqual(form.$('.o_list_view .o_data_row td:first').text(), 'new name', 'the updated row still has the correct values'); @@ -583,10 +583,10 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_field_x2many_list_row_add').length, 1, "should have the 'Add an item' link"); - assert.strictEqual(form.$('.o_list_record_remove').length, 2, "should have the 'Add an item' link"); + assert.containsOnce(form, '.o_field_x2many_list_row_add', "should have the 'Add an item' link"); + assert.containsN(form, '.o_list_record_remove', 2, "should have the 'Add an item' link"); form.destroy(); @@ -604,10 +604,10 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_field_x2many_list_row_add').length, 0, "should not have the 'Add an item' link"); - assert.strictEqual(form.$('.o_list_record_remove').length, 0, "should not have the 'Add an item' link"); + assert.containsNone(form, '.o_field_x2many_list_row_add', "should not have the 'Add an item' link"); + assert.containsNone(form, '.o_list_record_remove', "should not have the 'Add an item' link"); form.destroy(); }); @@ -631,7 +631,7 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o_field_x2many_list_row_add').length, '"Add an item" link should not be available in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(!form.$('.o_field_x2many_list_row_add').length, '"Add an item" link should not be available in edit either'); @@ -694,10 +694,10 @@ QUnit.module('fields', {}, function () { assert.ok(form.$('.custom-checkbox input').eq(2).prop('checked'), "third checkbox should be checked"); - form.$('.custom-checkbox input:checked').click(); // Uncheck default record - form.$('.custom-checkbox input').first().click(); // Check first record - form.$('.custom-checkbox input').first().click(); // Uncheck first record - form.$('.custom-checkbox input').first().click(); // Recheck first record + testUtils.dom.click(form.$('.custom-checkbox input:checked')); + testUtils.dom.click(form.$('.custom-checkbox input').first()); + testUtils.dom.click(form.$('.custom-checkbox input').first()); + testUtils.dom.click(form.$('.custom-checkbox input').first()); assert.ok(form.$('.custom-checkbox input').eq(0).prop('checked'), "first checkbox should be checked"); @@ -706,7 +706,7 @@ QUnit.module('fields', {}, function () { assert.notOk(form.$('.custom-checkbox input').eq(2).prop('checked'), "third checkbox should not be checked"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -741,10 +741,10 @@ QUnit.module('fields', {}, function () { assert.ok(form.$('.custom-checkbox input').eq(2).prop('checked'), "third checkbox should be checked"); - form.$('.custom-checkbox input:checked').click(); // Uncheck default record - form.$('.custom-checkbox input').first().click(); // Check first record - form.$('.custom-checkbox input').first().click(); // Uncheck first record - form.$('.custom-checkbox input').first().click(); // Recheck first record + testUtils.dom.click(form.$('.custom-checkbox input:checked')); + testUtils.dom.click(form.$('.custom-checkbox input').first()); + testUtils.dom.click(form.$('.custom-checkbox input').first()); + testUtils.dom.click(form.$('.custom-checkbox input').first()); assert.ok(form.$('.custom-checkbox input').eq(0).prop('checked'), "first checkbox should be checked"); @@ -753,7 +753,7 @@ QUnit.module('fields', {}, function () { assert.notOk(form.$('.custom-checkbox input').eq(2).prop('checked'), "third checkbox should not be checked"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -798,18 +798,18 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); - $('.modal .o_data_row:first').click(); // add a first record to the relation + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click($('.modal .o_data_row:first')); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "the record should have been added to the relation"); assert.strictEqual(form.$('.o_data_row:first .o_badge_text').text(), 'leonardodonatello', "inner m2m should have been fetched and correctly displayed"); - form.$('.o_field_x2many_list_row_add a').click(); - $('.modal .o_data_row:first').click(); // add a second record to the relation + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click($('.modal .o_data_row:first')); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, "the second record should have been added to the relation"); assert.strictEqual(form.$('.o_data_row:nth(1) .o_badge_text').text(), 'donatelloraphael', "inner m2m should have been fetched and correctly displayed"); @@ -859,7 +859,7 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .o_data_row').length, 1, "should contain only one row (gold)"); @@ -897,14 +897,14 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('td.o_data_cell:first').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('td.o_data_cell:first')); - $('.modal-body input[type="checkbox"]').click(); - $('.modal .modal-footer .btn-primary').first().click(); + testUtils.dom.click($('.modal-body input[type="checkbox"]')); + testUtils.dom.click($('.modal .modal-footer .btn-primary').first()); // there is nothing left to save -> should not do a 'write' RPC - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.verifySteps([ 'read', // read initial record (on partner) @@ -972,7 +972,7 @@ QUnit.module('fields', {}, function () { assert.verifySteps(['read']); - form.$('.o_field_widget[name=foo]').val('trigger onchange').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), 'trigger onchange'); assert.verifySteps(['read', 'onchange', 'read']); assert.strictEqual(form.$('.o_x2m_control_panel .o_pager_counter').text().trim(), @@ -980,27 +980,27 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_kanban_record:not(".o_kanban_ghost")').length, 40, 'there should be 40 records displayed on page 1'); - form.$('.o_pager_next').click(); + testUtils.dom.click(form.$('.o_pager_next')); assert.verifySteps(['read', 'onchange', 'read', 'read']); assert.strictEqual(form.$('.o_x2m_control_panel .o_pager_counter').text().trim(), '41-45 / 45', "pager should be correct"); assert.strictEqual(form.$('.o_kanban_record:not(".o_kanban_ghost")').length, 5, 'there should be 5 records displayed on page 2'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.strictEqual(form.$('.o_x2m_control_panel .o_pager_counter').text().trim(), '1-40 / 45', "pager should be correct"); assert.strictEqual(form.$('.o_kanban_record:not(".o_kanban_ghost")').length, 40, 'there should be 40 records displayed on page 1'); - form.$('.o_pager_next').click(); + testUtils.dom.click(form.$('.o_pager_next')); assert.strictEqual(form.$('.o_x2m_control_panel .o_pager_counter').text().trim(), '41-45 / 45', "pager should be correct"); assert.strictEqual(form.$('.o_kanban_record:not(".o_kanban_ghost")').length, 5, 'there should be 5 records displayed on page 2'); - form.$('.o_pager_next').click(); // back to page 1 + testUtils.dom.click(form.$('.o_pager_next')); assert.strictEqual(form.$('.o_x2m_control_panel .o_pager_counter').text().trim(), '1-40 / 45', "pager should be correct"); assert.strictEqual(form.$('.o_kanban_record:not(".o_kanban_ghost")').length, 40, @@ -1041,7 +1041,7 @@ QUnit.module('fields', {}, function () { '</form>', }); - form.$('.o_field_widget[name=int_field]').val(2).trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 2); form.destroy(); }); @@ -1109,45 +1109,45 @@ QUnit.module('fields', {}, function () { }); // First round: add 51 records in batch - form.$buttons.find('.btn.btn-primary.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$buttons.find('.btn.btn-primary.o_form_button_edit')); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); var $modal = $('.modal-lg'); assert.equal($modal.length, 1, 'There should be one modal'); - $modal.find('thead input[type=checkbox]').click(); //select all the records we created in batch + 'gold' + testUtils.dom.click($modal.find('thead input[type=checkbox]')); - $modal.find('.btn.btn-primary.o_select_button').click(); + testUtils.dom.click($modal.find('.btn.btn-primary.o_select_button')); var m2m_records = form.$('.o_field_many2many.o_field_widget.o_field_x2many.o_field_x2many_list .o_data_cell:not(.o_many2many_tags_cell)'); assert.equal(m2m_records.length, 51, 'We should have added all the records present in the search view to the m2m field'); // the 50 in batch + 'gold' - form.$buttons.find('.btn.btn-primary.o_form_button_save').click(); + testUtils.dom.click(form.$buttons.find('.btn.btn-primary.o_form_button_save')); // Secound round: remove one record - form.$buttons.find('.btn.btn-primary.o_form_button_edit').click(); + testUtils.dom.click(form.$buttons.find('.btn.btn-primary.o_form_button_edit')); var trash_buttons = form.$('.o_field_many2many.o_field_widget.o_field_x2many.o_field_x2many_list .o_list_record_remove'); - trash_buttons.first().click(); + testUtils.dom.click(trash_buttons.first()); var pager_limit = form.$('.o_field_many2many.o_field_widget.o_field_x2many.o_field_x2many_list .o_pager_limit'); assert.equal(pager_limit.text(), '50', 'We should have 50 records in the m2m field'); // Third round: re-add 1 records - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); $modal = $('.modal-lg'); assert.equal($modal.length, 1, 'There should be one modal'); - $modal.find('thead input[type=checkbox]').click(); + testUtils.dom.click($modal.find('thead input[type=checkbox]')); - $modal.find('.btn.btn-primary.o_select_button').click(); + testUtils.dom.click($modal.find('.btn.btn-primary.o_select_button')); pager_limit = form.$('.o_field_many2many.o_field_widget.o_field_x2many.o_field_x2many_list .o_pager_limit'); assert.equal(pager_limit.text(), '51', diff --git a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js index 72044b99d2f..855b7695415 100644 --- a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js @@ -189,18 +189,18 @@ QUnit.module('fields', {}, function () { }, }); - testUtils.intercept(form, 'do_action', function (event) { + testUtils.mock.intercept(form, 'do_action', function (event) { assert.strictEqual(event.data.action.res_id, 17, "should do a do_action with correct parameters"); }); assert.strictEqual(form.$('a.o_form_uri:contains(aaa)').length, 1, "should contain a link"); - form.$('a.o_form_uri').click(); // click on the link in readonly mode (should trigger do_action) + testUtils.dom.click(form.$('a.o_form_uri')); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('.o_external_button').click(); // click on the external button (should do an RPC) + testUtils.dom.click(form.$('.o_external_button')); assert.strictEqual($('.modal .modal-title').text().trim(), 'Open: custom label', "dialog title should display the custom string label"); @@ -237,16 +237,16 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // click on the external button (should do an RPC) - form.$('.o_external_button').click(); + testUtils.dom.click(form.$('.o_external_button')); // save and close modal - $('.modal .modal-footer .btn-primary:first').click(); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); // save form - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; // click next on pager - form.pager.$('.o_pager_next').click(); + testUtils.dom.click(form.pager.$('.o_pager_next')); // this checks that the view did not ask for confirmation that the // record is dirty @@ -306,19 +306,19 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // click on the external button (should do an RPC) - form.$('.o_external_button').click(); + testUtils.dom.click(form.$('.o_external_button')); - $('.modal input[name="foo"]').val('brandon').trigger('input'); + testUtils.fields.editInput($('.modal input[name="foo"]'), 'brandon'); // save and close modal - $('.modal .modal-footer .btn-primary:first').click(); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); // save form - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; // click next on pager - form.pager.$('.o_pager_next').click(); + testUtils.dom.click(form.pager.$('.o_pager_next')); // this checks that the view did not ask for confirmation that the // record is dirty @@ -359,13 +359,13 @@ QUnit.module('fields', {}, function () { assert.strictEqual($('a.o_form_uri').html(), 'aaa<br>Street<br>City ZIP', "input should have a multi-line content in readonly due to show_address"); - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('button.o_external_button:visible').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, 'button.o_external_button:visible', "should have an open record button"); - form.$('input.o_input').click(); + testUtils.dom.click(form.$('input.o_input')); - assert.strictEqual(form.$('button.o_external_button:visible').length, 1, + assert.containsOnce(form, 'button.o_external_button:visible', "should still have an open record button"); form.$('input.o_input').trigger('focusout'); assert.strictEqual($('.modal button:contains(Create and edit)').length, 0, @@ -410,7 +410,7 @@ QUnit.module('fields', {}, function () { }, }); // click the turtle field, opens a modal with the turtle form view - form.$('.o_data_row:first td.o_data_cell').click(); + testUtils.dom.click(form.$('.o_data_row:first td.o_data_cell')); assert.strictEqual($('[name="turtle_trululu"]').text(), "second recordrue morgueparis 75013", "The partner's address should be displayed"); @@ -454,7 +454,7 @@ QUnit.module('fields', {}, function () { }, }); // click the turtle field, opens a modal with the turtle form view - form.$('.o_data_row:first').click(); + testUtils.dom.click(form.$('.o_data_row:first')); assert.strictEqual($('.modal [name=turtle_trululu]').text(), "second recordrue morgueparis 75013", "The partner's address should be displayed"); @@ -501,18 +501,18 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').click(); - $dropdown.find('.o_m2o_dropdown_option:contains(Search)').mouseenter().click(); // Open Search More + testUtils.form.clickEdit(form); + + testUtils.fields.many2one.clickOpenDropdown('trululu'); + testUtils.fields.many2one.clickItem('trululu', 'Search'); assert.strictEqual($('tr.o_data_row').length, 9, "should display 9 records"); - $('button:contains(Filters)').click(); - $('.o_add_custom_filter:visible').click(); // Add a custom filter, datetime field is selected + testUtils.dom.click($('button:contains(Filters)')); + testUtils.dom.click($('.o_add_custom_filter:visible')); assert.strictEqual($('.o_filter_condition select.o_searchview_extended_prop_field').val(), 'datetime', "datetime field should be selected"); - $('.o_apply_filter').click(); + testUtils.dom.click($('.o_apply_filter')); assert.strictEqual($('tr.o_data_row').length, 0, "should display 0 records"); form.destroy(); @@ -552,17 +552,17 @@ QUnit.module('fields', {}, function () { }); // open the many2one in form view and change something - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_external_button').click(); - $('.modal-body input[name="other_field"]').val('wood').trigger('input'); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_external_button')); + testUtils.fields.editInput($('.modal-body input[name="other_field"]'), 'wood'); // save the modal and make sure an onchange is triggered - $('.modal .modal-footer .btn-primary').first().click(); + testUtils.dom.click($('.modal .modal-footer .btn-primary').first()); assert.verifySteps(['read', 'get_formview_id', 'load_views', 'read', 'write', 'onchange', 'read']); // save the main record, and check that no extra rpcs are done (record // is not dirty, only a related record was modified) - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.verifySteps(['read', 'get_formview_id', 'load_views', 'read', 'write', 'onchange', 'read']); form.destroy(); }); @@ -584,13 +584,12 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - assert.strictEqual(form.$('span.o_field_widget[name=trululu]').length, 1, + assert.containsOnce(form, 'span.o_field_widget[name=trululu]', "should be displayed inside a span (sanity check)"); - assert.strictEqual(form.$('span.o_form_uri').length, 0, "should not have an anchor"); + assert.containsNone(form, 'span.o_form_uri', "should not have an anchor"); - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_widget[name=trululu] .o_external_button').length, - 0, "should not have the button to open the record"); + testUtils.form.clickEdit(form); + assert.containsNone(form, '.o_field_widget[name=trululu] .o_external_button', "should not have the button to open the record"); form.destroy(); }); @@ -632,14 +631,15 @@ QUnit.module('fields', {}, function () { // the SelectCreateDialog requests the session, so intercept its custom // event to specify a fake session to prevent it from crashing - testUtils.intercept(form, 'get_session', function (event) { + testUtils.mock.intercept(form, 'get_session', function (event) { event.data.callback({ user_context: {} }); }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); + var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').click(); + testUtils.fields.many2one.clickOpenDropdown('trululu'); assert.ok($dropdown.is(':visible'), 'clicking on the m2o input should open the dropdown if it is not open yet'); assert.strictEqual($dropdown.find('li:not(.o_m2o_dropdown_option)').length, 7, @@ -647,21 +647,21 @@ QUnit.module('fields', {}, function () { assert.strictEqual($dropdown.find('li.o_m2o_dropdown_option').length, 2, 'autocomplete should contain "Search More" and Create and Edit..."'); - form.$('.o_field_many2one input').click(); + testUtils.fields.many2one.clickOpenDropdown('trululu'); assert.ok(!$dropdown.is(':visible'), 'clicking on the m2o input should close the dropdown if it is open'); // change the value of the m2o with a suggestion of the dropdown - form.$('.o_field_many2one input').click(); - $dropdown.find('li:first()').click(); + testUtils.fields.many2one.clickOpenDropdown('trululu'); + testUtils.fields.many2one.clickHighlightedItem('trululu'); assert.ok(!$dropdown.is(':visible'), 'clicking on a value should close the dropdown'); assert.strictEqual(form.$('.o_field_many2one input').val(), 'first record', 'value of the m2o should have been correctly updated'); // change the value of the m2o with a record in the 'Search More' modal - form.$('.o_field_many2one input').click(); + testUtils.fields.many2one.clickOpenDropdown('trululu'); // click on 'Search More' (mouseenter required by ui-autocomplete) - $dropdown.find('.o_m2o_dropdown_option:contains(Search)').mouseenter().click(); + testUtils.fields.many2one.clickItem('trululu', 'Search'); assert.ok($('.modal .o_list_view').length, "should have opened a list view in a modal"); assert.ok(!$('.modal .o_list_view .o_list_record_selector').length, "there should be no record selector in the list view"); @@ -674,14 +674,14 @@ QUnit.module('fields', {}, function () { assert.strictEqual($('.modal tbody tr').length, 10, "list should be restricted to records containing a P (10 records)"); // choose a record - $('.modal tbody tr:contains(Partner 20)').click(); // choose record 'Partner 20' + testUtils.dom.click($('.modal tbody tr:contains(Partner 20)')); assert.ok(!$('.modal').length, "should have closed the modal"); assert.ok(!$dropdown.is(':visible'), 'should have closed the dropdown'); assert.strictEqual(form.$('.o_field_many2one input').val(), 'Partner 20', 'value of the m2o should have been correctly updated'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.strictEqual(form.$('a.o_form_uri').text(), 'Partner 20', "should display correct value after save"); @@ -701,17 +701,17 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - assert.strictEqual(form.$('a.o_form_uri').length, 1, + assert.containsOnce(form, 'a.o_form_uri', "should display 1 m2o link in form"); - assert.strictEqual(form.$('a.o_form_uri').attr('href'), "#id=4&model=partner", + assert.hasAttrValue(form.$('a.o_form_uri'), 'href', "#id=4&model=partner", "href should contain id and model"); // Remove value from many2one and then save, there should not have href with id and model on m2o anchor - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); form.$('.o_field_many2one input').val('').trigger('keyup').trigger('focusout'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; - assert.strictEqual(form.$('a.o_form_uri').attr('href'), "#", + assert.hasAttrValue(form.$('a.o_form_uri'), 'href', "#", "href should have #"); form.destroy(); @@ -748,7 +748,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_field_many2one input').val(), 'aaa', "should be initially set to 'aaa'"); - form.$('.o_field_many2one input').click(); // should search with '' + testUtils.dom.click(form.$('.o_field_many2one input')); // unset the many2one -> should search again with '' form.$('.o_field_many2one input').val('').trigger('keydown'); concurrency.delay(0).then(function () { @@ -758,8 +758,8 @@ QUnit.module('fields', {}, function () { return concurrency.delay(0); }).then(function () { // close and re-open the dropdown -> should search with 'p' again - form.$('.o_field_many2one input').click(); - form.$('.o_field_many2one input').click(); + testUtils.dom.click(form.$('.o_field_many2one input')); + testUtils.dom.click(form.$('.o_field_many2one input')); assert.verifySteps(['search: ', 'search: ', 'search: p', 'search: p']); @@ -793,12 +793,12 @@ QUnit.module('fields', {}, function () { assert.ok(form.$('a:contains(and some address)').length, "should display additional result"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), "first record", "actual field value should be displayed to be edited"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.ok(form.$('a:contains(and some address)').length, "should still display additional result"); @@ -816,8 +816,8 @@ QUnit.module('fields', {}, function () { }); // edit first input, to trigger autocomplete - list.$('.o_data_row .o_data_cell').first().click(); - list.$('.o_data_cell input').val('').trigger('input'); + testUtils.dom.click(list.$('.o_data_row .o_data_cell').first()); + testUtils.fields.editInput(list.$('.o_data_cell input'), ''); // press keydown, to select first choice list.$('.o_data_cell input').focus().trigger($.Event('keydown', { @@ -829,15 +829,15 @@ QUnit.module('fields', {}, function () { // to the next line) var $dropdown = list.$('.o_field_many2one input').autocomplete('widget'); assert.ok($dropdown.is(':visible'), "dropdown should be visible"); - assert.ok(list.$('.o_data_row:eq(0)').hasClass('o_selected_row'), + assert.hasClass(list.$('.o_data_row:eq(0)'),'o_selected_row', 'first data row should still be selected'); - assert.ok(!list.$('.o_data_row:eq(1)').hasClass('o_selected_row'), + assert.doesNotHaveClass(list.$('.o_data_row:eq(1)'), 'o_selected_row', 'second data row should not be selected'); list.destroy(); }); - QUnit.test('standalone many2one field', function (assert) { + QUnit.test('standalone many2one field', async function (assert) { assert.expect(4); var done = assert.async(); @@ -867,7 +867,7 @@ QUnit.module('fields', {}, function () { }, }); var parent = new StandaloneWidget(model); - testUtils.addMockEnvironment(parent, { + testUtils.mock.addMockEnvironment(parent, { data: self.data, mockRPC: function (route, args) { assert.step(args.method); @@ -881,14 +881,12 @@ QUnit.module('fields', {}, function () { }); relField.appendTo(fixture); - $('input.o_input').val('xyzzrot').trigger('input'); + testUtils.fields.editInput($('input.o_input'), 'xyzzrot'); concurrency.delay(0).then(function () { - var $dropdown = $('input.o_input').autocomplete('widget'); - $dropdown.find('.o_m2o_dropdown_option:contains(Create)') - .first().mouseenter().click(); + testUtils.fields.many2one.clickItem('partner_id', 'Create'); - assert.strictEqual(relField.$('.o_external_button').length, 0, + assert.containsNone(relField, '.o_external_button', "should not have the button to open the record"); assert.verifySteps(['name_search', 'name_create']); @@ -923,21 +921,17 @@ QUnit.module('fields', {}, function () { // '</form>', // res_id: 1, // }); - // form.$buttons.find('.o_form_button_edit').click(); + // testUtils.form.clickEdit(form); // assert.strictEqual(form.$('input').eq(1).val(), 'xpad', "initial product_id val should be xpad"); - // form.$('input').eq(0).val("let us trigger an onchange").trigger('input'); + // testUtils.fields.editInput(form.$('input').eq(0), "let us trigger an onchange"); // assert.strictEqual(form.$('input').eq(1).val(), 'xphone', "onchange should have been applied"); // }); - QUnit.test('form: quick create then save directly', function (assert) { - var done = assert.async(); + QUnit.test('form: quick create then save directly', async function (assert) { assert.expect(5); - var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY; - relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0; - var def = $.Deferred(); var newRecordID; var form = createView({ @@ -964,33 +958,21 @@ QUnit.module('fields', {}, function () { return result; }, }); + await testUtils.fields.many2one.searchAndClickItem('trululu', 'b'); + testUtils.form.clickSave(form);; - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').val('b').trigger('keydown'); - concurrency.delay(0).then(function () { - $dropdown.find('li:first()').click(); // quick create 'b' - form.$buttons.find('.o_form_button_save').click(); - - assert.verifySteps(['name_create'], - "should wait for the name_create before creating the record"); - - def.resolve(); + assert.verifySteps(['name_create'], + "should wait for the name_create before creating the record"); - assert.verifySteps(['name_create', 'create']); + def.resolve(); - relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY; - form.destroy(); - done(); - }); + assert.verifySteps(['name_create', 'create']); + form.destroy(); }); - QUnit.test('list: quick create then save directly', function (assert) { - var done = assert.async(); + QUnit.test('list: quick create then save directly', async function (assert) { assert.expect(8); - var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY; - relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0; - var def = $.Deferred(); var newRecordID; var list = createView({ @@ -1018,40 +1000,30 @@ QUnit.module('fields', {}, function () { }, }); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); - var $dropdown = list.$('.o_field_many2one input').autocomplete('widget'); - list.$('.o_field_many2one input').val('b').trigger('keydown'); - concurrency.delay(0).then(function () { - $dropdown.find('li:first()').click(); // quick create 'b' - list.$buttons.find('.o_list_button_add').click(); + await testUtils.fields.many2one.searchAndClickItem('trululu', {search:'b'}); + list.$buttons.find('.o_list_button_add').show(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); - assert.verifySteps(['name_create'], - "should wait for the name_create before creating the record"); - assert.strictEqual(list.$('.o_data_row').length, 4, - "should wait for the name_create before adding the new row"); + assert.verifySteps(['name_create'], + "should wait for the name_create before creating the record"); + assert.containsN(list, '.o_data_row', 4, + "should wait for the name_create before adding the new row"); - def.resolve(); + def.resolve(); - assert.verifySteps(['name_create', 'create']); - assert.strictEqual(list.$('.o_data_row:nth(1) .o_data_cell').text(), 'b', - "created row should have the correct m2o value"); - assert.strictEqual(list.$('.o_data_row').length, 5, - "should have added the fifth row"); + assert.verifySteps(['name_create', 'create']); + assert.strictEqual(list.$('.o_data_row:nth(1) .o_data_cell').text(), 'b', + "created row should have the correct m2o value"); + assert.containsN(list, '.o_data_row', 5, "should have added the fifth row"); - relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY; - list.destroy(); - done(); - }); + list.destroy(); }); - QUnit.test('list in form: quick create then save directly', function (assert) { - var done = assert.async(); + QUnit.test('list in form: quick create then save directly', async function (assert) { assert.expect(6); - var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY; - relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0; - var def = $.Deferred(); var newRecordID; var form = createView({ @@ -1085,27 +1057,19 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); - - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').val('b').trigger('keydown'); - concurrency.delay(0).then(function () { - $dropdown.find('li:first()').click(); // quick create 'b' - form.$buttons.find('.o_form_button_save').click(); - - assert.verifySteps(['name_create'], - "should wait for the name_create before creating the record"); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.fields.many2one.searchAndClickItem('trululu', {search: 'b'}); + testUtils.form.clickSave(form);; - def.resolve(); + assert.verifySteps(['name_create'], + "should wait for the name_create before creating the record"); - assert.verifySteps(['name_create', 'create']); - assert.strictEqual(form.$('.o_data_row:first .o_data_cell').text(), 'b', - "first row should have the correct m2o value"); + def.resolve(); - relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY; - form.destroy(); - done(); - }); + assert.verifySteps(['name_create', 'create']); + assert.strictEqual(form.$('.o_data_row:first .o_data_cell').text(), 'b', + "first row should have the correct m2o value"); + form.destroy(); }); QUnit.test('list in form: quick create then add a new line directly', function (assert) { @@ -1154,31 +1118,29 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); - - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.$('.o_field_many2one input').val('b').trigger('keydown'); concurrency.delay(0).then(function () { - $dropdown.find('li:first()').click(); // quick create 'b' - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.fields.many2one.clickHighlightedItem('trululu'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "there should still be only one row"); - assert.ok(form.$('.o_data_row').hasClass('o_selected_row'), + assert.hasClass(form.$('.o_data_row'),'o_selected_row', "the row should still be in edition"); def.resolve(); assert.strictEqual(form.$('.o_data_row:first .o_data_cell').text(), 'b', "first row should have the correct m2o value"); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, "there should now be 2 rows"); - assert.ok(form.$('.o_data_row:nth(1)').hasClass('o_selected_row'), + assert.hasClass(form.$('.o_data_row:nth(1)'),'o_selected_row', "the second row should be in edition"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "there should be 1 row saved (the second one was empty and invalid)"); assert.strictEqual(form.$('.o_data_row .o_data_cell').text(), 'b', "should have the correct m2o value"); @@ -1304,9 +1266,9 @@ QUnit.module('fields', {}, function () { assert.strictEqual(requiredElement.text(), "", "should have empty string in the required field on this record"); - requiredElement.click(); + testUtils.dom.click(requiredElement); // discard by clicking on body - $('body').click(); + testUtils.dom.click($('body')); assert.strictEqual($('tr.o_data_row').length, 1, "should still have the record in the o2m"); @@ -1398,7 +1360,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('td.o_data_cell').first().next().text(), "first record", "should show display_name of trululu of 1st record"); - form.$('button.o_pager_next').click(); + testUtils.dom.click(form.$('button.o_pager_next')); assert.strictEqual(form.$('td.o_data_cell').first().text(), "record2", "should show display_name of 2nd record"); @@ -1451,7 +1413,7 @@ QUnit.module('fields', {}, function () { }); // check that there is a record in the editable list with empty string as required field - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should have a row in the editable list"); assert.strictEqual($('td.o_data_cell').first().text(), "entry", "should have the correct displayed name"); @@ -1462,12 +1424,12 @@ QUnit.module('fields', {}, function () { "should have empty string in the required field on this record"); // click on empty required field in editable list record - requiredField.click(); + testUtils.dom.click(requiredField); // click off so that the required field still stay empty - $('body').click(); + testUtils.dom.click($('body')); // record should not be dropped - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should not have dropped record in the editable list"); assert.strictEqual($('td.o_data_cell').first().text(), "entry", "should still have the correct displayed name"); @@ -1513,15 +1475,15 @@ QUnit.module('fields', {}, function () { }); // check no record in list - assert.strictEqual(form.$('.o_data_row').length, 0, + assert.containsNone(form, '.o_data_row', "should have no row in the editable list"); // select product_id to force on_change in editable list - form.$('.o_field_widget[name="product_id"] .o_input').click(); - $('.ui-menu-item').first().click(); + testUtils.dom.click(form.$('.o_field_widget[name="product_id"] .o_input')); + testUtils.dom.click($('.ui-menu-item').first()); // check that there is a record in the editable list with empty string as required field - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should have a row in the editable list"); assert.strictEqual($('td.o_data_cell').first().text(), "entry", "should have the correct displayed name"); @@ -1532,12 +1494,12 @@ QUnit.module('fields', {}, function () { "should have empty string in the required field on this record"); // click on empty required field in editable list record - requiredField.click(); + testUtils.dom.click(requiredField); // click off so that the required field still stay empty - $('body').click(); + testUtils.dom.click($('body')); // record should not be dropped - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should not have dropped record in the editable list"); assert.strictEqual($('td.o_data_cell').first().text(), "entry", "should still have the correct displayed name"); @@ -1569,13 +1531,13 @@ QUnit.module('fields', {}, function () { }); // Click on "Add an item" - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); var charField = form.$('.o_field_widget.o_field_char[name="display_name"]'); var requiredField = form.$('.o_field_widget.o_required_modifier[name="trululu"]'); charField.val("some text"); assert.strictEqual(charField.length, 1, "should have a char field 'display_name' on this record"); - assert.notOk(charField.hasClass('o_required_modifier'), + assert.doesNotHaveClass(charField, 'o_required_modifier', "the char field should not be required on this record"); assert.strictEqual(charField.val(), "some text", "should have entered text in the char field on this record"); @@ -1585,12 +1547,12 @@ QUnit.module('fields', {}, function () { "should have empty string in the required field on this record"); // click on empty required field in editable list record - requiredField.click(); + testUtils.dom.click(requiredField); // click off so that the required field still stay empty - $('body').click(); + testUtils.dom.click($('body')); // record should be dropped - assert.strictEqual(form.$('.o_data_row').length, 0, + assert.containsNone(form, '.o_data_row', "should have dropped record in the editable list"); form.destroy(); @@ -1621,12 +1583,12 @@ QUnit.module('fields', {}, function () { '</form>', }); - assert.strictEqual(form.$('.o_data_row').length, 0, + assert.containsNone(form, '.o_data_row', "should initially not have any record in the list"); // Click on "Add an item" - form.$('.o_field_x2many_list_row_add a').click(); - assert.strictEqual(form.$('.o_data_row').length, 1, + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + assert.containsOnce(form, '.o_data_row', "should have a temporary record in the list"); var $inputEditMode = form.$('.o_field_widget.o_required_modifier[name="trululu"] input'); @@ -1636,23 +1598,19 @@ QUnit.module('fields', {}, function () { "should have empty string in the required field on this record"); // add something to required field and leave edit mode of the record - $inputEditMode.click(); - $('li.ui-menu-item').first().click(); - $('body').click(); // leave edit mode on the line + testUtils.dom.click($inputEditMode); + testUtils.dom.click($('li.ui-menu-item').first()); + testUtils.dom.click($('body')); var $inputReadonlyMode = form.$('.o_data_cell.o_required_modifier'); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should not have dropped valid record when leaving edit mode"); assert.strictEqual($inputReadonlyMode.text(), "first record", "should have put some content in the required field on this record"); // remove the required field and leave edit mode of the record - $('.o_data_row').click(); // enter edit mode on the line - $inputEditMode.click(); - $inputEditMode.val(""); - $('body').click(); - - assert.strictEqual(form.$('.o_data_row').length, 1, + testUtils.dom.click($('.o_data_row')); + assert.containsOnce(form, '.o_data_row', "should not have dropped record in the list on discard (invalid on UPDATE)"); assert.strictEqual($inputReadonlyMode.text(), "first record", "should keep previous valid required field content on this record"); @@ -1714,9 +1672,9 @@ QUnit.module('fields', {}, function () { // edit the subrecord and save displayName = 'new value'; - form.$('.o_data_cell').click(); - form.$('.o_data_cell input').val(displayName).trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('.o_data_cell')); + testUtils.fields.editInput(form.$('.o_data_cell input'), displayName); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -1769,7 +1727,7 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -1819,11 +1777,11 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('td.o_data_cell:first').click(); // edit first one2many line - form.$('.o_external_button').click(); // open product sub view in modal - $('button:contains("Just do it !")').click(); // click on action button - $('button:contains("Just don\'t do it !")').click(); // click on object button + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('td.o_data_cell:first')); + testUtils.dom.click(form.$('.o_external_button')); + testUtils.dom.click($('button:contains("Just do it !")')); + testUtils.dom.click($('button:contains("Just don\'t do it !")')); form.destroy(); }); @@ -1891,9 +1849,9 @@ QUnit.module('fields', {}, function () { return this._super.apply(this, arguments); }, }).then(function (form) { - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_data_cell').click(); - form.$('.o_external_button').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_data_cell')); + testUtils.dom.click(form.$('.o_external_button')); var $modal = $('.modal'); assert.equal($modal.length, 1, @@ -1903,12 +1861,12 @@ QUnit.module('fields', {}, function () { assert.equal($handles.length, 2, 'There should be 2 sequence handlers'); - testUtils.dragAndDrop($handles.eq(1), $modal.find('tbody tr').first(), + testUtils.dom.dragAndDrop($handles.eq(1), $modal.find('tbody tr').first(), { position: 'top' }); // Saving the modal and then the original model - $modal.find('.modal-footer .btn-primary').click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click($modal.find('.modal-footer .btn-primary')); + testUtils.form.clickSave(form);; assert.verifySteps(['onchange sequence', 'partner_type write']); @@ -1937,9 +1895,9 @@ QUnit.module('fields', {}, function () { return this._super(route, args); } }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('input').click(); + testUtils.dom.click(form.$('input')); form.destroy(); }); @@ -1963,9 +1921,9 @@ QUnit.module('fields', {}, function () { return this._super(route, args); }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('input:eq(2)').click(); + testUtils.dom.click(form.$('input:eq(2)')); form.destroy(); }); @@ -2016,15 +1974,13 @@ QUnit.module('fields', {}, function () { res_id: 1, }); assert.strictEqual(form.$('a').text(), '', 'the tag a should be empty'); - form.$buttons.find('.o_form_button_edit').click(); - - form.$('.o_field_many2one input').click(); - form.$('.o_field_many2one input').autocomplete('widget').find('a').first().click(); - + testUtils.form.clickEdit(form); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickItem('product_id','xphone'); assert.strictEqual(form.$('input').val(), "xphone", "should have selected xphone"); - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.form.clickDiscard(form);; assert.strictEqual(form.$('a').text(), '', 'the tag a should be empty'); form.destroy(); }); @@ -2073,10 +2029,10 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_widget[name=product_id] input').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_widget[name=product_id] input')); - form.$('.o_field_widget[name=trululu] input').click(); + testUtils.dom.click(form.$('.o_field_widget[name=trululu] input')); form.destroy(); }); @@ -2105,7 +2061,7 @@ QUnit.module('fields', {}, function () { form.$('.o_field_many2one input').focus(); form.$('.o_field_many2one input').val('new partner').trigger('keyup').trigger('focusout'); - $('.modal .modal-footer .btn-primary').first().click(); + testUtils.dom.click($('.modal .modal-footer .btn-primary').first()); form.destroy(); }); @@ -2134,30 +2090,30 @@ QUnit.module('fields', {}, function () { // cancel the many2one creation with Cancel button form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur'); assert.strictEqual($('.modal').length, 1, "there should be one opened modal"); - $('.modal .modal-footer .btn:contains(Cancel)').click(); + testUtils.dom.click($('.modal .modal-footer .btn:contains(Cancel)')); assert.strictEqual(form.$('.o_field_many2one input').val(), "", 'the many2one should not set a value as its creation has been cancelled (with Cancel button)'); // cancel the many2one creation with Close button form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur'); - $('.modal .modal-header button').click(); + testUtils.dom.click($('.modal .modal-header button')); assert.strictEqual(form.$('.o_field_many2one input').val(), "", 'the many2one should not set a value as its creation has been cancelled (with Close button)'); // select a new value then cancel the creation of the new one --> restore the previous - form.$('.o_field_many2one input').click(); - form.$('.o_field_many2one input').autocomplete('widget').find('a').first().click(); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickItem('product_id','o'); assert.strictEqual(form.$('input').val(), "xphone", "should have selected xphone"); form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur'); assert.strictEqual($('.modal').length, 1, "there should be one opened modal"); - $('.modal .modal-footer .btn:contains(Cancel)').click(); + testUtils.dom.click($('.modal .modal-footer .btn:contains(Cancel)')); assert.strictEqual(form.$('.o_field_many2one input').val(), "xphone", 'should have restored the many2one with its previous selected value (xphone)'); // confirm the many2one creation form.$('.o_field_many2one input').focus(); form.$('.o_field_many2one input').val('new partner').trigger('keyup').trigger('blur'); - $('.modal .modal-footer .btn-primary').click(); + testUtils.dom.clickFirst($('.modal .modal-footer .btn-primary')); assert.strictEqual($('.modal .o_form_view').length, 1, 'a new modal should be opened and contain a form view'); @@ -2213,21 +2169,21 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_many2one input').click(); + testUtils.dom.click(form.$('.o_field_many2one input')); assert.strictEqual($('.ui-autocomplete .o_m2o_dropdown_option:contains(Create)').length, 0, "there shouldn't be any option to search and create"); - $('.ui-autocomplete li:contains(xpad)').mouseenter().click(); + testUtils.dom.click($('.ui-autocomplete li:contains(xpad)').mouseenter()); assert.strictEqual(form.$('.o_field_many2one input').val(), "xpad", "the correct record should be selected"); - assert.strictEqual(form.$('.o_field_many2one .o_external_button').length, 1, + assert.containsOnce(form, '.o_field_many2one .o_external_button', "there should be an external button displayed"); - form.$('.o_field_many2one .o_external_button').click(); + testUtils.dom.click(form.$('.o_field_many2one .o_external_button')); assert.strictEqual($('.modal .o_form_view.o_form_readonly').length, 1, "there should be a readonly form view opened"); - $('.modal .o_form_button_cancel').click(); + testUtils.dom.click($('.modal .o_form_button_cancel')); form.$('.o_field_many2one input').val('new product').trigger('keyup').trigger('focusout'); @@ -2248,13 +2204,13 @@ QUnit.module('fields', {}, function () { arch: '<tree editable="bottom"><field name="product_id"/></tree>', }); - list.$('td.o_data_cell:first').click(); - assert.strictEqual(list.$('.o_selected_row').length, 1, + testUtils.dom.click(list.$('td.o_data_cell:first')); + assert.containsOnce(list, '.o_selected_row', "should have a row in edit mode"); // we now write 'a' and press enter to check that the selection is // working, and prevent the navigation - list.$('td.o_data_cell input:first').val('a').trigger('input'); + testUtils.fields.editInput(list.$('td.o_data_cell input:first'), 'a'); concurrency.delay(0).then(function () { var $input = list.$('td.o_data_cell input:first'); var $dropdown = $input.autocomplete('widget'); @@ -2276,12 +2232,12 @@ QUnit.module('fields', {}, function () { assert.notOk(document.contains($input[0]), "input should no longer be in dom"); - assert.ok(list.$('tr.o_data_row:eq(1)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(1)'),'o_selected_row', "second row should now be selected"); // we now write again 'a' in the cell to select xpad. We will now // test with the tab key - list.$('td.o_data_cell input:first').val('a').trigger('input'); + testUtils.fields.editInput(list.$('td.o_data_cell input:first'), 'a'); return concurrency.delay(0); }).then(function () { var $input = list.$('td.o_data_cell input:first'); @@ -2302,7 +2258,7 @@ QUnit.module('fields', {}, function () { assert.notOk(document.contains($input[0]), "input should no longer be in dom"); - assert.ok(list.$('tr.o_data_row:eq(2)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(2)'),'o_selected_row', "third row should now be selected"); list.destroy(); relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY; @@ -2331,7 +2287,7 @@ QUnit.module('fields', {}, function () { }); var $input = form.$('.o_field_many2one input'); - $input.val("Something that does not exist").trigger('input'); + testUtils.fields.editInput($input, "Something that does not exist"); $('.ui-autocomplete .ui-menu-item a:contains(Create and)').trigger('mouseenter'); concurrency.delay(0).then(function () { $input.trigger($.Event('keydown', { @@ -2351,7 +2307,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual($('.modal').length, 1, "should have one modal in body"); // Check that discarding clears $input - $('.modal .o_form_button_cancel').click(); + testUtils.dom.click($('.modal .o_form_button_cancel')); assert.strictEqual($input.val(), '', "the field should be empty"); form.destroy(); @@ -2393,7 +2349,7 @@ QUnit.module('fields', {}, function () { }); var $input = form.$('.o_field_many2one input'); - $input.val("first").trigger('input'); + testUtils.fields.editInput($input, "first"); concurrency.delay(0).then(function () { var evOptions = { which: $.ui.keyCode.TAB, @@ -2452,8 +2408,8 @@ QUnit.module('fields', {}, function () { }, }); - list.$('td.o_data_cell:first').click(); - list.$('td.o_data_cell input:first').val('a').trigger('input'); + testUtils.dom.click(list.$('td.o_data_cell:first')); + testUtils.fields.editInput(list.$('td.o_data_cell input:first'), 'a'); concurrency.delay(0).then(function () { var $input = list.$('td.o_data_cell input:first'); $input.trigger($.Event('keydown', { @@ -2508,8 +2464,8 @@ QUnit.module('fields', {}, function () { }, }); - list.$('td.o_data_cell:first').click(); - list.$('td.o_data_cell input:first').val('a').trigger('input'); + testUtils.dom.click(list.$('td.o_data_cell:first')); + testUtils.fields.editInput(list.$('td.o_data_cell input:first'), 'a'); concurrency.delay(0).then(function () { var $input = list.$('td.o_data_cell input:first'); $input.trigger($.Event('keydown', { @@ -2572,13 +2528,13 @@ QUnit.module('fields', {}, function () { }); // trigger a name_search (domain should be []) - form.$('.o_field_widget[name=trululu] input').click(); + testUtils.dom.click(form.$('.o_field_widget[name=trululu] input')); // close the dropdown - form.$('.o_field_widget[name=trululu] input').click(); + testUtils.dom.click(form.$('.o_field_widget[name=trululu] input')); // trigger an onchange that will update the domain - form.$('.o_field_widget[name=int_field]').val(2).trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 2); // trigger a name_search (domain should be [['id', 'in', [10]]]) - form.$('.o_field_widget[name=trululu] input').click(); + testUtils.dom.click(form.$('.o_field_widget[name=trululu] input')); form.destroy(); }); @@ -2624,18 +2580,18 @@ QUnit.module('fields', {}, function () { // add a first row with a specific domain for the m2o domain = [['id', 'in', [10]]]; // domain for subrecord 1 - form.$('.o_field_x2many_list_row_add a').click(); // triggers the onchange - form.$('.o_field_widget[name=trululu] input').click(); // triggers the name_search + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('.o_field_widget[name=trululu] input')); // add a second row with another domain for the m2o domain = [['id', 'in', [5]]]; // domain for subrecord 2 - form.$('.o_field_x2many_list_row_add a').click(); // triggers the onchange - form.$('.o_field_widget[name=trululu] input').click(); // triggers the name_search + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('.o_field_widget[name=trululu] input')); // check again the first row to ensure that the domain hasn't change domain = [['id', 'in', [10]]]; // domain for subrecord 1 should have been kept - form.$('.o_data_row:first .o_data_cell').click(); - form.$('.o_field_widget[name=trululu] input').click(); // triggers the name_search + testUtils.dom.click(form.$('.o_data_row:first .o_data_cell')); + testUtils.dom.click(form.$('.o_field_widget[name=trululu] input')); form.destroy(); }); @@ -2673,15 +2629,15 @@ QUnit.module('fields', {}, function () { }); // Opening the modal - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_data_row td:contains(first record)').click(); - form.$('.o_external_button').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_data_row td:contains(first record)')); + testUtils.dom.click(form.$('.o_external_button')); assert.strictEqual($('.modal').length, 1, "should have one modal in body"); // Changing the 'trululu' value - $('.modal input[name="display_name"]').val('test').trigger('input'); - $('.modal button.btn-primary').click(); + testUtils.fields.editInput($('.modal input[name="display_name"]'), 'test'); + testUtils.dom.click($('.modal button.btn-primary')); // Test whether the value has changed assert.strictEqual($('.modal').length, 0, @@ -2716,12 +2672,12 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_data_row .o_list_number').text(), '124', "should have correct order initially"); - form.$('.o_list_view thead th:nth(1)').click(); + testUtils.dom.click(form.$('.o_list_view thead th:nth(1)')); assert.strictEqual(form.$('.o_data_row .o_list_number').text(), '412', "should have correct order (ASC)"); - form.$('.o_list_view thead th:nth(1)').click(); + testUtils.dom.click(form.$('.o_list_view thead th:nth(1)')); assert.strictEqual(form.$('.o_data_row .o_list_number').text(), '214', "should have correct order (DESC)"); @@ -2757,20 +2713,20 @@ QUnit.module('fields', {}, function () { } }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var x2mList = form.$('.o_field_x2many_list[name=p]'); // Add a record in the list - x2mList.find('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(x2mList.find('.o_field_x2many_list_row_add a')); var modal = $('.modal-lg'); var nameInput = modal.find('input.o_input[name=display_name]'); - nameInput.val('michelangelo').trigger('input'); + testUtils.fields.editInput(nameInput, 'michelangelo'); // Save the record in the modal (though it is still virtual) - modal.find('.btn-primary').first().click(); + testUtils.dom.click(modal.find('.btn-primary').first()); assert.equal(x2mList.find('.o_data_row').length, 1, 'There should be 1 records in the x2m list'); @@ -2783,7 +2739,7 @@ QUnit.module('fields', {}, function () { 'The display name field should have the right value'); // Save the whole thing - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; x2mList = form.$('.o_field_x2many_list[name=p]'); @@ -2828,15 +2784,15 @@ QUnit.module('fields', {}, function () { var x2mList = form.$('.o_field_x2many_list[name=p]'); // Add a record in the list - x2mList.find('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(x2mList.find('.o_field_x2many_list_row_add a')); var modal = $('.modal-lg'); var nameInput = modal.find('input.o_input[name=display_name]'); - nameInput.val('michelangelo').trigger('input'); + testUtils.fields.editInput(nameInput, 'michelangelo'); // Save the record in the modal (though it is still virtual) - modal.find('.btn-primary').first().click(); + testUtils.dom.click(modal.find('.btn-primary').first()); assert.equal(x2mList.find('.o_data_row').length, 1, 'There should be 1 records in the x2m list'); @@ -2871,13 +2827,13 @@ QUnit.module('fields', {}, function () { var x2mList = form.$('.o_field_x2many_list[name=p]'); // Add a first record in the list - x2mList.find('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(x2mList.find('.o_field_x2many_list_row_add a')); // Save & New - $('.modal-lg').find('.btn-primary').eq(1).click(); + testUtils.dom.click($('.modal-lg').find('.btn-primary').eq(1)); // Save & Close - $('.modal-lg').find('.btn-primary').eq(0).click(); + testUtils.dom.click($('.modal-lg').find('.btn-primary').eq(0)); assert.equal(x2mList.find('.o_data_row').length, 2, 'There should be 2 records in the x2m list'); @@ -2913,18 +2869,18 @@ QUnit.module('fields', {}, function () { '</form>', res_id: 1, }); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_many2one[name="product_id"] input').click(); - $('li.ui-menu-item a:contains(xpad)').trigger('mouseenter').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_many2one[name="product_id"] input')); + testUtils.dom.click($('li.ui-menu-item a:contains(xpad)').trigger('mouseenter')); + assert.containsOnce(form, 'th', "should be 1 column when the product_id is set"); form.$('.o_field_many2one[name="product_id"] input').val('').trigger('keyup'); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many when product_id is not set"); - form.$('.o_field_boolean[name="bar"] input').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.dom.click(form.$('.o_field_boolean[name="bar"] input')); + assert.containsOnce(form, 'th', "should be 1 column after the value change"); form.destroy(); }); @@ -2959,19 +2915,19 @@ QUnit.module('fields', {}, function () { }); // bar is false so there should be 1 column - assert.strictEqual(form.$('th').length, 1, + assert.containsOnce(form, 'th', "should be only 1 column ('foo') in the one2many"); - assert.strictEqual(form.$('.o_list_view .o_data_row').length, 1, "should contain one row"); + assert.containsOnce(form, '.o_list_view .o_data_row', "should contain one row"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // add a new o2m record - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.$('.o_field_one2many input:first').focus(); - form.$('.o_field_one2many input:first').val('New line').trigger('input'); - form.$el.click(); // click outside to save a line + testUtils.fields.editInput(form.$('.o_field_one2many input:first'), 'New line'); + testUtils.dom.click(form.$el); - assert.strictEqual(form.$('th').length, 2, "should be 2 columns('foo' + 'int_field')"); + assert.containsN(form, 'th', 2, "should be 2 columns('foo' + 'int_field')"); form.destroy(); }); @@ -3005,18 +2961,18 @@ QUnit.module('fields', {}, function () { '</tree>', }, }); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_many2one[name="product_id"] input').click(); - $('li.ui-menu-item a:contains(xpad)').trigger('mouseenter').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_many2one[name="product_id"] input')); + testUtils.dom.click($('li.ui-menu-item a:contains(xpad)').trigger('mouseenter')); + assert.containsOnce(form, 'th', "should be 1 column when the product_id is set"); form.$('.o_field_many2one[name="product_id"] input').val('').trigger('keyup'); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many when product_id is not set"); - form.$('.o_field_boolean[name="bar"] input').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.dom.click(form.$('.o_field_boolean[name="bar"] input')); + assert.containsOnce(form, 'th', "should be 1 column after the value change"); form.destroy(); }); diff --git a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js index 7181b5267b1..af508179830 100644 --- a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js @@ -198,7 +198,7 @@ QUnit.module('fields', {}, function () { // change the int_field through drag and drop // that way, we'll trigger the sorting and the name_get // of the lines of "p" - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(1), form.$('tbody tr').first(), { position: 'top' } @@ -240,7 +240,7 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list .o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list .o_field_x2many_list_row_add a')); var $dataRows = form.$('.o_field_x2many_list .o_data_row'); assert.equal($dataRows.length, 2, @@ -286,7 +286,6 @@ QUnit.module('fields', {}, function () { archs: { 'turtle,false,form': '<form><field name="parent_id" domain="[(\'id\', \'in\', parent.turtles)]"/></form>', }, - mockRPC: function (route, args) { if (route === '/web/dataset/call_kw/turtle/name_search') { // We are going to pass twice here @@ -295,29 +294,24 @@ QUnit.module('fields', {}, function () { assert.deepEqual(args.kwargs.args, [['id', 'in', []]]); } return this._super(route, args); - } + }, }); - form.$('.o_field_x2many_list[name=turtles] .o_field_x2many_list_row_add a').click(); - var $modal = $('.modal-content'); - - var $turtleParent = $modal.find('.o_field_many2one input'); - var $dropdown = $turtleParent.autocomplete('widget'); + testUtils.dom.click(form.$('.o_field_x2many_list[name=turtles] .o_field_x2many_list_row_add a')); - $turtleParent.click(); + testUtils.fields.many2one.clickOpenDropdown('parent_id'); + testUtils.fields.many2one.clickHighlightedItem('parent_id'); - $dropdown.find('li.o_m2o_dropdown_option:contains(Create)').first().mouseenter().click(); - - $modal = $('.modal-content'); + var $modal = $('.modal-content'); - $modal.eq(1).find('.modal-footer .btn-primary').eq(0).click(); // Confirm new Record - $modal.eq(0).find('.modal-footer .btn-primary').eq(1).click(); // Save & New + testUtils.dom.click($modal.eq(1).find('.modal-footer .btn-primary').eq(0)); + testUtils.dom.click($modal.eq(0).find('.modal-footer .btn-primary').eq(1)); assert.equal(form.$('.o_data_row').length, 1, 'The main record should have the new record in its o2m'); $modal = $('.modal-content'); - $modal.find('.o_field_many2one input').click(); + testUtils.dom.click($modal.find('.o_field_many2one input')); form.destroy(); }); @@ -350,16 +344,16 @@ QUnit.module('fields', {}, function () { } }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); var $targetInput = $('.o_selected_row .o_input[name=foo]'); assert.equal($targetInput[0], document.activeElement, 'The first input of the line should have the focus'); // Simulating hitting the 'f' key twice - $targetInput.val('f').trigger('input'); - $targetInput.val($targetInput.val() + 'f').trigger('input'); + testUtils.fields.editInput($targetInput, 'f'); + testUtils.fields.editInput($targetInput, $targetInput.val() + 'f'); assert.equal($targetInput[0], document.activeElement, 'The first input of the line should still have the focus'); @@ -373,10 +367,10 @@ QUnit.module('fields', {}, function () { 'The second input of the line should have the focus after the TAB press'); - $secondTarget.val(9).trigger('input'); - $secondTarget.val($secondTarget.val() + 9).trigger('input'); + testUtils.fields.editInput($secondTarget, 9); + testUtils.fields.editInput($secondTarget, $secondTarget.val() + 9); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -406,19 +400,19 @@ QUnit.module('fields', {}, function () { }); - assert.strictEqual(form.$('td.o_list_record_selector').length, 0, + assert.containsNone(form, 'td.o_list_record_selector', "embedded one2many should not have a selector"); assert.ok(!form.$('.o_field_x2many_list_row_add').length, "embedded one2many should not be editable"); assert.ok(!form.$('td.o_list_record_remove').length, "embedded one2many records should not have a remove icon"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(form.$('.o_field_x2many_list_row_add').length, "embedded one2many should now be editable"); - assert.strictEqual(form.$('.o_field_x2many_list_row_add').attr('colspan'), "2", + assert.hasAttrValue(form.$('.o_field_x2many_list_row_add'), 'colspan', "2", "should have colspan 2 (one for field foo, one for being below remove icon)"); assert.ok(form.$('td.o_list_record_remove').length, @@ -443,17 +437,17 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - assert.strictEqual(form.$('td.hey').length, 1, + assert.containsOnce(form, 'td.hey', 'should have a td with the desired class'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('td.hey').length, 1, + assert.containsOnce(form, 'td.hey', 'should have a td with the desired class'); - form.$('td.o_data_cell').click(); + testUtils.dom.click(form.$('td.o_data_cell')); - assert.strictEqual(form.$('input[name="turtle_foo"].hey').length, 1, + assert.containsOnce(form, 'input[name="turtle_foo"].hey', 'should have an input with the desired class'); form.destroy(); @@ -552,7 +546,7 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, 'should display 2 data rows'); form.destroy(); }); @@ -581,7 +575,7 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, 'should display 2 data rows'); form.destroy(); }); @@ -641,7 +635,7 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - assert.strictEqual(form.$('span.o_row_handle').length, 1, "should have 1 handles"); + assert.containsOnce(form, 'span.o_row_handle', "should have 1 handles"); form.destroy(); }); @@ -649,7 +643,7 @@ QUnit.module('fields', {}, function () { assert.expect(10); var nbConfirmChange = 0; - testUtils.patch(ListRenderer, { + testUtils.mock.patch(ListRenderer, { confirmChange: function () { nbConfirmChange++; return this._super.apply(this, arguments); @@ -679,21 +673,21 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - testUtils.intercept(form, "field_changed", function (event) { + testUtils.mock.intercept(form, "field_changed", function (event) { assert.step(event.data.changes.turtles.data.turtle_int.toString()); }, true); assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "yopblipkawa", "should have the 3 rows in the correct order"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "yopblipkawa", "should still have the 3 rows in the correct order"); assert.strictEqual(nbConfirmChange, 0, "should not have confirmed any change yet"); // Drag and drop the second line in first position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(1), form.$('tbody tr').first(), { position: 'top' } @@ -706,7 +700,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipyopkawa", "should have the 3 rows in the new order"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.deepEqual(_.map(this.data.turtle.records, function (turtle) { return _.pick(turtle, 'id', 'turtle_foo', 'turtle_int'); @@ -719,7 +713,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipyopkawa", "should still have the 3 rows in the new order"); - testUtils.unpatch(ListRenderer); + testUtils.mock.unpatch(ListRenderer); form.destroy(); }); @@ -779,11 +773,11 @@ QUnit.module('fields', {}, function () { } }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_data_cell').eq(1).click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_data_cell').eq(1)); var $cell = form.$('.o_selected_row .o_input[name=turtle_foo]'); - $cell.val("hop").trigger('change'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editSelect($cell, "hop"); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -841,11 +835,11 @@ QUnit.module('fields', {}, function () { assert.deepEqual(form.$('.o_many2many_tags_cell').text().trim(), "second record", "the partner_ids should be as specified at initialization"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_data_cell').eq(1).click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_data_cell').eq(1)); var $cell = form.$('.o_selected_row .o_input[name=turtle_foo]'); - $cell.val("hop").trigger("change"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editSelect($cell, "hop"); + testUtils.form.clickSave(form);; assert.deepEqual(form.$('.o_many2many_tags_cell').text().trim().split(/\s+/), ["second", "record", "aaa"], @@ -892,10 +886,10 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // Drag and drop the second line in first position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(1), form.$('tbody tr').first(), { position: 'top' } @@ -949,14 +943,14 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "yopblipkawa", "should have the 3 rows in the correct order"); // Drag and drop the second line in first position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(1), form.$('tbody tr').first(), { position: 'top' } @@ -966,7 +960,7 @@ QUnit.module('fields', {}, function () { "should still have the 3 rows in the correct order"); assert.strictEqual(turtleOnchange, 3, "should update all lines"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -1010,16 +1004,16 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$('.o_pager_next').click(); + testUtils.dom.click(form.$('.o_pager_next')); assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "yopblipkawa", "should have the 3 rows in the correct order"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_one2many .o_list_view tbody tr:first td:first').click(); - form.$('.o_field_one2many .o_list_view tbody tr:first input:first').val('blurp').trigger('input'); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_one2many .o_list_view tbody tr:first td:first')); + testUtils.fields.editInput(form.$('.o_field_one2many .o_list_view tbody tr:first input:first'), 'blurp'); // Drag and drop the third line in second position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(2), form.$('.o_field_one2many tbody tr').eq(1), { position: 'top' } @@ -1027,8 +1021,8 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_data_cell').text(), "blurpkawablip", "should display to record in 'turtle_int' order"); - form.$buttons.find('.o_form_button_save').click(); - form.$('.o_pager_next').click(); + testUtils.form.clickSave(form);; + testUtils.dom.click(form.$('.o_pager_next')); assert.strictEqual(form.$('.o_data_cell:not(.o_handle_cell)').text(), "blurpkawablip", "should display to record in 'turtle_int' order"); @@ -1095,29 +1089,29 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.equal(form.$('.o_field_one2many td[class="o_data_cell"]').text(), "#20#21#22#23#24#25#26#27#28#29", "should display the records in order"); - form.$('.o_field_one2many .o_list_view tbody tr:first td:first').click(); - form.$('.o_field_one2many .o_list_view tbody tr:first input:first').val('blurp').trigger('input'); + testUtils.dom.click(form.$('.o_field_one2many .o_list_view tbody tr:first td:first')); + testUtils.fields.editInput(form.$('.o_field_one2many .o_list_view tbody tr:first input:first'), 'blurp'); // the domain fail if the widget does not use the allready loaded data. - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.form.clickDiscard(form);; assert.equal(form.$('.o_field_one2many td[class="o_data_cell"]').text(), "blurp#21#22#23#24#25#26#27#28#29", "should display the records in order with the changes"); - $('.modal .modal-footer button:first').click(); + testUtils.dom.click($('.modal .modal-footer button:first')); assert.equal(form.$('.o_field_one2many td[class="o_data_cell"]').text(), "#20#21#22#23#24#25#26#27#28#29", "should cancel changes and display the records in order"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // Drag and drop the third line in second position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(2), form.$('.o_field_one2many tbody tr').eq(1), { position: 'top' } @@ -1127,7 +1121,7 @@ QUnit.module('fields', {}, function () { "should display the records in order after resequence (display record with turtle_int=0)"); // Drag and drop the third line in second position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(2), form.$('.o_field_one2many tbody tr').eq(1), { position: 'top' } @@ -1136,12 +1130,12 @@ QUnit.module('fields', {}, function () { assert.equal(form.$('.o_field_one2many td[class="o_data_cell"]').text(), "#20#39#40#41#42#43#44#45#46#47", "should display the records in order after resequence (display record with turtle_int=0)"); - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.form.clickDiscard(form);; assert.equal(form.$('.o_field_one2many td[class="o_data_cell"]').text(), "#20#39#40#41#42#43#44#45#46#47", "should display the records in order after resequence"); - $('.modal .modal-footer button:first').click(); + testUtils.dom.click($('.modal .modal-footer button:first')); assert.equal(form.$('.o_field_one2many td[class="o_data_cell"]').text(), "#20#21#22#23#24#25#26#27#28#29", "should cancel changes and display the records in order"); @@ -1189,33 +1183,33 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_pager_next').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_pager_next')); - form.$('.o_field_one2many .o_list_view tbody tr:eq(1) td:first').click(); - form.$('.o_field_one2many .o_list_view tbody tr:eq(1) input:first').val('value 1').trigger('input'); - form.$('.o_field_one2many .o_list_view tbody tr:eq(2) td:first').click(); - form.$('.o_field_one2many .o_list_view tbody tr:eq(2) input:first').val('value 2').trigger('input'); + testUtils.dom.click(form.$('.o_field_one2many .o_list_view tbody tr:eq(1) td:first')); + testUtils.fields.editInput(form.$('.o_field_one2many .o_list_view tbody tr:eq(1) input:first'), 'value 1'); + testUtils.dom.click(form.$('.o_field_one2many .o_list_view tbody tr:eq(2) td:first')); + testUtils.fields.editInput(form.$('.o_field_one2many .o_list_view tbody tr:eq(2) input:first'), 'value 2'); - assert.strictEqual(form.$('.o_data_row').length, 40, "should display 40 records"); + assert.containsN(form, '.o_data_row', 40, "should display 40 records"); assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#39))').index(), 0, "should display '#39' at the first line"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('.o_data_row').length, 40, "should display 39 records and the create line"); - assert.strictEqual(form.$('.o_data_row:first .o_field_char').length, 1, "should display the create line in first position"); + assert.containsN(form, '.o_data_row', 40, "should display 39 records and the create line"); + assert.containsOnce(form, '.o_data_row:first .o_field_char', "should display the create line in first position"); assert.strictEqual(form.$('.o_data_row:first .o_field_char').val(), "", "should an empty input"); assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#39))').index(), 1, "should display '#39' at the second line"); - form.$('.o_data_row input:first').val('value 3').trigger('input'); + testUtils.fields.editInput(form.$('.o_data_row input:first'), 'value 3'); - assert.strictEqual(form.$('.o_data_row:first .o_field_char').length, 1, "should display the create line in first position after onchange"); + assert.containsOnce(form, '.o_data_row:first .o_field_char', "should display the create line in first position after onchange"); assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#39))').index(), 1, "should display '#39' at the second line after onchange"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('.o_data_row').length, 40, "should display 39 records and the create line"); - assert.strictEqual(form.$('.o_data_row:first .o_field_char').length, 1, "should display the create line in first position"); + assert.containsN(form, '.o_data_row', 40, "should display 39 records and the create line"); + assert.containsOnce(form, '.o_data_row:first .o_field_char', "should display the create line in first position"); assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(value 3))').index(), 1, "should display the created line at the second position"); assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#39))').index(), 2, "should display '#39' at the third line"); @@ -1264,27 +1258,27 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_pager_next').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_pager_next')); - form.$('.o_field_one2many .o_list_view tbody tr:eq(1) td:first').click(); - form.$('.o_field_one2many .o_list_view tbody tr:eq(1) input:first').val('value 1').trigger('input'); - form.$('.o_field_one2many .o_list_view tbody tr:eq(2) td:first').click(); - form.$('.o_field_one2many .o_list_view tbody tr:eq(2) input:first').val('value 2').trigger('input'); + testUtils.dom.click(form.$('.o_field_one2many .o_list_view tbody tr:eq(1) td:first')); + testUtils.fields.editInput(form.$('.o_field_one2many .o_list_view tbody tr:eq(1) input:first'), 'value 1'); + testUtils.dom.click(form.$('.o_field_one2many .o_list_view tbody tr:eq(2) td:first')); + testUtils.fields.editInput(form.$('.o_field_one2many .o_list_view tbody tr:eq(2) input:first'), 'value 2'); - assert.strictEqual(form.$('.o_data_row').length, 40, "should display 40 records"); + assert.containsN(form, '.o_data_row', 40, "should display 40 records"); assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#77))').index(), 39, "should display '#77' at the last line"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('.o_data_row').length, 41, "should display 41 records and the create line"); + assert.containsN(form, '.o_data_row', 41, "should display 41 records and the create line"); assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#76))').index(), 38, "should display '#76' at the penultimate line"); assert.strictEqual(form.$('.o_data_row:has(.o_field_char)').index(), 40, "should display the create line at the last position"); - form.$('.o_data_row input:first').val('value 3').trigger('input'); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.fields.editInput(form.$('.o_data_row input:first'), 'value 3'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('.o_data_row').length, 42, "should display 42 records and the create line"); + assert.containsN(form, '.o_data_row', 42, "should display 42 records and the create line"); assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#76))').index(), 38, "should display '#76' at the penultimate line"); assert.strictEqual(form.$('.o_data_row:has(.o_field_char)').index(), 41, "should display the create line at the last position"); @@ -1318,13 +1312,13 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "there should be one record in the relation"); // change the value of foo to trigger the onchange - form.$('.o_field_widget[name=foo]').val('some value').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), 'some value'); - assert.strictEqual(form.$('.o_data_row').length, 3, + assert.containsN(form, '.o_data_row', 3, "there should be three records in the relation"); form.destroy(); @@ -1373,16 +1367,16 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "there should be one record in the relation"); assert.strictEqual(form.$('.o_data_row .o_field_widget[name=partner_ids]').text().replace(/\s/g, ''), 'secondrecordaaa', "many2many_tags should be correctly displayed"); // change the value of foo to trigger the onchange checkRPC = true; // enable flag to check read RPC for the m2m field - form.$('.o_field_widget[name=foo]').val('some value').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), 'some value'); - assert.strictEqual(form.$('.o_data_row').length, 3, + assert.containsN(form, '.o_data_row', 3, "there should be three records in the relation"); assert.strictEqual(form.$('.o_data_row:first .o_field_widget[name=partner_ids]').text().trim(), 'first record', "many2many_tags should be correctly displayed"); @@ -1431,16 +1425,16 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "there should be one record in the relation"); assert.strictEqual(form.$('.ref_field').text().trim(), 'xpad', "reference field should be correctly displayed"); // change the value of foo to trigger the onchange checkRPC = true; // enable flag to check read RPC for reference field - form.$('.o_field_widget[name=foo]').val('some value').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), 'some value'); - assert.strictEqual(form.$('.o_data_row').length, 3, + assert.containsN(form, '.o_data_row', 3, "there should be three records in the relation"); assert.strictEqual(form.$('.ref_field').text().trim(), 'xpadxphone', "reference fields should be correctly displayed"); @@ -1482,25 +1476,25 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "the onchange should have created one record in the relation"); // open the created o2m record in a form view, and add a m2m subrecord // in its relation - form.$('.o_data_row').click(); + testUtils.dom.click(form.$('.o_data_row')); assert.strictEqual($('.modal').length, 1, "should have opened a dialog"); assert.strictEqual($('.modal .o_data_row').length, 0, "there should be no record in the one2many in the dialog"); // add a many2many subrecord - $('.modal .o_field_x2many_list_row_add a').click(); + testUtils.dom.click($('.modal .o_field_x2many_list_row_add a')); assert.strictEqual($('.modal').length, 2, "should have opened a second dialog"); // select a many2many subrecord - $('.modal:nth(1) .o_list_view .o_data_cell:first').click(); + testUtils.dom.click($('.modal:nth(1) .o_list_view .o_data_cell:first')); assert.strictEqual($('.modal').length, 1, "second dialog should be closed"); @@ -1510,25 +1504,25 @@ QUnit.module('fields', {}, function () { 'm2m pager should be hidden'); // click on 'Save & Close' - $('.modal-footer .btn-primary:first').click(); + testUtils.dom.click($('.modal-footer .btn-primary:first')); assert.strictEqual($('.modal').length, 0, "dialog should be closed"); // reopen o2m record, and another m2m subrecord in its relation, but // discard the changes - form.$('.o_data_row').click(); + testUtils.dom.click(form.$('.o_data_row')); assert.strictEqual($('.modal').length, 1, "should have opened a dialog"); assert.strictEqual($('.modal .o_data_row').length, 1, "there should be one record in the one2many in the dialog"); // add another m2m subrecord - $('.modal .o_field_x2many_list_row_add a').click(); + testUtils.dom.click($('.modal .o_field_x2many_list_row_add a')); assert.strictEqual($('.modal').length, 2, "should have opened a second dialog"); - $('.modal:nth(1) .o_list_view .o_data_cell:first').click(); + testUtils.dom.click($('.modal:nth(1) .o_list_view .o_data_cell:first')); assert.strictEqual($('.modal').length, 1, "second dialog should be closed"); @@ -1536,12 +1530,12 @@ QUnit.module('fields', {}, function () { "there should be two records in the one2many in the dialog"); // click on 'Discard' - $('.modal-footer .btn-secondary').click(); + testUtils.dom.clickFirst($('.modal-footer .btn-secondary')); assert.strictEqual($('.modal').length, 0, "dialog should be closed"); // reopen o2m record to check that second changes have properly been discarded - form.$('.o_data_row').click(); + testUtils.dom.click(form.$('.o_data_row')); assert.strictEqual($('.modal').length, 1, "should have opened a dialog"); assert.strictEqual($('.modal .o_data_row').length, 1, @@ -1596,11 +1590,11 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - testUtils.intercept(form, "field_changed", function (event) { + testUtils.mock.intercept(form, "field_changed", function (event) { assert.step(form.model.get(event.data.changes.turtles.id).res_id); }, true); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var steps = []; var positions = [ @@ -1611,7 +1605,7 @@ QUnit.module('fields', {}, function () { function dragAndDrop() { var pos = positions.shift(); - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(pos[0]), form.$('tbody tr').eq(pos[1]), { position: pos[2] } @@ -1670,19 +1664,19 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - testUtils.intercept(form, "field_changed", function (event) { + testUtils.mock.intercept(form, "field_changed", function (event) { assert.step(event.data.changes.p.data.int_field.toString()); }, true); assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "My little Foo Valueblipyop", "should have the 3 rows in the correct order"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "My little Foo Valueblipyop", "should still have the 3 rows in the correct order"); // Drag and drop the second line in first position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(1), form.$('tbody tr').first(), { position: 'top' } @@ -1694,12 +1688,12 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipMy little Foo Valueyop", "should have the 3 rows in the new order"); - form.$('tbody tr:first td:first').click(); + testUtils.dom.click(form.$('tbody tr:first td:first')); assert.strictEqual(form.$('tbody tr:first td.o_data_cell:not(.o_handle_cell) input').val(), "blip", "should edit the correct row"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipMy little Foo Valueyop", "should still have the 3 rows in the new order"); @@ -1773,7 +1767,7 @@ QUnit.module('fields', {}, function () { // move to the second page of the o2m: 1 RPC should have been done to fetch // the 2 subrecords of page 2, and those records should now be displayed - form.$('.o_x2m_control_panel .o_pager_next').click(); + testUtils.dom.click(form.$('.o_x2m_control_panel .o_pager_next')); assert.strictEqual(count, 7, 'one RPC should have been done'); assert.strictEqual(form.$('.o_kanban_record:not(".o_kanban_ghost")').length, 2, 'one2many kanban should contain 2 cards for record 1 at page 2'); @@ -1788,7 +1782,7 @@ QUnit.module('fields', {}, function () { // been correctly reloaded form.pager.previous(); assert.strictEqual(count, 11, 'two RPCs should have been done'); - form.$('.o_x2m_control_panel .o_pager_next').click(); + testUtils.dom.click(form.$('.o_x2m_control_panel .o_pager_next')); assert.strictEqual(count, 12, 'one RPC should have been done'); assert.strictEqual(form.$('.o_kanban_record:not(".o_kanban_ghost")').length, 2, 'one2many kanban should contain 2 cards for record 1 at page 2'); @@ -1895,10 +1889,10 @@ QUnit.module('fields', {}, function () { // add a record on page one checkRead = true; - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o-kanban-button-new').click(); - $('.modal input').val('new record').trigger('input'); - $('.modal .modal-footer .btn-primary:first').click(); // save and close + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o-kanban-button-new')); + testUtils.fields.editInput($('.modal input'), 'new record'); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); // checks assert.strictEqual(readIDs, undefined, "should not have read any record"); assert.strictEqual(form.$('span:contains(new record)').length, 0, @@ -1910,14 +1904,14 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_kanban_record:first span:contains(new record)').length, 0, 'new record should not be on page 1'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; // delete a record on page one checkRead = true; - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_kanban_record:first span:contains(relational record 10)').length, 1, 'first record should be the one with id 10 (next checks rely on that)'); - form.$('.delete_icon:first').click(); + testUtils.dom.click(form.$('.delete_icon:first')); // checks assert.deepEqual(readIDs, [50], "should have read a record (to display 40 records on page 1)"); @@ -1926,31 +1920,31 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_x2m_control_panel .o_pager_counter').text().trim(), '1-40 / 45', "pager range should be correct"); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; // add and delete records in both pages - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); checkRead = true; readIDs = undefined; // add and delete a record in page 1 - form.$('.o-kanban-button-new').click(); - $('.modal input').val('new record page 1').trigger('input'); - $('.modal .modal-footer .btn-primary:first').click(); // save and close + testUtils.dom.click(form.$('.o-kanban-button-new')); + testUtils.fields.editInput($('.modal input'), 'new record page 1'); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); assert.strictEqual(form.$('.o_kanban_record:first span:contains(relational record 11)').length, 1, 'first record should be the one with id 11 (next checks rely on that)'); - form.$('.delete_icon:first').click(); + testUtils.dom.click(form.$('.delete_icon:first')); assert.deepEqual(readIDs, [51], "should have read a record (to display 40 records on page 1)"); // add and delete a record in page 2 - form.$('.o_x2m_control_panel .o_pager_next').click(); + testUtils.dom.click(form.$('.o_x2m_control_panel .o_pager_next')); assert.strictEqual(form.$('.o_kanban_record:first span:contains(relational record 52)').length, 1, 'first record should be the one with id 52 (next checks rely on that)'); checkRead = true; readIDs = undefined; - form.$('.delete_icon:first').click(); - form.$('.o-kanban-button-new').click(); - $('.modal input').val('new record page 2').trigger('input'); - $('.modal .modal-footer .btn-primary:first').click(); // save and close + testUtils.dom.click(form.$('.delete_icon:first')); + testUtils.dom.click(form.$('.o-kanban-button-new')); + testUtils.fields.editInput($('.modal input'), 'new record page 2'); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); assert.strictEqual(readIDs, undefined, "should not have read any record"); // checks assert.strictEqual(form.$('.o_kanban_record:not(".o_kanban_ghost")').length, 5, @@ -1962,7 +1956,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_kanban_record span:contains(new record page 2)').length, 1, 'new records should be on page 2'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -1991,16 +1985,16 @@ QUnit.module('fields', {}, function () { }, res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - $('input[name="turtle_int"]').val('5').trigger('input'); - $('.modal-footer button.btn-primary').first().click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput($('input[name="turtle_int"]'), '5'); + testUtils.dom.click($('.modal-footer button.btn-primary').first()); assert.strictEqual(form.$('tbody tr:eq(1) td.o_data_cell').text(), '5', 'should display 5 in the foo field'); - form.$('tbody tr:eq(1) td.o_data_cell').click(); + testUtils.dom.click(form.$('tbody tr:eq(1) td.o_data_cell')); - $('input[name="turtle_int"]').val('3').trigger('input'); - $('.modal-footer button.btn-primary').first().click(); + testUtils.fields.editInput($('input[name="turtle_int"]'), '3'); + testUtils.dom.click($('.modal-footer button.btn-primary').first()); assert.strictEqual(form.$('tbody tr:eq(1) td.o_data_cell').text(), '3', 'should now display 3 in the foo field'); form.destroy(); @@ -2041,13 +2035,13 @@ QUnit.module('fields', {}, function () { throw "should not render the whole form"; }; - form.$('table thead th:contains(Foo)').click(); + testUtils.dom.click(form.$('table thead th:contains(Foo)')); assert.strictEqual(rpcCount, 0, 'sort should be in memory, no extra RPCs should have been done'); assert.ok(form.$('table tbody tr:eq(2) td:contains(xyz)').length, "the 3rd record is the one with 'xyz' value"); - form.$('table thead th:contains(Foo)').click(); + testUtils.dom.click(form.$('table thead th:contains(Foo)')); assert.ok(form.$('table tbody tr:eq(2) td:contains(abc)').length, "the 3rd record is the one with 'abc' value"); @@ -2080,33 +2074,33 @@ QUnit.module('fields', {}, function () { // edit the first line of the o2m assert.strictEqual(form.$('.o_field_one2many tbody td').first().text(), 'relational record 1', "display name of first record in o2m list should be 'relational record 1'"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_one2many tbody td').first().click(); - assert.ok(form.$('.o_field_one2many tbody td').first().parent().hasClass('o_selected_row'), + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_one2many tbody td').first()); + assert.hasClass(form.$('.o_field_one2many tbody td').first().parent(),'o_selected_row', "first row of o2m should be in edition"); - form.$('.o_field_one2many tbody td').first().find('input').val("new value").trigger('input'); - assert.ok(form.$('.o_field_one2many tbody td').first().parent().hasClass('o_selected_row'), + testUtils.fields.editInput(form.$('.o_field_one2many tbody td').first().find('input'), "new value"); + assert.hasClass(form.$('.o_field_one2many tbody td').first().parent(),'o_selected_row', "first row of o2m should still be in edition"); // // leave o2m edition - form.$el.click(); - assert.ok(!form.$('.o_field_one2many tbody td').first().parent().hasClass('o_selected_row'), + testUtils.dom.click(form.$el); + assert.doesNotHaveClass(form.$('.o_field_one2many tbody td').first().parent(), 'o_selected_row', "first row of o2m should be readonly again"); // discard changes - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.form.clickDiscard(form);; assert.strictEqual(form.$('.o_field_one2many tbody td').first().text(), 'new value', "changes shouldn't have been discarded yet, waiting for user confirmation"); - $('.modal .modal-footer .btn-primary').click(); + testUtils.dom.click($('.modal .modal-footer .btn-primary')); assert.strictEqual(form.$('.o_field_one2many tbody td').first().text(), 'relational record 1', "display name of first record in o2m list should be 'relational record 1'"); // edit again and save - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_one2many tbody td').first().click(); - form.$('.o_field_one2many tbody td').first().find('input').val("new value").trigger('input'); - form.$el.click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_one2many tbody td').first()); + testUtils.fields.editInput(form.$('.o_field_one2many tbody td').first().find('input'), "new value"); + testUtils.dom.click(form.$el); + testUtils.form.clickSave(form);; // FIXME: this next test doesn't pass as the save of updates of // relational data is temporarily disabled // assert.strictEqual(form.$('.o_field_one2many tbody td').first().text(), 'new value', @@ -2134,7 +2128,7 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o_field_x2many_list_row_add').length, '"Add an item" link should not be available in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(!form.$('.o_field_x2many_list_row_add').length, '"Add an item" link should not be available in readonly'); @@ -2175,29 +2169,29 @@ QUnit.module('fields', {}, function () { '<form string="Partner"><field name="display_name"/></form>', }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('td.o_list_record_remove button').length, 3, + assert.containsN(form, 'td.o_list_record_remove button', 3, "should have 3 remove buttons"); - assert.ok(form.$('td.o_list_record_remove button').first().hasClass('fa fa-times'), + assert.hasClass(form.$('td.o_list_record_remove button').first(),'fa fa-times', "should have X icons to remove (unlink) records"); - form.$('td.o_list_record_remove button').first().click(); + testUtils.dom.click(form.$('td.o_list_record_remove button').first()); - assert.strictEqual(form.$('td.o_list_record_remove button').length, 2, + assert.containsN(form, 'td.o_list_record_remove button', 2, "should have 2 remove buttons (a record is supposed to have been unlinked)"); - form.$('tr.o_data_row').first().click(); + testUtils.dom.click(form.$('tr.o_data_row').first()); assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 1, 'there should be a modal having Remove Button'); - $('.modal .modal-footer .o_btn_remove').click(); + testUtils.dom.click($('.modal .modal-footer .o_btn_remove')); - assert.strictEqual(form.$('td.o_list_record_remove button').length, 1, + assert.containsOnce(form, 'td.o_list_record_remove button', "should have 1 delete button (another record is supposed to have been unlinked)"); // save and check that the correct command has been generated - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -2235,29 +2229,29 @@ QUnit.module('fields', {}, function () { '<form string="Partner"><field name="display_name"/></form>', }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('td.o_list_record_remove button').length, 3, + assert.containsN(form, 'td.o_list_record_remove button', 3, "should have 3 remove buttons"); - assert.ok(form.$('td.o_list_record_remove button').first().hasClass('fa fa-trash-o'), + assert.hasClass(form.$('td.o_list_record_remove button').first(),'fa fa-trash-o', "should have trash bin icons to remove (delete) records"); - form.$('td.o_list_record_remove button').first().click(); + testUtils.dom.click(form.$('td.o_list_record_remove button').first()); - assert.strictEqual(form.$('td.o_list_record_remove button').length, 2, + assert.containsN(form, 'td.o_list_record_remove button', 2, "should have 2 remove buttons (a record is supposed to have been deleted)"); - form.$('tr.o_data_row').first().click(); + testUtils.dom.click(form.$('tr.o_data_row').first()); assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 1, 'there should be a modal having Remove Button'); - $('.modal .modal-footer .o_btn_remove').click(); + testUtils.dom.click($('.modal .modal-footer .o_btn_remove')); - assert.strictEqual(form.$('td.o_list_record_remove button').length, 1, + assert.containsOnce(form, 'td.o_list_record_remove button', "should have 1 remove button (another record is supposed to have been deleted)"); // save and check that the correct command has been generated - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; // FIXME: it would be nice to test that the view is re-rendered correctly, // but as the relational data isn't re-fetched, the rendering is ok even @@ -2304,7 +2298,7 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o_field_one2many .o-kanban-button-new').length, '"Create" button should not be visible in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 1, 'should contain 1 record'); @@ -2316,46 +2310,46 @@ QUnit.module('fields', {}, function () { 'delete icon should be visible in edit'); assert.ok(form.$('.o_field_one2many .o-kanban-button-new').length, '"Create" button should be visible in edit'); - assert.ok(form.$('.o_field_one2many .o-kanban-button-new').hasClass('btn-secondary'), + assert.hasClass(form.$('.o_field_one2many .o-kanban-button-new'),'btn-secondary', "'Create' button should have className 'btn-secondary'"); assert.strictEqual(form.$('.o_field_one2many .o-kanban-button-new').text().trim(), "Add", 'Create button should have "Add" label'); // edit existing subrecord - form.$('.oe_kanban_global_click').click(); + testUtils.dom.click(form.$('.oe_kanban_global_click')); - $('.modal .o_form_view input').val('new name').trigger('input'); - $('.modal .modal-footer .btn-primary').click(); // save + testUtils.fields.editInput($('.modal .o_form_view input').first(), 'new name'); + testUtils.dom.click($('.modal .modal-footer .btn-primary')); assert.strictEqual(form.$('.o_kanban_record span:first').text(), 'new name', 'value of subrecord should have been updated'); // create a new subrecord - form.$('.o-kanban-button-new').click(); - $('.modal .o_form_view input').val('new subrecord 1').trigger('input'); - $('.modal .modal-footer .btn-primary').click(); // save and close + testUtils.dom.click(form.$('.o-kanban-button-new')); + testUtils.fields.editInput($('.modal .o_form_view input').first(), 'new subrecord 1'); + testUtils.dom.clickFirst($('.modal .modal-footer .btn-primary')); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 2, 'should contain 2 records'); assert.strictEqual(form.$('.o_kanban_record:nth(1) span').text(), 'new subrecord 1', 'value of newly created subrecord should be "new subrecord 1"'); // create two new subrecords - form.$('.o-kanban-button-new').click(); - $('.modal .o_form_view input').val('new subrecord 2').trigger('input'); - $('.modal .modal-footer .btn-primary:nth(1)').click(); // save and new - $('.modal .o_form_view input').val('new subrecord 3').trigger('input'); - $('.modal .modal-footer .btn-primary').click(); // save and close + testUtils.dom.click(form.$('.o-kanban-button-new')); + testUtils.fields.editInput($('.modal .o_form_view input').first(), 'new subrecord 2'); + testUtils.dom.click($('.modal .modal-footer .btn-primary:nth(1)')); + testUtils.fields.editInput($('.modal .o_form_view input').first(), 'new subrecord 3'); + testUtils.dom.clickFirst($('.modal .modal-footer .btn-primary')); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 4, 'should contain 4 records'); // delete subrecords - form.$('.oe_kanban_global_click').first().click(); + testUtils.dom.click(form.$('.oe_kanban_global_click').first()); assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 1, 'There should be a modal having Remove Button'); - $('.modal .modal-footer .o_btn_remove').click(); // Click Remove Button of Formview Dialog + testUtils.dom.click($('.modal .modal-footer .o_btn_remove')); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 3, 'should contain 3 records'); - form.$('.o_kanban_view .delete_icon:first()').click(); - form.$('.o_kanban_view .delete_icon:first()').click(); + testUtils.dom.click(form.$('.o_kanban_view .delete_icon:first()')); + testUtils.dom.click(form.$('.o_kanban_view .delete_icon:first()')); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 1, 'should contain 1 records'); assert.strictEqual(form.$('.o_kanban_record span:first').text(), 'new subrecord 3', @@ -2386,7 +2380,7 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_one2many[name="turtles"] .o-kanban-button-new').text().trim(), "Add turtle", "In O2M Kanban, Add button should have 'Add turtle' label"); @@ -2423,7 +2417,7 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o-kanban-button-new').length, '"Add" button should not be available in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(!form.$('.o-kanban-button-new').length, '"Add" button should not be available in edit'); @@ -2453,9 +2447,9 @@ QUnit.module('fields', {}, function () { }); // add a record, then click in form view to confirm it - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$el.click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$el); assert.strictEqual(form.$('.o_cp_pager').text().trim(), '1-3 / 5', "pager should display the correct total"); @@ -2498,9 +2492,9 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o_field_x2many_list_row_add').length, '"Add an item" should not be visible in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 2, + assert.containsN(form, '.o_list_view td.o_list_number', 2, 'should contain 2 records'); assert.strictEqual(form.$('.o_list_view tbody td:first()').text(), 'second record', 'display_name of first subrecord should be the one in DB'); @@ -2510,10 +2504,10 @@ QUnit.module('fields', {}, function () { '"Add an item" should not visible in edit'); // edit existing subrecord - form.$('.o_list_view tbody tr:first() td:eq(1)').click(); + testUtils.dom.click(form.$('.o_list_view tbody tr:first() td:eq(1)')); - $('.modal .o_form_view input').val('new name').trigger('input'); - $('.modal .modal-footer .btn-primary').click(); // save + testUtils.fields.editInput($('.modal .o_form_view input'), 'new name'); + testUtils.dom.click($('.modal .modal-footer .btn-primary')); assert.strictEqual(form.$('.o_list_view tbody td:first()').text(), 'new name', 'value of subrecord should have been updated'); assert.strictEqual(nbWrite, 0, "should not have write anything in DB"); @@ -2522,13 +2516,13 @@ QUnit.module('fields', {}, function () { // TODO when 'Add an item' will be implemented // remove subrecords - form.$('.o_list_record_remove:nth(1)').click(); - assert.strictEqual(form.$('.o_list_view td.o_list_number').length, 1, + testUtils.dom.click(form.$('.o_list_record_remove:nth(1)')); + assert.containsOnce(form, '.o_list_view td.o_list_number', 'should contain 1 subrecord'); assert.strictEqual(form.$('.o_list_view tbody td:first()').text(), 'new name', 'the remaining subrecord should be "new name"'); - form.$buttons.find('.o_form_button_save').click(); // save the record + testUtils.form.clickSave(form);; // save the record assert.strictEqual(nbWrite, 1, "should have write the changes in DB"); form.destroy(); @@ -2558,26 +2552,26 @@ QUnit.module('fields', {}, function () { assert.ok(!form.$('.o_field_x2many_list_row_add').length, '"Add an item" link should not be available in readonly'); - form.$('.o_list_view tbody td:first()').click(); + testUtils.dom.click(form.$('.o_list_view tbody td:first()')); assert.ok($('.modal .o_form_readonly').length, 'in readonly, clicking on a subrecord should open it in readonly in a dialog'); - $('.modal .o_form_button_cancel').click(); // close the dialog + testUtils.dom.click($('.modal .o_form_button_cancel')); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(form.$('.o_field_x2many_list_row_add').length, '"Add an item" link should be available in edit'); // edit existing subrecord - form.$('.o_list_view tbody td:first()').click(); + testUtils.dom.click(form.$('.o_list_view tbody td:first()')); assert.strictEqual($('.modal').length, 0, 'in edit, clicking on a subrecord should not open a dialog'); - assert.ok(form.$('.o_list_view tbody tr:first()').hasClass('o_selected_row'), + assert.hasClass(form.$('.o_list_view tbody tr:first()'),'o_selected_row', 'first row should be in edition'); - form.$('.o_list_view input:first()').val('new name').trigger('input'); + testUtils.fields.editInput(form.$('.o_list_view input:first()'), 'new name'); - form.$('.o_list_view tbody tr:nth(1) td:first').click(); // click on second record to validate the first one - assert.ok(!form.$('.o_list_view tbody tr:first').hasClass('o_selected_row'), + testUtils.dom.click(form.$('.o_list_view tbody tr:nth(1) td:first')); + assert.doesNotHaveClass(form.$('.o_list_view tbody tr:first'), 'o_selected_row', 'first row should not be in edition anymore'); assert.strictEqual(form.$('.o_list_view tbody td:first').text(), 'new name', 'value of subrecord should have been updated'); @@ -2614,22 +2608,22 @@ QUnit.module('fields', {}, function () { }); // edit mode, then click on Add an item and enter a value - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_selected_row > td input').val('kartoffel').trigger('input'); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_selected_row > td input'), 'kartoffel'); // click again on Add an item - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('td:contains(kartoffel)').length, 1, "should have one td with the new value"); - assert.strictEqual(form.$('.o_selected_row > td input').length, 1, + assert.containsOnce(form, '.o_selected_row > td input', "should have one other new td"); - assert.strictEqual(form.$('tr.o_data_row').length, 2, "should have 2 data rows"); + assert.containsN(form, 'tr.o_data_row', 2, "should have 2 data rows"); // enter another value and save - form.$('.o_selected_row > td input').val('gemuse').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('tr.o_data_row').length, 2, "should have 2 data rows"); + testUtils.fields.editInput(form.$('.o_selected_row > td input'), 'gemuse'); + testUtils.form.clickSave(form);; + assert.containsN(form, 'tr.o_data_row', 2, "should have 2 data rows"); assert.strictEqual(form.$('td:contains(kartoffel)').length, 1, "should have one td with the new value"); assert.strictEqual(form.$('td:contains(gemuse)').length, 1, @@ -2658,18 +2652,18 @@ QUnit.module('fields', {}, function () { }); // edit mode, then click on Add an item 2 times - assert.strictEqual(form.$('tr.o_data_row').length, 1, + assert.containsOnce(form, 'tr.o_data_row', "should have 1 data rows"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_x2many_list_row_add a').click(); - assert.strictEqual(form.$('tr.o_data_row').length, 3, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + assert.containsN(form, 'tr.o_data_row', 3, "should have 3 data rows"); // cancel the edition - form.$buttons.find('.o_form_button_cancel').click(); - $('.modal-footer button.btn-primary').first().click(); - assert.strictEqual(form.$('tr.o_data_row').length, 1, + testUtils.form.clickDiscard(form);; + testUtils.dom.click($('.modal-footer button.btn-primary').first()); + assert.containsOnce(form, 'tr.o_data_row', "should have 1 data rows"); form.destroy(); @@ -2706,18 +2700,16 @@ QUnit.module('fields', {}, function () { }); // edit mode, then click on Add an item - assert.strictEqual(form.$('tr.o_data_row').length, 0, + assert.containsNone(form, 'tr.o_data_row', "should have 0 data rows"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('textarea').val(), "", "field turtle_description should be empty"); // add a value in the turtle_trululu field to trigger an onchange - var $dropdown = form.$('.o_field_many2one[name=turtle_trululu] input') - .autocomplete('widget'); - form.$('.o_field_many2one[name=turtle_trululu] input').click(); - $dropdown.find('a:contains(first record)').mouseenter().click(); + testUtils.fields.many2one.clickOpenDropdown('turtle_trululu'); + testUtils.fields.many2one.clickHighlightedItem('turtle_trululu'); assert.strictEqual(form.$('textarea').val(), "Some Description", "field turtle_description should be set to the result of the onchange"); form.destroy(); @@ -2752,18 +2744,18 @@ QUnit.module('fields', {}, function () { }); // edit mode, then click on Add an item, then click elsewhere - assert.strictEqual(form.$('tr.o_data_row').length, 0, + assert.containsNone(form, 'tr.o_data_row', "should have 0 data rows"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('label.o_form_label').first().click(); - assert.strictEqual(form.$('tr.o_data_row').length, 0, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('label.o_form_label').first()); + assert.containsNone(form, 'tr.o_data_row', "should still have 0 data rows"); // click on Add an item again, then click on save - form.$('.o_field_x2many_list_row_add a').click(); - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('tr.o_data_row').length, 0, + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.form.clickSave(form);; + assert.containsNone(form, 'tr.o_data_row', "should still have 0 data rows"); assert.verifySteps(['read', 'default_get', 'default_get']); @@ -2789,8 +2781,8 @@ QUnit.module('fields', {}, function () { }); // add a record, to reach the page size limit - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); // the record currently being added should not count in the pager assert.ok(!form.$('.o_cp_pager').is(':visible'), @@ -2819,12 +2811,12 @@ QUnit.module('fields', {}, function () { }); // add a record, then discard - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.form.clickDiscard(form);; // confirm the discard operation - $('.modal .modal-footer .btn-primary').click(); // click on confirm + testUtils.dom.click($('.modal .modal-footer .btn-primary')); assert.strictEqual(form.$('.o_cp_pager').text().trim(), '1-3 / 4', "pager should still be visible"); @@ -2853,12 +2845,12 @@ QUnit.module('fields', {}, function () { }); // add a (empty) record - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); // go on next page. The new record is not valid and should be discarded - form.$('.o_pager_next').click(); - assert.strictEqual(form.$('tr.o_data_row').length, 1, + testUtils.dom.click(form.$('.o_pager_next')); + assert.containsOnce(form, 'tr.o_data_row', "should have 1 data rows"); form.destroy(); @@ -2887,23 +2879,23 @@ QUnit.module('fields', {}, function () { }); // add a record with a dirty state, but not valid - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('input[name="turtle_int"]').val(4321).trigger('input'); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('input[name="turtle_int"]'), 4321); // go to next page. The new record is not valid, but dirty. we should // see a confirm dialog - form.$('.o_pager_next').click(); + testUtils.dom.click(form.$('.o_pager_next')); assert.strictEqual(form.$('.o_cp_pager').text().trim(), '1-3 / 4', "pager should still display the correct total"); // click on cancel - $('.modal .modal-footer .btn-secondary').click(); // click on cancel + testUtils.dom.click($('.modal .modal-footer .btn-secondary')); assert.strictEqual(form.$('.o_cp_pager').text().trim(), '1-3 / 4', "pager should again display the correct total"); - assert.strictEqual(form.$('.o_field_one2many input.o_field_invalid').length, 1, + assert.containsOnce(form, '.o_field_one2many input.o_field_invalid', "there should be an invalid input in the one2many"); form.destroy(); }); @@ -2928,20 +2920,20 @@ QUnit.module('fields', {}, function () { }); // add a 4 records record (to make the pager appear) - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); // go on next page - form.$('.o_pager_next').click(); + testUtils.dom.click(form.$('.o_pager_next')); // discard - form.$buttons.find('.o_form_button_cancel').click(); - $('.modal .modal-footer .btn-primary').click(); + testUtils.form.clickDiscard(form);; + testUtils.dom.click($('.modal .modal-footer .btn-primary')); - assert.strictEqual(form.$('tr.o_data_row').length, 1, + assert.containsOnce(form, 'tr.o_data_row', "should have 1 data row"); assert.ok(!form.$('.o_cp_pager').is(':visible'), "pager should not be visible"); @@ -2973,31 +2965,31 @@ QUnit.module('fields', {}, function () { }); // edit mode, then click on Add an item, then click elsewhere - assert.strictEqual(form.$('tr.o_data_row').length, 0, + assert.containsNone(form, 'tr.o_data_row', "should have 0 data rows"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - assert.strictEqual(form.$('tr.o_data_row').length, 1, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + assert.containsOnce(form, 'tr.o_data_row', "should have 1 data rows"); // adding a value in the non required field, so it is dirty, but with // a missing required field - form.$('input[name="turtle_int"]').val('12345').trigger('input'); + testUtils.fields.editInput(form.$('input[name="turtle_int"]'), '12345'); // click elsewhere, - form.$('label.o_form_label').click(); + testUtils.dom.click(form.$('label.o_form_label')); assert.strictEqual($('.modal').length, 1, 'a confirmation model should be opened'); // click on cancel, the line should still be selected - $('.modal .modal-footer button.btn-secondary').click(); - assert.strictEqual(form.$('tr.o_data_row.o_selected_row').length, 1, + testUtils.dom.click($('.modal .modal-footer button.btn-secondary')); + assert.containsOnce(form, 'tr.o_data_row.o_selected_row', "should still have 1 selected data row"); // click elsewhere, and click on ok (on the confirmation dialog) - form.$('label.o_form_label').click(); - $('.modal .modal-footer button.btn-primary').click(); - assert.strictEqual(form.$('tr.o_data_row').length, 0, + testUtils.dom.click(form.$('label.o_form_label')); + testUtils.dom.click($('.modal .modal-footer button.btn-primary')); + assert.containsNone(form, 'tr.o_data_row', "should have 0 data rows (invalid line has been discarded"); form.destroy(); @@ -3029,13 +3021,13 @@ QUnit.module('fields', {}, function () { }); // edit mode, then click on Add an item, then click elsewhere - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.$('input[name="turtle_foo"]').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER, keyCode: $.ui.keyCode.ENTER, })); - assert.ok(form.$('input[name="turtle_foo"]').hasClass('o_field_invalid'), + assert.hasClass(form.$('input[name="turtle_foo"]'),'o_field_invalid', "input should be marked invalid"); assert.verifySteps(['read', 'default_get']); form.destroy(); @@ -3076,18 +3068,18 @@ QUnit.module('fields', {}, function () { }); // edit mode, then click on Add an item - assert.strictEqual(form.$('tr.o_data_row').length, 0, + assert.containsNone(form, 'tr.o_data_row', "should have 0 data rows"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); // input some text in required turtle_foo field - form.$('input[name="turtle_foo"]').val('aubergine').trigger('input'); + testUtils.fields.editInput(form.$('input[name="turtle_foo"]'), 'aubergine'); assert.strictEqual(form.$('input[name="turtle_int"]').val(), "9", "onchange should have been triggered"); // save and check everything is fine - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.strictEqual(form.$('.o_data_row td:contains(aubergine)').length, 1, "should have one row with turtle_foo value"); assert.strictEqual(form.$('.o_data_row td:contains(9)').length, 1, @@ -3118,13 +3110,13 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - assert.strictEqual(form.$('tr.o_data_row').length, 1, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + assert.containsOnce(form, 'tr.o_data_row', "there should be one data row"); form.$('input[name="turtle_foo"]').trigger({ type: 'keydown', which: $.ui.keyCode.ESCAPE }); - assert.strictEqual(form.$('tr.o_data_row').length, 0, + assert.containsNone(form, 'tr.o_data_row', "data row should have been discarded"); assert.verifySteps(['read', 'default_get']); form.destroy(); @@ -3153,13 +3145,13 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - assert.strictEqual(form.$('tr.o_data_row').length, 1, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + assert.containsOnce(form, 'tr.o_data_row', "there should be one data row"); form.$('input[name="turtle_foo"]').trigger({ type: 'keydown', which: $.ui.keyCode.ESCAPE }); - assert.strictEqual(form.$('tr.o_data_row').length, 0, + assert.containsNone(form, 'tr.o_data_row', "data row should have been discarded"); assert.verifySteps(['read', 'default_get']); form.destroy(); @@ -3196,8 +3188,8 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); - $('.modal .o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click($('.modal .o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .o_data_row.o_selected_row').length, 1, "there should be a row in edition in the dialog"); @@ -3243,10 +3235,10 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_data_cell:first').click(); + testUtils.dom.click(form.$('.o_data_cell:first')); form.$('.o_field_widget[name="product_id"] input').val('').trigger('keyup'); assert.verifySteps(['read', 'read'], 'no onchange should be done as line is invalid'); - form.$('.o_list_record_remove').click(); + testUtils.dom.click(form.$('.o_list_record_remove')); assert.verifySteps(['read', 'read', 'onchange'], 'onchange should have been done'); form.destroy(); @@ -3289,10 +3281,10 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_one2many tbody td').first().click(); - form.$('.o_field_one2many tbody td').first().find('input').val("new value").trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_one2many tbody td').first()); + testUtils.fields.editInput(form.$('.o_field_one2many tbody td').first().find('input'), "new value"); + testUtils.form.clickSave(form);; assert.strictEqual(form.$('.o_field_one2many tbody td').first().text(), 'from onchange', "display name of first record in o2m list should be 'new value'"); @@ -3388,10 +3380,10 @@ QUnit.module('fields', {}, function () { return this._super.apply(this, arguments); }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('td:contains(9)').click(); - form.$('td input[name="turtle_int"]').val("3").trigger('input'); + testUtils.dom.click(form.$('td:contains(9)')); + testUtils.fields.editInput(form.$('td input[name="turtle_int"]'), "3"); // the 'change' event is triggered on the input when we focus somewhere // else, for example by clicking in the body. However, if we try to @@ -3428,17 +3420,17 @@ QUnit.module('fields', {}, function () { return this._super.apply(this, arguments); }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('td:contains(01/25/2017)').click(); - form.$('.o_datepicker_input').click(); - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Month selection - $('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Year selection - $('.bootstrap-datetimepicker-widget .year:contains(2017)').click(); - $('.bootstrap-datetimepicker-widget .month').eq(1).click(); // February - $('.day:contains(22)').click(); // select the 22 February + testUtils.dom.click(form.$('td:contains(01/25/2017)')); + testUtils.dom.click(form.$('.o_datepicker_input')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch').first()); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch:eq(1)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .year:contains(2017)')); + testUtils.dom.click($('.bootstrap-datetimepicker-widget .month').eq(1)); + testUtils.dom.click($('.day:contains(22)')); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.verifySteps(['read', 'read', 'onchange', 'write', 'read', 'read']); form.destroy(); @@ -3482,34 +3474,34 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "o2m should contain one row"); // empty o2m by triggering the onchange - form.$('.o_field_widget[name=foo]').val('trigger onchange').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), 'trigger onchange'); - assert.strictEqual(form.$('.o_data_row').length, 0, + assert.containsNone(form, '.o_data_row', "rows of the o2m should have been deleted"); // add two new subrecords - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_widget[name=display_name]').val('x').trigger('input'); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_widget[name=display_name]').val('y').trigger('input'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'x'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'y'); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, "o2m should contain two rows"); // empty o2m by triggering the onchange - form.$('.o_field_widget[name=foo]').val('trigger onchange again').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), 'trigger onchange again'); - assert.strictEqual(form.$('.o_data_row').length, 0, + assert.containsNone(form, '.o_data_row', "rows of the o2m should have been deleted"); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_widget[name=display_name]').val('z').trigger('input'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'z'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -3568,13 +3560,13 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "o2m should contain one row"); - form.$('.o_field_one2many .o_list_view tbody tr:first td:first').click(); - form.$('.o_field_one2many .o_list_view tbody tr:first input:first').val('blurp').trigger('input'); + testUtils.dom.click(form.$('.o_field_one2many .o_list_view tbody tr:first td:first')); + testUtils.fields.editInput(form.$('.o_field_one2many .o_list_view tbody tr:first input:first'), 'blurp'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -3582,7 +3574,7 @@ QUnit.module('fields', {}, function () { assert.expect(5); var delta = 0; - testUtils.patch(AbstractField, { + testUtils.mock.patch(AbstractField, { init: function () { delta++; this._super.apply(this, arguments); @@ -3649,43 +3641,43 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 0, + assert.containsNone(form, '.o_data_row', "o2m shouldn't contain any row"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); // trigger the first onchange deactiveOnchange = false; - form.$('input[name="turtle_int"]').val('10').trigger('input'); + testUtils.fields.editInput(form.$('input[name="turtle_int"]'), '10'); // put the list back in non edit mode - form.$('input[name="foo"]').click(); + testUtils.dom.click(form.$('input[name="foo"]')); assert.strictEqual(form.$('.o_data_row').text(), "first10second-10", "should correctly refresh the records"); // trigger the second onchange - form.$('.o_field_x2many_list tbody tr:first td:first').click(); - form.$('input[name="turtle_int"]').val('20').trigger('input'); + testUtils.dom.click(form.$('.o_field_x2many_list tbody tr:first td:first')); + testUtils.fields.editInput(form.$('input[name="turtle_int"]'), '20'); - form.$('input[name="foo"]').click(); + testUtils.dom.click(form.$('input[name="foo"]')); assert.strictEqual(form.$('.o_data_row').text(), "first20second-20", "should correctly refresh the records"); - assert.strictEqual(form.$('.o_field_widget').length, delta, + assert.containsN(form, '.o_field_widget', delta, "all (non visible) field widgets should have been destroyed"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.strictEqual(form.$('.o_data_row').text(), "first20second-20", "should correctly refresh the records after save"); form.destroy(); - testUtils.unpatch(AbstractField); + testUtils.mock.unpatch(AbstractField); }); QUnit.test('editable one2many with sub widgets are rendered in readonly', function (assert) { assert.expect(2); var editableWidgets = 0; - testUtils.patch(AbstractField, { + testUtils.mock.patch(AbstractField, { init: function () { this._super.apply(this, arguments); if (this.mode === 'edit') { @@ -3714,13 +3706,13 @@ QUnit.module('fields', {}, function () { assert.strictEqual(editableWidgets, 1, "o2m is only widget in edit mode"); - form.$('tbody td.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); assert.strictEqual(editableWidgets, 3, "3 widgets currently in edit mode"); form.destroy(); - testUtils.unpatch(AbstractField); + testUtils.mock.unpatch(AbstractField); }); QUnit.test('one2many editable list with onchange keeps the order', function (assert) { @@ -3751,9 +3743,9 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_data_cell').text(), 'first recordsecond recordaaa', "records should be display in the correct order"); - form.$('.o_data_row:first .o_data_cell').click(); - form.$('.o_selected_row .o_field_widget[name=display_name]').val('new').trigger('input'); - form.$el.click(); // click outside to validate the row + testUtils.dom.click(form.$('.o_data_row:first .o_data_cell')); + testUtils.fields.editInput(form.$('.o_selected_row .o_field_widget[name=display_name]'), 'new'); + testUtils.dom.click(form.$el); assert.strictEqual(form.$('.o_data_cell').text(), 'newsecond recordaaa', "records should be display in the correct order"); @@ -3783,18 +3775,18 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.ok(form.$('.o_list_view tbody tr:eq(0) td:first').hasClass('o_readonly_modifier'), + assert.hasClass(form.$('.o_list_view tbody tr:eq(0) td:first'),'o_readonly_modifier', "first record should have display_name in readonly mode"); - assert.notOk(form.$('.o_list_view tbody tr:eq(1) td:first').hasClass('o_readonly_modifier'), + assert.doesNotHaveClass(form.$('.o_list_view tbody tr:eq(1) td:first'), 'o_readonly_modifier', "second record should not have display_name in readonly mode"); form.destroy(); }); QUnit.test('pager of one2many field in new record', function (assert) { - assert.expect(2); + assert.expect(3); this.data.partner.records[0].p = []; @@ -3805,23 +3797,18 @@ QUnit.module('fields', {}, function () { arch: '<form string="Partners">' + '<field name="p">' + '<tree editable="top">' + - '<field name="foo"/>' + + '<field name="foo"/>' + '</tree>' + '</field>' + '</form>', - archs: { - 'partner,false,form': - '<form string="Partner"><field name="foo"/></form>', - }, }); assert.ok(!form.$('.o_x2m_control_panel .o_cp_pager div').is(':visible'), 'o2m pager should be hidden'); // click to create a subrecord - form.$('tbody td.o_field_x2many_list_row_add a').click(); - $('.modal input').val('new record').trigger('input'); - $('.modal .modal-footer button:eq(0)').click(); // save and close + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); + assert.containsOnce(form, 'tr.o_data_row'); assert.ok(!form.$('.o_x2m_control_panel .o_cp_pager div').is(':visible'), 'o2m pager should be hidden'); @@ -3864,7 +3851,7 @@ QUnit.module('fields', {}, function () { "should trigger onchange with correct parameters"); } return this._super.apply(this, arguments); - } + }, }); assert.strictEqual(form.$('tbody td:contains(xphone)').length, 1, @@ -3872,18 +3859,14 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('tbody td:contains(xpad)').length, 0, "should not display 'xpad' anywhere"); - form.$buttons.find('.o_form_button_edit').click(); - - form.$('tbody td.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); - $('.modal .o_field_many2one input').click(); + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); - var $dropdown = $('.modal .o_field_many2one input').autocomplete('widget'); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickItem('product_id', 'xpad'); - $dropdown.find('li:eq(1) a').mouseenter(); - $dropdown.find('li:eq(1) a').click(); - - $('.modal .modal-footer button:eq(0)').click(); // save and close + testUtils.dom.click($('.modal .modal-footer button:eq(0)')); assert.strictEqual(form.$('tbody td:contains(xpad)').length, 1, "should display 'xpad' on a td"); @@ -3930,56 +3913,52 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('tbody td.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); // write in the many2one field, value = 37 (xphone) - $('.modal .o_field_many2one input').click(); - var $dropdown = $('.modal .o_field_many2one input').autocomplete('widget'); - $dropdown.find('li:eq(0) a').mouseenter(); - $dropdown.find('li:eq(0) a').click(); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickHighlightedItem('product_id'); // write in the integer field - $('.modal .modal-body input.o_field_widget').val('123').trigger('input'); + testUtils.fields.editInput($('.modal .modal-body input.o_field_widget'), '123'); // save and close - $('.modal .modal-footer button:eq(0)').click(); + testUtils.dom.click($('.modal .modal-footer button:eq(0)')); assert.strictEqual(form.$('tbody td:contains(xphone)').length, 1, "should display 'xphone' in a td"); // reopen the record in form view - form.$('tbody td:contains(xphone)').click(); + testUtils.dom.click(form.$('tbody td:contains(xphone)')); assert.strictEqual($('.modal .modal-body input').val(), "xphone", "should display 'xphone' in an input"); - $('.modal .modal-body input.o_field_widget').val('456').trigger('input'); + testUtils.fields.editInput($('.modal .modal-body input.o_field_widget'), '456'); // discard - $('.modal .modal-footer span:contains(Discard)').click(); + testUtils.dom.click($('.modal .modal-footer span:contains(Discard)')); // reopen the record in form view - form.$('tbody td:contains(xphone)').click(); + testUtils.dom.click(form.$('tbody td:contains(xphone)')); assert.strictEqual($('.modal .modal-body input.o_field_widget').val(), "123", "should display 123 (previous change has been discarded)"); // write in the many2one field, value = 41 (xpad) - $('.modal .o_field_many2one input').click(); - $dropdown = $('.modal .o_field_many2one input').autocomplete('widget'); - $dropdown.find('li:eq(1) a').mouseenter(); - $dropdown.find('li:eq(1) a').click(); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickItem('product_id', 'xpad'); // save and close - $('.modal .modal-footer button:eq(0)').click(); + testUtils.dom.click($('.modal .modal-footer button:eq(0)')); assert.strictEqual(form.$('tbody td:contains(xpad)').length, 1, "should display 'xpad' in a td"); // save the record - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -4018,12 +3997,12 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // open a modal - form.$('tr.o_data_row:eq(0) td:contains(xphone)').click(); + testUtils.dom.click(form.$('tr.o_data_row:eq(0) td:contains(xphone)')); // write in the many2one field - $('.modal .o_field_many2one input').click(); + testUtils.dom.click($('.modal .o_field_many2one input')); form.destroy(); }); @@ -4057,8 +4036,8 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_widget[name=product_id] input').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_widget[name=product_id] input')); form.destroy(); }); @@ -4091,12 +4070,12 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('tr.o_data_row:eq(0) td:contains(xphone)').click(); + testUtils.dom.click(form.$('tr.o_data_row:eq(0) td:contains(xphone)')); // trigger a name search - form.$('table td input').click(); + testUtils.dom.click(form.$('table td input')); form.destroy(); }); @@ -4131,8 +4110,8 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.destroy(); }); @@ -4169,10 +4148,10 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('input[name="turtle_foo"]').val('hammer').trigger('input'); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('input[name="turtle_foo"]'), 'hammer'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.destroy(); }); @@ -4194,20 +4173,20 @@ QUnit.module('fields', {}, function () { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('tbody td.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('td input.o_field_widget').length, 1, + assert.containsOnce(form, 'td input.o_field_widget', "should have created a row in edit mode"); - form.$('td input.o_field_widget').val('a').trigger('input'); + testUtils.fields.editInput(form.$('td input.o_field_widget'), 'a'); - assert.strictEqual(form.$('td input.o_field_widget').length, 1, + assert.containsOnce(form, 'td input.o_field_widget', "should not have unselected the row after edition"); - form.$('td input.o_field_widget').val('abc').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editInput(form.$('td input.o_field_widget'), 'abc'); + testUtils.form.clickSave(form);; assert.strictEqual(form.$('td:contains(abc)').length, 1, "should have a row with the correct value"); @@ -4240,8 +4219,8 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('tbody td.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); form.destroy(); }); @@ -4288,39 +4267,37 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .o_data_row').length, 2, "sould have 2 records in the select view (the last one is not displayed because it is already selected)"); - $('.modal .o_data_row:first .o_list_record_selector input').click(); - $('.modal .o_select_button').click(); - $('.o_form_button_save').click(); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click($('.modal .o_data_row:first .o_list_record_selector input')); + testUtils.dom.click($('.modal .o_select_button')); + testUtils.dom.click($('.o_form_button_save')); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .o_data_row').length, 1, "sould have 1 record in the select view"); - $('.modal-footer button:eq(1)').click(); - $('.modal input.o_field_widget[name="turtle_foo"]').val('tototo').trigger('input'); - $('.modal input.o_field_widget[name="turtle_int"]').val(50).trigger('input'); - var $many2one = $('.modal [name="product_id"] input').click(); - var $dropdown = $many2one.autocomplete('widget'); - $dropdown.find('li:first a').mouseenter(); - $dropdown.find('li:first a').click(); + testUtils.dom.click($('.modal-footer button:eq(1)')); + testUtils.fields.editInput($('.modal input.o_field_widget[name="turtle_foo"]'), 'tototo'); + testUtils.fields.editInput($('.modal input.o_field_widget[name="turtle_int"]'), 50); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickHighlightedItem('product_id'); - $('.modal-footer button:contains(&):first').click(); + testUtils.dom.click($('.modal-footer button:contains(&):first')); assert.strictEqual($('.modal').length, 0, "sould close the modals"); - assert.strictEqual(form.$('.o_data_row').length, 3, + assert.containsN(form, '.o_data_row', 3, "sould have 3 records in one2many list"); assert.strictEqual(form.$('.o_data_row').text(), "blip1.59yop1.50tototo1.550xphone", "should display the record values in one2many list"); - $('.o_form_button_save').click(); + testUtils.dom.click($('.o_form_button_save')); form.destroy(); }); @@ -4370,37 +4347,33 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_data_row:first').click(); + testUtils.dom.click(form.$('.o_data_row:first')); assert.strictEqual($('.modal .modal-title').first().text().trim(), 'Open: one2many turtle field', "modal should use the python field string as title"); - $('.modal .o_form_button_cancel').click(); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.dom.click($('.modal .o_form_button_cancel')); + testUtils.form.clickEdit(form); // edit the first one2many record - form.$('.o_data_row:first').click(); - var $many2one = $('.modal [name="product_id"] input').click(); - var $dropdown = $many2one.autocomplete('widget'); - $dropdown.find('li:first a').mouseenter(); - $dropdown.find('li:first a').click(); - $('.modal-footer button:first').click(); + testUtils.dom.click(form.$('.o_data_row:first')); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickHighlightedItem('product_id'); + testUtils.dom.click($('.modal-footer button:first')); - $('.o_form_button_save').click(); // don't save anything because the one2many does not change + testUtils.dom.click($('.o_form_button_save')); // add a one2many record - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - $('.modal .o_data_row:first .o_list_record_selector input').click(); - $('.modal .o_select_button').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click($('.modal .o_data_row:first .o_list_record_selector input')); + testUtils.dom.click($('.modal .o_select_button')); // edit the second one2many record - form.$('.o_data_row:eq(1)').click(); - $many2one = $('.modal [name="product_id"] input').click(); - $dropdown = $many2one.autocomplete('widget'); - $dropdown.find('li:first a').mouseenter(); - $dropdown.find('li:first a').click(); - $('.modal-footer button:first').click(); + testUtils.dom.click(form.$('.o_data_row:eq(1)')); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickHighlightedItem('product_id'); + testUtils.dom.click($('.modal-footer button:first')); - $('.o_form_button_save').click(); + testUtils.dom.click($('.o_form_button_save')); form.destroy(); }); @@ -4436,8 +4409,7 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('tbody td.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); form.destroy(); }); @@ -4468,8 +4440,8 @@ QUnit.module('fields', {}, function () { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('tbody td.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); form.destroy(); }); @@ -4499,9 +4471,7 @@ QUnit.module('fields', {}, function () { return this._super.apply(this, arguments); }, }); - - form.$buttons.find('.o_form_button_edit').click(); - form.$('tbody td.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); assert.verifySteps(['default_get', 'onchange', 'default_get', 'onchange']); form.destroy(); }); @@ -4559,9 +4529,9 @@ QUnit.module('fields', {}, function () { return this._super.apply(this, arguments); }, }); - form.$('td.o_field_x2many_list_row_add a').click(); - form.$('td input[name="turtle_foo"]').val('cat').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('td.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('td input[name="turtle_foo"]'), 'cat'); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -4588,9 +4558,9 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('tbody td.o_field_x2many_list_row_add a').click(); - $('.modal-footer button.btn-primary').first().click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('tbody td.o_field_x2many_list_row_add a')); + testUtils.dom.click($('.modal-footer button.btn-primary').first()); assert.strictEqual($('.modal').length, 1, "should still have an open modal"); assert.strictEqual($('.modal tbody label.o_field_invalid').length, 1, @@ -4631,7 +4601,7 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_list_button button').click(); + testUtils.dom.click(form.$('.o_list_button button')); form.destroy(); }); @@ -4675,7 +4645,7 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.oe_kanban_action_button').click(); + testUtils.dom.click(form.$('.oe_kanban_action_button')); form.destroy(); }); @@ -4720,7 +4690,7 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$('.oe_kanban_action:eq(0)').click(); + testUtils.dom.click(form.$('.oe_kanban_action:eq(0)')); assert.strictEqual($('.o_domain_selector').length, 1, "should add domain selector widget"); form.destroy(); }); @@ -4788,17 +4758,17 @@ QUnit.module('fields', {}, function () { } }); - form.$('.o_field_one2many .o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_one2many .o_field_x2many_list_row_add a')); assert.strictEqual($('.modal').length, 1, "form view dialog should be opened"); - $('.modal-body input[name="model_name"]').val('partner').trigger('input'); - $('.modal-footer button:first').click(); + testUtils.fields.editInput($('.modal-body input[name="model_name"]'), 'partner'); + testUtils.dom.click($('.modal-footer button:first')); assert.strictEqual(form.$('.o_field_one2many tbody tr:first').text(), "coucouhas changed[]", "the onchange should create one new record and remove the existing"); - form.$('.o_field_one2many .o_list_view tbody tr:eq(0) td:first').click(); + testUtils.dom.click(form.$('.o_field_one2many .o_list_view tbody tr:eq(0) td:first')); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.strictEqual(nbFetchSpecialDomain, 1, "should only fetch special domain once"); form.destroy(); @@ -4826,10 +4796,10 @@ QUnit.module('fields', {}, function () { } }); - assert.strictEqual(form.$('.o_field_widget[name="turtles"] .o_list_view').length, 1, + assert.containsOnce(form, '.o_field_widget[name="turtles"] .o_list_view', 'should display one2many list view in the modal'); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, 'should display the 2 turtles'); form.destroy(); @@ -4879,7 +4849,7 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, 'should display the 2 turtles'); assert.strictEqual(form.$('.o_data_row:first td:nth(1)').text(), 'xphone', "should correctly display the m2o"); @@ -4888,36 +4858,34 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_data_row:first td:nth(2) .badge:first span').text(), 'second record', "m2m values should have been correctly fetched"); - form.$('.o_data_row:first').click(); + testUtils.dom.click(form.$('.o_data_row:first')); assert.strictEqual($('.modal .o_field_widget').text(), "xphone", 'should display the form view dialog with the many2one value'); - $('.modal-footer button').click(); // close the modal + testUtils.dom.click($('.modal-footer button')); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // edit the m2m of first row - form.$('.o_list_view tbody td:first()').click(); + testUtils.dom.click(form.$('.o_list_view tbody td:first()')); // remove a tag - form.$('.o_field_many2manytags .badge:contains(aaa) .o_delete').click(); + testUtils.dom.click(form.$('.o_field_many2manytags .badge:contains(aaa) .o_delete')); assert.strictEqual(form.$('.o_selected_row .o_field_many2manytags .o_badge_text:contains(aaa)').length, 0, "tag should have been correctly removed"); // add a tag - var $m2mInput = form.$('.o_selected_row .o_field_many2manytags input'); - $m2mInput.click(); - $m2mInput.autocomplete('widget').find('li:first()').click(); + testUtils.fields.many2one.clickOpenDropdown('partner_ids'); + testUtils.fields.many2one.clickHighlightedItem('partner_ids'); assert.strictEqual(form.$('.o_selected_row .o_field_many2manytags .o_badge_text:contains(first record)').length, 1, "tag should have been correctly added"); // edit the m2o of first row - var $m2oInput = form.$('.o_selected_row .o_field_many2one:first input'); - $m2oInput.click(); - $m2oInput.autocomplete('widget').find('li:contains(xpad)').mouseover().click(); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickItem('product_id', 'xpad'); assert.strictEqual(form.$('.o_selected_row .o_field_many2one:first input').val(), 'xpad', "m2o value should have been updated"); // save (should correctly generate the commands) - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); @@ -4948,12 +4916,12 @@ QUnit.module('fields', {}, function () { return this._super.apply(this, arguments); }, }); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, 'there should be only 2 rows displayed'); - form.$('.o_list_record_remove').click(); - form.$('.o_list_record_remove').click(); + testUtils.dom.clickFirst(form.$('.o_list_record_remove')); + testUtils.dom.clickFirst(form.$('.o_list_record_remove')); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', 'there should be just one remaining row'); assert.verifySteps([ @@ -5035,20 +5003,20 @@ QUnit.module('fields', {}, function () { }); // add new line (first, xpad) - form.$('.o_field_x2many_list_row_add a').click(); - form.$('input[name="display_name"]').val('first').trigger('input'); - form.$('div[name="product_id"] input').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('input[name="display_name"]'), 'first'); + testUtils.dom.click(form.$('div[name="product_id"] input')); // the onchange won't be generated - $('li.ui-menu-item a:contains(xpad)').trigger('mouseenter').click(); + testUtils.dom.click($('li.ui-menu-item a:contains(xpad)').trigger('mouseenter')); - assert.strictEqual(form.$('.o_field_many2manytags.o_input').length, 1, + assert.containsOnce(form, '.o_field_many2manytags.o_input', 'should display the line in editable mode'); assert.strictEqual(form.$('.o_field_many2one input').val(), "xpad", 'should display the product xpad'); assert.strictEqual(form.$('.o_field_many2manytags.o_input .o_badge_text').text(), "first record", 'should display the tag from the onchange'); - form.$('input.o_field_integer[name="int_field"]').click(); + testUtils.dom.click(form.$('input.o_field_integer[name="int_field"]')); assert.strictEqual(form.$('.o_data_cell.o_required_modifier').text(), "xpad", 'should display the product xpad'); @@ -5056,7 +5024,7 @@ QUnit.module('fields', {}, function () { 'should display the tag in readonly'); // enable the many2many onchange and generate it - form.$('input.o_field_integer[name="int_field"]').val('10').trigger('input'); + testUtils.fields.editInput(form.$('input.o_field_integer[name="int_field"]'), '10'); assert.strictEqual(form.$('.o_data_cell.o_required_modifier').text(), "xenomorphexphone", 'should display the product xphone and xenomorphe'); @@ -5064,23 +5032,23 @@ QUnit.module('fields', {}, function () { 'should display the name, one2many and many2many value'); // disable the many2many onchange - form.$('input.o_field_integer[name="int_field"]').val('0').trigger('input'); + testUtils.fields.editInput(form.$('input.o_field_integer[name="int_field"]'), '0'); // remove and start over - form.$('.o_list_record_remove:first button').click(); - form.$('.o_list_record_remove:first button').click(); + testUtils.dom.click(form.$('.o_list_record_remove:first button')); + testUtils.dom.click(form.$('.o_list_record_remove:first button')); // enable the many2many onchange - form.$('input.o_field_integer[name="int_field"]').val('10').trigger('input'); + testUtils.fields.editInput(form.$('input.o_field_integer[name="int_field"]'), '10'); // add new line (first, xenomorphe) - form.$('.o_field_x2many_list_row_add a').click(); - form.$('input[name="display_name"]').val('first').trigger('input'); - form.$('div[name="product_id"] input').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('input[name="display_name"]'), 'first'); + testUtils.dom.click(form.$('div[name="product_id"] input')); // generate the onchange - $('li.ui-menu-item a:contains(xenomorphe)').trigger('mouseenter').click(); + testUtils.dom.click($('li.ui-menu-item a:contains(xenomorphe)').trigger('mouseenter')); - assert.strictEqual(form.$('.o_field_many2manytags.o_input').length, 1, + assert.containsOnce(form, '.o_field_many2manytags.o_input', 'should display the line in editable mode'); assert.strictEqual(form.$('.o_field_many2one input').val(), "xenomorphe", 'should display the product xenomorphe'); @@ -5088,19 +5056,19 @@ QUnit.module('fields', {}, function () { 'should display the tag from the onchange'); // put list in readonly mode - form.$('input.o_field_integer[name="int_field"]').click(); + testUtils.dom.click(form.$('input.o_field_integer[name="int_field"]')); assert.strictEqual(form.$('.o_data_cell.o_required_modifier').text(), "xenomorphexphone", 'should display the product xphone and xenomorphe'); assert.strictEqual(form.$('.o_field_many2manytags:not(.o_input) .o_badge_text').text(), "second recordfirst record", 'should display the tag in readonly (first record and second record)'); - form.$('input.o_field_integer[name="int_field"]').val('10').trigger('input'); + testUtils.fields.editInput(form.$('input.o_field_integer[name="int_field"]'), '10'); assert.strictEqual(form.$('.o_data_row').text().replace(/\s+/g, ' '), "firstxenomorphe second record new linexphone first record ", 'should display the name, one2many and many2many value'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.strictEqual(form.$('.o_data_row').text().replace(/\s+/g, ' '), "firstxenomorphe second record new linexphone first record ", 'should display the name, one2many and many2many value after save'); @@ -5141,10 +5109,10 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, 'should display the 2 turtles'); - form.$('.o_data_row:first').click(); + testUtils.dom.click(form.$('.o_data_row:first')); assert.strictEqual($('.modal .o_field_widget[name="partner_ids"] .o_list_view').length, 1, 'should display many2many list view in the modal'); @@ -5176,7 +5144,7 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_data_row:first').click(); + testUtils.dom.click(form.$('.o_data_row:first')); assert.strictEqual($('.modal .o_field_widget[name="turtle_foo"]').text(), 'blip', 'should open the modal and display the form field'); @@ -5225,18 +5193,17 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_data_row:first').click(); // edit first record + testUtils.dom.click(form.$('.o_data_row:first')); // edit first record - var $input = $('.modal .o_field_many2manytags input'); - $input.click(); // opens the dropdown - $input.autocomplete('widget').find('li').click(); // add 'first record' + testUtils.fields.many2one.clickOpenDropdown('partner_ids'); + testUtils.fields.many2one.clickHighlightedItem('partner_ids'); // add a many2many tag and save - $('.modal .o_field_x2many_list_row_add a').click(); - $('.modal .o_field_widget[name=name]').val('test').trigger('input'); - $('.modal .modal-footer .btn-primary').click(); // save + testUtils.dom.click($('.modal .o_field_many2manytags input')); + testUtils.fields.editInput($('.modal .o_field_many2manytags input'), 'test'); + testUtils.dom.click($('.modal .modal-footer .btn-primary')); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); @@ -5283,20 +5250,20 @@ QUnit.module('fields', {}, function () { }); // edit the first partner in the one2many partner form view - form.$('.o_data_row:first td.o_data_cell').click(); + testUtils.dom.click(form.$('.o_data_row:first td.o_data_cell')); // open form view for many2one - form.$('.o_external_button').click(); + testUtils.dom.click(form.$('.o_external_button')); // click on add, to add a new partner in the m2m - $('.modal .o_field_x2many_list_row_add a').click(); + testUtils.dom.click($('.modal .o_field_x2many_list_row_add a')); // select the partner_type 'gold' (this closes the 2nd modal) - $('.modal td:contains(gold)').click(); + testUtils.dom.click($('.modal td:contains(gold)')); // confirm the changes in the modal - $('.modal .modal-footer .btn-primary').click(); + testUtils.dom.click($('.modal .modal-footer .btn-primary')); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -5327,9 +5294,9 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_list_view .o_data_row').length, 2, + assert.containsN(form, '.o_list_view .o_data_row', 2, "one2many list should contain 2 rows"); - assert.strictEqual(form.$('.o_list_view .o_field_many2manytags[name="partner_ids"] .badge').length, 2, + assert.containsN(form, '.o_list_view .o_field_many2manytags[name="partner_ids"] .badge', 2, "m2mtags should contain two tags"); assert.strictEqual(form.$('.o_list_view .o_field_many2manytags[name="partner_ids"] .o_badge_text').text(), 'aaafirst record', "tag names should have been correctly loaded"); @@ -5361,7 +5328,7 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_data_row:first').click(); + testUtils.dom.click(form.$('.o_data_row:first')); assert.strictEqual($('.modal .o_field_widget[name="turtle_foo"]').text(), 'blip', 'should open the modal and display the form field'); @@ -5410,21 +5377,21 @@ QUnit.module('fields', {}, function () { res_id: 4, }); - assert.strictEqual(form.$('.o_field_widget .o_kanban_view').length, 1, + assert.containsOnce(form, '.o_field_widget .o_kanban_view', "should have one inner kanban view for the one2many field"); assert.strictEqual(form.$('.o_field_widget .o_kanban_view .o_kanban_record:not(.o_kanban_ghost)').length, 0, "should not have kanban records yet"); // // switch to edit mode and create a new kanban record - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_widget .o-kanban-button-new').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_widget .o-kanban-button-new')); // save & close the modal assert.strictEqual($('.modal-content input.o_field_widget').val(), 'My little Foo Value', "should already have the default value for field foo"); - $('.modal-content .btn-primary').first().click(); + testUtils.dom.click($('.modal-content .btn-primary').first()); - assert.strictEqual(form.$('.o_field_widget .o_kanban_view').length, 1, + assert.containsOnce(form, '.o_field_widget .o_kanban_view', "should have one inner kanban view for the one2many field"); assert.strictEqual(form.$('.o_field_widget .o_kanban_view .o_kanban_record:not(.o_kanban_ghost)').length, 1, "should now have one kanban record"); @@ -5434,8 +5401,8 @@ QUnit.module('fields', {}, function () { 'My little Foo Value', "should have a value for the foo field"); // save the view to force a create of the new record in the one2many - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_field_widget .o_kanban_view').length, 1, + testUtils.form.clickSave(form);; + assert.containsOnce(form, '.o_field_widget .o_kanban_view', "should have one inner kanban view for the one2many field"); assert.strictEqual(form.$('.o_field_widget .o_kanban_view .o_kanban_record:not(.o_kanban_ghost)').length, 1, "should now have one kanban record"); @@ -5467,9 +5434,9 @@ QUnit.module('fields', {}, function () { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('.o_data_row:first td:first').click(); + testUtils.dom.click(form.$('.o_data_row:first td:first')); assert.strictEqual(form.$('input[name="turtle_foo"]')[0], document.activeElement, "turtle foo field should have focus"); @@ -5508,21 +5475,21 @@ QUnit.module('fields', {}, function () { return this._super.apply(this, arguments); }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should start with one data row"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, "should have 2 data rows"); assert.strictEqual(form.$('tr.o_data_row:first input').val(), 'default foo turtle', "first row should be the new value"); - assert.ok(form.$('tr.o_data_row:first').hasClass('o_selected_row'), + assert.hasClass(form.$('tr.o_data_row:first'),'o_selected_row', "first row should be selected"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -5555,21 +5522,21 @@ QUnit.module('fields', {}, function () { return this._super.apply(this, arguments); }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should start with one data row"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, "should have 2 data rows"); assert.strictEqual(form.$('tr.o_data_row:eq(1) input').val(), 'default foo turtle', "second row should be the new value"); - assert.ok(form.$('tr.o_data_row:eq(1)').hasClass('o_selected_row'), + assert.hasClass(form.$('tr.o_data_row:eq(1)'),'o_selected_row', "second row should be selected"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -5601,7 +5568,7 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - assert.strictEqual(form.$('.o_field_one2many .o_kanban_view').length, 1, + assert.containsOnce(form, '.o_field_one2many .o_kanban_view', "should have rendered a kanban view"); form.destroy(); @@ -5638,17 +5605,17 @@ QUnit.module('fields', {}, function () { }, res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "0", "int_field should start with value 0"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "0", "int_field should still be 0 (no onchange should have been done yet"); assert.verifySteps(['read', 'default_get'], "no onchange should have been applied"); - form.$('.o_field_widget[name="turtle_foo"]').val("some text").trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name="turtle_foo"]'), "some text"); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "1", "int_field should now be 1 (the onchange should have been done"); @@ -5699,27 +5666,26 @@ QUnit.module('fields', {}, function () { }, res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "0", "int_field should start with value 0"); // add a new row (which is invalid at first) - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "0", "int_field should still be 0 (no onchange should have been done yet)"); assert.verifySteps(['load_views', 'read', 'default_get'], "no onchange should have been applied"); // fill turtle_foo field - form.$('.o_field_widget[name="turtle_foo"]').val("some text").trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name="turtle_foo"]'), "some text"); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "0", "int_field should still be 0 (no onchange should have been done yet)"); assert.verifySteps(['load_views', 'read', 'default_get'], "no onchange should have been applied"); // fill partner_ids field with a tag (all required fields will then be set) - var $m2mInput = form.$('.o_field_widget[name=partner_ids] input'); - $m2mInput.click(); - $m2mInput.autocomplete('widget').find('li:first()').click(); + testUtils.fields.many2one.clickOpenDropdown('partner_ids'); + testUtils.fields.many2one.clickHighlightedItem('partner_ids'); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "1", "int_field should now be 1 (the onchange should have been done"); @@ -5751,18 +5717,18 @@ QUnit.module('fields', {}, function () { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "10", "int_field should start with value 10"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "10", "int_field should still be 10 (no onchange, because line is not valid)"); // fill turtle_foo field - form.$('.o_field_widget[name="turtle_foo"]').val("some text").trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name="turtle_foo"]'), "some text"); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "1", "int_field should be 1 (onchange triggered, because line is now valid)"); @@ -5796,18 +5762,18 @@ QUnit.module('fields', {}, function () { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "10", "int_field should start with value 10"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "10", "int_field should still be 10 (no onchange, because line is not valid)"); // fill turtle_int field - form.$('.o_field_widget[name="turtle_int"]').val("1").trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name="turtle_int"]'), "1"); assert.strictEqual(form.$('.o_field_widget[name="int_field"]').val(), "1", "int_field should be 1 (onchange triggered, because line is now valid)"); @@ -5848,29 +5814,29 @@ QUnit.module('fields', {}, function () { }); // add a first line but hold the onchange back - form.$('.o_field_x2many_list_row_add a').click(); - assert.strictEqual(form.$('.o_data_row').length, 1, + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + assert.containsOnce(form, '.o_data_row', "should have created the first row immediately"); def = $.Deferred(); - form.$('.o_field_many2one input').click(); - form.$('.o_field_many2one input').autocomplete('widget').find('a').first().click(); + testUtils.fields.many2one.clickOpenDropdown('turtle_trululu'); + testUtils.fields.many2one.clickHighlightedItem('turtle_trululu'); // try to add a second line and check that it is correctly waiting // for the onchange to return - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal').length, 0, "no modal should be displayed"); assert.strictEqual($('.o_field_invalid').length, 0, "no field should be marked as invalid"); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should wait for the onchange to create the second row"); - assert.ok(form.$('.o_data_row').hasClass('o_selected_row'), + assert.hasClass(form.$('.o_data_row'),'o_selected_row', "first row should still be in edition"); // resolve the onchange def def.resolve(); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, "second row should now have been created"); - assert.notOk(form.$('.o_data_row:first').hasClass('o_selected_row'), + assert.doesNotHaveClass(form.$('.o_data_row:first'), 'o_selected_row', "first row should no more be in edition"); form.destroy(); @@ -5906,16 +5872,16 @@ QUnit.module('fields', {}, function () { // click twice to add a new line def = $.Deferred(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_x2many_list_row_add a').click(); - assert.strictEqual(form.$('.o_data_row').length, 0, + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + assert.containsNone(form, '.o_data_row', "no row should have been created yet (waiting for the onchange)"); // resolve the onchange def def.resolve(); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "only one row should have been created"); - assert.ok(form.$('.o_data_row:first').hasClass('o_selected_row'), + assert.hasClass(form.$('.o_data_row:first'),'o_selected_row', "the created row should be in edition"); form.destroy(); @@ -5960,17 +5926,17 @@ QUnit.module('fields', {}, function () { }); // trigger the two onchanges - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_data_row .o_field_widget').val('a name').trigger('input'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_data_row .o_field_widget'), 'a name'); def = $.Deferred(); - form.$('.o_datepicker_input').click(); // focusout o2m and set value to today + testUtils.dom.click(form.$('.o_datepicker_input')); var dateTimeVal = fieldUtils.format.datetime(moment(), { timezone: false }); - form.$('.o_datepicker_input').val(dateTimeVal).trigger('change'); + testUtils.fields.editSelect(form.$('.o_datepicker_input'), dateTimeVal); // resolve the onchange def def.resolve(); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should have one record in the o2m"); assert.strictEqual(form.$('.o_data_row .o_data_cell').text(), 'new', "should be the record created by the onchange"); @@ -6021,11 +5987,11 @@ QUnit.module('fields', {}, function () { }); // add a line (this should trigger an onchange and a warning) - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); // check if 'Add an item' still works (this should trigger an onchange // and a warning again) - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.verifySteps(['onchange', 'warning', 'onchange', 'warning']); @@ -6081,9 +6047,9 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$('.o_data_cell:first').click(); - form.$('.o_field_widget[name=display_name]').val('abc').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('.o_data_cell:first')); + testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'abc'); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -6114,7 +6080,7 @@ QUnit.module('fields', {}, function () { }, }); - form.$('input[name="foo"]').val('abcd').trigger('input'); + testUtils.fields.editInput(form.$('input[name="foo"]'), 'abcd'); assert.verifySteps(['read', 'onchange']); form.destroy(); @@ -6155,12 +6121,12 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "the one2many should contain one row"); - assert.strictEqual(form.$('.o_field_widget[name="timmy"]').length, 0, + assert.containsNone(form, '.o_field_widget[name="timmy"]', "timmy should not be displayed in the list view"); - form.$('.o_data_row td:first').click(); // open the record + testUtils.dom.click(form.$('.o_data_row td:first')); assert.strictEqual($('.modal .o_field_many2manytags[name="timmy"]').length, 1, "timmy should be displayed in the form view"); @@ -6199,10 +6165,10 @@ QUnit.module('fields', {}, function () { return this._super.apply(this, arguments); }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // triggers an onchange on partner, because the new record is valid - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.verifySteps(['read', 'default_get', 'onchange']); form.destroy(); @@ -6241,11 +6207,11 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); - $('.modal .o_field_x2many_list_row_add a').click(); - $('.modal .o_data_cell input').val('new record').trigger('input'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click($('.modal .o_field_x2many_list_row_add a')); + testUtils.fields.editInput($('.modal .o_data_cell input'), 'new record'); checkOnchange = true; - $('.modal .modal-footer .btn-primary').click(); // save (should trigger the onchange) + testUtils.dom.clickFirst($('.modal .modal-footer .btn-primary')); form.destroy(); }); @@ -6285,18 +6251,18 @@ QUnit.module('fields', {}, function () { }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('tr.o_data_row').length, 41, + assert.containsN(form, 'tr.o_data_row', 41, "should have 41 data rows on the current page"); - assert.ok(form.$('tr.o_data_row').last().hasClass('o_selected_row'), + assert.hasClass(form.$('tr.o_data_row').last(),'o_selected_row', "last row should be selected"); - form.$('.o_data_row input[name="turtle_foo"]').val('rainbow dash').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editInput(form.$('.o_data_row input[name="turtle_foo"]'), 'rainbow dash'); + testUtils.form.clickSave(form);; - assert.strictEqual(form.$('tr.o_data_row').length, 40, + assert.containsN(form, 'tr.o_data_row', 40, "should have 40 data rows on the current page"); assert.verifySteps(['read', 'read', 'default_get', 'write', 'read', 'read']); @@ -6328,13 +6294,13 @@ QUnit.module('fields', {}, function () { }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_data_row input[name="turtle_foo"]').val('rainbow dash').trigger('input'); - form.$('.o_x2m_control_panel .o_pager_next').click(); - form.$('.o_x2m_control_panel .o_pager_next').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_data_row input[name="turtle_foo"]'), 'rainbow dash'); + testUtils.dom.click(form.$('.o_x2m_control_panel .o_pager_next')); + testUtils.dom.click(form.$('.o_x2m_control_panel .o_pager_next')); - assert.strictEqual(form.$('tr.o_data_row').length, 3, + assert.containsN(form, 'tr.o_data_row', 3, "should have 3 data rows on the current page"); form.destroy(); }); @@ -6375,27 +6341,27 @@ QUnit.module('fields', {}, function () { }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_pager_next').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_pager_next')); - assert.strictEqual(form.$('tr.o_data_row').length, 2, + assert.containsN(form, 'tr.o_data_row', 2, "should have 2 data rows on the current page"); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('tr.o_data_row').length, 3, + assert.containsN(form, 'tr.o_data_row', 3, "should have 3 data rows on the current page (2 records and the created line)"); - assert.ok(form.$('tr.o_data_row').first().hasClass('o_selected_row'), + assert.hasClass(form.$('tr.o_data_row').first(),'o_selected_row', "first row should be selected"); assert.strictEqual(form.$('tr.o_data_row input').val(), 'default foo', "selected input should have correct string"); - form.$('.o_data_row input[name="turtle_foo"]').val('rainbow dash').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editInput(form.$('.o_data_row input[name="turtle_foo"]'), 'rainbow dash'); + testUtils.form.clickSave(form);; - assert.strictEqual(form.$('tr.o_data_row').length, 40, + assert.containsN(form, 'tr.o_data_row', 40, "should have 40 data rows on the current page"); assert.verifySteps(['read', 'read', 'read', 'default_get', 'write', 'read', 'read']); @@ -6435,11 +6401,9 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); def = $.Deferred(); - form.$('.o_field_widget[name=int_field]') - .val('44') - .trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), '44'); var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); // set trululu before onchange @@ -6490,19 +6454,17 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); def = $.Deferred(); - form.$('.o_field_widget[name=int_field]') - .val('44') - .trigger('input') - .trigger({ type: 'keydown', which: $.ui.keyCode.TAB }); + testUtils.fields.editAndTrigger(form.$('.o_field_widget[name=int_field]'), '44', + ['input', { type: 'keydown', which: $.ui.keyCode.TAB }]); def.resolve(); assert.strictEqual(document.activeElement, form.$('.o_field_widget[name=qux]')[0], "qux field should have the focus"); - form.$('.o_field_many2one input').click(); - form.$('.o_field_many2one input').autocomplete('widget').find('a').first().click(); + testUtils.fields.many2one.clickOpenDropdown('trululu'); + testUtils.fields.many2one.clickHighlightedItem('trululu'); assert.strictEqual(form.$('.o_field_many2one input').val(), 'first record', "the one2many field should have the expected value"); @@ -6529,9 +6491,9 @@ QUnit.module('fields', {}, function () { '</form>', }); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - form.$('.o_field_widget[name=bar] input').click(); + testUtils.dom.click(form.$('.o_field_widget[name=bar] input')); assert.notOk(form.$('.o_field_widget[name=bar] input').prop('checked'), "the checkbox should be unticked"); @@ -6560,15 +6522,15 @@ QUnit.module('fields', {}, function () { }); // edit the line and enter an invalid value for int_field - form.$('.o_data_row .o_data_cell:nth(1)').click(); - form.$('.o_field_widget[name=int_field]').val('e').trigger('input'); - form.$el.click(); // try to validate the line + testUtils.dom.click(form.$('.o_data_row .o_data_cell:nth(1)')); + testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 'e'); + testUtils.dom.click(form.$el); - assert.strictEqual(form.$('.o_data_row.o_selected_row').length, 1, + assert.containsOnce(form, '.o_data_row.o_selected_row', "line should not have been removed and should still be in edition"); assert.strictEqual($('.modal').length, 1, "a confirmation dialog should be opened"); - assert.ok(form.$('.o_field_widget[name=int_field]').hasClass('o_field_invalid'), + assert.hasClass(form.$('.o_field_widget[name=int_field]'),'o_field_invalid', "should indicate that int_field is invalid"); form.destroy(); @@ -6609,7 +6571,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual(form.$('.o_data_cell').text(), '1 record', "should correctly display the value of the inner o2m"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -6656,23 +6618,23 @@ QUnit.module('fields', {}, function () { "initial text should be correct"); // click and edit value to 'foo', which will trigger onchange - form.$('.o_data_row .o_data_cell:nth(0)').click(); - form.$('.o_field_widget[name=turtle_foo]').val('foo').trigger('input'); - form.$el.click(); + testUtils.dom.click(form.$('.o_data_row .o_data_cell:nth(0)')); + testUtils.fields.editInput(form.$('.o_field_widget[name=turtle_foo]'), 'foo'); + testUtils.dom.click(form.$el); assert.strictEqual(form.$('.o_data_row .o_data_cell:nth(0)').text(), 'foo', "field should have been changed to foo"); // click and edit value to 'pinky', which trigger a failed onchange - form.$('.o_data_row .o_data_cell:nth(0)').click(); - form.$('.o_field_widget[name=turtle_foo]').val('pinky').trigger('input'); - form.$el.click(); + testUtils.dom.click(form.$('.o_data_row .o_data_cell:nth(0)')); + testUtils.fields.editInput(form.$('.o_field_widget[name=turtle_foo]'), 'pinky'); + testUtils.dom.click(form.$el); assert.strictEqual(form.$('.o_data_row .o_data_cell:nth(0)').text(), 'foo', "turtle_foo text should now be set back to foo"); // we make sure here that when we save, the values are the current // values displayed in the field. - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -6700,9 +6662,9 @@ QUnit.module('fields', {}, function () { }, viewOptions: { context: { flutter: 'shy' } }, }); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('input[name="turtle_foo"]').val('pinky pie').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('input[name="turtle_foo"]'), 'pinky pie'); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -6756,19 +6718,19 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_widget[name=display_name]').val('trigger onchange').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'trigger onchange'); assert.strictEqual(form.$('.o_data_cell').text(), 'test', "should have added the new row to the one2many"); // open the new subrecord to check the value of the nested o2m, and to // ensure that it will be saved - form.$('.o_data_cell:first').click(); + testUtils.dom.click(form.$('.o_data_cell:first')); assert.strictEqual($('.modal .o_data_cell').text(), 'test nested', "should have added the new row to the nested one2many"); - $('.modal .modal-footer .btn-primary').click(); + testUtils.dom.clickFirst($('.modal .modal-footer .btn-primary')); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; form.destroy(); }); @@ -6810,7 +6772,7 @@ QUnit.module('fields', {}, function () { mode: 'edit', }, }); - form.$('.o_list_record_remove:first button').click(); + testUtils.dom.click(form.$('.o_list_record_remove:first button')); assert.strictEqual(form.$('.o_data_row').text(), 'from onchange', 'onchange has been properly applied'); form.destroy(); @@ -6854,7 +6816,7 @@ QUnit.module('fields', {}, function () { mode: 'edit', }, }); - form.$('.o_list_record_remove:first button').click(); + testUtils.dom.click(form.$('.o_list_record_remove:first button')); assert.strictEqual(form.$('.o_data_row').text(), 'from onchange id2from onchange id3', 'onchange has been properly applied'); form.destroy(); @@ -6893,9 +6855,9 @@ QUnit.module('fields', {}, function () { // check line is at the correct place var inputText = 'ninja'; - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_input[name="turtle_foo"]').val(inputText).trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_input[name="turtle_foo"]'), inputText); + testUtils.form.clickSave(form);; assert.strictEqual($('.o_data_cell').text(), "blipyopkawa" + inputText); form.destroy(); @@ -6934,9 +6896,9 @@ QUnit.module('fields', {}, function () { // check line is at the correct place var inputText = 'ninja'; - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_input[name="turtle_foo"]').val(inputText).trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_input[name="turtle_foo"]'), inputText); + testUtils.form.clickSave(form);; assert.strictEqual($('.o_data_cell').text(), inputText + "blipyopkawa"); form.destroy(); @@ -6980,13 +6942,13 @@ QUnit.module('fields', {}, function () { // check line is at the correct place var inputText = 'ninja'; - $('.o_field_x2many_list_row_add a').click(); - $('.o_input[name="turtle_foo"]').val(inputText).trigger('input'); - $('.modal .modal-footer .btn-primary:first').click(); + testUtils.dom.click($('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput($('.o_input[name="turtle_foo"]'), inputText); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); assert.strictEqual($('.o_data_cell').text(), "blipyopkawa" + inputText); - $('.o_form_button_save').click(); + testUtils.dom.click($('.o_form_button_save')); assert.strictEqual($('.o_data_cell').text(), "blipyopkawa" + inputText); form.destroy(); }); @@ -7020,7 +6982,7 @@ QUnit.module('fields', {}, function () { // click add a new line // check turtle_int for new is the current max of the page - $('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click($('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .o_input[name="turtle_int"]').val(), '10'); form.destroy(); }); @@ -7054,7 +7016,7 @@ QUnit.module('fields', {}, function () { // click add a new line // check turtle_int for new is the current max of the page +1 - $('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click($('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .o_input[name="turtle_int"]').val(), '22'); form.destroy(); }); @@ -7108,11 +7070,11 @@ QUnit.module('fields', {}, function () { var inputText1 = 'relax'; var inputText2 = 'max'; - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_input[name="turtle_foo"]').val(inputText1).trigger('input'); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_input[name="turtle_foo"]').val(inputText2).trigger('input'); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_input[name="turtle_foo"]'), inputText1); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_input[name="turtle_foo"]'), inputText2); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.o_data_cell:nth-child(2)').text(), inputText1 + inputText2); @@ -7120,7 +7082,7 @@ QUnit.module('fields', {}, function () { assert.equal($handles.length, 3, 'There should be 3 sequence handlers'); - testUtils.dragAndDrop($handles.eq(1), + testUtils.dom.dragAndDrop($handles.eq(1), form.$('tbody tr').first(), { position: 'top' } ); @@ -7186,9 +7148,9 @@ QUnit.module('fields', {}, function () { "should display two records out of three, in the correct order"); // edit turtle_int field of first row - form.$('.o_data_cell:first').click(); - form.$('.o_field_widget[name=turtle_int]').val(3).trigger('input'); - form.$el.click(); // leave edition + testUtils.dom.click(form.$('.o_data_cell:first')); + testUtils.fields.editInput(form.$('.o_field_widget[name=turtle_int]'), 3); + testUtils.dom.click(form.$el); assert.strictEqual(form.$('.o_data_cell.foo').text(), 'blipkawa', "should still display the same two records"); @@ -7225,7 +7187,7 @@ QUnit.module('fields', {}, function () { }); assert.strictEqual(form.$('.o_data_row').text(), 'yopblip', 'data has been properly loaded'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; assert.strictEqual(form.$('.o_data_row').text(), 'yopblip', 'data has been properly saved'); @@ -7266,10 +7228,10 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); - assert.strictEqual(form.$('.o_data_row').length, 4, 'should have 4 data rows'); - form.$('.o_input[name="turtle_foo"]').val('a').trigger('input'); - assert.strictEqual(form.$('.o_data_row').length, 4, + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + assert.containsN(form, '.o_data_row', 4, 'should have 4 data rows'); + testUtils.fields.editInput(form.$('.o_input[name="turtle_foo"]'), 'a'); + assert.containsN(form, '.o_data_row', 4, 'should still have 4 data rows (the limit is increased to 4)'); form.destroy(); @@ -7306,7 +7268,7 @@ QUnit.module('fields', {}, function () { }); // swap 2 lines in the one2many - testUtils.dragAndDrop(form.$('.ui-sortable-handle:eq(1)'), form.$('tbody tr').first(), + testUtils.dom.dragAndDrop(form.$('.ui-sortable-handle:eq(1)'), form.$('tbody tr').first(), { position: 'top' }); assert.verifySteps(['load_views', 'read', 'read', 'onchange', 'onchange']); form.destroy(); @@ -7341,8 +7303,8 @@ QUnit.module('fields', {}, function () { }); // add a row and trigger the onchange - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_data_row .o_field_widget[name=display_name]').val('a name').trigger('input'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput(form.$('.o_data_row .o_field_widget[name=display_name]'), 'a name'); assert.strictEqual(form.$('.o_data_row .o_field_widget[name=turtle_int]').val(), "44", "should have triggered the onchange"); @@ -7374,31 +7336,31 @@ QUnit.module('fields', {}, function () { '</form>', }); - assert.strictEqual(form.$('.o_data_row').length, 0, + assert.containsNone(form, '.o_data_row', "there should be no record in the relation"); // add a new record - form.$('.o_field_x2many_list_row_add a').click(); - $('.modal .o_field_widget').val('new record').trigger('input'); - $('.modal .modal-footer .btn-primary:first').click(); // Save & Close + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput($('.modal .o_field_widget'), 'new record'); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); assert.strictEqual(form.$('.o_data_row .o_data_cell').text(), 'new record', "should display the new record"); // reopen freshly added record and edit it - form.$('.o_data_row .o_data_cell').click(); - $('.modal .o_field_widget').val('new record edited').trigger('input'); + testUtils.dom.click(form.$('.o_data_row .o_data_cell')); + testUtils.fields.editInput($('.modal .o_field_widget'), 'new record edited'); // save it, and choose to directly create another record - $('.modal .modal-footer .btn-primary:nth(1)').click(); // Save & New + testUtils.dom.click($('.modal .modal-footer .btn-primary:nth(1)')); assert.strictEqual($('.modal').length, 1, "the model should still be open"); assert.strictEqual($('.modal .o_field_widget').text(), '', "should have cleared the input"); - $('.modal .o_field_widget').val('another new record').trigger('input'); - $('.modal .modal-footer .btn-primary:first').click(); // Save & Close + testUtils.fields.editInput($('.modal .o_field_widget'), 'another new record'); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); assert.strictEqual(form.$('.o_data_row .o_data_cell').text(), 'new record editedanother new record', "should display the two records"); @@ -7443,16 +7405,16 @@ QUnit.module('fields', {}, function () { // click add food // check it's empty - form.$('.o_field_x2many_list_row_add a:eq(0)').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a:eq(0)')); assert.strictEqual($('.o_data_cell').text(), ""); // click add pizza // save the modal // check it's pizza - form.$('.o_field_x2many_list_row_add a:eq(1)').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a:eq(1)')); // click add pasta - form.$('.o_field_x2many_list_row_add a:eq(2)').click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a:eq(2)')); + testUtils.form.clickSave(form);; assert.strictEqual($('.o_data_cell').text(), "pizzapasta"); form.destroy(); @@ -7495,22 +7457,22 @@ QUnit.module('fields', {}, function () { // click add food // check it's empty - form.$('.o_field_x2many_list_row_add a:eq(0)').click(); - $('.modal .modal-footer .btn-primary:first').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a:eq(0)')); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); assert.strictEqual($('.o_data_cell').text(), ""); // click add pizza // save the modal // check it's pizza - form.$('.o_field_x2many_list_row_add a:eq(1)').click(); - $('.modal .modal-footer .btn-primary:first').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a:eq(1)')); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); assert.strictEqual($('.o_data_cell').text(), "pizza"); // click add pasta // save the whole record // check it's pizzapasta - form.$('.o_field_x2many_list_row_add a:eq(2)').click(); - $('.modal .modal-footer .btn-primary:first').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a:eq(2)')); + testUtils.dom.click($('.modal .modal-footer .btn-primary:first')); assert.strictEqual($('.o_data_cell').text(), "pizzapasta"); form.destroy(); @@ -7582,27 +7544,27 @@ QUnit.module('fields', {}, function () { }, }); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "there should be one record in the one2many"); assert.strictEqual(form.$('.o_data_cell').text(), 'second record', "initial display_name of o2m record should be correct"); // open one2many record in form view - form.$('.o_data_cell:first').click(); + testUtils.dom.click(form.$('.o_data_cell:first')); assert.strictEqual($('.modal .o_form_view').length, 1, "should have opened the form view in a dialog"); assert.strictEqual($('.modal .o_form_view .o_data_row').length, 0, "there should be no record in the many2many"); // click on the action button - $('.modal .o_form_view button').click(); + testUtils.dom.click($('.modal .o_form_view button')); assert.strictEqual($('.modal .o_data_row').length, 1, "fields in the o2m form view should have been read"); assert.strictEqual($('.modal .o_data_cell').text(), 'gold', "many2many subrecord should have been fetched"); // save the dialog - $('.modal .modal-footer .btn-primary').click(); + testUtils.dom.click($('.modal .modal-footer .btn-primary')); assert.strictEqual(form.$('.o_data_cell').text(), 'new name', "fields in the o2m list view should have been read as well"); @@ -7668,32 +7630,32 @@ QUnit.module('fields', {}, function () { }); // add a turtle on second partner - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_data_row:eq(1)').click(); - $('.modal .o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_data_row:eq(1)')); + testUtils.dom.click($('.modal .o_field_x2many_list_row_add a')); $('.modal input[name="display_name"]').val('michelangelo').change(); - $('.modal .btn-primary').click(); + testUtils.dom.click($('.modal .btn-primary')); // open first partner so changes from previous action are applied - form.$('.o_data_row:eq(0)').click(); - $('.modal .btn-primary').click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('.o_data_row:eq(0)')); + testUtils.dom.click($('.modal .btn-primary')); + testUtils.form.clickSave(form);; assert.strictEqual(numUserOnchange, 2, 'there should 2 and only 2 onchange from closing the partner modal'); - form.$('.o_data_row:eq(0)').click(); + testUtils.dom.click(form.$('.o_data_row:eq(0)')); assert.strictEqual($('.modal .o_data_row').length, 1, 'only 1 turtle for first partner'); assert.strictEqual($('.modal .o_data_row').text(), 'donatello', 'first partner turtle is donatello'); - $('.modal .o_form_button_cancel').click(); + testUtils.dom.click($('.modal .o_form_button_cancel')); - form.$('.o_data_row:eq(1)').click(); + testUtils.dom.click(form.$('.o_data_row:eq(1)')); assert.strictEqual($('.modal .o_data_row').length, 1, 'only 1 turtle for second partner'); assert.strictEqual($('.modal .o_data_row').text(), 'michelangelo', 'second partner turtle is michelangelo'); - $('.modal .o_form_button_cancel').click(); + testUtils.dom.click($('.modal .o_form_button_cancel')); form.destroy(); }); @@ -7719,11 +7681,11 @@ QUnit.module('fields', {}, function () { res_id: 1, }); - form.$('.o_email_cell a').click(); + testUtils.dom.click(form.$('.o_email_cell a')); assert.strictEqual($('.modal .o_form_view').length, 0, 'click should not open the modal'); - form.$('.o_url_cell a').click(); + testUtils.dom.click(form.$('.o_url_cell a')); assert.strictEqual($('.modal .o_form_view').length, 0, 'click should not open the modal'); form.destroy(); @@ -7748,14 +7710,13 @@ QUnit.module('fields', {}, function () { }, }); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - assert.strictEqual(form.$('.o_selected_row').length, 1, + assert.containsOnce(form, '.o_selected_row', "should have create a new row in edition"); - var $input = form.$('.o_field_widget[name="turtle_trululu"] input'); - $input.click(); - $input.autocomplete('widget').find('.o_m2o_dropdown_option').focus().click(); + testUtils.fields.many2one.clickOpenDropdown('turtle_trululu'); + testUtils.fields.many2one.clickItem('turtle_trululu','Create and Edit...'); assert.strictEqual($('.modal .o_form_view').length, 1, "should have opened a form view in a dialog"); @@ -7767,7 +7728,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual($('.modal .o_form_view').length, 0, "should have closed the dialog"); - assert.strictEqual(form.$('.o_selected_row').length, 1, + assert.containsOnce(form, '.o_selected_row', "new row should still be present"); form.destroy(); @@ -7803,8 +7764,8 @@ QUnit.module('fields', {}, function () { }, }); - $('button[name="action_invoice_open"]').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click($('button[name="action_invoice_open"]')); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.destroy(); }); @@ -7830,18 +7791,16 @@ QUnit.module('fields', {}, function () { }); // add a row, fill it, then trigger the tab shortcut - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_input[name="turtle_foo"]') - .val('ninja') - .trigger('input') - .trigger($.Event('keydown', { - which: $.ui.keyCode.TAB, - keyCode: $.ui.keyCode.TAB, - })); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editAndTrigger( + form.$('.o_input[name="turtle_foo"]'), + 'ninja', + ['input', $.Event('keydown', {which: $.ui.keyCode.TAB, keyCode: $.ui.keyCode.TAB,})] + );; assert.strictEqual(form.$('.o_field_text').text(), 'blipninja', 'current line should be saved'); - assert.strictEqual(form.$('textarea.o_field_text').length, 1, + assert.containsOnce(form, 'textarea.o_field_text', 'new line should be created'); form.destroy(); @@ -7881,14 +7840,14 @@ QUnit.module('fields', {}, function () { var value = "hello"; // add a new line - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); // we want to add a delay to simulate an onchange def = $.Deferred(); // write something in the field var $input = form.$('input[name="turtle_foo"]'); - $input.val(value).trigger('input'); + testUtils.fields.editInput($input, value); // trigger keydown ENTER $input.trigger($.Event('keydown', { @@ -7898,7 +7857,7 @@ QUnit.module('fields', {}, function () { // check that nothing changed before the onchange finished assert.strictEqual($input.val(), value, "input content shouldn't change"); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "should still contain only one row"); // unlock onchange @@ -7907,7 +7866,7 @@ QUnit.module('fields', {}, function () { // check the current line is added with the correct content and a new line is editable assert.strictEqual(form.$('td.o_data_cell').text(), value); assert.strictEqual(form.$('input[name="turtle_foo"]').val(), ''); - assert.strictEqual(form.$('.o_data_row').length, 2, + assert.containsN(form, '.o_data_row', 2, "should now contain two rows"); form.destroy(); @@ -7939,15 +7898,15 @@ QUnit.module('fields', {}, function () { fieldDebounce: 5000, }); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); - form.$('input').val('some foo value').trigger('input'); + testUtils.fields.editInput(form.$('input'), 'some foo value'); // click to add a second row to unselect the current one, then save - form.$('.o_field_x2many_list_row_add a').click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.form.clickSave(form);; - assert.strictEqual(form.$('.o_form_readonly').length, 1, + assert.containsOnce(form, '.o_form_readonly', "form view should be in readonly"); assert.strictEqual(form.$('.o_data_row').text(), 'some foo value', "foo field should have correct value"); @@ -7992,20 +7951,20 @@ QUnit.module('fields', {}, function () { } }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var x2mList = form.$('.o_field_x2many_list[name=p]'); // Add a record in the list - x2mList.find('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(x2mList.find('.o_field_x2many_list_row_add a')); var modal = $('.modal-lg'); var nameInput = modal.find('input.o_input[name=display_name]'); - nameInput.val('michelangelo').trigger('input'); + testUtils.fields.editInput(nameInput, 'michelangelo'); // Save the record in the modal (though it is still virtual) - modal.find('.btn-primary').first().click(); + testUtils.dom.click(modal.find('.btn-primary').first()); assert.equal(x2mList.find('.o_data_row').length, 1, 'There should be 1 records in the x2m list'); @@ -8018,7 +7977,7 @@ QUnit.module('fields', {}, function () { 'The display name field should have the right value'); // Save the whole thing - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form);; x2mList = form.$('.o_field_x2many_list[name=p]'); @@ -8064,18 +8023,18 @@ QUnit.module('fields', {}, function () { '</form>', res_id: 1, }); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_many2one[name="product_id"] input').click(); - $('li.ui-menu-item a:contains(xpad)').trigger('mouseenter').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_many2one[name="product_id"] input')); + testUtils.dom.click($('li.ui-menu-item a:contains(xpad)').trigger('mouseenter')); + assert.containsOnce(form, 'th', "should be 1 column when the product_id is set"); form.$('.o_field_many2one[name="product_id"] input').val('').trigger('keyup'); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many when product_id is not set"); - form.$('.o_field_boolean[name="bar"] input').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.dom.click(form.$('.o_field_boolean[name="bar"] input')); + assert.containsOnce(form, 'th', "should be 1 column after the value change"); form.destroy(); }); @@ -8110,19 +8069,19 @@ QUnit.module('fields', {}, function () { }); // bar is false so there should be 1 column - assert.strictEqual(form.$('th').length, 1, + assert.containsOnce(form, 'th', "should be only 1 column ('foo') in the one2many"); - assert.strictEqual(form.$('.o_list_view .o_data_row').length, 1, "should contain one row"); + assert.containsOnce(form, '.o_list_view .o_data_row', "should contain one row"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // add a new o2m record - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.$('.o_field_one2many input:first').focus(); - form.$('.o_field_one2many input:first').val('New line').trigger('input'); - form.$el.click(); // click outside to save a line + testUtils.fields.editInput(form.$('.o_field_one2many input:first'), 'New line'); + testUtils.dom.click(form.$el); - assert.strictEqual(form.$('th').length, 2, "should be 2 columns('foo' + 'int_field')"); + assert.containsN(form, 'th', 2, "should be 2 columns('foo' + 'int_field')"); form.destroy(); }); @@ -8156,18 +8115,18 @@ QUnit.module('fields', {}, function () { '</tree>', }, }); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_many2one[name="product_id"] input').click(); - $('li.ui-menu-item a:contains(xpad)').trigger('mouseenter').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_many2one[name="product_id"] input')); + testUtils.dom.click($('li.ui-menu-item a:contains(xpad)').trigger('mouseenter')); + assert.containsOnce(form, 'th', "should be 1 column when the product_id is set"); form.$('.o_field_many2one[name="product_id"] input').val('').trigger('keyup'); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many when product_id is not set"); - form.$('.o_field_boolean[name="bar"] input').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.dom.click(form.$('.o_field_boolean[name="bar"] input')); + assert.containsOnce(form, 'th', "should be 1 column after the value change"); form.destroy(); }); diff --git a/addons/web/static/tests/fields/relational_fields_mobile_tests.js b/addons/web/static/tests/fields/relational_fields_mobile_tests.js index 8a1ab7ce1a5..1f2b2655e02 100644 --- a/addons/web/static/tests/fields/relational_fields_mobile_tests.js +++ b/addons/web/static/tests/fields/relational_fields_mobile_tests.js @@ -91,27 +91,27 @@ QUnit.module('relational_fields', { }, }); - assert.strictEqual(form.$('.o_field_one2many .o-kanban-button-new').length, 0, + assert.containsNone(form, '.o_field_one2many .o-kanban-button-new', '"Create" button should not be visible in readonly'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_field_one2many .o-kanban-button-new').length, 1, + assert.containsOnce(form, '.o_field_one2many .o-kanban-button-new', '"Create" button should be visible in edit'); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 2, "should have 2 records"); // open and delete record - form.$('.oe_kanban_global_click').first().click(); + testUtils.dom.click(form.$('.oe_kanban_global_click').first()); assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 1, 'there should be a Remove button in the modal footer'); - $('.modal .modal-footer .o_btn_remove').click(); + testUtils.dom.click($('.modal .modal-footer .o_btn_remove')); assert.strictEqual($('.o_modal').length, 0, "there shoul be no more modal"); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 1, 'should contain 1 records'); // save and check that the correct command has been generated - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); }); diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index ed34b56574b..f69c7004e54 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -183,12 +183,9 @@ QUnit.module('relational_fields', { assert.strictEqual(count, 1, 'once search_read should have been done to fetch the relational values'); assert.strictEqual(nb_fields_fetched, 1, 'search_read should only fetch field id'); - assert.strictEqual(form.$('.o_statusbar_status button:not(.dropdown-toggle)').length, 2, "should have 2 status"); - assert.strictEqual(form.$('.o_statusbar_status button:disabled').length, 2, - "all status should be disabled"); - assert.ok(form.$('.o_statusbar_status button[data-value="4"]').hasClass('btn-primary'), - "selected status should be btn-primary"); - + assert.containsN(form, '.o_statusbar_status button:not(.dropdown-toggle)', 2); + assert.containsN(form, '.o_statusbar_status button:disabled', 2); + assert.hasClass(form.$('.o_statusbar_status button[data-value="4"]'), 'btn-primary'); form.destroy(); }); @@ -217,7 +214,7 @@ QUnit.module('relational_fields', { }); QUnit.test('clickable statusbar widget on many2one field', function (assert) { - assert.expect(3); + assert.expect(5); var form = createView({ View: FormView, @@ -230,16 +227,17 @@ QUnit.module('relational_fields', { config: {device: {isMobile: false}}, }); - var $selectedStatus = form.$('.o_statusbar_status button[data-value="4"]'); - assert.ok($selectedStatus.hasClass('btn-primary') && $selectedStatus.hasClass('disabled'), - "selected status should be btn-primary and disabled"); + + assert.hasClass(form.$('.o_statusbar_status button[data-value="4"]'), 'btn-primary'); + assert.hasClass(form.$('.o_statusbar_status button[data-value="4"]'), 'disabled'); + + assert.containsN(form, '.o_statusbar_status button.btn-secondary:not(.dropdown-toggle):not(:disabled)', 2); + var $clickable = form.$('.o_statusbar_status button.btn-secondary:not(.dropdown-toggle):not(:disabled)'); - assert.strictEqual($clickable.length, 2, - "other status should be btn-secondary and not disabled"); - $clickable.last().click(); // (last is visually the first here (css)) - var $status = form.$('.o_statusbar_status button[data-value="1"]'); - assert.ok($status.hasClass("btn-primary") && $status.hasClass("disabled"), - "value should have been updated"); + testUtils.dom.click($clickable.last()); // (last is visually the first here (css)) + + assert.hasClass(form.$('.o_statusbar_status button[data-value="1"]'), "btn-primary"); + assert.hasClass(form.$('.o_statusbar_status button[data-value="1"]'), "disabled"); form.destroy(); }); @@ -259,8 +257,7 @@ QUnit.module('relational_fields', { config: {device: {isMobile: false}}, }); - assert.ok(form.$('.o_statusbar_status').hasClass('o_field_empty'), - 'statusbar widget should have class o_field_empty'); + assert.hasClass(form.$('.o_statusbar_status'), 'o_field_empty'); assert.strictEqual(form.$('.o_statusbar_status').children().length, 0, 'statusbar widget should be empty'); form.destroy(); @@ -282,8 +279,7 @@ QUnit.module('relational_fields', { config: {device: {isMobile: false}}, }); - assert.strictEqual(form.$('.o_statusbar_status button:disabled').length, 2, "should have 2 status"); - + assert.containsN(form, '.o_statusbar_status button:disabled', 2); form.destroy(); }); @@ -304,13 +300,10 @@ QUnit.module('relational_fields', { config: {device: {isMobile: false}}, }); - form.$buttons.find('.o_form_button_edit').click(); - - var $buttons = form.$('.o_statusbar_status button:not(.dropdown-toggle)'); - assert.strictEqual($buttons.length, 3, "there should be 3 status"); - $buttons.last().click(); // (last is visually the first here (css)) - assert.strictEqual(form.$('.o_statusbar_status button:not(.dropdown-toggle)').length, 2, - "there should be 2 status left"); + testUtils.form.clickEdit(form); + assert.containsN(form, '.o_statusbar_status button:not(.dropdown-toggle)', 3); + testUtils.dom.click(form.$('.o_statusbar_status button:not(.dropdown-toggle)').last()); + assert.containsN(form, '.o_statusbar_status button:not(.dropdown-toggle)', 2); form.destroy(); }); @@ -333,10 +326,10 @@ QUnit.module('relational_fields', { config: {device: {isMobile: false}}, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_statusbar_status:first .dropdown-menu button.disabled').length, 1, "should have 1 folded status"); - assert.strictEqual(form.$('.o_statusbar_status:last button.disabled').length, 1, "should have 1 status (other discarded)"); + assert.containsOnce(form, '.o_statusbar_status:first .dropdown-menu button.disabled'); + assert.containsOnce(form, '.o_statusbar_status:last button.disabled'); form.destroy(); }); @@ -368,14 +361,14 @@ QUnit.module('relational_fields', { config: {device: {isMobile: false}}, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_statusbar_status button.disabled').length, 3, "should have 3 status"); + assert.containsN(form, '.o_statusbar_status button.disabled', 3); assert.strictEqual(rpcCount, 1, "should have done 1 search_read rpc"); - form.$('input:first').val(9.5).trigger("input").trigger("change"); - assert.strictEqual(form.$('.o_statusbar_status button.disabled').length, 2, "should have 2 status"); + testUtils.fields.editInput(form.$('input[name=qux]'), 9.5); + assert.containsN(form, '.o_statusbar_status button.disabled', 2); assert.strictEqual(rpcCount, 2, "should have done 1 more search_read rpc"); - form.$('input:last').val("hey").trigger("input").trigger("change"); + testUtils.fields.editInput(form.$('input[name=qux]'), "hey"); assert.strictEqual(rpcCount, 2, "should not have done 1 more search_read rpc"); form.destroy(); @@ -401,7 +394,7 @@ QUnit.module('relational_fields', { assert.strictEqual(list.$('td:contains(Red)').length, 3, "should have 3 rows with correct value"); - list.$('td:contains(Red):first').click(); + testUtils.dom.click(list.$('td:contains(Red):first')); var $td = list.$('tbody tr.o_selected_row td:not(.o_list_record_selector)'); @@ -443,9 +436,9 @@ QUnit.module('relational_fields', { assert.strictEqual(form.$('.o_field_widget[name=color]').text(), 'Red', "should have rendered the selection field correctly"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('select').length, 3, + assert.containsN(form, 'select', 3, "should have 3 select tag in dom"); assert.strictEqual(form.$('select[name="product_id"] option:contains(xphone)').length, 1, "should have fetched xphone option"); @@ -455,7 +448,7 @@ QUnit.module('relational_fields', { "should have correct product_id value"); assert.strictEqual(form.$('select[name="trululu"]').val(), "false", "should not have any value in trululu field"); - form.$('select[name="product_id"]').val(41).trigger('change'); + testUtils.fields.editSelect(form.$('select[name="product_id"]'), 41); assert.strictEqual(form.$('select[name="product_id"]').val(), "41", "should have a value of xphone"); @@ -493,7 +486,7 @@ QUnit.module('relational_fields', { assert.strictEqual(form.$('.o_field_widget').text(), 'Value O', "the displayed value should be 'Value O'"); - assert.notOk(form.$('.o_field_widget').hasClass('o_field_empty'), + assert.doesNotHaveClass(form.$('.o_field_widget'), 'o_field_empty', "should not have class o_field_empty"); form.destroy(); @@ -523,7 +516,7 @@ QUnit.module('relational_fields', { assert.strictEqual(form.$('.o_field_widget').text(), '', "there should be no displayed value"); - assert.ok(form.$('.o_field_widget').hasClass('o_field_empty'), + assert.hasClass(form.$('.o_field_widget'),'o_field_empty', "should have class o_field_empty"); form.destroy(); @@ -552,8 +545,8 @@ QUnit.module('relational_fields', { }, }); - form.$('select').val("false").trigger('change'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editSelect(form.$('select'), "false"); + testUtils.form.clickSave(form); form.destroy(); }); @@ -615,13 +608,13 @@ QUnit.module('relational_fields', { }, }); - assert.strictEqual(form.$('.o_field_widget[name=trululu] option').length, 4, + assert.containsN(form, '.o_field_widget[name=trululu] option', 4, "should be 4 options in the selection"); // trigger an onchange that will update the domain - form.$('.o_field_widget[name=int_field]').val(2).trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 2); - assert.strictEqual(form.$('.o_field_widget[name=trululu] option').length, 1, + assert.containsOnce(form, '.o_field_widget[name=trululu] option', "should be 1 option in the selection"); form.destroy(); @@ -648,14 +641,14 @@ QUnit.module('relational_fields', { res_id: 1 }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget[name=color]')[0].options.length, 3, "non required selection field must have 3 options 1 blank option and 2 value options"); assert.strictEqual(form.$('.o_field_widget[name=feedback_value]')[0].options.length, 2, "should have only 2 options without blank option"); // change value to update widget modifier values - form.$('.o_field_widget[name=feedback_value]').val('"bad"').trigger('change'); + testUtils.fields.editSelect(form.$('.o_field_widget[name=feedback_value]'), '"bad"'); assert.strictEqual(form.$('.o_field_widget[name=color]')[0].options.length, 2, "should have only 2 options"); @@ -687,17 +680,16 @@ QUnit.module('relational_fields', { }); // add a tag on field partner_ids - var $input = form.$('.o_field_many2manytags[name="partner_ids"] input'); - $input.click(); // opens the dropdown - $input.autocomplete('widget').find('li:first()').click(); // adds a tag + testUtils.fields.many2one.clickOpenDropdown('partner_ids'); + testUtils.fields.many2one.clickHighlightedItem('partner_ids'); // add a tag on field timmy - $input = form.$('.o_field_many2manytags[name="timmy"] input'); - $input.click(); // opens the dropdown + testUtils.fields.many2one.clickOpenDropdown('timmy'); + var $input = form.$('.o_field_many2manytags[name="timmy"] input'); assert.strictEqual($input.autocomplete('widget').find('li').length, 3, - "autocomplete dropdown should have 3 entries (2 values + 'Search and Edit...')"); - $input.autocomplete('widget').find('li:first()').click(); // adds a tag - assert.strictEqual(form.$('.o_field_many2manytags[name="timmy"] .badge').length, 1, + "autocomplete dropdown should have 3 entries (2 values + 'Search and Edit...')"); + testUtils.fields.many2one.clickHighlightedItem('timmy'); + assert.containsOnce(form, '.o_field_many2manytags[name="timmy"] .badge', "should contain 1 tag"); assert.ok(form.$('.o_field_many2manytags[name="timmy"] .badge:contains("gold")').length, "should contain newly added tag 'gold'"); @@ -732,7 +724,7 @@ QUnit.module('relational_fields', { return this._super.apply(this, arguments); }, }); - assert.strictEqual(form.$('.o_field_many2manytags .badge .dropdown-toggle').length, 2, + assert.containsN(form, '.o_field_many2manytags .badge .dropdown-toggle', 2, "should contain 2 tags"); assert.ok(form.$('.badge .dropdown-toggle:contains(gold)').length, 'should have fetched and rendered gold partner tag'); @@ -741,24 +733,24 @@ QUnit.module('relational_fields', { assert.strictEqual(form.$('.badge:first()').data('color'), 2, 'should have correctly fetched the color'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_field_many2manytags .badge .dropdown-toggle').length, 2, + assert.containsN(form, '.o_field_many2manytags .badge .dropdown-toggle', 2, "should still contain 2 tags in edit mode"); assert.ok(form.$('.o_tag_color_2 .o_badge_text:contains(gold)').length, 'first tag should still contain "gold" and be color 2 in edit mode'); - assert.strictEqual(form.$('.o_field_many2manytags .o_delete').length, 2, + assert.containsN(form, '.o_field_many2manytags .o_delete', 2, "tags should contain a delete button"); // add an other existing tag var $input = form.$('.o_field_many2manytags input'); - $input.click(); // opens the dropdown + testUtils.fields.many2one.clickOpenDropdown('timmy'); assert.strictEqual($input.autocomplete('widget').find('li').length, 1, "autocomplete dropdown should have 1 entry"); assert.strictEqual($input.autocomplete('widget').find('li a:contains("red")').length, 1, "autocomplete dropdown should contain 'red'"); - $input.autocomplete('widget').find('li').click(); // add 'red' - assert.strictEqual(form.$('.o_field_many2manytags .badge .dropdown-toggle').length, 3, + testUtils.fields.many2one.clickHighlightedItem('timmy'); + assert.containsN(form, '.o_field_many2manytags .badge .dropdown-toggle', 3, "should contain 3 tags"); assert.ok(form.$('.o_field_many2manytags .badge .dropdown-toggle:contains("red")').length, "should contain newly added tag 'red'"); @@ -766,34 +758,34 @@ QUnit.module('relational_fields', { "should have fetched the color of added tag"); // remove tag with id 14 - form.$('.o_field_many2manytags .badge[data-id=14] .o_delete').click(); - assert.strictEqual(form.$('.o_field_many2manytags .badge .dropdown-toggle').length, 2, + testUtils.dom.click(form.$('.o_field_many2manytags .badge[data-id=14] .o_delete')); + assert.containsN(form, '.o_field_many2manytags .badge .dropdown-toggle', 2, "should contain 2 tags"); assert.ok(!form.$('.o_field_many2manytags .badge .dropdown-toggle:contains("silver")').length, "should not contain tag 'silver' anymore"); // save the record (should do the write RPC with the correct commands) - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); // checkbox 'Hide in Kanban' $input = form.$('.o_field_many2manytags .badge[data-id=13] .dropdown-toggle'); // selects 'red' tag - $input.click(); // opens the colorpicker dropdown + testUtils.dom.click($input); var $checkBox = form.$('.o_field_many2manytags .badge[data-id=13] .custom-checkbox input'); assert.strictEqual($checkBox.length, 1, "should have a checkbox in the colorpicker dropdown menu"); assert.notOk($checkBox.is(':checked'), "should have unticked checkbox in colorpicker dropdown menu"); - $checkBox.mousedown().click(); + testUtils.fields.editAndTrigger($checkBox, null,['mouseenter','mousedown']); $input = form.$('.o_field_many2manytags .badge[data-id=13] .dropdown-toggle'); // refresh - $input.click(); + testUtils.dom.click($input); $checkBox = form.$('.o_field_many2manytags .badge[data-id=13] .custom-checkbox input'); // refresh assert.equal($input.parent().data('color'), "0", "should become transparent when toggling on checkbox"); assert.ok($checkBox.is(':checked'), "should have a ticked checkbox in colorpicker dropdown menu after mousedown"); - $checkBox.mousedown().click(); + testUtils.fields.editAndTrigger($checkBox, null,['mouseenter','mousedown']); $input = form.$('.o_field_many2manytags .badge[data-id=13] .dropdown-toggle'); // refresh - $input.click(); + testUtils.dom.click($input); $checkBox = form.$('.o_field_many2manytags .badge[data-id=13] .custom-checkbox input'); // refresh assert.equal($input.parent().data('color'), "8", "should revert to old color when toggling off checkbox"); assert.notOk($checkBox.is(':checked'), "should have an unticked checkbox in colorpicker dropdown menu after 2nd click"); @@ -828,22 +820,22 @@ QUnit.module('relational_fields', { return this._super.apply(this, arguments); } }); - assert.strictEqual(form.$('.o_field_many2manytags .badge').length, 1, + assert.containsOnce(form, '.o_field_many2manytags .badge', "should contain 1 tag"); assert.ok(form.$('.badge:contains(gold)').length, 'should have fetched and rendered gold partner tag'); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // add an other existing tag var $input = form.$('.o_field_many2manytags input'); - $input.click(); // opens the dropdown + testUtils.fields.many2one.clickOpenDropdown('timmy'); assert.strictEqual($input.autocomplete('widget').find('li').length, 1, - "autocomplete dropdown should have 1 entry"); + "autocomplete dropdown should have 1 entry"); assert.strictEqual($input.autocomplete('widget').find('li a:contains("silver")').length, 1, - "autocomplete dropdown should contain 'silver'"); - $input.autocomplete('widget').find('li').click(); // add 'silver' - assert.strictEqual(form.$('.o_field_many2manytags .badge').length, 2, + "autocomplete dropdown should contain 'silver'"); + testUtils.fields.many2one.clickHighlightedItem('timmy'); + assert.containsN(form, '.o_field_many2manytags .badge', 2, "should contain 2 tags"); assert.ok(form.$('.o_field_many2manytags .badge:contains("silver")').length, "should contain newly added tag 'silver'"); @@ -871,20 +863,20 @@ QUnit.module('relational_fields', { return this._super.apply(this, arguments); } }); - assert.ok(form.$('.o_form_view').hasClass('o_form_editable'), "form should be in edit mode"); + assert.hasClass(form.$('.o_form_view'),'o_form_editable', "form should be in edit mode"); - var $input = form.$('.o_field_many2manytags input'); - $input.click(); // opens the dropdown - assert.strictEqual($input.autocomplete('widget').find('li').length, 3, + testUtils.fields.many2one.clickOpenDropdown('timmy'); + assert.strictEqual(form.$('.o_field_many2manytags input').autocomplete('widget').find('li').length, 3, "autocomplete dropdown should have 3 entries (2 values + 'Search and Edit...')"); - $input.autocomplete('widget').find('li:first()').click(); // adds a tag - assert.strictEqual(form.$('.o_field_many2manytags .badge').length, 1, + testUtils.fields.many2one.clickHighlightedItem('timmy'); + + assert.containsOnce(form, '.o_field_many2manytags .badge', "should contain 1 tag"); assert.ok(form.$('.o_field_many2manytags .badge:contains("gold")').length, "should contain newly added tag 'gold'"); // save the record (should do the write RPC with the correct commands) - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); @@ -918,15 +910,15 @@ QUnit.module('relational_fields', { // Update the color in readonly color = 1; - form.$('.badge:first() .dropdown-toggle').click(); + testUtils.dom.click(form.$('.badge:first() .dropdown-toggle')); $('.o_colorpicker a[data-color="' + color + '"]').trigger('mousedown'); // choose color 1 assert.strictEqual(form.$('.badge:first()').data('color'), color, 'should have correctly updated the color (in readonly)'); // Update the color in edit color = 6; - form.$buttons.find('.o_form_button_edit').click(); - form.$('.badge:first() .dropdown-toggle').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.badge:first() .dropdown-toggle')); $('.o_colorpicker a[data-color="' + color + '"]').trigger('mousedown'); // choose color 6 assert.strictEqual(form.$('.badge:first()').data('color'), color, 'should have correctly updated the color (in edit)'); @@ -957,33 +949,32 @@ QUnit.module('relational_fields', { } }); - assert.strictEqual(list.$('.o_data_row:first .o_field_many2manytags .badge').length, 1, + assert.containsOnce(list, '.o_data_row:first .o_field_many2manytags .badge', "m2m field should contain one tag"); // edit first row - list.$('.o_data_row:first td:nth(2)').click(); + testUtils.dom.click(list.$('.o_data_row:first td:nth(2)')); var $m2o = list.$('.o_data_row:first .o_field_many2manytags .o_field_many2one'); assert.strictEqual($m2o.length, 1, "a many2one widget should have been instantiated"); // add a tag - var $input = $m2o.find('input'); - $input.click(); - $input.autocomplete('widget').find('li:first()').click(); // adds a tag + testUtils.fields.many2one.clickOpenDropdown('timmy'); + testUtils.fields.many2one.clickHighlightedItem('timmy'); - assert.strictEqual(list.$('.o_data_row:first .o_field_many2manytags .badge').length, 2, + assert.containsN(list, '.o_data_row:first .o_field_many2manytags .badge', 2, "m2m field should contain 2 tags"); // leave edition - list.$('.o_data_row:nth(1) td:nth(2)').click(); + testUtils.dom.click(list.$('.o_data_row:nth(1) td:nth(2)')); - assert.strictEqual(list.$('.o_data_row:first .o_field_many2manytags .badge').length, 2, + assert.containsN(list, '.o_data_row:first .o_field_many2manytags .badge', 2, "m2m field should contain 2 tags"); list.destroy(); }); - QUnit.test('search more in many2one: group and use the pager', function (assert) { + QUnit.test('search more in many2one: group and use the pager', async function (assert) { assert.expect(2); this.data.partner.records.push({ @@ -1030,19 +1021,16 @@ QUnit.module('relational_fields', { mode: 'edit', }, }); + testUtils.fields.many2one.clickOpenDropdown('trululu'); + await testUtils.fields.many2one.clickItem('trululu', 'Search'); + testUtils.dom.click($('.modal .o_search_options .fa-bars')); + testUtils.dom.click($('.modal .o_search_options .o_group_by_menu a:contains(Bar)')); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').click(); - $dropdown.find('.o_m2o_dropdown_option:contains(Search)').mouseenter().click(); // Open Search More - - $('.modal .o_search_options .fa-bars').click(); - $('.modal .o_search_options .o_group_by_menu a:contains(Bar)').click(); // group by 'Bar' - - $('.modal .o_group_header:first').click(); + testUtils.dom.click($('.modal .o_group_header:first')); assert.strictEqual($('.modal tbody:nth(1) .o_data_row').length, 7, "should display 7 records in the first page"); - $('.modal .o_group_header:first .o_pager_next').click(); + testUtils.dom.click($('.modal .o_group_header:first .o_pager_next')); assert.strictEqual($('.modal tbody:nth(1) .o_data_row').length, 1, "should display 1 record in the second page"); @@ -1067,7 +1055,7 @@ QUnit.module('relational_fields', { '</form>', res_id: 1, }); - assert.strictEqual(form.$('.o_field_widget[name="partner_ids"] .badge').length, 100, + assert.containsN(form, '.o_field_widget[name="partner_ids"] .badge', 100, 'should have rendered 100 tags'); form.destroy(); }); @@ -1091,30 +1079,32 @@ QUnit.module('relational_fields', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_field_many2manytags .badge').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, '.o_field_many2manytags .badge', "should contain one tag"); // update foo, which will trigger an onchange and update timmy // -> m2mtags input should not have taken the focus form.$('input:first').focus(); - form.$('input:first').val('trigger onchange').trigger('input'); - assert.strictEqual(form.$('.o_field_many2manytags .badge').length, 0, + testUtils.fields.editInput(form.$('input:first'), 'trigger onchange'); + assert.containsNone(form, '.o_field_many2manytags .badge', "should contain no tags"); assert.strictEqual(form.$('input:first').get(0), document.activeElement, "foo input should have kept the focus"); // add a tag -> m2mtags input should still have the focus - form.$('.o_field_many2manytags input').click(); // opens the dropdown - form.$('.o_field_many2manytags input').autocomplete('widget').find('li:first').click(); - assert.strictEqual(form.$('.o_field_many2manytags .badge').length, 1, + testUtils.fields.many2one.clickOpenDropdown('timmy'); + testUtils.fields.many2one.clickHighlightedItem('timmy'); + + + assert.containsOnce(form, '.o_field_many2manytags .badge', "should contain a tag"); assert.strictEqual(form.$('.o_field_many2manytags input').get(0), document.activeElement, "m2m tags input should have kept the focus"); // remove a tag -> m2mtags input should still have the focus - form.$('.o_field_many2manytags .o_delete').click(); - assert.strictEqual(form.$('.o_field_many2manytags .badge').length, 0, + testUtils.dom.click(form.$('.o_field_many2manytags .o_delete')); + assert.containsNone(form, '.o_field_many2manytags .badge', "should contain no tags"); assert.strictEqual(form.$('.o_field_many2manytags input').get(0), document.activeElement, "m2m tags input should have kept the focus"); @@ -1174,13 +1164,13 @@ QUnit.module('relational_fields', { "colorpicker should be closed"); // click on the badge to open colorpicker - form.$('.o_field_many2manytags .badge .dropdown-toggle').click(); + testUtils.dom.click(form.$('.o_field_many2manytags .badge .dropdown-toggle')); assert.strictEqual($('.o_colorpicker:visible').length, 1, "colorpicker should be open"); // click on the badge again to close colorpicker - form.$('.o_field_many2manytags .badge .dropdown-toggle').click(); + testUtils.dom.click(form.$('.o_field_many2manytags .badge .dropdown-toggle')); assert.strictEqual($('.o_field_many2manytags .badge').data('color'), 0, "tag should still have color 0"); @@ -1188,13 +1178,13 @@ QUnit.module('relational_fields', { "colorpicker should be closed"); // click on the badge to open colorpicker - form.$('.o_field_many2manytags .badge .dropdown-toggle').click(); + testUtils.dom.click(form.$('.o_field_many2manytags .badge .dropdown-toggle')); assert.strictEqual($('.o_colorpicker:visible').length, 1, "colorpicker should be open"); // click on the colorpicker, but not on a color - form.$('.o_colorpicker').click(); + testUtils.dom.click(form.$('.o_colorpicker')); assert.strictEqual($('.o_field_many2manytags .badge').data('color'), 0, "tag should still have color 0"); @@ -1202,7 +1192,7 @@ QUnit.module('relational_fields', { "colorpicker should be closed"); // click on the badge to open colorpicker - form.$('.o_field_many2manytags .badge .dropdown-toggle').click(); + testUtils.dom.click(form.$('.o_field_many2manytags .badge .dropdown-toggle')); // click on a color in the colorpicker form.$('.o_colorpicker .o_tag_color_2').trigger('mousedown'); @@ -1230,15 +1220,15 @@ QUnit.module('relational_fields', { }); assert.ok(form.$('div.o_radio_item').length, "should have rendered outer div"); - assert.strictEqual(form.$('input.o_radio_input').length, 2, "should have 2 possible choices"); + assert.containsN(form, 'input.o_radio_input', 2, "should have 2 possible choices"); assert.ok(form.$('label.o_form_label:contains(xphone)').length, "one of them should be xphone"); - assert.strictEqual(form.$('input:checked').length, 0, "none of the input should be checked"); + assert.containsNone(form, 'input:checked', "none of the input should be checked"); - form.$("input.o_radio_input:first").click(); + testUtils.dom.click(form.$("input.o_radio_input:first")); - assert.strictEqual(form.$('input:checked').length, 1, "one of the input should be checked"); + assert.containsOnce(form, 'input:checked', "one of the input should be checked"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); var newRecord = _.last(this.data.partner.records); assert.strictEqual(newRecord.product_id, 37, "should have saved record with correct value"); @@ -1264,12 +1254,12 @@ QUnit.module('relational_fields', { '</form>', }); - form.$("input[type='checkbox']").click(); - assert.strictEqual(form.$('input.o_radio_input[data-value="37"]:checked').length, 1, "one of the input should be checked"); - assert.strictEqual(form.$('input.o_radio_input[data-value="black"]:checked').length, 1, "the other of the input should be checked"); - form.$("input[type='checkbox']").click(); - assert.strictEqual(form.$('input.o_radio_input[data-value="41"]:checked').length, 1, "the other of the input should be checked"); - assert.strictEqual(form.$('input.o_radio_input[data-value="red"]:checked').length, 1, "one of the input should be checked"); + testUtils.dom.click(form.$("input[type='checkbox']")); + assert.containsOnce(form, 'input.o_radio_input[data-value="37"]:checked', "one of the input should be checked"); + assert.containsOnce(form, 'input.o_radio_input[data-value="black"]:checked', "the other of the input should be checked"); + testUtils.dom.click(form.$("input[type='checkbox']")); + assert.containsOnce(form, 'input.o_radio_input[data-value="41"]:checked', "the other of the input should be checked"); + assert.containsOnce(form, 'input.o_radio_input[data-value="red"]:checked', "one of the input should be checked"); form.destroy(); }); @@ -1288,13 +1278,13 @@ QUnit.module('relational_fields', { assert.ok(form.$('div.o_radio_item').length, "should have rendered outer div"); - assert.strictEqual(form.$('input.o_radio_input').length, 2, "should have 2 possible choices"); + assert.containsN(form, 'input.o_radio_input', 2, "should have 2 possible choices"); assert.ok(form.$('label.o_form_label:contains(Red)').length, "one of them should be Red"); // click on 2nd option - form.$("input.o_radio_input").eq(1).click(); + testUtils.dom.click(form.$("input.o_radio_input").eq(1)); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); var newRecord = _.last(this.data.partner.records); assert.strictEqual(newRecord.color, 'black', "should have saved record with correct value"); @@ -1355,21 +1345,21 @@ QUnit.module('relational_fields', { assert.strictEqual(form.$('.o_field_widget').text(), '', "field should be unset"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_radio_input:checked').length, 0, + assert.containsNone(form, '.o_radio_input:checked', "no value should be checked"); - form.$("input.o_radio_input:nth(1)").click(); // click on 2nd option + testUtils.dom.click(form.$("input.o_radio_input:nth(1)")); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget').text(), 'Black', "value should be 'Black'"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_radio_input[data-index=1]:checked').length, 1, + assert.containsOnce(form, '.o_radio_input[data-index=1]:checked', "'Black' should be checked"); form.destroy(); @@ -1415,13 +1405,13 @@ QUnit.module('relational_fields', { }, }); - assert.strictEqual(form.$('.o_field_widget[name=trululu] .o_radio_item').length, 3, + assert.containsN(form, '.o_field_widget[name=trululu] .o_radio_item', 3, "should be 3 radio buttons"); // trigger an onchange that will update the domain - form.$('.o_field_widget[name=int_field]').val(2).trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 2); - assert.strictEqual(form.$('.o_field_widget[name=trululu] .o_radio_item').length, 0, + assert.containsNone(form, '.o_field_widget[name=trululu] .o_radio_item', "should be no more radio button"); form.destroy(); @@ -1443,15 +1433,15 @@ QUnit.module('relational_fields', { }); assert.ok(form.$('span.o_selection_badge').length, "should have rendered outer div"); - assert.strictEqual(form.$('span.o_selection_badge').length, 2, "should have 2 possible choices"); + assert.containsN(form, 'span.o_selection_badge', 2, "should have 2 possible choices"); assert.ok(form.$('span.o_selection_badge:contains(xphone)').length, "one of them should be xphone"); - assert.strictEqual(form.$('span.active').length, 0, "none of the input should be checked"); + assert.containsNone(form, 'span.active', "none of the input should be checked"); - $("span.o_selection_badge:first").click(); + testUtils.dom.click($("span.o_selection_badge:first")); - assert.strictEqual(form.$('span.active').length, 1, "one of the input should be checked"); + assert.containsOnce(form, 'span.active', "one of the input should be checked"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); var newRecord = _.last(this.data.partner.records); assert.strictEqual(newRecord.product_id, 37, "should have saved record with correct value"); @@ -1471,13 +1461,13 @@ QUnit.module('relational_fields', { }); assert.ok(form.$('span.o_selection_badge').length, "should have rendered outer div"); - assert.strictEqual(form.$('span.o_selection_badge').length, 2, "should have 2 possible choices"); + assert.containsN(form, 'span.o_selection_badge', 2, "should have 2 possible choices"); assert.ok(form.$('span.o_selection_badge:contains(Red)').length, "one of them should be Red"); // click on 2nd option - form.$("span.o_selection_badge").eq(1).click(); + testUtils.dom.click(form.$("span.o_selection_badge").eq(1)); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); var newRecord = _.last(this.data.partner.records); assert.strictEqual(newRecord.color, 'black', "should have saved record with correct value"); @@ -1496,7 +1486,7 @@ QUnit.module('relational_fields', { '</form>', }); - assert.strictEqual(form.$('span.o_readonly_modifier').length, 1, "should have 1 possible value in readonly mode"); + assert.containsOnce(form, 'span.o_readonly_modifier', "should have 1 possible value in readonly mode"); form.destroy(); }); @@ -1516,7 +1506,7 @@ QUnit.module('relational_fields', { res_id: 1, }); - assert.strictEqual(form.$('div.o_field_widget div.custom-checkbox').length, 2, + assert.containsN(form, 'div.o_field_widget div.custom-checkbox', 2, "should have fetched and displayed the 2 values of the many2many"); assert.ok(form.$('div.o_field_widget div.custom-checkbox input').eq(0).prop('checked'), @@ -1527,23 +1517,23 @@ QUnit.module('relational_fields', { assert.ok(form.$('div.o_field_widget div.custom-checkbox input').prop('disabled'), "the checkboxes should be disabled"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.notOk(form.$('div.o_field_widget div.custom-checkbox input').prop('disabled'), "the checkboxes should not be disabled"); // add a m2m value by clicking on input - form.$('div.o_field_widget div.custom-checkbox input').eq(1).click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('div.o_field_widget div.custom-checkbox input').eq(1)); + testUtils.form.clickSave(form); assert.deepEqual(this.data.partner.records[0].timmy, [12, 14], "should have added the second element to the many2many"); - assert.strictEqual(form.$('input:checked').length, 2, + assert.containsN(form, 'input:checked', 2, "both checkboxes should be checked"); // remove a m2m value by clinking on label - form.$buttons.find('.o_form_button_edit').click(); - form.$('div.o_field_widget div.custom-checkbox > label').eq(0).click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('div.o_field_widget div.custom-checkbox > label').eq(0)); + testUtils.form.clickSave(form); assert.deepEqual(this.data.partner.records[0].timmy, [14], "should have removed the first element to the many2many"); assert.notOk(form.$('div.o_field_widget div.custom-checkbox input').eq(0).prop('checked'), @@ -1569,9 +1559,9 @@ QUnit.module('relational_fields', { viewOptions: {mode: 'edit'}, }); - form.$('div.o_field_widget div.custom-checkbox input').eq(0).click(); - form.$('div.o_field_widget div.custom-checkbox input').eq(1).click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.dom.click(form.$('div.o_field_widget div.custom-checkbox input').eq(0)); + testUtils.dom.click(form.$('div.o_field_widget div.custom-checkbox input').eq(1)); + testUtils.form.clickSave(form); assert.notOk(form.$('div.o_field_widget div.custom-checkbox input').eq(0).prop('checked'), "first checkbox should not be checked"); assert.notOk(form.$('div.o_field_widget div.custom-checkbox input').eq(1).prop('checked'), @@ -1622,29 +1612,29 @@ QUnit.module('relational_fields', { }, }); - assert.strictEqual(form.$('div.o_field_widget.oe_fileupload').length, 1, + assert.containsOnce(form, 'div.o_field_widget.oe_fileupload', "there should be the attachment widget"); assert.strictEqual(form.$('div.o_field_widget.oe_fileupload .oe_attachments').children().length, 1, "there should be no attachment"); - assert.strictEqual(form.$('div.o_field_widget.oe_fileupload .o_attach').length, 0, + assert.containsNone(form, 'div.o_field_widget.oe_fileupload .o_attach', "there should not be an Add button (readonly)"); - assert.strictEqual(form.$('div.o_field_widget.oe_fileupload .oe_attachment .oe_delete').length, 0, + assert.containsNone(form, 'div.o_field_widget.oe_fileupload .oe_attachment .oe_delete', "there should not be a Delete button (readonly)"); // to edit mode - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('div.o_field_widget.oe_fileupload .o_attach').length, 1, + testUtils.form.clickEdit(form); + assert.containsOnce(form, 'div.o_field_widget.oe_fileupload .o_attach', "there should be an Add button"); assert.strictEqual(form.$('div.o_field_widget.oe_fileupload .o_attach').text().trim(), "Pictures", "the button should be correctly named"); - assert.strictEqual(form.$('div.o_field_widget.oe_fileupload .o_hidden_input_file form').length, 1, + assert.containsOnce(form, 'div.o_field_widget.oe_fileupload .o_hidden_input_file form', "there should be a hidden form to upload attachments"); // TODO: add an attachment // no idea how to test this // delete the attachment - form.$('div.o_field_widget.oe_fileupload .oe_attachment .oe_delete').click(); + testUtils.dom.click(form.$('div.o_field_widget.oe_fileupload .oe_attachment .oe_delete')); assert.verifySteps([ @@ -1652,7 +1642,7 @@ QUnit.module('relational_fields', { '/web/dataset/call_kw/ir.attachment/read', ]); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('div.o_field_widget.oe_fileupload .oe_attachments').children().length, 0, "there should be no attachment"); @@ -1660,13 +1650,9 @@ QUnit.module('relational_fields', { form.destroy(); }); - QUnit.test('name_create in form dialog', function (assert) { - var done = assert.async(); + QUnit.test('name_create in form dialog', async function (assert) { assert.expect(2); - var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY; - relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0; - var form = createView({ View: FormView, model: 'partner', @@ -1691,18 +1677,13 @@ QUnit.module('relational_fields', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - var $dropdown = $('.modal .o_field_many2one input').autocomplete('widget'); - $('.modal input').val('new record').trigger('keydown'); - concurrency.delay(0).then(function () { - $dropdown.find('li:first()').click(); // quick create 'new record' - assert.verifySteps(['name_create']); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.fields.many2one.searchAndClickItem('product_id', + {selector:'.modal', search:'new record'}); - relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY; - form.destroy(); - done(); - }); + assert.verifySteps(['name_create']); + + form.destroy(); }); QUnit.module('FieldReference'); @@ -1737,7 +1718,7 @@ QUnit.module('relational_fields', { assert.equal($cell_o2m.text(), 'second record', 'the list should have one record'); - $cell_o2m.click(); + testUtils.dom.click($cell_o2m); // In modal var $modal = $('.modal-lg'); @@ -1747,7 +1728,7 @@ QUnit.module('relational_fields', { assert.equal($modal.find('.o_form_uri.o_field_widget[name=reference]').text(), 'xpad', 'The field reference in the modal should have the right value'); - $modal.find('.o_form_button_cancel').click(); + testUtils.dom.click($modal.find('.o_form_button_cancel')); form.destroy(); }); @@ -1775,7 +1756,7 @@ QUnit.module('relational_fields', { }); // current form - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var $fieldRef = form.$('.o_field_widget.o_field_many2one[name=reference]'); assert.equal($fieldRef.find('option:selected').text(), 'Product', @@ -1783,7 +1764,7 @@ QUnit.module('relational_fields', { assert.equal($fieldRef.find('.o_input.ui-autocomplete-input').val(), 'xphone', 'The reference field\'s record should be xphone'); - form.$('.o_data_cell').click(); + testUtils.dom.click(form.$('.o_data_cell')); // In modal var $modal = $('.modal-lg'); @@ -1846,20 +1827,20 @@ QUnit.module('relational_fields', { }, }); - testUtils.intercept(form, 'do_action', function (event) { + testUtils.mock.intercept(form, 'do_action', function (event) { assert.strictEqual(event.data.action.res_id, 17, "should do a do_action with correct parameters"); }); assert.strictEqual(form.$('a.o_form_uri:contains(xphone)').length, 1, "should contain a link"); - form.$('a.o_form_uri').click(); // click on the link in readonly mode (should trigger do_action) + testUtils.dom.click(form.$('a.o_form_uri')); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_field_widget').length, 2, + assert.containsN(form, '.o_field_widget', 2, "should contain two field widgets (selection and many2one)"); - assert.strictEqual(form.$('.o_field_many2one').length, 1, + assert.containsOnce(form, '.o_field_many2one', "should contain one many2one"); assert.strictEqual(form.$('.o_field_widget select').val(), "product", "widget should contain one select with the model"); @@ -1872,22 +1853,21 @@ QUnit.module('relational_fields', { assert.deepEqual(options, ['', 'product', 'partner_type', 'partner'], "the options should be correctly set"); - form.$('.o_external_button').click(); // click on the external button (should do an RPC) + testUtils.dom.click(form.$('.o_external_button')); assert.strictEqual($('.modal .modal-title').text().trim(), 'Open: custom label', "dialog title should display the custom string label"); - $('.modal .o_form_button_cancel').click(); + testUtils.dom.click($('.modal .o_form_button_cancel')); - form.$('.o_field_widget select').val('partner_type').trigger('change'); + testUtils.fields.editSelect(form.$('.o_field_widget select'), 'partner_type'); assert.strictEqual(form.$('.o_field_widget input').val(), "", "many2one value should be reset after model change"); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - // change the value of the m2o with a suggestion of the dropdown - form.$('.o_field_many2one input').click(); // will trigger a name_search on partner_type model - $dropdown.find('li:first()').click(); + testUtils.fields.many2one.clickOpenDropdown('reference'); + testUtils.fields.many2one.clickHighlightedItem('reference'); + - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('a.o_form_uri:contains(gold)').length, 1, "should contain a link with the new value"); @@ -1936,7 +1916,7 @@ QUnit.module('relational_fields', { "reference field value should be correctly set"); // trigger onchange - form.$('.o_field_widget[name=int_field]').val(12).trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 12); assert.verifySteps(['product', 'partner_type'], "the second name_get should have been done"); assert.strictEqual(form.$('.o_field_widget[name="reference"] select').val(), "partner_type", @@ -2019,7 +1999,7 @@ QUnit.module('relational_fields', { "foo field should be correctly set"); // trigger onchange - form.$('.o_field_widget[name=int_field]').val(41).trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 41); assert.strictEqual(nbNameGet, 2, "the second name_get should have been done"); @@ -2039,7 +2019,7 @@ QUnit.module('relational_fields', { }); // edit first row - list.$('.o_data_row .o_data_cell').first().click(); + testUtils.dom.click(list.$('.o_data_row .o_data_cell').first()); assert.strictEqual(list.$('.o_data_row:eq(0) .o_field_widget[name="reference"] input')[0], document.activeElement, 'input of first data row should be selected'); @@ -2082,20 +2062,20 @@ QUnit.module('relational_fields', { } }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var x2mList = form.$('.o_field_x2many_list[name=p]'); // Add a record in the list - x2mList.find('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(x2mList.find('.o_field_x2many_list_row_add a')); var modal = $('.modal-lg'); var nameInput = modal.find('input.o_input[name=display_name]'); - nameInput.val('michelangelo').trigger('input'); + testUtils.fields.editInput(nameInput, 'michelangelo'); // Save the record in the modal (though it is still virtual) - modal.find('.btn-primary').first().click(); + testUtils.dom.click(modal.find('.btn-primary').first()); assert.equal(x2mList.find('.o_data_row').length, 1, 'There should be 1 records in the x2m list'); @@ -2108,7 +2088,7 @@ QUnit.module('relational_fields', { 'The display name field should have the right value'); // Save the whole thing - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); x2mList = form.$('.o_field_x2many_list[name=p]'); @@ -2154,18 +2134,18 @@ QUnit.module('relational_fields', { '</form>', res_id: 1, }); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_many2one[name="product_id"] input').click(); - $('li.ui-menu-item a:contains(xpad)').trigger('mouseenter').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_many2one[name="product_id"] input')); + testUtils.dom.click($('li.ui-menu-item a:contains(xpad)').trigger('mouseenter')); + assert.containsOnce(form, 'th', "should be 1 column when the product_id is set"); form.$('.o_field_many2one[name="product_id"] input').val('').trigger('keyup'); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many when product_id is not set"); - form.$('.o_field_boolean[name="bar"] input').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.dom.click(form.$('.o_field_boolean[name="bar"] input')); + assert.containsOnce(form, 'th', "should be 1 column after the value change"); form.destroy(); }); @@ -2200,19 +2180,19 @@ QUnit.module('relational_fields', { }); // bar is false so there should be 1 column - assert.strictEqual(form.$('th').length, 1, + assert.containsOnce(form, 'th', "should be only 1 column ('foo') in the one2many"); - assert.strictEqual(form.$('.o_list_view .o_data_row').length, 1, "should contain one row"); + assert.containsOnce(form, '.o_list_view .o_data_row', "should contain one row"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // add a new o2m record - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.$('.o_field_one2many input:first').focus(); - form.$('.o_field_one2many input:first').val('New line').trigger('input'); - form.$el.click(); // click outside to save a line + testUtils.fields.editInput(form.$('.o_field_one2many input:first'), 'New line'); + testUtils.dom.click(form.$el); - assert.strictEqual(form.$('th').length, 2, "should be 2 columns('foo' + 'int_field')"); + assert.containsN(form, 'th', 2, "should be 2 columns('foo' + 'int_field')"); form.destroy(); }); @@ -2246,18 +2226,18 @@ QUnit.module('relational_fields', { '</tree>', }, }); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_many2one[name="product_id"] input').click(); - $('li.ui-menu-item a:contains(xpad)').trigger('mouseenter').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_many2one[name="product_id"] input')); + testUtils.dom.click($('li.ui-menu-item a:contains(xpad)').trigger('mouseenter')); + assert.containsOnce(form, 'th', "should be 1 column when the product_id is set"); form.$('.o_field_many2one[name="product_id"] input').val('').trigger('keyup'); - assert.strictEqual(form.$('th').length, 2, + assert.containsN(form, 'th', 2, "should be 2 columns in the one2many when product_id is not set"); - form.$('.o_field_boolean[name="bar"] input').click(); - assert.strictEqual(form.$('th').length, 1, + testUtils.dom.click(form.$('.o_field_boolean[name="bar"] input')); + assert.containsOnce(form, 'th', "should be 1 column after the value change"); form.destroy(); }); @@ -2343,7 +2323,7 @@ QUnit.module('relational_fields', { which: $.ui.keyCode.TAB, keyCode: $.ui.keyCode.TAB, })); - document.activeElement.click(); + testUtils.dom.click(document.activeElement); assert.strictEqual(assert.strictEqual(form.$el.find('input[name="turtle_foo"]')[0], document.activeElement, "after tab, the focus should be on the many2one")); @@ -2500,16 +2480,16 @@ QUnit.module('relational_fields', { }); // add a new line - form.$el.find('.o_field_x2many_list_row_add>a').click(); + testUtils.dom.click(form.$el.find('.o_field_x2many_list_row_add>a')); // open the field turtle_trululu (one2many) var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY; relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0; - form.$el.find('.o_input_dropdown>input').click(); + testUtils.dom.click(form.$el.find('.o_input_dropdown>input')); concurrency.delay(0).then(function () { // click create and edit - $('.ui-autocomplete .ui-menu-item a:contains(Create and)').trigger('mouseenter').click(); + testUtils.dom.click($('.ui-autocomplete .ui-menu-item a:contains(Create and)').trigger('mouseenter')); // hit escape immediately var escapeKey = $.ui.keyCode.ESCAPE; diff --git a/addons/web/static/tests/fields/special_fields.js b/addons/web/static/tests/fields/special_fields.js index f9df1a6f4e3..8654c3e0a9f 100644 --- a/addons/web/static/tests/fields/special_fields.js +++ b/addons/web/static/tests/fields/special_fields.js @@ -208,7 +208,7 @@ QUnit.module('special_fields', { '<field name="tz" widget="timezone_mismatch"/>' + '</form>', }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('select').length, 1, "should have the select field"); form.destroy(); }); diff --git a/addons/web/static/tests/fields/upgrade_fields_tests.js b/addons/web/static/tests/fields/upgrade_fields_tests.js index 15c32eeeaf0..65de67a7951 100644 --- a/addons/web/static/tests/fields/upgrade_fields_tests.js +++ b/addons/web/static/tests/fields/upgrade_fields_tests.js @@ -32,7 +32,7 @@ QUnit.module('upgrade_fields', { arch: '<form><field name="bar" widget="upgrade_boolean"/></form>', }); - form.$('input:checkbox').click(); + testUtils.dom.click(form.$('input:checkbox')); assert.strictEqual($('.modal').length, 1, "the 'Upgrade to Enterprise' dialog should be opened"); @@ -52,9 +52,9 @@ QUnit.module('upgrade_fields', { '</form>', }); - assert.strictEqual(form.$('.o_field .badge').length, 0, + assert.containsNone(form, '.o_field .badge', "the upgrade badge shouldn't be inside the field section"); - assert.strictEqual(form.$('.o_label .badge').length, 1, + assert.containsOnce(form, '.o_label .badge', "the upgrade badge should be inside the label section"); assert.strictEqual(form.$('.o_label').text(), "Bar EnterpriseCoucou", "the upgrade label should be inside the label section"); |
