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/core | |
| 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/core')
| -rw-r--r-- | addons/web/static/tests/core/dom_tests.js | 9 | ||||
| -rw-r--r-- | addons/web/static/tests/core/mixins_tests.js | 2 | ||||
| -rw-r--r-- | addons/web/static/tests/core/widget_tests.js | 16 |
3 files changed, 14 insertions, 13 deletions
diff --git a/addons/web/static/tests/core/dom_tests.js b/addons/web/static/tests/core/dom_tests.js index 08966cd484a..ab10bbb78f8 100644 --- a/addons/web/static/tests/core/dom_tests.js +++ b/addons/web/static/tests/core/dom_tests.js @@ -2,6 +2,7 @@ odoo.define('web.dom_tests', function (require) { "use strict"; var dom = require('web.dom'); +var testUtils = require('web.test_utils'); /** * Create an autoresize text area with 'border-box' as box sizing rule. @@ -43,7 +44,7 @@ QUnit.module('dom', {}, function () { $fixedTextarea[0].scrollHeight + 'px', "autoresized textarea should have height of fixed textarea + padding (0 line)"); - $textarea.val('a\nb\nc\nd').trigger('input'); + testUtils.fields.editInput($textarea, 'a\nb\nc\nd'); assert.strictEqual($textarea.css('height'), $fixedTextarea[0].scrollHeight + 'px', "autoresized textarea should have height of fixed textarea + padding (4 lines)"); @@ -63,7 +64,7 @@ QUnit.module('dom', {}, function () { expectedTextAreaHeight + 'px', "autoresized textarea should have height of fixed textarea + padding (0 line)"); - $textarea.val('a\nb\nc\nd').trigger('input'); + testUtils.fields.editInput($textarea, 'a\nb\nc\nd'); // twice the padding of 10px expectedTextAreaHeight = $fixedTextarea[0].scrollHeight + 2*10; assert.strictEqual($textarea.css('height'), @@ -88,7 +89,7 @@ QUnit.module('dom', {}, function () { expectedTextAreaHeight + 'px', "autoresized textarea should have height of fixed textarea + border (0 line)"); - $textarea.val('a\nb\nc\nd').trigger('input'); + testUtils.fields.editInput($textarea, 'a\nb\nc\nd'); // top (2px) + bottom (3px) borders expectedTextAreaHeight = $fixedTextarea[0].scrollHeight + (2 + 3); assert.strictEqual($textarea.css('height'), @@ -114,7 +115,7 @@ QUnit.module('dom', {}, function () { expectedTextAreaHeight + 'px', "autoresized textarea should have height of fixed textarea + border (0 line)"); - $textarea.val('a\nb\nc\nd').trigger('input'); + testUtils.fields.editInput($textarea, 'a\nb\nc\nd'); // twice padding (10px) + top (2px) + bottom (3px) borders expectedTextAreaHeight = $fixedTextarea[0].scrollHeight + (2*10 + 2 + 3); assert.strictEqual($textarea.css('height'), diff --git a/addons/web/static/tests/core/mixins_tests.js b/addons/web/static/tests/core/mixins_tests.js index c49c33ec648..27c87870876 100644 --- a/addons/web/static/tests/core/mixins_tests.js +++ b/addons/web/static/tests/core/mixins_tests.js @@ -13,7 +13,7 @@ QUnit.module('core', {}, function () { var widget = new Widget(); - testUtils.intercept(widget, 'do_action', function (event) { + testUtils.mock.intercept(widget, 'do_action', function (event) { assert.strictEqual(event.data.action, 'test.some_action_id', "should have sent proper action name"); assert.deepEqual(event.data.options, {clear_breadcrumbs: true}, diff --git a/addons/web/static/tests/core/widget_tests.js b/addons/web/static/tests/core/widget_tests.js index f61d4a18f9b..834033a1769 100644 --- a/addons/web/static/tests/core/widget_tests.js +++ b/addons/web/static/tests/core/widget_tests.js @@ -122,7 +122,7 @@ QUnit.module('core', {}, function () { widget.renderElement(); assert.strictEqual(widget.el.attributes.length, 1, "should have one attribute"); - assert.strictEqual(widget.$el.attr('id'), 'foo', "should have generated the id attribute"); + assert.hasAttrValue(widget.$el, 'id', 'foo', "should have generated the id attribute"); assert.strictEqual(widget.el.id, 'foo', "should also be available via property"); }); @@ -135,7 +135,7 @@ QUnit.module('core', {}, function () { widget.renderElement(); assert.strictEqual(widget.el.className, 'oe_some_class', "should have the right property"); - assert.strictEqual(widget.$el.attr('class'), 'oe_some_class', "should have the right attribute"); + assert.hasAttrValue(widget.$el, 'class', 'oe_some_class', "should have the right attribute"); }); QUnit.test('no template, bunch of attributes', function (assert) { @@ -156,16 +156,16 @@ QUnit.module('core', {}, function () { assert.strictEqual(widget.el.attributes.length, 5, "should have all the specified attributes"); assert.strictEqual(widget.el.id, 'some_id'); - assert.strictEqual(widget.$el.attr('id'), 'some_id'); + assert.hasAttrValue(widget.$el, 'id', 'some_id'); assert.strictEqual(widget.el.className, 'some_class'); - assert.strictEqual(widget.$el.attr('class'), 'some_class'); + assert.hasAttrValue(widget.$el, 'class', 'some_class'); - assert.strictEqual(widget.$el.attr('data-foo'), 'data attribute'); + assert.hasAttrValue(widget.$el, 'data-foo', 'data attribute'); assert.strictEqual(widget.$el.data('foo'), 'data attribute'); - assert.strictEqual(widget.$el.attr('clark'), 'gable'); - assert.strictEqual(widget.$el.attr('spoiler'), 'snape kills dumbledore'); + assert.hasAttrValue(widget.$el, 'clark', 'gable'); + assert.hasAttrValue(widget.$el, 'spoiler', 'snape kills dumbledore'); }); QUnit.test('template', function (assert) { @@ -383,7 +383,7 @@ QUnit.module('core', {}, function () { var def; var parent = new Widget(); - testUtils.addMockEnvironment(parent, { + testUtils.mock.addMockEnvironment(parent, { session: { rpc: function () { def = $.Deferred(); |
