Debian Codegraph @

addons/spreadsheet/static/tests/links/model/link_menu_cells.test.js

raw
1 import { describe, expect, test } from "@odoo/hoot";
2 import { Model } from "@odoo/o-spreadsheet";
3 import { defineSpreadsheetModels } from "@spreadsheet/../tests/helpers/data";
4 import { makeSpreadsheetMockEnv } from "@spreadsheet/../tests/helpers/model";
5
6 import { setCellContent } from "@spreadsheet/../tests/helpers/commands";
7 import { getCell, getEvaluatedCell } from "@spreadsheet/../tests/helpers/getters";
8 import { getMenuServerData } from "../menu_data_utils";
9
10 describe.current.tags("headless");
11 defineSpreadsheetModels();
12
13 test("ir.menu linked based on xml id", async function () {
14 const env = await makeSpreadsheetMockEnv({ serverData: getMenuServerData() });
15 const model = new Model({}, { custom: { env } });
16 setCellContent(model, "A1", "[label](odoo://ir_menu_xml_id/test_menu)");
17 const cell = getCell(model, "A1");
18 const evaluatedCell = getEvaluatedCell(model, "A1");
19 expect(evaluatedCell.value).toBe("label", { message: "The value should be the menu name" });
20 expect(cell.content).toBe("[label](odoo://ir_menu_xml_id/test_menu)", {
21 message: "The content should be the complete markdown link",
22 });
23 expect(evaluatedCell.link.label).toBe("label", {
24 message: "The link label should be the menu name",
25 });
26 expect(evaluatedCell.link.url).toBe("odoo://ir_menu_xml_id/test_menu", {
27 message: "The link url should reference the correct menu",
28 });
29 });
30
31 test("ir.menu linked based on record id", async function () {
32 const env = await makeSpreadsheetMockEnv({ serverData: getMenuServerData() });
33 const model = new Model({}, { custom: { env } });
34 setCellContent(model, "A1", "[label](odoo://ir_menu_id/12)");
35 const cell = getCell(model, "A1");
36 const evaluatedCell = getEvaluatedCell(model, "A1");
37 expect(evaluatedCell.value).toBe("label", { message: "The value should be the menu name" });
38 expect(cell.content).toBe("[label](odoo://ir_menu_id/12)", {
39 message: "The content should be the complete markdown link",
40 });
41 expect(evaluatedCell.link.label).toBe("label", {
42 message: "The link label should be the menu name",
43 });
44 expect(evaluatedCell.link.url).toBe("odoo://ir_menu_id/12", {
45 message: "The link url should reference the correct menu",
46 });
47 });
48
49 test("ir.menu linked based on xml id which does not exists", async function () {
50 const env = await makeSpreadsheetMockEnv({ serverData: getMenuServerData() });
51 const model = new Model({}, { custom: { env } });
52 setCellContent(model, "A1", "[label](odoo://ir_menu_xml_id/does_not_exists)");
53 expect(getCell(model, "A1").content).toBe("[label](odoo://ir_menu_xml_id/does_not_exists)");
54 expect(getEvaluatedCell(model, "A1").value).toBe("#LINK");
55 expect(getEvaluatedCell(model, "A1").message).toBe(
56 "Menu does_not_exists not found. You may not have the required access rights."
57 );
58 });
59
60 test("ir.menu linked based on record id which does not exists", async function () {
61 const env = await makeSpreadsheetMockEnv({ serverData: getMenuServerData() });
62 const model = new Model({}, { custom: { env } });
63 setCellContent(model, "A1", "[label](odoo://ir_menu_id/9999)");
64 expect(getCell(model, "A1").content).toBe("[label](odoo://ir_menu_id/9999)");
65 expect(getEvaluatedCell(model, "A1").value).toBe("#LINK");
66 expect(getEvaluatedCell(model, "A1").message).toBe(
67 "Menu 9999 not found. You may not have the required access rights."
68 );
69 });
70
71 test("Odoo link cells can be imported/exported", async function () {
72 const env = await makeSpreadsheetMockEnv({ serverData: getMenuServerData() });
73 const model = new Model({}, { custom: { env } });
74 setCellContent(model, "A1", "[label](odoo://ir_menu_id/12)");
75 let cell = getCell(model, "A1");
76 let evaluatedCell = getEvaluatedCell(model, "A1");
77 expect(evaluatedCell.value).toBe("label", { message: "The value should be the menu name" });
78 expect(cell.content).toBe("[label](odoo://ir_menu_id/12)", {
79 message: "The content should be the complete markdown link",
80 });
81 expect(evaluatedCell.link.label).toBe("label", {
82 message: "The link label should be the menu name",
83 });
84 expect(evaluatedCell.link.url).toBe("odoo://ir_menu_id/12", {
85 message: "The link url should reference the correct menu",
86 });
87 const model2 = new Model(model.exportData(), { custom: { env } });
88 cell = getCell(model2, "A1");
89 evaluatedCell = getEvaluatedCell(model, "A1");
90 expect(evaluatedCell.value).toBe("label", { message: "The value should be the menu name" });
91 expect(cell.content).toBe("[label](odoo://ir_menu_id/12)", {
92 message: "The content should be the complete markdown link",
93 });
94 expect(evaluatedCell.link.label).toBe("label", {
95 message: "The link label should be the menu name",
96 });
97 expect(evaluatedCell.link.url).toBe("odoo://ir_menu_id/12", {
98 message: "The link url should reference the correct menu",
99 });
100 });