|
| 1 | +/* global QUnit */ |
| 2 | +odoo.define("web_hide_custom_search.tests", function (require) { |
| 3 | + const CustomFilterItem = require("web.CustomFilterItem"); |
| 4 | + const CustomGroupByItem = require("web.CustomGroupByItem"); |
| 5 | + const ActionModel = require("web.ActionModel"); |
| 6 | + const testUtils = require("web.test_utils"); |
| 7 | + const rpc = require("web.rpc"); |
| 8 | + const {createComponent} = testUtils; |
| 9 | + |
| 10 | + function createTestComponent(Component, rpcVisible = true) { |
| 11 | + const originalQuery = rpc.query; |
| 12 | + rpc.query = (params) => { |
| 13 | + if ( |
| 14 | + params.model === "ir.model" && |
| 15 | + params.method === "is_custom_search_visible" |
| 16 | + ) { |
| 17 | + return Promise.resolve(rpcVisible); |
| 18 | + } |
| 19 | + return originalQuery.apply(this, arguments); |
| 20 | + }; |
| 21 | + return createComponent(Component, { |
| 22 | + props: { |
| 23 | + fields: [ |
| 24 | + {sortable: true, name: "date", string: "Super Date", type: "date"}, |
| 25 | + ], |
| 26 | + }, |
| 27 | + env: { |
| 28 | + searchModel: new ActionModel(), |
| 29 | + }, |
| 30 | + }).then((cmp) => { |
| 31 | + rpc.query = originalQuery; // Restore after setup |
| 32 | + return cmp; |
| 33 | + }); |
| 34 | + } |
| 35 | + |
| 36 | + QUnit.module("Components", {}, function () { |
| 37 | + QUnit.module("web_hide_custom_search"); |
| 38 | + |
| 39 | + QUnit.test("Custom Filter Visible", async function (assert) { |
| 40 | + assert.expect(1); |
| 41 | + const cgi = await createTestComponent(CustomFilterItem); |
| 42 | + assert.strictEqual(cgi.el.innerText.trim(), "Add Custom Filter"); |
| 43 | + cgi.destroy(); |
| 44 | + }); |
| 45 | + |
| 46 | + QUnit.test("Custom Filter Invisible", async function (assert) { |
| 47 | + assert.expect(1); |
| 48 | + const cgi = await createTestComponent(CustomFilterItem, false); |
| 49 | + assert.notStrictEqual(cgi.el.innerText.trim(), "Add Custom Filter"); |
| 50 | + cgi.destroy(); |
| 51 | + }); |
| 52 | + |
| 53 | + QUnit.test("Custom Group By Visible", async function (assert) { |
| 54 | + assert.expect(1); |
| 55 | + const cgi = await createTestComponent(CustomGroupByItem); |
| 56 | + assert.strictEqual(cgi.el.innerText.trim(), "Add Custom Group"); |
| 57 | + cgi.destroy(); |
| 58 | + }); |
| 59 | + |
| 60 | + QUnit.test("Custom Group By Invisible", async function (assert) { |
| 61 | + assert.expect(1); |
| 62 | + const cgi = await createTestComponent(CustomGroupByItem, false); |
| 63 | + assert.notStrictEqual(cgi.el.innerText.trim(), "Add Custom Group"); |
| 64 | + cgi.destroy(); |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments