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/mail/static/tests/document_viewer_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/mail/static/tests/document_viewer_tests.js')
| -rw-r--r-- | addons/mail/static/tests/document_viewer_tests.js | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/addons/mail/static/tests/document_viewer_tests.js b/addons/mail/static/tests/document_viewer_tests.js index bbd2d9a6fa1..ef825f84e2a 100644 --- a/addons/mail/static/tests/document_viewer_tests.js +++ b/addons/mail/static/tests/document_viewer_tests.js @@ -32,7 +32,7 @@ var createViewer = function (params) { return $.when(); } }; - testUtils.addMockEnvironment(parent, { + testUtils.mock.addMockEnvironment(parent, { mockRPC: function () { if (params.mockRPC) { var _super = this._super; @@ -82,19 +82,19 @@ QUnit.module('DocumentViewer', { attachments: this.attachments, }); - assert.strictEqual(viewer.$('.o_viewer_content').length, 1, + assert.containsOnce(viewer, '.o_viewer_content', "there should be a preview"); - assert.strictEqual(viewer.$('.o_close_btn').length, 1, + assert.containsOnce(viewer, '.o_close_btn', "there should be a close button"); - assert.strictEqual(viewer.$('.o_viewer-header').length, 1, + assert.containsOnce(viewer, '.o_viewer-header', "there should be a header"); - assert.strictEqual(viewer.$('.o_image_caption').length, 1, + assert.containsOnce(viewer, '.o_image_caption', "there should be an image caption"); - assert.strictEqual(viewer.$('.o_viewer_zoomer').length, 1, + assert.containsOnce(viewer, '.o_viewer_zoomer', "there should be a zoomer"); - assert.strictEqual(viewer.$('.fa-chevron-right').length, 1, + assert.containsOnce(viewer, '.fa-chevron-right', "there should be a right nav icon"); - assert.strictEqual(viewer.$('.fa-chevron-left').length, 1, + assert.containsOnce(viewer, '.fa-chevron-left', "there should be a left nav icon"); viewer.destroy(); @@ -120,14 +120,14 @@ QUnit.module('DocumentViewer', { }, }); - assert.strictEqual(viewer.$('.o_page_number_input').length, 1, + assert.containsOnce(viewer, '.o_page_number_input', "pdf should have a page input"); - assert.strictEqual(viewer.$('.o_remainder_input').length, 1, + assert.containsOnce(viewer, '.o_remainder_input', "pdf should have a remainder checkbox"); - assert.strictEqual(viewer.$('.o_split_btn').length, 1, + assert.containsOnce(viewer, '.o_split_btn', "pdf should have a split button"); - viewer.$('.o_split_btn').click(); + testUtils.dom.click(viewer.$('.o_split_btn')); assert.ok(viewer.isDestroyed(), 'viewer should be destroyed'); }); @@ -149,7 +149,7 @@ QUnit.module('DocumentViewer', { assert.strictEqual(viewer.$(".o_image_caption:contains('urlYoutubeName')").length, 1, "the viewer should be on the right attachment"); - assert.strictEqual(viewer.$('.o_viewer_text[data-src="' + youtubeURL + '"]').length, 1, + assert.containsOnce(viewer, '.o_viewer_text[data-src="' + youtubeURL + '"]', "there should be a video player"); viewer.destroy(); @@ -165,7 +165,7 @@ QUnit.module('DocumentViewer', { assert.strictEqual(viewer.$(".o_image_caption:contains('text.html')").length, 1, "the viewer be on the right attachment"); - assert.strictEqual(viewer.$('iframe[data-src="/web/content/4"]').length, 1, + assert.containsOnce(viewer, 'iframe[data-src="/web/content/4"]', "there should be an iframe with the right src"); viewer.destroy(); @@ -181,7 +181,7 @@ QUnit.module('DocumentViewer', { assert.strictEqual(viewer.$(".o_image_caption:contains('video.mp4')").length, 1, "the viewer be on the right attachment"); - assert.strictEqual(viewer.$('.o_viewer_video').length, 1, + assert.containsOnce(viewer, '.o_viewer_video', "there should be a video player"); viewer.destroy(); @@ -197,7 +197,7 @@ QUnit.module('DocumentViewer', { assert.strictEqual(viewer.$(".o_image_caption:contains('image.jpg')").length, 1, "the viewer be on the right attachment"); - assert.strictEqual(viewer.$('img[data-src="/web/image/6?unique=1&signature=999"]').length, 1, + assert.containsOnce(viewer, 'img[data-src="/web/image/6?unique=1&signature=999"]', "there should be a video player"); viewer.destroy(); @@ -211,12 +211,12 @@ QUnit.module('DocumentViewer', { attachments: this.attachments, }); - assert.strictEqual(viewer.$('.o_viewer_content').length, 1, + assert.containsOnce(viewer, '.o_viewer_content', "should have a document viewer"); - assert.strictEqual(viewer.$('.o_close_btn').length, 1, + assert.containsOnce(viewer, '.o_close_btn', "should have a close button"); - viewer.$('.o_close_btn').click(); + testUtils.dom.click(viewer.$('.o_close_btn')); assert.ok(viewer.isDestroyed(), 'viewer should be destroyed'); }); @@ -229,12 +229,12 @@ QUnit.module('DocumentViewer', { attachments: this.attachments, }); - assert.strictEqual(viewer.$('.o_viewer_content').length, 1, + assert.containsOnce(viewer, '.o_viewer_content', "should have a document viewer"); - assert.strictEqual(viewer.$('.o_viewer_img_wrapper').length, 1, + assert.containsOnce(viewer, '.o_viewer_img_wrapper', "should have a wrapper"); - viewer.$('.o_viewer_img_wrapper').click(); + testUtils.dom.click(viewer.$('.o_viewer_img_wrapper')); assert.ok(viewer.isDestroyed(), 'viewer should be destroyed'); }); |
