diff options
| author | Aaron Bohy <aab@odoo.com> | 2018-03-01 11:19:23 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-03-06 09:12:21 +0100 |
| commit | cdb01d52ea0a7b3b02594f2bd98d1a7bdf2fa2a3 (patch) | |
| tree | d2969057a9670a18b5c0f1ca5e9de5a1e4b91c15 /addons/web/static/tests | |
| parent | bc66da2dfaf399f642836256c67a65a5468cd47a (diff) | |
[FIX] web: create favorite filters in dialogs
This is a manual forwardport of rev. b466b3bc608.
Consider the following scenario: open in edit mode a form view
containing a many2many field displayed with widget many2many_tags,
on the many2many field dropdown, click on 'Search More' (it opens
a dialog), and in the dialog, try to save the current search in
the searchview's favorite menu.
Before this rev., it crashed because it tried to retrieve the
action's context (to add to the saved filter), whereas there is no
action in this case.
Actually, the action's context should never been used in this case.
What must be used is the controller's context (this mainly makes
sense for Pivot and Graph views).
Fixes #23293
Diffstat (limited to 'addons/web/static/tests')
| -rw-r--r-- | addons/web/static/tests/chrome/action_manager_tests.js | 65 | ||||
| -rw-r--r-- | addons/web/static/tests/views/view_dialogs_tests.js | 60 |
2 files changed, 124 insertions, 1 deletions
diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index 4d682b8994c..7fdaa138754 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -5,6 +5,7 @@ var ReportClientAction = require('report.client_action'); var ControlPanelMixin = require('web.ControlPanelMixin'); var core = require('web.core'); +var ListController = require('web.ListController'); var ReportService = require('web.ReportService'); var testUtils = require('web.test_utils'); var Widget = require('web.Widget'); @@ -2347,6 +2348,70 @@ QUnit.module('ActionManager', { actionManager.destroy(); }); + QUnit.test('save current search', function (assert) { + assert.expect(4); + + testUtils.patch(ListController, { + getContext: function () { + return { + shouldBeInFilterContext: true, + }; + }, + }); + + _.extend(this.archs, { + 'partner,7,search': + '<search>' + + '<filter name="bar" help="Bar" domain="[(\'bar\', \'=\', 1)]"/>' + + '</search>', + }); + + this.actions.push({ + id: 33, + context: { + shouldNotBeInFilterContext: false, + }, + name: 'Partners', + res_model: 'partner', + search_view_id: [7, 'a custom search view'], + type: 'ir.actions.act_window', + views: [[false, 'list']], + }); + + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + intercepts: { + create_filter: function (event) { + var filter = event.data.filter; + assert.deepEqual(filter.domain, [['bar', '=', 1]], + "should save the correct domain"); + assert.deepEqual(filter.context, {shouldBeInFilterContext: true}, + "should save the correct context"); + }, + }, + }); + actionManager.doAction(33); + + assert.strictEqual(actionManager.$('.o_data_row').length, 5, + "should contain 5 records"); + + // filter on bar + $('.o_control_panel .o_filters_menu a:contains(Bar)').click(); + + assert.strictEqual(actionManager.$('.o_data_row').length, 2, + "should contain 2 records"); + + // save filter + $('.o_control_panel .o_save_search a').click(); // toggle 'Save current search' + $('.o_control_panel .o_save_name input[type=text]').val('some name'); // name the filter + $('.o_control_panel .o_save_name button').click(); // click on 'Save' + + testUtils.unpatch(ListController); + actionManager.destroy(); + }); + QUnit.module('Actions in target="new"'); QUnit.test('can execute act_window actions in target="new"', function (assert) { diff --git a/addons/web/static/tests/views/view_dialogs_tests.js b/addons/web/static/tests/views/view_dialogs_tests.js index 1f958fb38bc..6ec4f50ab4b 100644 --- a/addons/web/static/tests/views/view_dialogs_tests.js +++ b/addons/web/static/tests/views/view_dialogs_tests.js @@ -1,8 +1,9 @@ odoo.define('web.view_dialogs_tests', function (require) { "use strict"; -var testUtils = require('web.test_utils'); var dialogs = require('web.view_dialogs'); +var ListController = require('web.ListController'); +var testUtils = require('web.test_utils'); var Widget = require('web.Widget'); QUnit.module('Views', { @@ -241,6 +242,63 @@ QUnit.module('Views', { parent.destroy(); }); + QUnit.test('SelectCreateDialog: save current search', function (assert) { + assert.expect(4); + + testUtils.patch(ListController, { + getContext: function () { + return { + shouldBeInFilterContext: true, + }; + }, + }); + + var parent = createParent({ + data: this.data, + archs: { + 'partner,false,list': + '<tree>' + + '<field name="display_name"/>' + + '</tree>', + 'partner,false,search': + '<search>' + + '<filter name="bar" help="Bar" domain="[(\'bar\', \'=\', True)]"/>' + + '</search>', + + }, + intercepts: { + create_filter: function (event) { + var filter = event.data.filter; + assert.deepEqual(filter.domain, [['bar', '=', true]], + "should save the correct domain"); + assert.deepEqual(filter.context, {shouldBeInFilterContext: true}, + "should save the correct context"); + }, + }, + }); + + var dialog = new dialogs.SelectCreateDialog(parent, { + context: {shouldNotBeInFilterContext: false}, + res_model: 'partner', + }).open(); + + assert.strictEqual(dialog.$('.o_data_row').length, 3, + "should contain 3 records"); + + // filter on bar + dialog.$('.o_filters_menu a:contains(Bar)').click(); + + assert.strictEqual(dialog.$('.o_data_row').length, 2, + "should contain 2 records"); + + // save filter + dialog.$('.o_save_search a').click(); // toggle 'Save current search' + dialog.$('.o_save_name input[type=text]').val('some name'); // name the filter + dialog.$('.o_save_name button').click(); // click on 'Save' + + testUtils.unpatch(ListController); + parent.destroy(); + }); }); }); |
