| 1 |
import { describe, expect, test } from "@odoo/hoot"; |
| 2 |
import { createSpreadsheetWithChart } from "@spreadsheet/../tests/helpers/chart"; |
| 3 |
import { createBasicChart } from "@spreadsheet/../tests/helpers/commands"; |
| 4 |
import { defineSpreadsheetModels } from "@spreadsheet/../tests/helpers/data"; |
| 5 |
import { makeMockEnv } from "@web/../tests/web_test_helpers"; |
| 6 |
|
| 7 |
import { Model } from "@odoo/o-spreadsheet"; |
| 8 |
|
| 9 |
const chartId = "uuid1"; |
| 10 |
|
| 11 |
describe.current.tags("headless"); |
| 12 |
|
| 13 |
defineSpreadsheetModels(); |
| 14 |
|
| 15 |
test("Links between charts and ir.menus are correctly imported/exported", async function () { |
| 16 |
const env = await makeMockEnv(); |
| 17 |
const model = new Model({}, { custom: { env } }); |
| 18 |
createBasicChart(model, chartId); |
| 19 |
model.dispatch("LINK_ODOO_MENU_TO_CHART", { |
| 20 |
chartId, |
| 21 |
odooMenuId: 1, |
| 22 |
}); |
| 23 |
const exportedData = model.exportData(); |
| 24 |
expect(exportedData.chartOdooMenusReferences[chartId]).toBe(1, { |
| 25 |
message: "Link to odoo menu is exported", |
| 26 |
}); |
| 27 |
const importedModel = new Model(exportedData, { custom: { env } }); |
| 28 |
const chartMenu = importedModel.getters.getChartOdooMenu(chartId); |
| 29 |
expect(chartMenu.id).toBe(1, { message: "Link to odoo menu is imported" }); |
| 30 |
}); |
| 31 |
|
| 32 |
test("Can undo-redo a LINK_ODOO_MENU_TO_CHART", async function () { |
| 33 |
const env = await makeMockEnv(); |
| 34 |
const model = new Model({}, { custom: { env } }); |
| 35 |
createBasicChart(model, chartId); |
| 36 |
model.dispatch("LINK_ODOO_MENU_TO_CHART", { |
| 37 |
chartId, |
| 38 |
odooMenuId: 1, |
| 39 |
}); |
| 40 |
expect(model.getters.getChartOdooMenu(chartId).id).toBe(1); |
| 41 |
model.dispatch("REQUEST_UNDO"); |
| 42 |
expect(model.getters.getChartOdooMenu(chartId)).toBe(undefined); |
| 43 |
model.dispatch("REQUEST_REDO"); |
| 44 |
expect(model.getters.getChartOdooMenu(chartId).id).toBe(1); |
| 45 |
}); |
| 46 |
|
| 47 |
test("link is removed when figure is deleted", async function () { |
| 48 |
const env = await makeMockEnv(); |
| 49 |
const model = new Model({}, { custom: { env } }); |
| 50 |
createBasicChart(model, chartId); |
| 51 |
model.dispatch("LINK_ODOO_MENU_TO_CHART", { |
| 52 |
chartId, |
| 53 |
odooMenuId: 1, |
| 54 |
}); |
| 55 |
expect(model.getters.getChartOdooMenu(chartId).id).toBe(1); |
| 56 |
model.dispatch("DELETE_FIGURE", { |
| 57 |
sheetId: model.getters.getActiveSheetId(), |
| 58 |
figureId: model.getters.getFigureIdFromChartId(chartId), |
| 59 |
}); |
| 60 |
expect(model.getters.getChartOdooMenu(chartId)).toBe(undefined); |
| 61 |
}); |
| 62 |
|
| 63 |
test("Links of Odoo charts are duplicated when duplicating a sheet", async function () { |
| 64 |
const { model } = await createSpreadsheetWithChart({ type: "odoo_pie" }); |
| 65 |
const sheetId = model.getters.getActiveSheetId(); |
| 66 |
const secondSheetId = "mySecondSheetId"; |
| 67 |
const chartId = model.getters.getChartIds(sheetId)[0]; |
| 68 |
model.dispatch("DUPLICATE_SHEET", { |
| 69 |
sheetId, |
| 70 |
sheetIdTo: secondSheetId, |
| 71 |
sheetNameTo: "Next Name", |
| 72 |
}); |
| 73 |
const newChartId = model.getters.getChartIds(secondSheetId)[0]; |
| 74 |
expect(model.getters.getChartOdooMenu(newChartId)).toEqual( |
| 75 |
model.getters.getChartOdooMenu(chartId) |
| 76 |
); |
| 77 |
}); |
| 78 |
|
| 79 |
test("Links of standard charts are duplicated when duplicating a sheet", async function () { |
| 80 |
const env = await makeMockEnv(); |
| 81 |
const model = new Model({}, { custom: { env } }); |
| 82 |
const sheetId = model.getters.getActiveSheetId(); |
| 83 |
const secondSheetId = "mySecondSheetId"; |
| 84 |
createBasicChart(model, chartId); |
| 85 |
model.dispatch("LINK_ODOO_MENU_TO_CHART", { |
| 86 |
chartId, |
| 87 |
odooMenuId: 1, |
| 88 |
}); |
| 89 |
model.dispatch("DUPLICATE_SHEET", { |
| 90 |
sheetId, |
| 91 |
sheetIdTo: secondSheetId, |
| 92 |
sheetNameTo: "Next Name", |
| 93 |
}); |
| 94 |
const newChartId = model.getters.getChartIds(secondSheetId)[0]; |
| 95 |
expect(model.getters.getChartOdooMenu(newChartId)).toEqual( |
| 96 |
model.getters.getChartOdooMenu(chartId) |
| 97 |
); |
| 98 |
}); |