mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-19 17:32:05 +02:00
Initial commit: Core packages
This commit is contained in:
commit
12c29a983b
9512 changed files with 8379910 additions and 0 deletions
|
|
@ -0,0 +1,158 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { click, getFixture, triggerEvent, nextTick } from "@web/../tests/helpers/utils";
|
||||
import { ControlPanel } from "@web/search/control_panel/control_panel";
|
||||
import {
|
||||
editSearch,
|
||||
makeWithSearch,
|
||||
setupControlPanelServiceRegistry,
|
||||
} from "@web/../tests/search/helpers";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { uiService } from "@web/core/ui/ui_service";
|
||||
|
||||
let serverData;
|
||||
let target;
|
||||
|
||||
QUnit.module("Search", (hooks) => {
|
||||
hooks.beforeEach(async () => {
|
||||
setupControlPanelServiceRegistry();
|
||||
target = getFixture();
|
||||
registry.category("services").add("ui", uiService);
|
||||
|
||||
serverData = {
|
||||
models: {
|
||||
foo: {
|
||||
fields: {
|
||||
birthday: { string: "Birthday", type: "date", store: true, sortable: true },
|
||||
date_field: { string: "Date", type: "date", store: true, sortable: true },
|
||||
},
|
||||
records: [{ date_field: "2022-02-14" }],
|
||||
},
|
||||
},
|
||||
views: {
|
||||
"foo,false,search": `
|
||||
<search>
|
||||
<filter name="birthday" date="birthday"/>
|
||||
<filter name="date_field" date="date_field"/>
|
||||
</search>
|
||||
`,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
QUnit.module("Control Panel (mobile)");
|
||||
|
||||
QUnit.test("Display control panel mobile", async (assert) => {
|
||||
await makeWithSearch({
|
||||
serverData,
|
||||
resModel: "foo",
|
||||
Component: ControlPanel,
|
||||
searchMenuTypes: ["filter"],
|
||||
searchViewId: false,
|
||||
});
|
||||
|
||||
assert.containsOnce(target, ".breadcrumb");
|
||||
assert.containsOnce(target, ".o_enable_searchview");
|
||||
assert.containsNone(target, ".o_searchview");
|
||||
assert.containsNone(target, ".o_toggle_searchview_full");
|
||||
|
||||
await click(target, ".o_enable_searchview");
|
||||
|
||||
assert.containsNone(target, ".breadcrumb");
|
||||
assert.containsOnce(target, ".o_enable_searchview");
|
||||
assert.containsOnce(target, ".o_searchview");
|
||||
assert.containsOnce(target, ".o_toggle_searchview_full");
|
||||
|
||||
await click(target, ".o_toggle_searchview_full");
|
||||
|
||||
assert.containsOnce(document.body, ".o_searchview.o_mobile_search");
|
||||
assert.containsN(document.body, ".o_mobile_search .o_mobile_search_button", 2);
|
||||
assert.strictEqual(
|
||||
document.body.querySelector(".o_mobile_search_header").textContent.trim(),
|
||||
"FILTER CLEAR"
|
||||
);
|
||||
assert.containsOnce(document.body, ".o_searchview.o_mobile_search .o_cp_searchview");
|
||||
assert.containsOnce(document.body, ".o_searchview.o_mobile_search .o_mobile_search_footer");
|
||||
|
||||
await click(document.body.querySelector(".o_mobile_search_button"));
|
||||
|
||||
assert.containsNone(target, ".breadcrumb");
|
||||
assert.containsOnce(target, ".o_enable_searchview");
|
||||
assert.containsOnce(target, ".o_searchview");
|
||||
assert.containsOnce(target, ".o_toggle_searchview_full");
|
||||
|
||||
await click(target, ".o_enable_searchview");
|
||||
|
||||
assert.containsOnce(target, ".breadcrumb");
|
||||
assert.containsOnce(target, ".o_enable_searchview");
|
||||
assert.containsNone(target, ".o_searchview");
|
||||
assert.containsNone(target, ".o_toggle_searchview_full");
|
||||
});
|
||||
|
||||
QUnit.test("Make a simple search in mobile mode", async (assert) => {
|
||||
await makeWithSearch({
|
||||
serverData,
|
||||
resModel: "foo",
|
||||
Component: ControlPanel,
|
||||
searchMenuTypes: ["filter"],
|
||||
searchViewFields: {
|
||||
birthday: { string: "Birthday", type: "date", store: true, sortable: true },
|
||||
},
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<field name="birthday"/>
|
||||
</search>
|
||||
`,
|
||||
});
|
||||
assert.containsNone(target, ".o_searchview");
|
||||
|
||||
await click(target, ".o_enable_searchview");
|
||||
assert.containsOnce(target, ".o_searchview");
|
||||
const input = target.querySelector(".o_searchview input");
|
||||
assert.containsNone(target, ".o_searchview_autocomplete");
|
||||
|
||||
await editSearch(target, "2022-02-14");
|
||||
assert.strictEqual(input.value, "2022-02-14", "input value should be updated");
|
||||
assert.containsOnce(target, ".o_searchview_autocomplete");
|
||||
|
||||
await triggerEvent(input, null, "keydown", { key: "Escape" });
|
||||
assert.containsNone(target, ".o_searchview_autocomplete");
|
||||
|
||||
await click(target, ".o_enable_searchview");
|
||||
assert.containsNone(target, ".o_searchview");
|
||||
});
|
||||
|
||||
QUnit.test("Control panel is shown/hide on top when scrolling", async (assert) => {
|
||||
await makeWithSearch({
|
||||
serverData,
|
||||
resModel: "foo",
|
||||
Component: ControlPanel,
|
||||
searchMenuTypes: ["filter"],
|
||||
});
|
||||
const contentHeight = 200;
|
||||
const sampleContent = document.createElement("div");
|
||||
sampleContent.style.minHeight = `${2 * contentHeight}px`;
|
||||
target.appendChild(sampleContent);
|
||||
const { maxHeight, overflow } = target.style;
|
||||
target.style.maxHeight = `${contentHeight}px`;
|
||||
target.style.overflow = "auto";
|
||||
target.scrollTo({ top: 50 });
|
||||
await nextTick();
|
||||
|
||||
assert.hasClass(
|
||||
target.querySelector(".o_control_panel"),
|
||||
"o_mobile_sticky",
|
||||
"control panel becomes sticky when the target is not on top"
|
||||
);
|
||||
target.scrollTo({ top: -50 });
|
||||
await nextTick();
|
||||
|
||||
assert.doesNotHaveClass(
|
||||
target.querySelector(".o_control_panel"),
|
||||
"o_mobile_sticky",
|
||||
"control panel is not sticky anymore"
|
||||
);
|
||||
target.style.maxHeight = maxHeight;
|
||||
target.style.overflow = overflow;
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { click, getFixture } from "@web/../tests/helpers/utils";
|
||||
import { SearchPanel } from "@web/search/search_panel/search_panel";
|
||||
import { makeWithSearch, setupControlPanelServiceRegistry } from "@web/../tests/search/helpers";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { uiService } from "@web/core/ui/ui_service";
|
||||
|
||||
import { Component, xml } from "@odoo/owl";
|
||||
|
||||
let serverData;
|
||||
let target;
|
||||
|
||||
QUnit.module("Search", (hooks) => {
|
||||
hooks.beforeEach(async () => {
|
||||
setupControlPanelServiceRegistry();
|
||||
target = getFixture();
|
||||
registry.category("services").add("ui", uiService);
|
||||
|
||||
serverData = {
|
||||
models: {
|
||||
foo: {
|
||||
fields: {
|
||||
tag_id: {
|
||||
string: "Many2One",
|
||||
type: "many2one",
|
||||
relation: "tag",
|
||||
store: true,
|
||||
sortable: true,
|
||||
},
|
||||
},
|
||||
records: [
|
||||
{ id: 1, tag_id: 2 },
|
||||
{ id: 2, tag_id: 1 },
|
||||
{ id: 3, tag_id: 1 },
|
||||
],
|
||||
},
|
||||
tag: {
|
||||
fields: {
|
||||
name: { string: "Name", type: "string" },
|
||||
},
|
||||
records: [
|
||||
{ id: 1, name: "Gold" },
|
||||
{ id: 2, name: "Silver" },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
QUnit.module("Search Panel (mobile)");
|
||||
|
||||
QUnit.test("basic search panel rendering", async (assert) => {
|
||||
class Parent extends Component {}
|
||||
Parent.components = { SearchPanel };
|
||||
Parent.template = xml`<SearchPanel/>`;
|
||||
await makeWithSearch({
|
||||
serverData,
|
||||
resModel: "foo",
|
||||
Component: Parent,
|
||||
searchViewFields: serverData.models.foo.fields,
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<searchpanel>
|
||||
<field name="tag_id" icon="fa-bars" string="Tags"/>
|
||||
</searchpanel>
|
||||
</search>`,
|
||||
});
|
||||
assert.containsOnce(target, ".o_search_panel.o_search_panel_summary");
|
||||
|
||||
await click(target, ".o_search_panel .o_search_panel_current_selection");
|
||||
assert.containsOnce(document.body, ".o_search_panel.o_mobile_search");
|
||||
assert.containsN(document.body, ".o_search_panel_category_value", 3); // All, Gold, Silver
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue