summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/chrome/action_manager_tests.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2018-03-01 11:19:23 +0100
committerAaron Bohy <aab@odoo.com>2018-03-06 09:12:21 +0100
commitcdb01d52ea0a7b3b02594f2bd98d1a7bdf2fa2a3 (patch)
treed2969057a9670a18b5c0f1ca5e9de5a1e4b91c15 /addons/web/static/tests/chrome/action_manager_tests.js
parentbc66da2dfaf399f642836256c67a65a5468cd47a (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/chrome/action_manager_tests.js')
-rw-r--r--addons/web/static/tests/chrome/action_manager_tests.js65
1 files changed, 65 insertions, 0 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) {