diff options
| author | Robot Odoo <xmo+roboto@odoo.com> | 2018-11-19 15:38:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-19 15:38:25 +0100 |
| commit | 7c3d5dc067c7c331dcc0b52bafbdfd067087a3c4 (patch) | |
| tree | 6058f8a893815bf0ed2495649c125523f4def762 /addons/im_support/static | |
| parent | 8fc246da31aa2a1c770732ae97e0cb4e840f07cf (diff) | |
| parent | abf32b8b21394491040e5c11c1fea809c1d7c62c (diff) | |
[MERGE][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.notOk(form.$('button').hasClass('btn-primary'));
-> assert.doesNotHaveClass(form.$('button'), 'btn-primary');
* 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).
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.
closes odoo/odoo#28784
Diffstat (limited to 'addons/im_support/static')
| -rw-r--r-- | addons/im_support/static/tests/helpers/test_utils.js | 4 | ||||
| -rw-r--r-- | addons/im_support/static/tests/systray_no_support_tests.js | 7 | ||||
| -rw-r--r-- | addons/im_support/static/tests/systray_tests.js | 43 |
3 files changed, 24 insertions, 30 deletions
diff --git a/addons/im_support/static/tests/helpers/test_utils.js b/addons/im_support/static/tests/helpers/test_utils.js index 3347c43029f..e0a5bdfd73a 100644 --- a/addons/im_support/static/tests/helpers/test_utils.js +++ b/addons/im_support/static/tests/helpers/test_utils.js @@ -58,7 +58,7 @@ function addMockSupportEnvironment(widget, params) { } return result; }; - testUtils.addMockEnvironment(widget, params); + testUtils.mock.addMockEnvironment(widget, params); var widgetDestroy = widget.destroy; widget.destroy = function () { supportSession.rpc = originalRPC; @@ -69,7 +69,7 @@ function addMockSupportEnvironment(widget, params) { // 'im_support.poll_timeout', to simulate a pending longpolling connection to // the Support server, such that the initSupport initiates a poll connection if (params.enableSupportPoll) { - testUtils.intercept(widget, 'call_service', function (ev) { + testUtils.mock.intercept(widget, 'call_service', function (ev) { if (ev.data.service === 'local_storage') { if (ev.data.method === 'getItem' && ev.data.args[0] === 'im_support.poll_timeout') { ev.data.callback(Date.now() + (60 * 1000)); diff --git a/addons/im_support/static/tests/systray_no_support_tests.js b/addons/im_support/static/tests/systray_no_support_tests.js index 89cb5b0389d..f835c0e55b7 100644 --- a/addons/im_support/static/tests/systray_no_support_tests.js +++ b/addons/im_support/static/tests/systray_no_support_tests.js @@ -38,15 +38,14 @@ QUnit.test('messaging menu does not display the Support channel if not available assert.expect(1); var messagingMenu = new MessagingMenu(); - testUtils.addMockEnvironment(messagingMenu, { + testUtils.mock.addMockEnvironment(messagingMenu, { data: this.data, services: this.services, }); messagingMenu.appendTo($('#qunit-fixture')); - messagingMenu.$('.dropdown-toggle').click(); - assert.strictEqual(messagingMenu.$('.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]').length, - 0, "should not display the Support channel"); + testUtils.dom.click(messagingMenu.$('.dropdown-toggle')); + assert.containsNone(messagingMenu, '.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]', "should not display the Support channel"); messagingMenu.destroy(); }); diff --git a/addons/im_support/static/tests/systray_tests.js b/addons/im_support/static/tests/systray_tests.js index 3bf05417d7e..9f50ce1d29c 100644 --- a/addons/im_support/static/tests/systray_tests.js +++ b/addons/im_support/static/tests/systray_tests.js @@ -40,9 +40,8 @@ QUnit.test('messaging menu displays the Support channel', function (assert) { }); messagingMenu.appendTo($('#qunit-fixture')); - messagingMenu.$('.dropdown-toggle').click(); - assert.strictEqual(messagingMenu.$('.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]').length, - 1, "should display the Support channel"); + testUtils.dom.click(messagingMenu.$('.dropdown-toggle')); + assert.containsOnce(messagingMenu, '.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]', "should display the Support channel"); messagingMenu.destroy(); }); @@ -74,11 +73,10 @@ QUnit.test('clicking on Support channel: channel not available', function (asser }); messagingMenu.appendTo($('#qunit-fixture')); - messagingMenu.$('.dropdown-toggle').click(); - assert.strictEqual(messagingMenu.$('.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]').length, - 1, "should display the Support channel"); + testUtils.dom.click(messagingMenu.$('.dropdown-toggle')); + assert.containsOnce(messagingMenu, '.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]'); - messagingMenu.$('.o_mail_preview[data-preview-id=SupportChannel]').click(); + testUtils.dom.click(messagingMenu.$('.o_mail_preview[data-preview-id=SupportChannel]')); assert.strictEqual($('.o_thread_window').length, 1, "should have open a chat window"); assert.strictEqual($('.o_thread_window .o_thread_window_title').text().trim(), 'Support (offline)', @@ -119,11 +117,10 @@ QUnit.test('clicking on Support channel: channel available', function (assert) { }); messagingMenu.appendTo($('#qunit-fixture')); - messagingMenu.$('.dropdown-toggle').click(); - assert.strictEqual(messagingMenu.$('.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]').length, - 1, "should display the Support channel"); + testUtils.dom.click(messagingMenu.$('.dropdown-toggle')); + assert.containsOnce(messagingMenu, '.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]'); - messagingMenu.$('.o_mail_preview[data-preview-id=SupportChannel]').click(); + testUtils.dom.click(messagingMenu.$('.o_mail_preview[data-preview-id=SupportChannel]')); assert.strictEqual($('.o_thread_window').length, 1, "should have open a chat window"); assert.strictEqual($('.o_thread_window .o_thread_window_title').text().trim(), 'Support', @@ -164,11 +161,10 @@ QUnit.test('post messages in Support channel', function (assert) { }); messagingMenu.appendTo($('#qunit-fixture')); - messagingMenu.$('.dropdown-toggle').click(); - assert.strictEqual(messagingMenu.$('.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]').length, - 1, "should display the Support channel"); + testUtils.dom.click(messagingMenu.$('.dropdown-toggle')); + assert.containsOnce(messagingMenu, '.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]'); - messagingMenu.$('.o_mail_preview[data-preview-id=SupportChannel]').click(); + testUtils.dom.click(messagingMenu.$('.o_mail_preview[data-preview-id=SupportChannel]')); assert.strictEqual($('.o_thread_window .o_composer_input').length, 1, "should have a composer"); @@ -208,25 +204,24 @@ QUnit.test('fold Support channel', function (assert) { services: this.services, session: this.supportParams, }); - testUtils.intercept(messagingMenu, 'call_service', function (ev) { + testUtils.mock.intercept(messagingMenu, 'call_service', function (ev) { if (ev.data.service === 'local_storage') { assert.step('LocalStorage: ' + ev.data.method + ' ' + ev.data.args); } }, true); messagingMenu.appendTo($('#qunit-fixture')); - messagingMenu.$('.dropdown-toggle').click(); - assert.strictEqual(messagingMenu.$('.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]').length, - 1, "should display the Support channel"); + testUtils.dom.click(messagingMenu.$('.dropdown-toggle')); + assert.containsOnce(messagingMenu, '.o_mail_systray_dropdown_bottom .o_mail_preview[data-preview-id=SupportChannel]'); - messagingMenu.$('.o_mail_preview[data-preview-id=SupportChannel]').click(); + testUtils.dom.click(messagingMenu.$('.o_mail_preview[data-preview-id=SupportChannel]')); assert.strictEqual($('.o_thread_window').length, 1, "should have open a chat window"); // fold, re-open and close channel - $('.o_thread_window .o_thread_window_title').click(); - $('.o_thread_window .o_thread_window_title').click(); - $('.o_thread_window .o_thread_window_close').click(); + testUtils.dom.click($('.o_thread_window .o_thread_window_title')); + testUtils.dom.click($('.o_thread_window .o_thread_window_title')); + testUtils.dom.click($('.o_thread_window .o_thread_window_close')); assert.verifySteps([ '/mail/init_messaging', @@ -322,7 +317,7 @@ QUnit.test('receive messages in the Support channel', function (assert) { "there should be a new message in the thread"); assert.strictEqual($('.o_thread_window .o_thread_message .o_thread_author ').text().trim(), 'An operator', "should correctly display the author"); - assert.strictEqual($('.o_thread_window .o_thread_message .o_thread_message_avatar').attr('data-src'), + assert.hasAttrValue($('.o_thread_window .o_thread_message .o_thread_message_avatar'), 'data-src', '/mail/static/src/img/odoo_o.png', "should have correct avatar"); assert.strictEqual($('.o_thread_window .o_thread_message .o_thread_message_content ').text().trim(), 'A message', "message is correct"); |
