Skip to content

Commit 4a702ef

Browse files
[ADD] web_hide_custom_search: add tests
1 parent 338b985 commit 4a702ef

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

web_hide_custom_search/__manifest__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"web.assets_backend": [
2020
"web_hide_custom_search/static/src/js/*.esm.js",
2121
],
22+
"web.qunit_suite_tests": [
23+
"web_hide_custom_search/static/tests/*.esm.js",
24+
],
2225
},
2326
"installable": True,
2427
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)