diff options
| author | Géry Debongnie <ged@odoo.com> | 2018-11-19 08:18:28 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-11-19 11:24:28 +0000 |
| commit | abf32b8b21394491040e5c11c1fea809c1d7c62c (patch) | |
| tree | 6058f8a893815bf0ed2495649c125523f4def762 /addons/web/static/tests/fields/basic_fields_tests.js | |
| parent | bcbb7ee3fecaad3c7e801fa5dbc90a566faac27f (diff) | |
[REF] *: update js test suite to use helpers
This rev. introduces robust helpers to use in the JS tests suite to
interact with DOM and components, and starts using them (almost)
everywhere.
All the helpers are exposed though testUtils.js.
There are 2 kinds of helpers:
1. Assertions
-------------
* assert.containsNone, containsN, containsOnce check that the DOM
(or a specific part of the DOM) contains a `selector`. It
generates a correct error message automatically.
ex: assert.strictEqual(form.$('.o_form_editable'), 1, "msg");
-> assert.containsOnce(form, '.o_form_editable');
* assert.isVisible, isNotVisible check that the DOM has an element
visible or not. They also check that the element is actually in
the DOM (before most tests didn't verify this).
* assert.hasClass, doesNotHaveClass, hasAttrVAlue, check specific
properties of a DOM element, and also validate that it is
applied on a single existing DOM element (before most tests
didn't verify this).
ex: assert.notOk(form.$('button').hasClass('btn-primary'));
-> assert.doesNotHaveClass(form.$('button'), 'btn-primary');
2. Utilities
------------
The goal of the utilities is to centralize the definition of many
standard components and interactions, ensuring that when we
refactor the JS framework, we do not need to change all the tests.
Existing mock utilities (addMockEnvironment, intercept, path,
patchDate, unpatch and fieldsViewGet) are moved to
'testUtils.mock.*'.
Existing DOM utilities are moved to 'testUtils.dom.*'.
New dom utilities are created for opendDatePicker, click,
clickFirst and clickLast. Helper `click` verifies that there is
exactly 1 element visible in the DOM you click on, `clickFirst`
and `clickLast` verify that there are more than one element on the
DOM.
ex: form.$('button').click();
-> testUtils.dom.click(form.$('button'));
New Form utilities: (testUtils.form.*)
clickEdit, clickSave, clickCreate, clickDiscard, all clicks on
the control panel buttons of the form.
`reload` reloads the form data.
New modal, graph, kanban and pivot utils (testUtils.pivot.*,
testUtils.kanban.*, etc.).
New fields utils: (testUtils.fields.*)
* editInput, editSelect: allow to change the value of a field,
using a selector to identify it. They validate that the input
exists and trigger the change event automatically.
* editAndTrigger: allow to modify a field and trigger specific
events after the value change
* many2one (testUtils.fields.many2one.*)
clickOpenDropdown, clickHighlightedItem, clickItem,
searchAndClickItem: use a field name instead of a selector and
do all the complex mechanism to open, filter and highlight
many2one fields.
Joint work with aab, dam, ged, mge, svs and vsc.
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 1056 |
1 files changed, 528 insertions, 528 deletions
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(); }); |
