summaryrefslogtreecommitdiff
path: root/addons/barcodes/static/tests
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2018-11-19 08:18:28 +0000
committerAaron Bohy <aab@odoo.com>2018-11-19 11:24:28 +0000
commitabf32b8b21394491040e5c11c1fea809c1d7c62c (patch)
tree6058f8a893815bf0ed2495649c125523f4def762 /addons/barcodes/static/tests
parentbcbb7ee3fecaad3c7e801fa5dbc90a566faac27f (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/barcodes/static/tests')
-rw-r--r--addons/barcodes/static/tests/barcode_tests.js24
1 files changed, 12 insertions, 12 deletions
diff --git a/addons/barcodes/static/tests/barcode_tests.js b/addons/barcodes/static/tests/barcode_tests.js
index 0e2996d8608..58cf13925b7 100644
--- a/addons/barcodes/static/tests/barcode_tests.js
+++ b/addons/barcodes/static/tests/barcode_tests.js
@@ -11,7 +11,7 @@ var testUtils = require('web.test_utils');
var NotificationService = require('web.NotificationService');
var createView = testUtils.createView;
-var triggerKeypressEvent = testUtils.triggerKeypressEvent;
+var triggerKeypressEvent = testUtils.dom.triggerKeypressEvent;
QUnit.module('Barcodes', {
beforeEach: function () {
@@ -109,23 +109,23 @@ QUnit.test('edit, save and cancel buttons', function (assert) {
// O-CMD.EDIT
_.each(["O","-","C","M","D",".","E","D","I","T","Enter"], triggerKeypressEvent);
- assert.strictEqual(form.$(".o_form_editable").length, 1,
+ assert.containsOnce(form, ".o_form_editable",
"should have switched to 'edit' mode");
// dummy change to check that it actually saves
- form.$('.o_field_widget').val('test').trigger('input');
+ testUtils.fields.editInput(form.$('.o_field_widget'), 'test');
// O-CMD.SAVE
_.each(["O","-","C","M","D",".","S","A","V","E","Enter"], triggerKeypressEvent);
- assert.strictEqual(form.$(".o_form_readonly").length, 1,
+ assert.containsOnce(form, ".o_form_readonly",
"should have switched to 'readonly' mode");
assert.verifySteps(['save'], 'should have saved');
// O-CMD.EDIT
_.each(["O","-","C","M","D",".","E","D","I","T","Enter"], triggerKeypressEvent);
// dummy change to check that it correctly discards
- form.$('.o_field_widget').val('test').trigger('input');
+ testUtils.fields.editInput(form.$('.o_field_widget'), 'test');
// O-CMD.CANCEL
_.each(["O","-","C","M","D",".","D","I","S","C","A","R","D","Enter"], triggerKeypressEvent);
- assert.strictEqual(form.$(".o_form_readonly").length, 1,
+ assert.containsOnce(form, ".o_form_readonly",
"should have switched to 'readonly' mode");
assert.verifySteps(['save'], 'should not have saved');
@@ -169,7 +169,7 @@ QUnit.test('do no update form twice after a command barcode scanned', function (
var delay = barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms;
barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = 0;
- testUtils.patch(FormController, {
+ testUtils.mock.patch(FormController, {
update: function () {
assert.step('update');
return this._super.apply(this, arguments);
@@ -212,7 +212,7 @@ QUnit.test('do no update form twice after a command barcode scanned', function (
form.destroy();
barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = delay;
- testUtils.unpatch(FormController);
+ testUtils.mock.unpatch(FormController);
});
QUnit.test('widget field_float_scannable', function (assert) {
@@ -250,7 +250,7 @@ QUnit.test('widget field_float_scannable', function (assert) {
assert.strictEqual(form.$('.o_field_widget[name=int_field]').text(), '4',
"should display the correct value in readonly");
- form.$buttons.find('.o_form_button_edit').click();
+ testUtils.form.clickEdit(form);
assert.strictEqual(form.$('.o_field_widget[name=int_field]').val(), '4',
"should display the correct value in edit");
@@ -387,7 +387,7 @@ QUnit.test('specification of widget barcode_handler', function (assert) {
},
});
- assert.strictEqual(form.$('.o_data_row').length, 2,
+ assert.containsN(form, '.o_data_row', 2,
"one2many should contain 2 rows");
// scan twice product 1
@@ -403,7 +403,7 @@ QUnit.test('specification of widget barcode_handler', function (assert) {
assert.strictEqual(form.$('.o_data_row:nth(1) .o_data_cell:nth(1)').text(), '1',
"quantity of line one should have been incremented");
- form.$buttons.find('.o_form_button_save').click();
+ testUtils.form.clickSave(form);
form.destroy();
barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = delay;
@@ -526,7 +526,7 @@ QUnit.test('barcode_scanned only trigger error for active view', function (asser
},
});
- form.$('.o_data_row:first').click();
+ testUtils.dom.click(form.$('.o_data_row:first'));
// We do not trigger on the body since modal and
// form view are both inside it.