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/views/view_dialogs_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/views/view_dialogs_tests.js')
| -rw-r--r-- | addons/web/static/tests/views/view_dialogs_tests.js | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/addons/web/static/tests/views/view_dialogs_tests.js b/addons/web/static/tests/views/view_dialogs_tests.js index 372edbc0f24..8898e520618 100644 --- a/addons/web/static/tests/views/view_dialogs_tests.js +++ b/addons/web/static/tests/views/view_dialogs_tests.js @@ -60,7 +60,7 @@ QUnit.module('Views', { function createParent(params) { var widget = new Widget(); - testUtils.addMockEnvironment(widget, params); + testUtils.mock.addMockEnvironment(widget, params); return widget; } @@ -80,7 +80,7 @@ QUnit.module('Views', { }, }); - testUtils.intercept(parent, 'env_updated', function () { + testUtils.mock.intercept(parent, 'env_updated', function () { throw new Error("The environment should not be propagated to the action manager"); }); @@ -121,7 +121,7 @@ QUnit.module('Views', { assert.strictEqual($('.modal button.btn-primary').length, 1, "should have 1 buttons in modal"); - $('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click($('.o_field_x2many_list_row_add a')); $('input.o_input').trigger($.Event('keydown', { which: $.ui.keyCode.ESCAPE, keyCode: $.ui.keyCode.ESCAPE, @@ -199,8 +199,8 @@ QUnit.module('Views', { }, }).open(); - dialog.$('.o_searchview_facet:contains(groupby_bar) .o_facet_remove').click(); - dialog.$('.o_searchview_facet .o_facet_remove').click(); + testUtils.dom.click(dialog.$('.o_searchview_facet:contains(groupby_bar) .o_facet_remove')); + testUtils.dom.click(dialog.$('.o_searchview_facet .o_facet_remove')); parent.destroy(); }); @@ -264,7 +264,7 @@ QUnit.module('Views', { }).open(); // click on the first row to see if the list is editable - dialog.$('.o_list_view tbody tr:first td:not(.o_list_record_selector):first').click(); + testUtils.dom.click(dialog.$('.o_list_view tbody tr:first td:not(.o_list_record_selector):first')); assert.equal(dialog.$('.o_list_view tbody tr:first td:not(.o_list_record_selector):first input').length, 0, "list view should not be editable in a SelectCreateDialog"); @@ -329,17 +329,17 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_widget .o_field_many2one[name=instrument] input').click(); - $('ul.ui-autocomplete.ui-front.ui-menu.ui-widget.ui-widget-content li.o_m2o_dropdown_option').first().click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('.o_field_widget .o_field_many2one[name=instrument] input')); + testUtils.dom.click($('ul.ui-autocomplete.ui-front.ui-menu.ui-widget.ui-widget-content li.o_m2o_dropdown_option').first()); var $modal = $('.modal-lg'); assert.equal($modal.length, 1, 'There should be one modal'); - $modal.find('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click($modal.find('.o_field_x2many_list_row_add a')); var $modals = $('.modal-lg'); @@ -347,9 +347,9 @@ QUnit.module('Views', { 'There should be two modals'); var $second_modal = $modals.not($modal); - $second_modal.find('.o_list_view.table.table-sm.table-striped.o_list_view_ungrouped .o_data_row input[type=checkbox]').click(); + testUtils.dom.click($second_modal.find('.o_list_view.table.table-sm.table-striped.o_list_view_ungrouped .o_data_row input[type=checkbox]')); - $second_modal.find('.o_select_button').click(); + testUtils.dom.click($second_modal.find('.o_select_button')); $modal = $('.modal-lg'); @@ -359,7 +359,7 @@ QUnit.module('Views', { assert.equal($modal.find('.o_data_cell').text(), 'Awsome', 'There should be one item in the list of the modal'); - $modal.find('.btn.btn-primary').click(); + testUtils.dom.click($modal.find('.btn.btn-primary')); form.destroy(); }); @@ -422,7 +422,7 @@ QUnit.module('Views', { QUnit.test('SelectCreateDialog: save current search', function (assert) { assert.expect(4); - testUtils.patch(ListController, { + testUtils.mock.patch(ListController, { getContext: function () { return { shouldBeInFilterContext: true, @@ -459,21 +459,23 @@ QUnit.module('Views', { res_model: 'partner', }).open(); - assert.strictEqual(dialog.$('.o_data_row').length, 3, + assert.containsN(dialog, '.o_data_row', 3, "should contain 3 records"); // filter on bar - dialog.$('.o_filters_menu a:contains(Bar)').click(); + testUtils.dom.click(dialog.$('.o_dropdown_toggler_btn:contains(Filters)')); + testUtils.dom.click(dialog.$('.o_filters_menu a:contains(Bar)')); - assert.strictEqual(dialog.$('.o_data_row').length, 2, + assert.containsN(dialog, '.o_data_row', 2, "should contain 2 records"); // save filter - dialog.$('.o_save_search a').click(); // toggle 'Save current search' + testUtils.dom.click(dialog.$('.o_dropdown_toggler_btn:contains(Favorites)')); + testUtils.dom.click(dialog.$('.o_save_search')); dialog.$('.o_save_name input[type=text]').val('some name'); // name the filter - dialog.$('.o_save_name button').click(); // click on 'Save' + testUtils.dom.click(dialog.$('.o_save_name button')); - testUtils.unpatch(ListController); + testUtils.mock.unpatch(ListController); parent.destroy(); }); }); |
