19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:27 +01:00
parent d1963a3c3a
commit 2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions

View file

@ -0,0 +1,434 @@
import { addToBoardItem } from "@board/add_to_board/add_to_board";
import { defineMailModels } from "@mail/../tests/mail_test_helpers";
import { beforeEach, describe, expect, test } from "@odoo/hoot";
import { hover, press, queryOne } from "@odoo/hoot-dom";
import { animationFrame } from "@odoo/hoot-mock";
import * as dsHelpers from "@web/../tests/core/domain_selector/domain_selector_helpers";
import {
contains,
defineModels,
fields,
getDropdownMenu,
getService,
models,
mountWithCleanup,
onRpc,
openAddCustomFilterDialog,
removeFacet,
selectGroup,
serverState,
switchView,
toggleMenuItem,
toggleSearchBarMenu,
} from "@web/../tests/web_test_helpers";
import { registry } from "@web/core/registry";
import { WebClient } from "@web/webclient/webclient";
describe.current.tags("desktop");
class Board extends models.Model {}
class Partner extends models.Model {
name = fields.Char();
foo = fields.Char({
string: "Foo",
default: "My little Foo Value",
searchable: true,
});
bar = fields.Boolean({ string: "Bar" });
int_field = fields.Integer({
string: "Integer field",
aggregator: "sum",
});
_records = [
{
id: 1,
name: "first record",
foo: "yop",
int_field: 3,
},
{
id: 2,
name: "second record",
foo: "lalala",
int_field: 5,
},
{
id: 4,
name: "aaa",
foo: "abc",
int_field: 2,
},
];
}
defineModels([Board, Partner]);
defineMailModels();
const favoriteMenuRegistry = registry.category("favoriteMenu");
function getAddToDashboardMenu() {
return getDropdownMenu(".o_add_to_board button.dropdown-toggle");
}
beforeEach(() => {
favoriteMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 });
});
test("save actions to dashboard", async () => {
expect.assertions(6);
Partner._views = {
list: '<list><field name="foo"/></list>',
};
onRpc("/board/add_to_dashboard", async (request) => {
const { params: args } = await request.json();
expect(args.context_to_save.group_by).toEqual(["foo"], {
message: "The group_by should have been saved",
});
expect(args.context_to_save.orderedBy).toEqual(
[
{
name: "foo",
asc: true,
},
],
{ message: "The orderedBy should have been saved" }
);
expect(args.context_to_save.fire).toBe("on the bayou", {
message: "The context of a controller should be passed and flattened",
});
expect(args.action_id).toBe(1, { message: "should save the correct action" });
expect(args.view_mode).toBe("list", { message: "should save the correct view type" });
return true;
});
await mountWithCleanup(WebClient);
await getService("action").doAction({
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
context: { fire: "on the bayou" },
views: [[false, "list"]],
});
expect(".o_list_view").toHaveCount(1, { message: "should display the list view" });
// Sort the list
await contains(".o_column_sortable").click();
// Group It
await toggleSearchBarMenu();
await selectGroup("foo");
// add this action to dashboard
await hover(".o_add_to_board button.dropdown-toggle");
await animationFrame();
await contains(queryOne("input", { root: getAddToDashboardMenu() })).edit("a name", {
confirm: false,
});
await contains(queryOne("button", { root: getAddToDashboardMenu() })).click();
});
test("save two searches to dashboard", async () => {
// the second search saved should not be influenced by the first
expect.assertions(2);
Partner._views = {
list: '<list><field name="foo"/></list>',
search: `
<search>
<filter name="filter_on_a" string="Filter on a" domain="[['name', 'ilike', 'a']]"/>
<filter name="filter_on_b" string="Filter on b" domain="[['name', 'ilike', 'b']]"/>
</search>
`,
};
onRpc("/board/add_to_dashboard", async (request) => {
const { params: args } = await request.json();
if (filter_count === 0) {
expect(args.domain).toEqual([["name", "ilike", "a"]], {
message: "the correct domain should be sent",
});
}
if (filter_count === 1) {
expect(args.domain).toEqual([["name", "ilike", "b"]], {
message: "the correct domain should be sent",
});
}
filter_count += 1;
return true;
});
await mountWithCleanup(WebClient);
await getService("action").doAction({
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "list"]],
});
let filter_count = 0;
// Add a first filter
await toggleSearchBarMenu();
await toggleMenuItem("Filter on a");
// Add it to dashboard
await hover(".o_add_to_board button.dropdown-toggle");
await animationFrame();
await contains(queryOne("button", { root: getAddToDashboardMenu() })).click();
// Remove it
await removeFacet("Filter on a");
// Add the second filter
await toggleSearchBarMenu();
await toggleMenuItem("Filter on b");
// Add it to dashboard
await hover(".o_add_to_board button.dropdown-toggle");
await animationFrame();
await contains(queryOne("button", { root: getAddToDashboardMenu() })).click();
});
test("save an action domain to dashboard", async () => {
// View domains are to be added to the dashboard domain
expect.assertions(1);
const viewDomain = ["name", "ilike", "a"];
const filterDomain = ["name", "ilike", "b"];
const expectedDomain = ["&", viewDomain, filterDomain];
Partner._views = {
list: '<list><field name="foo"/></list>',
search: `
<search>
<filter name="filter" string="Filter" domain="[['name', 'ilike', 'b']]"/>
</search>
`,
};
onRpc("/board/add_to_dashboard", async (request) => {
const { params: args } = await request.json();
expect(args.domain).toEqual(expectedDomain, {
message: "the correct domain should be sent",
});
return true;
});
await mountWithCleanup(WebClient);
await getService("action").doAction({
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "list"]],
domain: [viewDomain],
});
// Add a filter
await toggleSearchBarMenu();
await toggleMenuItem("Filter");
// Add it to dashboard
await hover(".o_add_to_board button.dropdown-toggle");
await animationFrame();
// add
await contains(queryOne("button", { root: getAddToDashboardMenu() })).click();
});
test("add to dashboard with no action id", async () => {
expect.assertions(2);
Partner._views = {
pivot: '<pivot><field name="foo"/></pivot>',
};
await mountWithCleanup(WebClient);
await getService("action").doAction({
id: false,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
await toggleSearchBarMenu();
expect(".o_add_to_board").toHaveCount(0);
// Sanity check
await getService("action").doAction({
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
await toggleSearchBarMenu();
expect(".o_add_to_board").toHaveCount(1);
});
test("Add a view to dashboard (keynav)", async () => {
Partner._views = {
pivot: '<pivot><field name="foo"/></pivot>',
};
// makes mouseEnter work
onRpc("/board/add_to_dashboard", () => {
expect.step("add to board");
return true;
});
await mountWithCleanup(WebClient);
await getService("action").doAction({
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
await toggleSearchBarMenu();
await hover(".o_add_to_board button.dropdown-toggle");
await animationFrame();
await contains(queryOne("input", { root: getAddToDashboardMenu() })).edit("Pipeline", {
confirm: false,
});
await press("Enter");
expect.verifySteps(["add to board"]);
});
test("Add a view with dynamic domain", async () => {
expect.assertions(1);
Partner._views = {
pivot: '<pivot><field name="foo"/></pivot>',
search: `
<search>
<filter name="filter" domain="[('user_id','=',uid)]"/>
</search>`,
};
// makes mouseEnter work
onRpc("/board/add_to_dashboard", async (request) => {
const { params: args } = await request.json();
expect(args.domain).toEqual(["&", ["int_field", "<=", 3], ["user_id", "=", 7]]);
return true;
});
await mountWithCleanup(WebClient);
await getService("action").doAction({
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
domain: [["int_field", "<=", 3]],
context: { search_default_filter: 1 },
});
await toggleSearchBarMenu();
await hover(".o_add_to_board button.dropdown-toggle");
await animationFrame();
await contains(queryOne("input", { root: getAddToDashboardMenu() })).edit("Pipeline");
});
test("Add a view to dashboard doesn't save default filters", async () => {
expect.assertions(2);
Partner._views = {
pivot: '<pivot><field name="foo"/></pivot>',
list: '<list><field name="foo"/></list>',
search: `
<search>
<filter name="filter" domain="[('foo','!=','yop')]"/>
</search>`,
};
// makes mouseEnter work
serverState.debug = "1";
onRpc("/board/add_to_dashboard", async (request) => {
const { params: args } = await request.json();
expect(args.domain).toEqual([["foo", "=", "yop"]]);
expect(args.context_to_save).toEqual({
pivot_measures: ["__count"],
pivot_column_groupby: [],
pivot_row_groupby: [],
orderedBy: [],
group_by: [],
dashboard_merge_domains_contexts: false,
});
return true;
});
onRpc("/web/domain/validate", () => {
return true;
});
await mountWithCleanup(WebClient);
await getService("action").doAction({
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [
[false, "list"],
[false, "pivot"],
],
context: { search_default_filter: 1 },
});
await switchView("pivot");
// Remove default filter ['foo', '!=', 'yop']
await removeFacet("filter");
// Add a filter ['foo', '=', 'yop']
await toggleSearchBarMenu();
await openAddCustomFilterDialog();
await contains(dsHelpers.SELECTORS.debugArea).edit(`[("foo", "=", "yop")]`);
await contains(".modal footer button").click();
// Add to dashboard
await toggleSearchBarMenu();
await hover(".o_add_to_board button.dropdown-toggle");
await animationFrame();
await contains(queryOne("input", { root: getAddToDashboardMenu() })).edit("Pipeline");
});
test("Add to my dashboard is not available in form views", async () => {
Partner._views = {
list: '<list><field name="foo"/></list>',
form: '<form><field name="foo"/></form>',
};
await mountWithCleanup(WebClient);
await getService("action").doAction({
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
context: { fire: "on the bayou" },
views: [
[false, "list"],
[false, "form"],
],
});
expect(".o_list_view").toHaveCount(1, { message: "should display the list view" });
// sanity check
await contains(".o_cp_action_menus .dropdown-toggle").click();
expect(".o-dropdown--menu .o_add_to_board").toHaveCount(1);
// open form view
await contains(".o_data_cell").click();
expect(".o_form_view").toHaveCount(1);
await contains(".o_cp_action_menus .dropdown-toggle").click();
expect(".o-dropdown--menu").toHaveCount(1);
expect(".o-dropdown--menu .o_add_to_board").toHaveCount(0);
});

View file

@ -1,526 +0,0 @@
/** @odoo-module **/
import { addToBoardItem } from "@board/add_to_board/add_to_board";
import {
click,
getFixture,
patchWithCleanup,
mouseEnter,
triggerEvent,
} from "@web/../tests/helpers/utils";
import {
applyFilter,
applyGroup,
editConditionField,
editConditionOperator,
editConditionValue,
removeFacet,
toggleAddCustomFilter,
toggleAddCustomGroup,
toggleComparisonMenu,
toggleFavoriteMenu,
toggleFilterMenu,
toggleGroupByMenu,
toggleMenuItem,
toggleMenuItemOption,
} from "@web/../tests/search/helpers";
import { createWebClient, doAction } from "@web/../tests/webclient/helpers";
import { browser } from "@web/core/browser/browser";
import { registry } from "@web/core/registry";
import LegacyAddToBoard from "board.AddToBoardMenu";
import LegacyFavoriteMenu from "web.FavoriteMenu";
import testUtils from "web.test_utils";
import { makeFakeUserService } from "@web/../tests/helpers/mock_services";
const patchDate = testUtils.mock.patchDate;
const favoriteMenuRegistry = registry.category("favoriteMenu");
let serverData;
let target;
QUnit.module("Board", (hooks) => {
hooks.beforeEach(() => {
const models = {
board: {
fields: {},
records: [],
},
partner: {
fields: {
display_name: { string: "Displayed name", type: "char", searchable: true },
foo: {
string: "Foo",
type: "char",
default: "My little Foo Value",
searchable: true,
},
bar: { string: "Bar", type: "boolean" },
int_field: {
string: "Integer field",
type: "integer",
group_operator: "sum",
},
},
records: [
{
id: 1,
display_name: "first record",
foo: "yop",
int_field: 3,
},
{
id: 2,
display_name: "second record",
foo: "lalala",
int_field: 5,
},
{
id: 4,
display_name: "aaa",
foo: "abc",
int_field: 2,
},
],
},
};
LegacyFavoriteMenu.registry.add("add-to-board-menu", LegacyAddToBoard, 10);
favoriteMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 });
serverData = { models };
target = getFixture();
});
QUnit.module("Add to dashboard");
QUnit.test("save actions to dashboard", async function (assert) {
assert.expect(6);
serverData.models.partner.fields.foo.sortable = true;
serverData.views = {
"partner,false,list": '<list><field name="foo"/></list>',
"partner,false,search": "<search></search>",
};
patchWithCleanup(browser, { setTimeout: (fn) => fn() });
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(
args.context_to_save.group_by,
["foo"],
"The group_by should have been saved"
);
assert.deepEqual(
args.context_to_save.orderedBy,
[
{
name: "foo",
asc: true,
},
],
"The orderedBy should have been saved"
);
assert.strictEqual(
args.context_to_save.fire,
"on the bayou",
"The context of a controller should be passed and flattened"
);
assert.strictEqual(args.action_id, 1, "should save the correct action");
assert.strictEqual(args.view_mode, "list", "should save the correct view type");
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
context: { fire: "on the bayou" },
views: [[false, "list"]],
});
assert.containsOnce(target, ".o_list_view", "should display the list view");
// Sort the list
await click(document.querySelector(".o_column_sortable"));
// Group It
await toggleGroupByMenu(target);
await toggleAddCustomGroup(target);
await applyGroup(target);
// add this action to dashboard
await toggleFavoriteMenu(target);
await testUtils.dom.triggerEvent($(".o_add_to_board button.dropdown-toggle"), "mouseenter");
await testUtils.fields.editInput($(".o_add_to_board input"), "a name");
await testUtils.dom.click($(".o_add_to_board .dropdown-menu button"));
});
QUnit.test("save two searches to dashboard", async function (assert) {
// the second search saved should not be influenced by the first
assert.expect(2);
patchWithCleanup(browser, { setTimeout: (fn) => fn() });
serverData.views = {
"partner,false,list": '<list><field name="foo"/></list>',
"partner,false,search": "<search></search>",
};
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
if (filter_count === 0) {
assert.deepEqual(
args.domain,
[["display_name", "ilike", "a"]],
"the correct domain should be sent"
);
}
if (filter_count === 1) {
assert.deepEqual(
args.domain,
[["display_name", "ilike", "b"]],
"the correct domain should be sent"
);
}
filter_count += 1;
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "list"]],
});
var filter_count = 0;
// Add a first filter
await toggleFilterMenu(target);
await toggleAddCustomFilter(target);
await editConditionValue(target, 0, "a");
await applyFilter(target);
// Add it to dashboard
await toggleFavoriteMenu(target);
await testUtils.dom.triggerEvent($(".o_add_to_board button.dropdown-toggle"), "mouseenter");
await testUtils.dom.click($(".o_add_to_board .dropdown-menu button"));
// Remove it
await testUtils.dom.click(target.querySelector(".o_facet_remove"));
// Add the second filter
await toggleFilterMenu(target);
await toggleAddCustomFilter(target);
await editConditionValue(target, 0, "b");
await applyFilter(target);
// Add it to dashboard
await toggleFavoriteMenu(target);
await testUtils.dom.triggerEvent(
target.querySelector(".o_add_to_board button.dropdown-toggle"),
"mouseenter"
);
await testUtils.dom.click(target.querySelector(".o_add_to_board .dropdown-menu button"));
});
QUnit.test("save a action domain to dashboard", async function (assert) {
// View domains are to be added to the dashboard domain
assert.expect(1);
patchWithCleanup(browser, { setTimeout: (fn) => fn() });
var view_domain = ["display_name", "ilike", "a"];
var filter_domain = ["display_name", "ilike", "b"];
var expected_domain = ["&", view_domain, filter_domain];
serverData.views = {
"partner,false,list": '<list><field name="foo"/></list>',
"partner,false,search": "<search></search>",
};
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(args.domain, expected_domain, "the correct domain should be sent");
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "list"]],
domain: [view_domain],
});
// Add a filter
await toggleFilterMenu(target);
await toggleAddCustomFilter(target);
await editConditionValue(target, 0, "b");
await applyFilter(target);
// Add it to dashboard
await toggleFavoriteMenu(target);
await testUtils.dom.triggerEvent(
target.querySelector(".o_add_to_board button.dropdown-toggle"),
"mouseenter"
);
// add
await testUtils.dom.click(target.querySelector(".o_add_to_board .dropdown-menu button"));
});
QUnit.test("add to dashboard with no action id", async function (assert) {
assert.expect(2);
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,search": "<search/>",
};
registry.category("services").add("user", makeFakeUserService());
const webClient = await createWebClient({ serverData });
await doAction(webClient, {
id: false,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
await toggleFavoriteMenu(target);
assert.containsNone(target, ".o_add_to_board");
// Sanity check
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
await toggleFavoriteMenu(target);
assert.containsOnce(target, ".o_add_to_board");
});
QUnit.test(
"correctly save the time ranges of a reporting view in comparison mode",
async function (assert) {
assert.expect(1);
const unpatchDate = patchDate(2020, 6, 1, 11, 0, 0);
serverData.models.partner.fields.date = {
string: "Date",
type: "date",
sortable: true,
};
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,search": '<search><filter name="Date" date="date"/></search>',
};
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(args.context_to_save.comparison, {
domains: [
{
arrayRepr: [
"&",
["date", ">=", "2020-07-01"],
["date", "<=", "2020-07-31"],
],
description: "July 2020",
},
{
arrayRepr: [
"&",
["date", ">=", "2020-06-01"],
["date", "<=", "2020-06-30"],
],
description: "June 2020",
},
],
fieldName: "date",
});
return Promise.resolve(true);
}
};
registry.category("services").add("user", makeFakeUserService());
patchWithCleanup(browser, { setTimeout: (fn) => fn() }); // makes mouseEnter work
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
// filter on July 2020
await toggleFilterMenu(target);
await toggleMenuItem(target, "Date");
await toggleMenuItemOption(target, "Date", "July");
// compare July 2020 to June 2020
await toggleComparisonMenu(target);
await toggleMenuItem(target, 0);
// add the view to the dashboard
await toggleFavoriteMenu(target);
await mouseEnter(target.querySelector(".o_add_to_board .dropdown-toggle"));
const input = target.querySelector(".o_add_to_board .dropdown-menu input");
await testUtils.fields.editInput(input, "Pipeline");
await testUtils.dom.click($(".o_add_to_board div button"));
unpatchDate();
}
);
QUnit.test("Add a view to dashboard (keynav)", async function (assert) {
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,search": "<search/>",
};
registry.category("services").add("user", makeFakeUserService());
patchWithCleanup(browser, { setTimeout: (fn) => fn() }); // makes mouseEnter work
const mockRPC = (route) => {
if (route === "/board/add_to_dashboard") {
assert.step("add to board");
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
await toggleFavoriteMenu(target);
await mouseEnter(target.querySelector(".o_add_to_board .dropdown-toggle"));
const input = target.querySelector(".o_add_to_board .dropdown-menu input");
await testUtils.fields.editInput(input, "Pipeline");
await triggerEvent(input, null, "keydown", { key: "Enter" });
assert.verifySteps(["add to board"]);
});
QUnit.test("Add a view with dynamic domain", async function (assert) {
assert.expect(1);
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,search": `
<search>
<filter name="filter" domain="[('user_id','=',uid)]"/>
</search>`,
};
registry.category("services").add("user", makeFakeUserService());
patchWithCleanup(browser, { setTimeout: (fn) => fn() }); // makes mouseEnter work
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(args.domain, ["&", ["int_field", "<=", 3], ["user_id", "=", 7]]);
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
domain: [["int_field", "<=", 3]],
context: { search_default_filter: 1 },
});
await toggleFavoriteMenu(target);
await mouseEnter(target.querySelector(".o_add_to_board .dropdown-toggle"));
const input = target.querySelector(".o_add_to_board .dropdown-menu input");
await testUtils.fields.editInput(input, "Pipeline");
await triggerEvent(input, null, "keydown", { key: "Enter" });
});
QUnit.test("Add a view to dashboard doesn't save default filters", async function (assert) {
assert.expect(2);
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,list": '<list><field name="foo"/></list>',
"partner,false,search": `
<search>
<filter name="filter" domain="[('foo','!=','yop')]"/>
</search>`,
};
registry.category("services").add("user", makeFakeUserService());
patchWithCleanup(browser, { setTimeout: (fn) => fn() }); // makes mouseEnter work
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(args.domain, [["foo", "=", "yop"]]);
assert.deepEqual(args.context_to_save, {
pivot_measures: ["__count"],
pivot_column_groupby: [],
pivot_row_groupby: [],
orderedBy: [],
group_by: [],
dashboard_merge_domains_contexts: false,
});
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [
[false, "list"],
[false, "pivot"],
],
context: { search_default_filter: 1 },
});
await click(target, ".o_switch_view.o_pivot");
// Remove default filter ['foo', '!=', 'yop']
await removeFacet(target);
// Add a filter ['foo', '=', 'yop']
await toggleFilterMenu(target);
await toggleAddCustomFilter(target);
await editConditionField(target, 0, "foo");
await editConditionOperator(target, 0, "=");
await editConditionValue(target, 0, "yop");
await applyFilter(target);
// Add to dashboard
await toggleFavoriteMenu(target);
await mouseEnter(target.querySelector(".o_add_to_board .dropdown-toggle"));
const input = target.querySelector(".o_add_to_board .dropdown-menu input");
await testUtils.fields.editInput(input, "Pipeline");
await triggerEvent(input, null, "keydown", { key: "Enter" });
});
});

View file

@ -0,0 +1,711 @@
import { BoardAction } from "@board/board_action";
import { defineMailModels } from "@mail/../tests/mail_test_helpers";
import { beforeEach, describe, expect, test } from "@odoo/hoot";
import { queryAllTexts, queryOne } from "@odoo/hoot-dom";
import {
contains,
defineModels,
fields,
mockService,
models,
mountView,
onRpc,
serverState,
} from "@web/../tests/web_test_helpers";
class Board extends models.Model {}
class Partner extends models.Model {
name = fields.Char({ string: "Displayed name", searchable: true });
foo = fields.Char({
string: "Foo",
default: "My little Foo Value",
searchable: true,
});
bar = fields.Boolean({ string: "Bar" });
int_field = fields.Integer({
string: "Integer field",
aggregator: "sum",
});
_records = [
{
id: 1,
name: "first record",
foo: "yop",
int_field: 3,
},
{
id: 2,
name: "second record",
foo: "lalala",
int_field: 5,
},
{
id: 4,
name: "aaa",
foo: "abc",
int_field: 2,
},
];
_views = {
"form,100000001": "<form/>",
"search,100000002": "<search/>",
"list,4": '<list string="Partner"><field name="foo"/></list>',
};
}
defineModels([Board, Partner]);
defineMailModels();
beforeEach(() => {
BoardAction.cache = {};
});
describe.tags("desktop");
describe("board_desktop", () => {
test("display the no content helper", async () => {
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column></column>
</board>
</form>`,
});
expect(".o_view_nocontent").toHaveCount(1);
});
test("basic functionality, with one sub action", async () => {
expect.assertions(19);
onRpc("/web/action/load", () => {
expect.step("load action");
return {
res_model: "partner",
views: [[4, "list"]],
};
});
onRpc("web_search_read", (args) => {
expect(args.kwargs.domain).toEqual([["foo", "!=", "False"]], {
message: "the domain should be passed",
});
expect(args.kwargs.context.orderedBy).toEqual(
[
{
name: "foo",
asc: true,
},
],
{
message:
"orderedBy is present in the search read when specified on the custom action",
}
);
});
onRpc("/web/view/edit_custom", () => {
expect.step("edit custom");
return true;
});
onRpc("partner", "get_views", (args) => {
expect(args.kwargs.views.find((v) => v[1] === "list")).toEqual([4, "list"]);
});
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
expect(".o-dashboard-header").toHaveCount(1, { message: "should have rendered a header" });
expect("div.o-dashboard-layout-2-1").toHaveCount(1, {
message: "should have rendered a div with layout",
});
expect("td.o_list_record_selector").toHaveCount(0, {
message: "td should not have a list selector",
});
expect("h3 span:contains(ABC)").toHaveCount(1, {
message: "should have rendered a header with action string",
});
expect("tr.o_data_row").toHaveCount(3, { message: "should have rendered 3 data rows" });
expect(".o-dashboard-action .o_list_view").toHaveCount(1);
await contains("h3 i.fa-window-minimize").click();
expect(".o-dashboard-action .o_list_view").toHaveCount(0);
await contains("h3 i.fa-window-maximize").click();
// content is visible again
expect(".o-dashboard-action .o_list_view").toHaveCount(1);
expect.verifySteps(["load action", "edit custom", "edit custom"]);
// header should have dropdown with correct image
expect(
".o-dashboard-header .dropdown img[data-src='/board/static/img/layout_2-1.png']"
).toHaveCount(1);
// change layout to 1-1
await contains(".o-dashboard-header .dropdown img").click();
await contains(".dropdown-item:nth-child(2)").click();
expect(
".o-dashboard-header .dropdown img[data-src='/board/static/img/layout_1-1.png']"
).toHaveCount(1);
expect("div.o-dashboard-layout-1-1").toHaveCount(1, {
message: "should have rendered a div with layout",
});
expect.verifySteps(["edit custom"]);
});
test("views in the dashboard do not have a control panel", async () => {
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [
[4, "list"],
[5, "form"],
],
}));
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
expect(".o-dashboard-action .o_list_view").toHaveCount(1);
expect(".o-dashboard-action .o_control_panel").toHaveCount(0);
});
test("can render an action without view_mode attribute", async () => {
// The view_mode attribute is automatically set to the 'action' nodes when
// the action is added to the dashboard using the 'Add to dashboard' button
// in the searchview. However, other dashboard views can be written by hand
// (see openacademy tutorial), and in this case, we don't want hardcode
// action's params (like context or domain), as the dashboard can directly
// retrieve them from the action. Same applies for the view_type, as the
// first view of the action can be used, by default.
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [
[4, "list"],
[false, "form"],
],
}));
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
expect(".o-dashboard-action .o_list_view").toHaveCount(1);
});
test("can sort a sub list", async () => {
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "list"]],
}));
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
expect(queryAllTexts("tr.o_data_row")).toEqual(["yop", "lalala", "abc"], {
message: "should have correct initial data",
});
await contains("th.o_column_sortable:contains(Foo)").click();
expect(queryAllTexts("tr.o_data_row")).toEqual(["abc", "lalala", "yop"], {
message: "data should have been sorted",
});
});
test("can open a record", async () => {
expect.assertions(1);
mockService("action", {
doAction(action) {
expect(action).toEqual({
res_id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "form"]],
});
return true;
},
});
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "list"]],
}));
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
await contains("tr.o_data_row td:contains(yop)").click();
});
test("can open record using action form view", async () => {
expect.assertions(1);
Partner._views["form,5"] = '<form string="Partner"><field name="name"/></form>';
mockService("action", {
doAction(action) {
expect(action).toEqual({
res_id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[5, "form"]],
});
return true;
},
});
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [
[4, "list"],
[5, "form"],
],
}));
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
await contains("tr.o_data_row td:contains(yop)").click();
});
test("can drag and drop a view", async () => {
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "list"]],
}));
onRpc("/web/view/edit_custom", () => {
expect.step("edit custom");
return true;
});
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
expect('.o-dashboard-column[data-idx="0"] .o-dashboard-action').toHaveCount(1);
expect('.o-dashboard-column[data-idx="1"] .o-dashboard-action').toHaveCount(0);
await contains('.o-dashboard-column[data-idx="0"] .o-dashboard-action-header').dragAndDrop(
'.o-dashboard-column[data-idx="1"]'
);
expect('.o-dashboard-column[data-idx="0"] .o-dashboard-action').toHaveCount(0);
expect('.o-dashboard-column[data-idx="1"] .o-dashboard-action').toHaveCount(1);
expect.verifySteps(["edit custom"]);
});
test("twice the same action in a dashboard", async () => {
Partner._views["kanban,5"] = `
<kanban>
<templates>
<t t-name="card">
<field name="foo"/>
</t>
</templates>
</kanban>`;
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [
[4, "list"],
[5, "kanban"],
],
}));
onRpc("/web/view/edit_custom", () => {
expect.step("edit custom");
return true;
});
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{}" view_mode="list" string="ABC" name="51" domain="[]"></action>
<action context="{}" view_mode="kanban" string="DEF" name="51" domain="[]"></action>
</column>
</board>
</form>`,
});
expect(".o-dashboard-action:eq(0) .o_list_view").toHaveCount(1);
expect(".o-dashboard-action:eq(1) .o_kanban_view").toHaveCount(1);
});
test("non-existing action in a dashboard", async () => {
onRpc(
"/web/action/load",
() =>
// server answer if the action doesn't exist anymore
false
);
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
expect("h3 span:contains(ABC)").toHaveCount(1);
expect(".o-dashboard-action div:contains(Invalid action)").toHaveCount(1);
});
test(`clicking on a kanban's button should trigger the action`, async () => {
expect.assertions(4);
Partner._views.kanban = `
<kanban>
<templates>
<t t-name="card">
<field name="foo"/>
<button name="sitting_on_a_park_bench" type="object">Eying little girls with bad intent</button>
</t>
</templates>
</kanban>`;
mockService("action", {
doActionButton(params) {
expect(params.resModel).toBe("partner");
expect(params.resId).toBe(1);
expect(params.name).toBe("sitting_on_a_park_bench");
expect(params.type).toBe("object");
},
});
onRpc("/web/action/load", () => ({
res_model: "partner",
view_mode: "kanban",
views: [[false, "kanban"]],
}));
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action name="149" string="Partner" view_mode="kanban" id="action_0_1"></action>
</column>
</board>
</form>`,
});
await contains(".btn.oe_kanban_action").click();
});
test("Views should be loaded in the user's language", async () => {
expect.assertions(2);
serverState.lang = "fr_FR";
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "list"]],
}));
onRpc("get_views", (args) => {
expect(args.kwargs.context.lang).toBe("fr_FR");
});
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'lang': 'en_US'}" view_mode="list" string="ABC" name="51" domain="[]"></action>
</column>
</board>
</form>`,
});
});
test("Dashboard should use correct groupby", async () => {
expect.assertions(1);
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "list"]],
}));
onRpc("web_read_group", (args) => {
expect(args.kwargs.groupby).toEqual(["bar"]);
});
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'group_by': ['bar']}" string="ABC" name="51"></action>
</column>
</board>
</form>`,
});
});
test("Dashboard should use correct groupby when defined as a string of one field", async () => {
expect.assertions(1);
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "list"]],
}));
onRpc("web_read_group", ({ kwargs }) => {
expect(kwargs.groupby).toEqual(["bar"]);
});
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'group_by': 'bar'}" string="ABC" name="51"></action>
</column>
</board>
</form>`,
});
});
test("click on a cell of pivot view inside dashboard", async () => {
Partner._views["pivot,4"] = '<pivot><field name="int_field" type="measure"/></pivot>';
mockService("action", {
doAction(action) {
expect.step("do action");
expect(action.views).toEqual([
[false, "list"],
[false, "form"],
]);
},
});
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "pivot"]],
}));
onRpc("formatted_read_group", (args) => {
expect(args.kwargs.groupby).toEqual([]);
});
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action view_mode="pivot" string="ABC" name="51"></action>
</column>
</board>
</form>`,
});
expect.verifySteps([]);
await contains(".o_pivot_view .o_pivot_cell_value").click();
expect.verifySteps(["do action"]);
});
test("graphs in dashboard aren't squashed", async () => {
Partner._views["graph,4"] = '<graph><field name="int_field" type="measure"/></graph>';
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "graph"]],
}));
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action string="ABC" name="51"></action>
</column>
</board>
</form>`,
});
expect(".o-dashboard-action .o_graph_renderer").toHaveCount(1);
expect(queryOne(".o-dashboard-action .o_graph_renderer canvas").offsetHeight).toBe(300);
});
test("pivot view with property in pivot_column_groupby", async function () {
Partner._fields.properties_definition = fields.PropertiesDefinition();
Partner._fields.properties_definition = fields.PropertiesDefinition();
Partner._fields.parent_id = fields.Many2one({ relation: "partner" });
Partner._fields.properties = fields.Properties({
definition_record: "parent_id",
definition_record_field: "properties_definition",
});
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[false, "pivot"]],
}));
onRpc(({ method, kwargs }) => {
if (method === "get_property_definition") {
return {};
} else if (method === "formatted_read_grouping_sets") {
return [
[{ __count: 3, __extra_domain: [] }],
[
{
"properties.my_char": false,
__extra_domain: [["properties.my_char", "=", false]],
__count: 2,
},
{
"properties.my_char": "aaa",
__extra_domain: [["properties.my_char", "=", "aaa"]],
__count: 1,
},
],
];
}
});
await mountView({
type: "form",
resModel: "board",
arch: `
<form js_class="board">
<board style="2-1">
<column>
<action context="{'pivot_column_groupby':['properties.my_char']}"/>
</column>
</board>
</form>`,
});
expect(queryAllTexts(".o_pivot_cell_value div")).toEqual(["2", "1", "3"]);
});
});
describe.tags("mobile");
describe("board_mobile", () => {
test("can't switch views in the dashboard", async () => {
Partner._views["list,4"] = '<list string="Partner"><field name="foo"/></list>';
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "list"]],
}));
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
expect(".o-dashboard-header").toHaveCount(0, {
message: "Couldn't allow user to Change layout",
});
expect(".o-dashboard-layout-1").toHaveCount(1, {
message: "The display layout is force to 1",
});
expect(".o-dashboard-action .o_control_panel").not.toHaveCount();
expect(".o-dashboard-action-header .fa-close").toHaveCount(0, {
message: "Should not have a close action button",
});
});
test("Correctly soft switch to '1' layout on small screen", async () => {
Partner._views["list,4"] = '<list string="Partner"><field name="foo"/></list>';
onRpc("/web/action/load", () => ({
res_model: "partner",
views: [[4, "list"]],
}));
await mountView({
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
});
expect(".o-dashboard-layout-1").toHaveCount(1, {
message: "The display layout is force to 1",
});
expect(".o-dashboard-column").toHaveCount(1, {
message: "The display layout is force to 1 column",
});
expect(".o-dashboard-action").toHaveCount(2, {
message: "The display should contains the 2 actions",
});
});
});

View file

@ -1,907 +0,0 @@
/** @odoo-module **/
import { BoardAction } from "@board/board_action";
import { fakeCookieService } from "@web/../tests/helpers/mock_services";
import { click, dragAndDrop, getFixture, patchWithCleanup } from "@web/../tests/helpers/utils";
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
import { registry } from "@web/core/registry";
import { session } from "@web/session";
import AbstractModel from "web.AbstractModel";
import AbstractView from "web.AbstractView";
import ListView from "web.ListView";
import legacyViewRegistry from "web.view_registry";
const serviceRegistry = registry.category("services");
let serverData;
let target;
QUnit.module("Board", (hooks) => {
hooks.beforeEach(async () => {
target = getFixture();
BoardAction.cache = {};
serverData = {
models: {
board: {
fields: {},
records: [],
},
partner: {
fields: {
display_name: { string: "Displayed name", type: "char", searchable: true },
foo: {
string: "Foo",
type: "char",
default: "My little Foo Value",
searchable: true,
},
bar: { string: "Bar", type: "boolean" },
int_field: {
string: "Integer field",
type: "integer",
group_operator: "sum",
},
},
records: [
{
id: 1,
display_name: "first record",
foo: "yop",
int_field: 3,
},
{
id: 2,
display_name: "second record",
foo: "lalala",
int_field: 5,
},
{
id: 4,
display_name: "aaa",
foo: "abc",
int_field: 2,
},
],
},
},
views: {
"partner,100000001,form": "<form/>",
"partner,100000002,search": "<search/>",
},
};
setupViewRegistries();
});
QUnit.module("BoardView");
QUnit.test("display the no content helper", async function (assert) {
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column></column>
</board>
</form>`,
});
assert.containsOnce(target, ".o_view_nocontent");
});
QUnit.test("basic functionality, with one sub action", async function (assert) {
assert.expect(23);
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
assert.step("load action");
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (route === "/web/dataset/call_kw/partner/web_search_read") {
assert.deepEqual(
args.kwargs.domain,
[["foo", "!=", "False"]],
"the domain should be passed"
);
assert.deepEqual(
args.kwargs.context.orderedBy,
[
{
name: "foo",
asc: true,
},
],
"orderedBy is present in the search read when specified on the custom action"
);
}
if (route === "/web/view/edit_custom") {
assert.step("edit custom");
return Promise.resolve(true);
}
if (args.method === "get_views" && args.model == "partner") {
assert.deepEqual(
args.kwargs.views.find((v) => v[1] === "list"),
[4, "list"]
);
}
},
});
assert.containsOnce(target, ".o-dashboard-header", "should have rendered a header");
assert.containsOnce(
target,
"div.o-dashboard-layout-2-1",
"should have rendered a div with layout"
);
assert.containsNone(
target,
"td.o_list_record_selector",
"td should not have a list selector"
);
assert.containsOnce(
target,
"h3 span:contains(ABC)",
"should have rendered a header with action string"
);
assert.containsN(target, "tr.o_data_row", 3, "should have rendered 3 data rows");
assert.containsOnce(target, ".o-dashboard-action .o_list_view");
await click(target, "h3 i.fa-window-minimize");
assert.containsNone(target, ".o-dashboard-action .o_list_view");
await click(target, "h3 i.fa-window-maximize");
// content is visible again
assert.containsOnce(target, ".o-dashboard-action .o_list_view");
assert.verifySteps(["load action", "edit custom", "edit custom"]);
// header should have dropdown with correct image
assert.containsOnce(
target,
".o-dashboard-header .dropdown img[data-src='/board/static/img/layout_2-1.png']"
);
// change layout to 1-1
await click(target, ".o-dashboard-header .dropdown img");
await click(target, ".o-dashboard-header .dropdown-item:nth-child(2)");
assert.containsOnce(
target,
".o-dashboard-header .dropdown img[data-src='/board/static/img/layout_1-1.png']"
);
assert.containsOnce(
target,
"div.o-dashboard-layout-1-1",
"should have rendered a div with layout"
);
assert.verifySteps(["edit custom"]);
});
QUnit.test("views in the dashboard do not have a control panel", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [
[4, "list"],
[5, "form"],
],
});
}
},
});
assert.containsOnce(target, ".o-dashboard-action .o_list_view");
assert.containsNone(target, ".o-dashboard-action .o_control_panel");
});
QUnit.test("can render an action without view_mode attribute", async function (assert) {
// The view_mode attribute is automatically set to the 'action' nodes when
// the action is added to the dashboard using the 'Add to dashboard' button
// in the searchview. However, other dashboard views can be written by hand
// (see openacademy tutorial), and in this case, we don't want hardcode
// action's params (like context or domain), as the dashboard can directly
// retrieve them from the action. Same applies for the view_type, as the
// first view of the action can be used, by default.
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [
[4, "list"],
[false, "form"],
],
});
}
},
});
assert.containsOnce(target, ".o-dashboard-action .o_list_view");
});
QUnit.test("can sort a sub list", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
serverData.models.partner.fields.foo.sortable = true;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
},
});
assert.strictEqual(
$("tr.o_data_row").text(),
"yoplalalaabc",
"should have correct initial data"
);
await click($(target).find("th.o_column_sortable:contains(Foo)")[0]);
assert.strictEqual(
$("tr.o_data_row").text(),
"abclalalayop",
"data should have been sorted"
);
});
QUnit.test("can open a record", async function (assert) {
assert.expect(1);
const fakeActionService = {
start() {
return {
doAction(action) {
assert.deepEqual(action, {
res_id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "form"]],
});
return Promise.resolve(true);
},
};
},
};
serviceRegistry.add("action", fakeActionService, { force: true });
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
serverData.models.partner.fields.foo.sortable = true;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
},
});
await click($(target).find("tr.o_data_row td:contains(yop)")[0]);
});
QUnit.test("can open record using action form view", async function (assert) {
assert.expect(1);
const fakeActionService = {
start() {
return {
doAction(action) {
assert.deepEqual(action, {
res_id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[5, "form"]],
});
return Promise.resolve(true);
},
};
},
};
serviceRegistry.add("action", fakeActionService, { force: true });
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
serverData.views["partner,5,form"] =
'<form string="Partner"><field name="display_name"/></form>';
serverData.models.partner.fields.foo.sortable = true;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [
[4, "list"],
[5, "form"],
],
});
}
},
});
await click($(target).find("tr.o_data_row td:contains(yop)")[0]);
});
QUnit.skip("can drag and drop a view", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (route === "/web/view/edit_custom") {
assert.step("edit custom");
return Promise.resolve(true);
}
},
});
assert.strictEqual(
target.querySelectorAll('.o-dashboard-column[data-idx="0"] .o-dashboard-action').length,
1
);
assert.strictEqual(
target.querySelectorAll('.o-dashboard-column[data-idx="1"] .o-dashboard-action').length,
0
);
await dragAndDrop(
'.o-dashboard-column[data-idx="0"] .o-dashboard-action-header',
'.o-dashboard-column[data-idx="1"]'
);
assert.strictEqual(
target.querySelectorAll('.o-dashboard-column[data-idx="0"] .o-dashboard-action').length,
0
);
assert.strictEqual(
target.querySelectorAll('.o-dashboard-column[data-idx="1"] .o-dashboard-action').length,
1
);
assert.verifySteps(["edit custom"]);
});
QUnit.test("twice the same action in a dashboard", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
serverData.views["partner,5,kanban"] = `
<kanban>
<templates>
<t t-name="kanban-box">
<div><field name="foo"/></div>
</t>
</templates>
</kanban>`;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{}" view_mode="list" string="ABC" name="51" domain="[]"></action>
<action context="{}" view_mode="kanban" string="DEF" name="51" domain="[]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [
[4, "list"],
[5, "kanban"],
],
});
}
if (route === "/web/view/edit_custom") {
assert.step("edit custom");
return Promise.resolve(true);
}
},
});
var $firstAction = $(".o-dashboard-action:eq(0)");
assert.strictEqual(
$firstAction.find(".o_list_view").length,
1,
"list view should be displayed in 'ABC' block"
);
var $secondAction = $(".o-dashboard-action:eq(1)");
assert.strictEqual(
$secondAction.find(".o_kanban_view").length,
1,
"kanban view should be displayed in 'DEF' block"
);
});
QUnit.test("clicking on a kanban's button should trigger the action", async function (assert) {
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
// server answer if the action doesn't exist anymore
return Promise.resolve(false);
}
},
});
assert.containsOnce(target, "h3 span:contains(ABC)");
assert.containsOnce(target, "div.text-center:contains(Invalid action)");
});
QUnit.test("twice the same action in a dashboard", async function (assert) {
assert.expect(4);
serverData.views["partner,false,kanban"] = `
<kanban>
<templates>
<t t-name="kanban-box">
<div>
<div><field name="foo"/></div>
<button name="sitting_on_a_park_bench" type="object">Eying little girls with bad intent</button>
</div>
</t>
</templates>
</kanban>`;
const view = await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action name="149" string="Partner" view_mode="kanban" id="action_0_1"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
view_mode: "kanban",
views: [[false, "kanban"]],
});
}
if (route === "/web/dataset/search_read") {
return Promise.resolve({ records: [{ foo: "aqualung" }] });
}
},
});
patchWithCleanup(view.env.services.action, {
doActionButton(params) {
assert.strictEqual(params.resModel, "partner");
assert.strictEqual(params.resId, 1);
assert.strictEqual(params.name, "sitting_on_a_park_bench");
assert.strictEqual(params.type, "object");
},
});
await click(document.querySelector(".btn.oe_kanban_action"));
});
QUnit.test("Views should be loaded in the user's language", async function (assert) {
assert.expect(2);
patchWithCleanup(session.user_context, { lang: "fr_FR" });
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'lang': 'en_US'}" view_mode="list" string="ABC" name="51" domain="[]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (args.method === "get_views") {
assert.strictEqual(args.kwargs.context.lang, "fr_FR");
}
},
});
});
QUnit.test("Dashboard should use correct groupby", async function (assert) {
assert.expect(1);
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'group_by': ['bar']}" string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (args.method === "web_read_group") {
assert.deepEqual(args.kwargs.groupby, ["bar"]);
}
},
});
});
QUnit.test("Dashboard should read comparison from context", async function (assert) {
assert.expect(2);
serverData.views["partner,4,pivot"] =
'<pivot><field name="int_field" type="measure"/></pivot>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action
name="356"
string="Sales Analysis pivot"
view_mode="pivot"
context="{
'comparison': {
'fieldName': 'date',
'domains': [
{
'arrayRepr': [],
'description': 'February 2023',
},
{
'arrayRepr': [],
'description': 'January 2023',
},
]
},
}"
/>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "pivot"]],
});
}
},
});
const columns = document.querySelectorAll(".o_pivot_origin_row");
assert.equal(columns[0].firstChild.textContent, "January 2023");
assert.equal(columns[1].firstChild.textContent, "February 2023");
});
QUnit.test(
"Dashboard should use correct groupby when defined as a string of one field",
async function (assert) {
assert.expect(1);
serverData.views["partner,4,list"] =
'<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'group_by': 'bar'}" string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (args.method === "web_read_group") {
assert.deepEqual(args.kwargs.groupby, ["bar"]);
}
},
});
}
);
QUnit.test(
"Dashboard should pass groupbys to legacy views",
async function (assert) {
assert.expect(2);
const TestModel = AbstractModel.extend({
__load: function (params) {
assert.deepEqual(params.groupedBy, ["bar"]);
}
});
const TestGridView = AbstractView.extend({
viewType: 'test_grid',
config: Object.assign({}, AbstractView.prototype.config, {
Model: TestModel,
}),
init: function (viewInfo, params) {
this._super.apply(this, arguments);
assert.deepEqual(params.groupBy, ["bar"]);
this.loadParams.groupedBy = params.groupBy;
}
});
legacyViewRegistry.add("test_grid", TestGridView);
serverData.views["partner,false,test_grid"] = `<div/>`;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'group_by': 'bar'}" string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[false, "test_grid"]],
});
}
},
});
delete legacyViewRegistry.map.test_grid
}
);
QUnit.test("click on a cell of pivot view inside dashboard", async function (assert) {
serverData.views["partner,4,pivot"] =
'<pivot><field name="int_field" type="measure"/></pivot>';
const fakeActionService = {
start() {
return {
doAction(action) {
assert.step("do action");
assert.deepEqual(action.views, [
[false, "list"],
[false, "form"],
]);
},
};
},
};
serviceRegistry.add("action", fakeActionService, { force: true });
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action view_mode="pivot" string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "pivot"]],
});
}
if (args.method === "web_read_group") {
assert.deepEqual(args.kwargs.groupby, ["bar"]);
}
},
});
assert.verifySteps([]);
await click(document.querySelector(".o_pivot_view .o_pivot_cell_value"));
assert.verifySteps(["do action"]);
});
QUnit.test("graphs in dashboard aren't squashed", async function (assert) {
registry.category("services").add("cookie", fakeCookieService);
serverData.views["partner,4,graph"] =
'<graph><field name="int_field" type="measure"/></graph>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "graph"]],
});
}
},
});
assert.containsOnce(target, ".o-dashboard-action .o_graph_renderer");
assert.strictEqual(
target.querySelector(".o-dashboard-action .o_graph_renderer canvas").offsetHeight,
300
);
});
QUnit.test("Carry over the filter to legacy views", async function (assert) {
const TestView = ListView.extend({
viewType: "test_view",
});
legacyViewRegistry.add("test_view", TestView);
serverData.views["partner,false,test_view"] = `<tree string="Partner"></tree>`;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action string="ABC" name="Partners Action 1" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return {
id: 1,
name: "Partners Action 1",
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "test_view"]],
};
}
if (route === "/web/dataset/search_read") {
assert.deepEqual(args.domain, [["foo", "!=", "False"]]);
}
},
});
});
});

View file

@ -1,124 +0,0 @@
/** @odoo-module **/
import { getFixture } from "@web/../tests/helpers/utils";
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
let serverData;
let target;
QUnit.module("Board", (hooks) => {
hooks.beforeEach(async () => {
target = getFixture();
serverData = {
models: {
board: {
fields: {},
records: [],
},
partner: {
fields: {
foo: {
string: "Foo",
type: "char",
default: "My little Foo Value",
searchable: true,
},
},
records: [
{
id: 1,
foo: "yop",
},
],
},
},
views: {
"partner,100000001,form": "<form/>",
"partner,100000002,search": "<search/>",
},
};
setupViewRegistries();
});
QUnit.module("BoardView");
QUnit.test("can't switch views in the dashboard", async (assert) => {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
},
});
assert.containsNone(target, ".o-dashboard-header", "Couldn't allow user to Change layout");
assert.containsOnce(target, ".o-dashboard-layout-1", "The display layout is force to 1");
assert.isNotVisible(
target.querySelector(".o-dashboard-action .o_control_panel"),
"views in the dashboard do not have a control panel"
);
assert.containsNone(
target,
".o-dashboard-action-header .fa-close",
"Should not have a close action button"
);
});
QUnit.test("Correctly soft switch to '1' layout on small screen", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
},
});
assert.containsOnce(target, ".o-dashboard-layout-1", "The display layout is force to 1");
assert.containsOnce(
target,
".o-dashboard-column",
"The display layout is force to 1 column"
);
assert.containsN(
target,
".o-dashboard-action",
2,
"The display should contains the 2 actions"
);
});
});