mirror of
https://github.com/bringout/oca-ocb-report.git
synced 2026-04-22 09:42:03 +02:00
19.0 vanilla
This commit is contained in:
parent
62d197ac8b
commit
184bb0e321
667 changed files with 691406 additions and 239886 deletions
|
|
@ -1,96 +0,0 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended";
|
||||
import { getFixture } from "@web/../tests/helpers/utils";
|
||||
import { getDashboardServerData } from "../utils/data";
|
||||
import { createSpreadsheetDashboard } from "../utils/dashboard_action";
|
||||
import { getBasicData } from "@spreadsheet/../tests/utils/data";
|
||||
|
||||
const { Model } = spreadsheet;
|
||||
|
||||
async function createDashboardWithModel(model) {
|
||||
return createDashboardWithData(model.exportData());
|
||||
}
|
||||
|
||||
async function createDashboardWithData(spreadsheetData) {
|
||||
const serverData = getDashboardServerData();
|
||||
const json = JSON.stringify(spreadsheetData);
|
||||
const dashboard = serverData.models["spreadsheet.dashboard"].records[0];
|
||||
dashboard.raw = json;
|
||||
dashboard.json_data = json;
|
||||
serverData.models = {
|
||||
...serverData.models,
|
||||
...getBasicData(),
|
||||
};
|
||||
await createSpreadsheetDashboard({ serverData, spreadsheetId: dashboard.id });
|
||||
return getFixture();
|
||||
}
|
||||
|
||||
QUnit.module("spreadsheet_dashboard > clickable cells");
|
||||
|
||||
QUnit.test("A link in a dashboard should be clickable", async (assert) => {
|
||||
const data = {
|
||||
sheets: [
|
||||
{
|
||||
cells: { A1: { content: "[Odoo](https://odoo.com)" } },
|
||||
},
|
||||
],
|
||||
};
|
||||
const model = new Model(data, { mode: "dashboard" });
|
||||
const target = await createDashboardWithModel(model);
|
||||
assert.containsOnce(target, ".o-dashboard-clickable-cell");
|
||||
});
|
||||
|
||||
QUnit.test("Invalid pivot/list formulas should not be clickable", async (assert) => {
|
||||
const data = {
|
||||
sheets: [
|
||||
{
|
||||
cells: {
|
||||
A1: { content: `=ODOO.PIVOT("1", "measure")` },
|
||||
A2: { content: `=ODOO.LIST("1", 1, "name")` },
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const model = new Model(data, { mode: "dashboard" });
|
||||
const target = await createDashboardWithModel(model);
|
||||
assert.containsNone(target, ".o-dashboard-clickable-cell");
|
||||
});
|
||||
|
||||
QUnit.test("pivot/list formulas should be clickable", async (assert) => {
|
||||
const data = {
|
||||
sheets: [
|
||||
{
|
||||
cells: {
|
||||
A1: { content: '=ODOO.PIVOT(1,"probability")' },
|
||||
A2: { content: '=ODOO.LIST(1, 1, "foo")' },
|
||||
},
|
||||
},
|
||||
],
|
||||
pivots: {
|
||||
1: {
|
||||
id: 1,
|
||||
colGroupBys: [],
|
||||
domain: [],
|
||||
measures: [{ field: "probability", operator: "avg" }],
|
||||
model: "partner",
|
||||
rowGroupBys: [],
|
||||
context: {},
|
||||
fieldMatching: {},
|
||||
},
|
||||
},
|
||||
lists: {
|
||||
1: {
|
||||
id: 1,
|
||||
columns: ["foo", "contact_name"],
|
||||
domain: [],
|
||||
model: "partner",
|
||||
orderBy: [],
|
||||
context: {},
|
||||
fieldMatching: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
const target = await createDashboardWithData(data);
|
||||
assert.containsN(target, ".o-dashboard-clickable-cell", 2);
|
||||
});
|
||||
|
|
@ -0,0 +1,208 @@
|
|||
import { describe, expect, test } from "@odoo/hoot";
|
||||
import { click, queryAll, queryFirst } from "@odoo/hoot-dom";
|
||||
import { createDashboardActionWithData } from "@spreadsheet_dashboard/../tests/helpers/dashboard_action";
|
||||
import { defineSpreadsheetDashboardModels } from "@spreadsheet_dashboard/../tests/helpers/data";
|
||||
import { Partner } from "@spreadsheet/../tests/helpers/data";
|
||||
import { getCellIcons } from "@spreadsheet/../tests/helpers/getters";
|
||||
import { fields } from "@web/../tests/web_test_helpers";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
|
||||
describe.current.tags("desktop");
|
||||
defineSpreadsheetDashboardModels();
|
||||
|
||||
test("A link in a dashboard should be clickable", async () => {
|
||||
const data = {
|
||||
sheets: [
|
||||
{
|
||||
cells: { A1: "[Odoo](https://odoo.com)" },
|
||||
},
|
||||
],
|
||||
};
|
||||
await createDashboardActionWithData(data);
|
||||
expect(".o-dashboard-clickable-cell").toHaveCount(1);
|
||||
});
|
||||
|
||||
test("Invalid pivot/list formulas should not be clickable", async () => {
|
||||
const data = {
|
||||
sheets: [
|
||||
{
|
||||
cells: {
|
||||
A1: '=PIVOT.VALUE("1", "measure")',
|
||||
A2: '=ODOO.LIST("1", 1, "name")',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
await createDashboardActionWithData(data);
|
||||
expect(".o-dashboard-clickable-cell").toHaveCount(0);
|
||||
});
|
||||
|
||||
test("pivot/list formulas should be clickable", async () => {
|
||||
const data = {
|
||||
version: 16,
|
||||
sheets: [
|
||||
{
|
||||
cells: {
|
||||
A1: { content: '=PIVOT.VALUE("1", "probability", "bar", "false")' },
|
||||
A2: { content: '=ODOO.LIST(1, 1, "foo")' },
|
||||
},
|
||||
},
|
||||
],
|
||||
lists: {
|
||||
1: {
|
||||
id: 1,
|
||||
columns: ["foo"],
|
||||
domain: [],
|
||||
model: "partner",
|
||||
orderBy: [],
|
||||
},
|
||||
},
|
||||
pivots: {
|
||||
1: {
|
||||
id: 1,
|
||||
colGroupBys: ["foo"],
|
||||
domain: [],
|
||||
measures: [{ field: "probability", operator: "avg" }],
|
||||
model: "partner",
|
||||
rowGroupBys: ["bar"],
|
||||
context: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
await createDashboardActionWithData(data);
|
||||
expect(".o-dashboard-clickable-cell").toHaveCount(2);
|
||||
});
|
||||
|
||||
test("list sorting clickable cell", async () => {
|
||||
Partner._fields.foo = fields.Integer({ sortable: true });
|
||||
Partner._fields.bar = fields.Boolean({ sortable: false });
|
||||
const data = {
|
||||
sheets: [
|
||||
{
|
||||
cells: {
|
||||
A1: '=ODOO.LIST.HEADER(1, "foo")',
|
||||
A2: '=ODOO.LIST(1, 1, "foo")',
|
||||
},
|
||||
},
|
||||
],
|
||||
lists: {
|
||||
1: {
|
||||
id: 1,
|
||||
columns: [],
|
||||
domain: [],
|
||||
model: "partner",
|
||||
orderBy: [],
|
||||
},
|
||||
},
|
||||
};
|
||||
const { model } = await createDashboardActionWithData(data);
|
||||
expect(getCellIcons(model, "A1")).toHaveLength(0);
|
||||
expect(".o-dashboard-clickable-cell .fa-sort").toHaveCount(1);
|
||||
|
||||
await click(queryFirst(".o-dashboard-clickable-cell .sorting-icon"));
|
||||
expect(model.getters.getListDefinition(1).orderBy).toEqual([{ name: "foo", asc: true }]);
|
||||
await animationFrame();
|
||||
expect(getCellIcons(model, "A1")).toMatchObject([{ type: "list_dashboard_sorting_asc" }]);
|
||||
|
||||
await click(queryFirst(".o-dashboard-clickable-cell"));
|
||||
expect(model.getters.getListDefinition(1).orderBy).toEqual([{ name: "foo", asc: false }]);
|
||||
await animationFrame();
|
||||
expect(getCellIcons(model, "A1")).toMatchObject([{ type: "list_dashboard_sorting_desc" }]);
|
||||
|
||||
await click(queryFirst(".o-dashboard-clickable-cell"));
|
||||
expect(getCellIcons(model, "A1")).toHaveLength(0);
|
||||
expect(model.getters.getListDefinition(1).orderBy).toEqual([]);
|
||||
});
|
||||
|
||||
test("list sort multiple fields", async () => {
|
||||
Partner._fields.foo = fields.Integer({ sortable: true });
|
||||
Partner._fields.bar = fields.Boolean({ sortable: true });
|
||||
const data = {
|
||||
sheets: [
|
||||
{
|
||||
cells: {
|
||||
A1: '=ODOO.LIST.HEADER(1, "foo")',
|
||||
A2: '=ODOO.LIST.HEADER(1, "bar")',
|
||||
},
|
||||
},
|
||||
],
|
||||
lists: {
|
||||
1: {
|
||||
id: 1,
|
||||
columns: [],
|
||||
domain: [],
|
||||
model: "partner",
|
||||
orderBy: [],
|
||||
},
|
||||
},
|
||||
};
|
||||
const { model } = await createDashboardActionWithData(data);
|
||||
|
||||
await click(queryAll(".o-dashboard-clickable-cell")[0]);
|
||||
expect(model.getters.getListDefinition(1).orderBy).toEqual([{ name: "foo", asc: true }]);
|
||||
await animationFrame();
|
||||
|
||||
await click(queryAll(".o-dashboard-clickable-cell")[1]);
|
||||
expect(model.getters.getListDefinition(1).orderBy).toEqual([
|
||||
{ name: "bar", asc: true },
|
||||
{ name: "foo", asc: true },
|
||||
]);
|
||||
|
||||
await click(queryAll(".o-dashboard-clickable-cell")[0]);
|
||||
expect(model.getters.getListDefinition(1).orderBy).toEqual([
|
||||
{ name: "foo", asc: true },
|
||||
{ name: "bar", asc: true },
|
||||
]);
|
||||
await animationFrame();
|
||||
|
||||
await click(queryAll(".o-dashboard-clickable-cell")[0]);
|
||||
expect(model.getters.getListDefinition(1).orderBy).toEqual([
|
||||
{ name: "foo", asc: false },
|
||||
{ name: "bar", asc: true },
|
||||
]);
|
||||
await animationFrame();
|
||||
|
||||
await click(queryAll(".o-dashboard-clickable-cell")[0]);
|
||||
expect(model.getters.getListDefinition(1).orderBy).toEqual([]);
|
||||
await animationFrame();
|
||||
});
|
||||
|
||||
test("Clickable ignores spill and empty cells for list sorting", async () => {
|
||||
const data = {
|
||||
sheets: [
|
||||
{
|
||||
cells: {
|
||||
A1: "foo",
|
||||
B1: "bar",
|
||||
// spill cells
|
||||
A2: "=ODOO.LIST.HEADER(1, A1:B1)",
|
||||
A3: '=ODOO.LIST(1, sequence(2), "foo")',
|
||||
},
|
||||
},
|
||||
],
|
||||
lists: {
|
||||
1: {
|
||||
id: 1,
|
||||
columns: [],
|
||||
domain: [],
|
||||
model: "partner",
|
||||
orderBy: [],
|
||||
},
|
||||
},
|
||||
};
|
||||
const { model } = await createDashboardActionWithData(data);
|
||||
expect(getCellIcons(model, "A2")).toHaveLength(0);
|
||||
expect(".o-dashboard-clickable-cell .fa-sort").toHaveCount(0);
|
||||
|
||||
expect(getCellIcons(model, "B2")).toHaveLength(0);
|
||||
expect(".o-dashboard-clickable-cell .fa-sort").toHaveCount(0);
|
||||
|
||||
expect(getCellIcons(model, "A3")).toHaveLength(0);
|
||||
expect(".o-dashboard-clickable-cell .fa-sort").toHaveCount(0);
|
||||
|
||||
expect(getCellIcons(model, "A4")).toHaveLength(0);
|
||||
expect(".o-dashboard-clickable-cell .fa-sort").toHaveCount(0);
|
||||
|
||||
expect(getCellIcons(model, "C10")).toHaveLength(0); // unrelated empty cell
|
||||
expect(".o-dashboard-clickable-cell .fa-sort").toHaveCount(0);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue