diff options
| author | Géry Debongnie <ged@odoo.com> | 2018-12-06 12:39:06 +0000 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2018-12-07 13:16:06 +0000 |
| commit | 40dd121938552d3f88289d2e5fcd1d57a0dd01bb (patch) | |
| tree | 4830c8ffdea1e10d35c7ddf096f536bd8999240f /addons/web/static/tests/views/control_panel_tests.js | |
| parent | 48a50b4bc011fc6dfc82a673f921fad941dc79cf (diff) | |
[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>
Diffstat (limited to 'addons/web/static/tests/views/control_panel_tests.js')
| -rw-r--r-- | addons/web/static/tests/views/control_panel_tests.js | 334 |
1 files changed, 334 insertions, 0 deletions
diff --git a/addons/web/static/tests/views/control_panel_tests.js b/addons/web/static/tests/views/control_panel_tests.js new file mode 100644 index 00000000000..513cdb32e08 --- /dev/null +++ b/addons/web/static/tests/views/control_panel_tests.js @@ -0,0 +1,334 @@ +odoo.define('web.control_panel_tests', function (require) { +"use strict"; + +var ControlPanelView = require('web.ControlPanelView'); +var testUtils = require('web.test_utils'); + +var createControlPanel = testUtils.createControlPanel; + +function createControlPanelFactory(arch, fields, params) { + params = params || {}; + arch = arch || "<search></search>"; + fields = fields || {}; + var viewInfo = {arch: arch, fields: fields}; + var controlPanelFactory = new ControlPanelView({viewInfo: viewInfo, context: {}}); + return controlPanelFactory; +} + +QUnit.module('Views', { + beforeEach: function () { + this.data = { + partner: { + fields: { + display_name: { string: "Displayed name", type: 'char' }, + foo: {string: "Foo", type: "char", default: "My little Foo Value", store: true, sortable: true}, + date_field: {string: "Date", type: "date", store: true, sortable: true}, + float_field: {string: "Float", type: "float"}, + bar: {string: "Bar", type: "many2one", relation: 'partner'}, + }, + records: [], + onchanges: {}, + }, + }; + } +}, function () { + QUnit.module('ControlPanelView'); + + QUnit.module('Control Panel Arch Parsing'); + + QUnit.test('empty arch', function (assert) { + assert.expect(1); + + var controlPanelFactory = createControlPanelFactory(); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [], + "there should be no group at all" + ); + }); + + QUnit.test('parse one field tag', function (assert) { + assert.expect(1); + var arch = "<search>" + + "<field name=\"bar\"/>" + + "</search>"; + var fields = this.data.partner.fields; + var controlPanelFactory = createControlPanelFactory(arch, fields); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [[{ + attrs: { + name: "bar", + string: "Bar" + }, + autoCompleteValues: [], + description: "bar", + isDefault: false, + type: "field" + }]], + "there should be one group with one field" + ); + }); + + QUnit.test('parse one separator tag', function (assert) { + assert.expect(1); + var arch = "<search>" + + "<separator/>" + + "</search>"; + var fields = this.data.partner.fields; + var controlPanelFactory = createControlPanelFactory(arch, fields); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [], + "there should be no group at all"); + }); + + QUnit.test('parse one separator tag and one field tag', function (assert) { + assert.expect(1); + var arch = "<search>" + + "<separator/>" + + "<field name=\"bar\"/>" + + "</search>"; + var fields = this.data.partner.fields; + var controlPanelFactory = createControlPanelFactory(arch, fields); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [[ + { + attrs: { + name: "bar", + string: "Bar" + }, + autoCompleteValues: [], + description: "bar", + isDefault: false, + type: "field" + } + ]], + "there should be one group with one field" + ); + }); + + QUnit.test('parse one filter tag', function (assert) { + assert.expect(1); + var arch = "<search>" + + "<filter name=\"filter\" string=\"Hello\" " + + "domain=\"[]\"/>" + + "</search>"; + var fields = this.data.partner.fields; + var controlPanelFactory = createControlPanelFactory(arch, fields); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [[{ + description: "Hello", + groupNumber: 2, + domain: "[]", + isDefault: false, + type: "filter" + }]], + "there should be one group with one filter" + ); + }); + + QUnit.test('parse one groupBy tag', function (assert) { + assert.expect(1); + var arch = "<search>" + + "<groupBy name=\"groupby\" string=\"Hi\" " + + "context=\"{\'group_by\': \'date_field:day\'}\"/>" + + "</search>"; + var fields = this.data.partner.fields; + var controlPanelFactory = createControlPanelFactory(arch, fields); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [[ + { + currentOptionId: false, + defaultOptionId: "day", + description: "Hi", + fieldName: "date_field", + fieldType: "date", + groupNumber: 2, + hasOptions: true, + isDefault: false, + options: [ + { + description: "Day", + groupId: 1, + optionId: "day" + }, + { + description: "Week", + groupId: 1, + optionId: "week" + }, + { + description: "Month", + groupId: 1, + optionId: "month" + }, + { + description: "Quarter", + groupId: 1, + optionId: "quarter" + }, + { + description: "Year", + groupId: 1, + optionId: "year" + } + ], + type: "groupBy" + } + ]], + "there should be one group with one groupBy with options" + ); + }); + + QUnit.test('parse two filter tags', function (assert) { + assert.expect(1); + var arch = "<search>" + + "<filter name=\"filter_1\" string=\"Hello One\" " + + "domain=\"[]\"/>" + + "<filter name=\"filter_2\" string=\"Hello Two\" " + + "domain=\"[(\'bar\', \'=\', 3)]\"/>" + + "</search>"; + var fields = this.data.partner.fields; + var controlPanelFactory = createControlPanelFactory(arch, fields); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [[ + { + "description": "Hello One", + "domain": "[]", + "groupNumber": 2, + "isDefault": false, + "type": "filter" + }, + { + "description": "Hello Two", + "domain": "[('bar', '=', 3)]", + "groupNumber": 2, + "isDefault": false, + "type": "filter" + } + ]], + 'there should be one group of two filters' + ); + }); + + QUnit.test('parse two filter tags separated by a separator', function (assert) { + assert.expect(1); + var arch = "<search>" + + "<filter name=\"filter_1\" string=\"Hello One\" " + + "domain=\"[]\"/>" + + "<separator/>" + + "<filter name=\"filter_2\" string=\"Hello Two\" " + + "domain=\"[(\'bar\', \'=\', 3)]\"/>" + + "</search>"; + + var fields = this.data.partner.fields; + var controlPanelFactory = createControlPanelFactory(arch, fields); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [ + [ + { + description: "Hello One", + domain: "[]", + groupNumber: 2, + isDefault: false, + type: "filter" + } + ], + [ + { + description: "Hello Two", + domain: "[('bar', '=', 3)]", + groupNumber: 4, + isDefault: false, + type: "filter" + } + ] + ], + "there should be two groups of one filter" + ); + }); + + QUnit.test('parse one filter tag and one field', function (assert) { + assert.expect(1); + var arch = "<search>" + + "<filter name=\"filter\" string=\"Hello\" domain=\"[]\"/>" + + "<field name=\"bar\"/>" + + "</search>"; + var fields = this.data.partner.fields; + var controlPanelFactory = createControlPanelFactory(arch, fields); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [ + [ + { + description: "Hello", + domain: "[]", + groupNumber: 2, + isDefault: false, + type: "filter" + } + ], + [ + { + attrs: { + name: "bar", + string: "Bar" + }, + autoCompleteValues: [], + description: "bar", + isDefault: false, + type: "field" + } + ] + ], + "there should be one group with a filter and one group with a field" + ); + }); + + QUnit.test('parse two field tags', function (assert) { + assert.expect(1); + var arch = "<search>" + + "<field name=\"foo\"/>" + + "<field name=\"bar\"/>" + + "</search>"; + var fields = this.data.partner.fields; + var controlPanelFactory = createControlPanelFactory(arch, fields); + assert.deepEqual( + controlPanelFactory.loadParams.groups, + [ + [ + { + attrs: { + name: "foo", + string: "Foo" + }, + autoCompleteValues: [], + description: "foo", + isDefault: false, + type: "field" + } + ], + [ + { + attrs: { + name: "bar", + string: "Bar" + }, + autoCompleteValues: [], + description: "bar", + isDefault: false, + type: "field" + } + ] + ], + "there should be two groups of a single field" + ); + }); +}); +}); |
