Files
odoo_source/addons/web/static/tests/tools/debug_manager_tests.js
T
40dd121938 [REF] web: move ControlPanel inside controllers/actions
This branch introduces a large-scale reorganization of the
component tree generated by the web client.  The short version is
that now, the control panel is a child of the view controller and
no longer a sibling. Graphically (and simplified), we go from
this:

                  webClient
                 /    |    \
               ...   ...  actionManager
                           /         \
                   controlPanel   viewController
                                    /       \

to this:

           	  webClient
                 /    |    \
               ...   ...  actionManager
                               |
                          viewController
                            /   |   \
          ControlPanelController
              /           \
         CPRenderer     CPModel

The motivation is that this work moves the code where it should be.
Before this commit, it was kind of weird to have code in the
controllers to render buttons outside of their root node (in
renderButtons).  Also, the action manager had to take care of
coordinating search view states between view transitions.

So, this work simplifies the code.  It also makes it easier to
extend. We see day after day that Odoo needs to take care of more
complex UI needs, and in many cases, these needs were quite
difficult to implement (we prefer spaghettis in our plates, not in
our code).  The changes in this branch should open the way to
implement these features.

For example,
- it will now be easy to add the possibility of views (for example,
  the search view or a new ControlPanel view) to add custom buttons
  (of type action or object) in the control panel.
- Another need will be to serialize/ restore the state of the
  search view across action boundaries (needed by the dashboard).
- Another example is the possibility for views to customize easily
  the presence/absence of sub menus (filters/groupbys/favorites/
  time range/...)
- Another need is an easier way for views/client action to customize
  their control panel.

This commit also contains a large rewrite of the search view (so it
is more inline with our architecture and easier to maintain).

Part of task 1893568

Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
2018-12-07 13:16:06 +00:00

172 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 = {
controlPanelFieldsView: {},
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();
});
});
});