Files
odoo_source/addons/web/static/tests/tools/debug_manager_tests.js
T
Géry Debongnie abf32b8b21 [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.
2018-11-19 11:24:28 +00:00

171 lines
5.5 KiB
JavaScript

odoo.define('web.debugManagerTests', function (require) {
"use strict";
var testUtils = require('web.test_utils');
var FormView = require('web.FormView');
var createDebugManager = testUtils.createDebugManager;
QUnit.module('DebugManager', {}, function () {
QUnit.test("list: edit view menu item", function (assert) {
assert.expect(3);
var debugManager = createDebugManager();
debugManager.appendTo($('#qunit-fixture'));
// Simulate update debug manager from web client
var action = {
views: [{
displayName: "List",
fieldsView: {
view_id: 1,
},
type: "list",
}],
};
var view = {
viewType: "list",
};
debugManager.update('action', action, view);
var $editView = debugManager.$('a[data-action=edit][data-model="ir.ui.view"]');
assert.strictEqual($editView.length, 1, "should have edit view menu item");
assert.strictEqual($editView.text().trim(), "Edit View: List",
"should have correct menu item text for editing view");
assert.strictEqual($editView.data('id'), 1, "should have correct view_id");
debugManager.destroy();
});
QUnit.test("form: Manage Attachments option", function (assert) {
assert.expect(3);
var debugManager = createDebugManager({
intercepts: {
do_action: function (event) {
assert.deepEqual(event.data.action, {
domain: [["res_model", "=", "test.model"],["res_id", "=", 5]],
name: "Manage Attachments",
res_model: "ir.attachment",
type: "ir.actions.act_window",
views: [[false, "list"],[false, "form"]],
});
},
},
});
debugManager.appendTo($('#qunit-fixture'));
// Simulate update debug manager from web client
var action = {
views: [{
displayName: "Form",
fieldsView: {
view_id: 2,
},
type: "form",
}],
res_model: "test.model",
};
var view = {
viewType: "form",
getSelectedIds: function () {
return [5];
},
};
debugManager.update('action', action, view);
var $attachmentMenu = debugManager.$('a[data-action=get_attachments]');
assert.strictEqual($attachmentMenu.length, 1, "should have Manage Attachments menu item");
assert.strictEqual($attachmentMenu.text().trim(), "Manage Attachments",
"should have correct menu item text");
testUtils.dom.click(debugManager.$('> a')); // open dropdown
testUtils.dom.click($attachmentMenu);
debugManager.destroy();
});
QUnit.test("Debug: Set defaults with right model", function (assert) {
assert.expect(2);
/* Click on debug > set default,
* set some defaults, click on save
* model and some other data should be sent to server
*/
// We'll need a full blown architecture with some data
var data = {
partner: {
fields: {
foo: {string: "Foo", type: "char", default: "My little Foo Value"},
},
records: [{
id: 1,
foo: "yop",
}]
},
'ir.default': { // We just need this to be defined
fields: {},
},
}
var form = testUtils.createView({
View: FormView,
model: 'partner',
data: data,
arch: '<form string="Partners">' +
'<field name="foo" />' +
'</form>',
res_id: 1,
});
// Now the real tested component
var debugManager = createDebugManager({
data: data,
mockRPC: function (route, args) {
if (route == "/web/dataset/call_kw/ir.default/set") {
assert.deepEqual(args.args, ["partner", "foo", "yop", true, true, false],
'Model, field, value and booleans for current user/company should have been passed');
return $.when();
}
return this._super.apply(this, arguments);
}
});
debugManager.appendTo($('#qunit-fixture'));
// Simulate update debug manager from web client
var action = {
views: [{
fieldsView: {
view_id: 1,
model: 'partner',
type: 'form',
},
type: "form",
}],
res_model: 'partner',
};
// We are all set
debugManager.update('action', action, form);
// click on set_defaults dropdown
testUtils.dom.click(debugManager.$('> a')); // open dropdown
testUtils.dom.click(debugManager.$('a[data-action="set_defaults"]'));
var $modal = $('.modal-content');
assert.strictEqual($modal.length, 1, 'One modal present');
$modal.find('select[id=formview_default_fields] option[value=foo]').prop('selected', true);
// Save
testUtils.dom.click($modal.find('.modal-footer button').eq(1));
form.destroy();
debugManager.destroy();
});
});
});