@odoo/o-spreadsheet 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +20 -0
- package/.husky/post-checkout +9 -0
- package/.husky/pre-commit +39 -0
- package/.prettierignore +1 -0
- package/astToFormula.patch +0 -0
- package/demo/data.js +255 -0
- package/demo/index.html +9 -0
- package/demo/libs/Chart.bundle.js +20755 -0
- package/demo/main.js +101 -0
- package/doc/readme.md +46 -0
- package/package.json +78 -0
- package/readme.md +39 -0
- package/rollup.config.js +23 -0
- package/src/base_plugin.ts +102 -0
- package/src/components/autofill.ts +146 -0
- package/src/components/bottom_bar.ts +199 -0
- package/src/components/color_picker.ts +150 -0
- package/src/components/composer/autocomplete_dropdown.ts +135 -0
- package/src/components/composer/composer.ts +487 -0
- package/src/components/composer/content_editable_helper.ts +146 -0
- package/src/components/figures/chart.ts +70 -0
- package/src/components/figures/container.ts +268 -0
- package/src/components/figures/text_figure.ts +36 -0
- package/src/components/grid.ts +635 -0
- package/src/components/helpers/dom_helpers.ts +7 -0
- package/src/components/helpers/drag_and_drop.ts +17 -0
- package/src/components/icons.ts +36 -0
- package/src/components/index.ts +1 -0
- package/src/components/menu.ts +288 -0
- package/src/components/overlay.ts +457 -0
- package/src/components/scrollbar.ts +22 -0
- package/src/components/selection_input.ts +168 -0
- package/src/components/side_panel/cell_is_rule_editor.ts +169 -0
- package/src/components/side_panel/chart_panel.ts +104 -0
- package/src/components/side_panel/color_scale_rule_editor.ts +145 -0
- package/src/components/side_panel/conditional_formatting.ts +396 -0
- package/src/components/side_panel/side_panel.ts +127 -0
- package/src/components/side_panel/translations_terms.ts +45 -0
- package/src/components/spreadsheet.ts +198 -0
- package/src/components/top_bar.ts +535 -0
- package/src/constants.ts +26 -0
- package/src/data.ts +149 -0
- package/src/fonts.ts +41 -0
- package/src/formulas/compiler.ts +258 -0
- package/src/formulas/composer_tokenizer.ts +70 -0
- package/src/formulas/index.ts +15 -0
- package/src/formulas/normalize.ts +52 -0
- package/src/formulas/parser.ts +280 -0
- package/src/formulas/range_tokenizer.ts +97 -0
- package/src/formulas/tokenizer.ts +242 -0
- package/src/functions/arguments.ts +114 -0
- package/src/functions/dates.ts +302 -0
- package/src/functions/helpers.ts +592 -0
- package/src/functions/index.ts +52 -0
- package/src/functions/module_database.ts +282 -0
- package/src/functions/module_date.ts +743 -0
- package/src/functions/module_info.ts +69 -0
- package/src/functions/module_logical.ts +208 -0
- package/src/functions/module_lookup.ts +185 -0
- package/src/functions/module_math.ts +1252 -0
- package/src/functions/module_operators.ts +291 -0
- package/src/functions/module_statistical.ts +882 -0
- package/src/functions/module_text.ts +370 -0
- package/src/helpers/color.ts +30 -0
- package/src/helpers/coordinates.ts +71 -0
- package/src/helpers/grid_manipulation.ts +68 -0
- package/src/helpers/index.ts +7 -0
- package/src/helpers/misc.ts +76 -0
- package/src/helpers/numbers.ts +117 -0
- package/src/helpers/uuid.ts +19 -0
- package/src/helpers/zones.ts +263 -0
- package/src/history.ts +186 -0
- package/src/index.ts +84 -0
- package/src/model.ts +261 -0
- package/src/plugins/autofill.ts +412 -0
- package/src/plugins/chart.ts +404 -0
- package/src/plugins/clipboard.ts +461 -0
- package/src/plugins/conditional_format.ts +445 -0
- package/src/plugins/core.ts +1502 -0
- package/src/plugins/edition.ts +157 -0
- package/src/plugins/evaluation.ts +428 -0
- package/src/plugins/figures.ts +123 -0
- package/src/plugins/formatting.ts +630 -0
- package/src/plugins/highlight.ts +187 -0
- package/src/plugins/index.ts +32 -0
- package/src/plugins/merge.ts +524 -0
- package/src/plugins/renderer.ts +571 -0
- package/src/plugins/selection.ts +562 -0
- package/src/plugins/selection_inputs.ts +326 -0
- package/src/registries/autofill_modifiers.ts +76 -0
- package/src/registries/autofill_rules.ts +98 -0
- package/src/registries/figure_registry.ts +30 -0
- package/src/registries/index.ts +7 -0
- package/src/registries/menu_items_registry.ts +110 -0
- package/src/registries/menus/cell_menu_registry.ts +79 -0
- package/src/registries/menus/col_menu_registry.ts +63 -0
- package/src/registries/menus/index.ts +6 -0
- package/src/registries/menus/menu_items_actions.ts +425 -0
- package/src/registries/menus/row_menu_registry.ts +63 -0
- package/src/registries/menus/sheet_menu_registry.ts +75 -0
- package/src/registries/menus/topbar_menu_registry.ts +204 -0
- package/src/registries/side_panel_registry.ts +26 -0
- package/src/registries/topbar_component_registry.ts +12 -0
- package/src/registry.ts +51 -0
- package/src/translation.ts +44 -0
- package/src/types/autofill.ts +48 -0
- package/src/types/chart.ts +26 -0
- package/src/types/commands.ts +716 -0
- package/src/types/conditional_formatting.ts +124 -0
- package/src/types/env.ts +13 -0
- package/src/types/functions.ts +35 -0
- package/src/types/getters.ts +103 -0
- package/src/types/index.ts +20 -0
- package/src/types/misc.ts +143 -0
- package/src/types/rendering.ts +41 -0
- package/src/types/workbook_data.ts +62 -0
- package/tests/__mocks__/uuid.ts +7 -0
- package/tests/canvas.mock.ts +34 -0
- package/tests/components/__mocks__/content_editable_helper.ts +79 -0
- package/tests/components/__mocks__/scrollbar.ts +18 -0
- package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +29 -0
- package/tests/components/__snapshots__/bottom_bar_test.ts.snap +75 -0
- package/tests/components/__snapshots__/context_menu_test.ts.snap +88 -0
- package/tests/components/__snapshots__/grid_test.ts.snap +60 -0
- package/tests/components/__snapshots__/spreadsheet_test.ts.snap +455 -0
- package/tests/components/__snapshots__/top_bar_test.ts.snap +705 -0
- package/tests/components/autocomplete_dropdown_test.ts +315 -0
- package/tests/components/autofill_test.ts +167 -0
- package/tests/components/bottom_bar_test.ts +262 -0
- package/tests/components/chart_side_panel_test.ts +123 -0
- package/tests/components/composer_test.ts +400 -0
- package/tests/components/context_menu_test.ts +825 -0
- package/tests/components/grid_manipulation_test.ts +163 -0
- package/tests/components/grid_test.ts +581 -0
- package/tests/components/overlay_test.ts +541 -0
- package/tests/components/selection_input_test.ts +259 -0
- package/tests/components/side_panel_test.ts +148 -0
- package/tests/components/spreadsheet_test.ts +194 -0
- package/tests/components/top_bar_test.ts +427 -0
- package/tests/data_test.ts +175 -0
- package/tests/dom_helper.ts +42 -0
- package/tests/formulas/__snapshots__/compiler_test.ts.snap +302 -0
- package/tests/formulas/compiler_test.ts +266 -0
- package/tests/formulas/composer_tokenizer_test.ts +137 -0
- package/tests/formulas/expressions_test.ts +57 -0
- package/tests/formulas/formulas_test.ts +80 -0
- package/tests/formulas/normalize_test.ts +82 -0
- package/tests/formulas/parser_test.ts +224 -0
- package/tests/formulas/range_tokenizer_test.ts +187 -0
- package/tests/formulas/tokenizer_test.ts +164 -0
- package/tests/functions/arguments_test.ts +141 -0
- package/tests/functions/dates_test.ts +1081 -0
- package/tests/functions/functions_test.ts +53 -0
- package/tests/functions/helper_test.ts +98 -0
- package/tests/functions/module_database_test.ts +311 -0
- package/tests/functions/module_date_test.ts +941 -0
- package/tests/functions/module_info_test.ts +139 -0
- package/tests/functions/module_logical_test.ts +369 -0
- package/tests/functions/module_lookup_test.ts +541 -0
- package/tests/functions/module_math_test.ts +2482 -0
- package/tests/functions/module_operators_test.ts +955 -0
- package/tests/functions/module_statistical_test.ts +2014 -0
- package/tests/functions/module_text_test.ts +667 -0
- package/tests/helpers/coordinates_test.ts +25 -0
- package/tests/helpers/misc_test.ts +95 -0
- package/tests/helpers/numbers_test.ts +196 -0
- package/tests/helpers/zones_test.ts +97 -0
- package/tests/helpers.ts +384 -0
- package/tests/menu_items_registry_test.ts +540 -0
- package/tests/model/plugins/__snapshots__/chart_test.ts.snap +90 -0
- package/tests/model/plugins/chart_test.ts +562 -0
- package/tests/model_test.ts +82 -0
- package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +131 -0
- package/tests/plugins/__snapshots__/renderer_test.ts.snap +371 -0
- package/tests/plugins/autofill_test.ts +457 -0
- package/tests/plugins/borders_test.ts +295 -0
- package/tests/plugins/clipboard_test.ts +1180 -0
- package/tests/plugins/conditional_formatting_test.ts +1253 -0
- package/tests/plugins/core_test.ts +614 -0
- package/tests/plugins/edition_test.ts +100 -0
- package/tests/plugins/evaluation_async_test.ts +332 -0
- package/tests/plugins/evaluation_dates_test.ts +79 -0
- package/tests/plugins/evaluation_test.ts +901 -0
- package/tests/plugins/figures_test.ts +327 -0
- package/tests/plugins/formatting_test.ts +391 -0
- package/tests/plugins/grid_manipulation_test.ts +1366 -0
- package/tests/plugins/highlight_test.ts +413 -0
- package/tests/plugins/history_test.ts +142 -0
- package/tests/plugins/import_export_test.ts +276 -0
- package/tests/plugins/merges_test.ts +490 -0
- package/tests/plugins/navigation_test.ts +181 -0
- package/tests/plugins/plugins/evaluation_test.ts +111 -0
- package/tests/plugins/renderer_test.ts +598 -0
- package/tests/plugins/resizing_test.ts +152 -0
- package/tests/plugins/selection_input_test.ts +409 -0
- package/tests/plugins/selection_test.ts +442 -0
- package/tests/plugins/sheets_test.ts +643 -0
- package/tests/plugins/style_test.ts +90 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { Component, hooks, tags } from "@odoo/owl";
|
|
2
|
+
import { TopBar } from "../../src/components/top_bar";
|
|
3
|
+
import { DEFAULT_FONT_SIZE } from "../../src/constants";
|
|
4
|
+
import { Model } from "../../src/model";
|
|
5
|
+
import { topbarComponentRegistry } from "../../src/registries";
|
|
6
|
+
import { topbarMenuRegistry } from "../../src/registries/menus/topbar_menu_registry";
|
|
7
|
+
import { ConditionalFormat } from "../../src/types";
|
|
8
|
+
import { triggerMouseEvent } from "../dom_helper";
|
|
9
|
+
import { getCell, GridParent, makeTestFixture, nextTick } from "../helpers";
|
|
10
|
+
|
|
11
|
+
const { xml } = tags;
|
|
12
|
+
const { useSubEnv } = hooks;
|
|
13
|
+
|
|
14
|
+
let fixture: HTMLElement;
|
|
15
|
+
|
|
16
|
+
class Parent extends Component<any, any> {
|
|
17
|
+
static template = xml`<TopBar model="model" t-on-ask-confirmation="askConfirmation"/>`;
|
|
18
|
+
static components = { TopBar };
|
|
19
|
+
model: Model;
|
|
20
|
+
constructor(model: Model) {
|
|
21
|
+
super();
|
|
22
|
+
useSubEnv({
|
|
23
|
+
openSidePanel: (panel: string) => {},
|
|
24
|
+
dispatch: model.dispatch,
|
|
25
|
+
getters: model.getters,
|
|
26
|
+
askConfirmation: jest.fn(),
|
|
27
|
+
});
|
|
28
|
+
this.model = model;
|
|
29
|
+
}
|
|
30
|
+
mounted() {
|
|
31
|
+
this.model.on("update", this, this.render);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
willUnmount() {
|
|
35
|
+
this.model.off("update", this);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
fixture = makeTestFixture();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
fixture.remove();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("TopBar component", () => {
|
|
48
|
+
test("simple rendering", async () => {
|
|
49
|
+
const parent = new Parent(new Model());
|
|
50
|
+
await parent.mount(fixture);
|
|
51
|
+
|
|
52
|
+
expect(fixture.querySelector(".o-spreadsheet-topbar")).toMatchSnapshot();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("opening a second menu closes the first one", async () => {
|
|
56
|
+
const model = new Model();
|
|
57
|
+
model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
|
|
58
|
+
const parent = new Parent(model);
|
|
59
|
+
await parent.mount(fixture);
|
|
60
|
+
|
|
61
|
+
expect(fixture.querySelectorAll(".o-dropdown-content").length).toBe(0);
|
|
62
|
+
fixture.querySelector('span[title="Borders"]')!.dispatchEvent(new Event("click"));
|
|
63
|
+
await nextTick();
|
|
64
|
+
expect(fixture.querySelectorAll(".o-dropdown-content").length).toBe(1);
|
|
65
|
+
expect(fixture.querySelectorAll(".o-line-item").length).not.toBe(0);
|
|
66
|
+
fixture
|
|
67
|
+
.querySelector('.o-tool[title="Horizontal align"] span')!
|
|
68
|
+
.dispatchEvent(new Event("click"));
|
|
69
|
+
await nextTick();
|
|
70
|
+
expect(fixture.querySelectorAll(".o-dropdown-content").length).toBe(1);
|
|
71
|
+
expect(fixture.querySelectorAll(".o-color-line").length).toBe(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("merging cell button state is correct", async () => {
|
|
75
|
+
const model = new Model({
|
|
76
|
+
sheets: [
|
|
77
|
+
{
|
|
78
|
+
colNumber: 10,
|
|
79
|
+
rowNumber: 10,
|
|
80
|
+
cells: { B2: { content: "b2" } },
|
|
81
|
+
merges: ["A1:B1"],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
const parent = new Parent(model);
|
|
86
|
+
await parent.mount(fixture);
|
|
87
|
+
const mergeTool = fixture.querySelector('.o-tool[title="Merge Cells"]')!;
|
|
88
|
+
expect(mergeTool.classList.contains("active")).toBeTruthy();
|
|
89
|
+
|
|
90
|
+
// increase the selection to A2 (so, it is now A1:B2) => merge tool
|
|
91
|
+
// shoul not be active
|
|
92
|
+
model.dispatch("ALTER_SELECTION", { cell: [0, 1] });
|
|
93
|
+
await nextTick();
|
|
94
|
+
expect(mergeTool.classList.contains("active")).toBeFalsy();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("multiple selection zones => merge tools is disabled", async () => {
|
|
98
|
+
const model = new Model();
|
|
99
|
+
model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
|
|
100
|
+
|
|
101
|
+
const parent = new Parent(model);
|
|
102
|
+
await parent.mount(fixture);
|
|
103
|
+
const mergeTool = fixture.querySelector('.o-tool[title="Merge Cells"]')!;
|
|
104
|
+
|
|
105
|
+
// should be disabled, because the selection is just one cell
|
|
106
|
+
expect(mergeTool.classList.contains("o-disabled")).toBeTruthy();
|
|
107
|
+
|
|
108
|
+
model.dispatch("ALTER_SELECTION", { cell: [1, 0] });
|
|
109
|
+
await nextTick();
|
|
110
|
+
// should be enabled, because two cells are selected
|
|
111
|
+
expect(mergeTool.classList.contains("o-disabled")).toBeFalsy();
|
|
112
|
+
|
|
113
|
+
model.dispatch("START_SELECTION_EXPANSION");
|
|
114
|
+
model.dispatch("SELECT_CELL", { col: 3, row: 3 });
|
|
115
|
+
|
|
116
|
+
await nextTick();
|
|
117
|
+
// should be disabled, because multiple zones are selected
|
|
118
|
+
expect(mergeTool.classList.contains("o-disabled")).toBeTruthy();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("undo/redo tools", async () => {
|
|
122
|
+
const model = new Model();
|
|
123
|
+
|
|
124
|
+
const parent = new Parent(model);
|
|
125
|
+
await parent.mount(fixture);
|
|
126
|
+
const undoTool = fixture.querySelector('.o-tool[title="Undo"]')!;
|
|
127
|
+
const redoTool = fixture.querySelector('.o-tool[title="Redo"]')!;
|
|
128
|
+
|
|
129
|
+
expect(undoTool.classList.contains("o-disabled")).toBeTruthy();
|
|
130
|
+
expect(redoTool.classList.contains("o-disabled")).toBeTruthy();
|
|
131
|
+
|
|
132
|
+
model.dispatch("SET_FORMATTING", {
|
|
133
|
+
sheet: "Sheet1",
|
|
134
|
+
target: [{ left: 0, right: 0, top: 0, bottom: 0 }],
|
|
135
|
+
style: { bold: true },
|
|
136
|
+
});
|
|
137
|
+
await nextTick();
|
|
138
|
+
|
|
139
|
+
expect(undoTool.classList.contains("o-disabled")).toBeFalsy();
|
|
140
|
+
expect(redoTool.classList.contains("o-disabled")).toBeTruthy();
|
|
141
|
+
expect(model["workbook"].activeSheet.cells.A1.style).toBeDefined();
|
|
142
|
+
|
|
143
|
+
undoTool.dispatchEvent(new Event("click"));
|
|
144
|
+
await nextTick();
|
|
145
|
+
expect(undoTool.classList.contains("o-disabled")).toBeTruthy();
|
|
146
|
+
expect(redoTool.classList.contains("o-disabled")).toBeFalsy();
|
|
147
|
+
|
|
148
|
+
expect(getCell(model, "A1")).toBeNull();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("paint format tools", async () => {
|
|
152
|
+
const model = new Model();
|
|
153
|
+
|
|
154
|
+
const parent = new Parent(model);
|
|
155
|
+
await parent.mount(fixture);
|
|
156
|
+
const paintFormatTool = fixture.querySelector('.o-tool[title="Paint Format"]')!;
|
|
157
|
+
|
|
158
|
+
expect(paintFormatTool.classList.contains("active")).toBeFalsy();
|
|
159
|
+
|
|
160
|
+
paintFormatTool.dispatchEvent(new Event("click"));
|
|
161
|
+
await nextTick();
|
|
162
|
+
|
|
163
|
+
expect(paintFormatTool.classList.contains("active")).toBeTruthy();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("can clear formatting", async () => {
|
|
167
|
+
const model = new Model();
|
|
168
|
+
model.dispatch("SELECT_CELL", { col: 1, row: 0 });
|
|
169
|
+
model.dispatch("SET_FORMATTING", {
|
|
170
|
+
sheet: model.getters.getActiveSheet(),
|
|
171
|
+
target: model.getters.getSelectedZones(),
|
|
172
|
+
border: "all",
|
|
173
|
+
});
|
|
174
|
+
expect(model["workbook"].activeSheet.cells.B1.border).toBeDefined();
|
|
175
|
+
const parent = new Parent(model);
|
|
176
|
+
await parent.mount(fixture);
|
|
177
|
+
const clearFormatTool = fixture.querySelector('.o-tool[title="Clear Format"]')!;
|
|
178
|
+
clearFormatTool.dispatchEvent(new Event("click"));
|
|
179
|
+
expect(getCell(model, "B1")).toBeNull();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("can set cell format", async () => {
|
|
183
|
+
const model = new Model();
|
|
184
|
+
expect(getCell(model, "A1")).toBeNull();
|
|
185
|
+
const parent = new Parent(model);
|
|
186
|
+
await parent.mount(fixture);
|
|
187
|
+
const formatTool = fixture.querySelector('.o-tool[title="More formats"]')!;
|
|
188
|
+
formatTool.dispatchEvent(new Event("click"));
|
|
189
|
+
await nextTick();
|
|
190
|
+
expect(parent.el).toMatchSnapshot();
|
|
191
|
+
formatTool
|
|
192
|
+
.querySelector('[data-format="percent"]')!
|
|
193
|
+
.dispatchEvent(new Event("click", { bubbles: true }));
|
|
194
|
+
await nextTick();
|
|
195
|
+
expect(model["workbook"].activeSheet.cells.A1.format).toEqual("0.00%");
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("can set font size", async () => {
|
|
199
|
+
const model = new Model();
|
|
200
|
+
const parent = new Parent(model);
|
|
201
|
+
await parent.mount(fixture);
|
|
202
|
+
const fontSizeTool = fixture.querySelector('.o-tool[title="Font Size"]')!;
|
|
203
|
+
expect(fontSizeTool.textContent!.trim()).toBe(DEFAULT_FONT_SIZE.toString());
|
|
204
|
+
fontSizeTool.dispatchEvent(new Event("click"));
|
|
205
|
+
await nextTick();
|
|
206
|
+
fontSizeTool
|
|
207
|
+
.querySelector('[data-size="8"]')!
|
|
208
|
+
.dispatchEvent(new Event("click", { bubbles: true }));
|
|
209
|
+
await nextTick();
|
|
210
|
+
expect(fontSizeTool.textContent!.trim()).toBe("8");
|
|
211
|
+
const style = model.getters.getCellStyle(model["workbook"].activeSheet.cells.A1);
|
|
212
|
+
expect(style.fontSize).toBe(8);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("opening, then closing same menu", async () => {
|
|
216
|
+
const model = new Model();
|
|
217
|
+
model.dispatch("SET_VALUE", { xc: "B2", text: "b2" });
|
|
218
|
+
const parent = new Parent(model);
|
|
219
|
+
await parent.mount(fixture);
|
|
220
|
+
|
|
221
|
+
expect(fixture.querySelectorAll(".o-dropdown-content").length).toBe(0);
|
|
222
|
+
fixture.querySelector('span[title="Borders"]')!.dispatchEvent(new Event("click"));
|
|
223
|
+
await nextTick();
|
|
224
|
+
expect(fixture.querySelectorAll(".o-dropdown-content").length).toBe(1);
|
|
225
|
+
fixture.querySelector('span[title="Borders"]')!.dispatchEvent(new Event("click"));
|
|
226
|
+
await nextTick();
|
|
227
|
+
expect(fixture.querySelectorAll(".o-dropdown-content").length).toBe(0);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("Can open a Topbar menu", async () => {
|
|
231
|
+
const parent = new Parent(new Model());
|
|
232
|
+
await parent.mount(fixture);
|
|
233
|
+
expect(fixture.querySelectorAll(".o-menu")).toHaveLength(0);
|
|
234
|
+
const items = topbarMenuRegistry.getAll();
|
|
235
|
+
const number = items.filter((item) => item.children.length !== 0).length;
|
|
236
|
+
expect(fixture.querySelectorAll(".o-topbar-menu")).toHaveLength(number);
|
|
237
|
+
triggerMouseEvent(".o-topbar-menu[data-id='file']", "click");
|
|
238
|
+
await nextTick();
|
|
239
|
+
expect(fixture.querySelectorAll(".o-menu")).toHaveLength(1);
|
|
240
|
+
const file = topbarMenuRegistry.get("file");
|
|
241
|
+
const numberChild = topbarMenuRegistry
|
|
242
|
+
.getChildren(file, parent.env)
|
|
243
|
+
.filter((item) => item.children.length !== 0 || item.action).length;
|
|
244
|
+
expect(fixture.querySelectorAll(".o-menu-item")).toHaveLength(numberChild);
|
|
245
|
+
triggerMouseEvent(".o-spreadsheet-topbar", "click");
|
|
246
|
+
await nextTick();
|
|
247
|
+
expect(fixture.querySelectorAll(".o-menu")).toHaveLength(0);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("Can open a Topbar menu with mousemove", async () => {
|
|
251
|
+
const parent = new Parent(new Model());
|
|
252
|
+
await parent.mount(fixture);
|
|
253
|
+
triggerMouseEvent(".o-topbar-menu[data-id='file']", "click");
|
|
254
|
+
await nextTick();
|
|
255
|
+
const file = topbarMenuRegistry.get("file");
|
|
256
|
+
let numberChild = topbarMenuRegistry
|
|
257
|
+
.getChildren(file, parent.env)
|
|
258
|
+
.filter((item) => item.children.length !== 0 || item.action).length;
|
|
259
|
+
expect(fixture.querySelectorAll(".o-menu-item")).toHaveLength(numberChild);
|
|
260
|
+
expect(fixture.querySelectorAll(".o-menu")).toHaveLength(1);
|
|
261
|
+
triggerMouseEvent(".o-topbar-menu[data-id='insert']", "mouseover");
|
|
262
|
+
await nextTick();
|
|
263
|
+
const insert = topbarMenuRegistry.get("insert");
|
|
264
|
+
numberChild = topbarMenuRegistry
|
|
265
|
+
.getChildren(insert, parent.env)
|
|
266
|
+
.filter((item) => item.children.length !== 0 || item.action).length;
|
|
267
|
+
expect(fixture.querySelectorAll(".o-menu-item")).toHaveLength(numberChild);
|
|
268
|
+
expect(fixture.querySelectorAll(".o-menu")).toHaveLength(1);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test("Can click on a menuItem do execute action and close menus", async () => {
|
|
272
|
+
const menuDefinitions = Object.assign({}, topbarMenuRegistry.content);
|
|
273
|
+
let number = 0;
|
|
274
|
+
topbarMenuRegistry.add("test", { name: "Test", sequence: 1 });
|
|
275
|
+
topbarMenuRegistry.addChild("testaction", ["test"], {
|
|
276
|
+
name: "TestAction",
|
|
277
|
+
sequence: 1,
|
|
278
|
+
action: () => {
|
|
279
|
+
number++;
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
const parent = new Parent(new Model());
|
|
283
|
+
await parent.mount(fixture);
|
|
284
|
+
triggerMouseEvent(".o-topbar-menu[data-id='test']", "click");
|
|
285
|
+
await nextTick();
|
|
286
|
+
triggerMouseEvent(".o-menu-item", "click");
|
|
287
|
+
await nextTick();
|
|
288
|
+
expect(fixture.querySelectorAll(".o-menu-dropdown-content")).toHaveLength(0);
|
|
289
|
+
expect(number).toBe(1);
|
|
290
|
+
topbarMenuRegistry.content = menuDefinitions;
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("Can add a custom component to topbar", async () => {
|
|
294
|
+
const compDefinitions = Object.assign({}, topbarComponentRegistry.content);
|
|
295
|
+
class Comp extends Component {
|
|
296
|
+
static template = xml`<div class="o-topbar-test">Test</div>`;
|
|
297
|
+
}
|
|
298
|
+
topbarComponentRegistry.add("1", { component: Comp });
|
|
299
|
+
const parent = new Parent(new Model());
|
|
300
|
+
await parent.mount(fixture);
|
|
301
|
+
expect(fixture.querySelectorAll(".o-topbar-test")).toHaveLength(1);
|
|
302
|
+
topbarComponentRegistry.content = compDefinitions;
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("Can show/hide a TopBarComponent based on condition", async () => {
|
|
307
|
+
const compDefinitions = Object.assign({}, topbarComponentRegistry.content);
|
|
308
|
+
class Comp1 extends Component {
|
|
309
|
+
static template = xml`<div class="o-topbar-test1">Test1</div>`;
|
|
310
|
+
}
|
|
311
|
+
class Comp2 extends Component {
|
|
312
|
+
static template = xml`<div class="o-topbar-test2">Test2</div>`;
|
|
313
|
+
}
|
|
314
|
+
topbarComponentRegistry.add("1", {
|
|
315
|
+
component: Comp1,
|
|
316
|
+
isVisible: (env) => true,
|
|
317
|
+
});
|
|
318
|
+
topbarComponentRegistry.add("2", {
|
|
319
|
+
component: Comp2,
|
|
320
|
+
isVisible: (env) => false,
|
|
321
|
+
});
|
|
322
|
+
const parent = new Parent(new Model());
|
|
323
|
+
await parent.mount(fixture);
|
|
324
|
+
expect(fixture.querySelectorAll(".o-topbar-test1")).toHaveLength(1);
|
|
325
|
+
expect(fixture.querySelectorAll(".o-topbar-test2")).toHaveLength(0);
|
|
326
|
+
topbarComponentRegistry.content = compDefinitions;
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
describe("TopBar - CF", () => {
|
|
330
|
+
test("open sidepanel with no CF in selected zone", async () => {
|
|
331
|
+
const model = new Model();
|
|
332
|
+
const parent = new GridParent(model);
|
|
333
|
+
await parent.mount(fixture);
|
|
334
|
+
triggerMouseEvent(".o-topbar-menu[data-id='format']", "click");
|
|
335
|
+
await nextTick();
|
|
336
|
+
triggerMouseEvent(".o-menu-item[data-name='format_cf']", "click");
|
|
337
|
+
await nextTick();
|
|
338
|
+
expect(
|
|
339
|
+
fixture.querySelector(".o-sidePanel .o-sidePanelBody .o-cf .o-cf-preview-list")
|
|
340
|
+
).toBeTruthy();
|
|
341
|
+
expect(
|
|
342
|
+
fixture.querySelector(".o-sidePanel .o-sidePanelBody .o-cf .o-cf-ruleEditor")
|
|
343
|
+
).toBeFalsy();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test("open sidepanel with one CF in selected zone", async () => {
|
|
347
|
+
const model = new Model();
|
|
348
|
+
const parent = new GridParent(model);
|
|
349
|
+
await parent.mount(fixture);
|
|
350
|
+
|
|
351
|
+
const cfRule: ConditionalFormat = {
|
|
352
|
+
ranges: ["A1:C7"],
|
|
353
|
+
id: "1",
|
|
354
|
+
rule: {
|
|
355
|
+
values: ["2"],
|
|
356
|
+
operator: "Equal",
|
|
357
|
+
type: "CellIsRule",
|
|
358
|
+
style: { fillColor: "#FF0000" },
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
model.dispatch("ADD_CONDITIONAL_FORMAT", {
|
|
362
|
+
cf: cfRule,
|
|
363
|
+
sheet: model.getters.getActiveSheet(),
|
|
364
|
+
});
|
|
365
|
+
const zone = { left: 0, top: 0, bottom: 10, right: 10 };
|
|
366
|
+
model.dispatch("SET_SELECTION", { zones: [zone], anchor: [0, 0] });
|
|
367
|
+
|
|
368
|
+
triggerMouseEvent(".o-topbar-menu[data-id='format']", "click");
|
|
369
|
+
await nextTick();
|
|
370
|
+
triggerMouseEvent(".o-menu-item[data-name='format_cf']", "click");
|
|
371
|
+
await nextTick();
|
|
372
|
+
expect(
|
|
373
|
+
fixture.querySelector(".o-sidePanel .o-sidePanelBody .o-cf .o-cf-preview-list")
|
|
374
|
+
).toBeFalsy();
|
|
375
|
+
expect(
|
|
376
|
+
fixture.querySelector(".o-sidePanel .o-sidePanelBody .o-cf .o-cf-ruleEditor")
|
|
377
|
+
).toBeTruthy();
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test("open sidepanel with with more then one CF in selected zone", async () => {
|
|
381
|
+
const model = new Model();
|
|
382
|
+
const parent = new GridParent(model);
|
|
383
|
+
await parent.mount(fixture);
|
|
384
|
+
|
|
385
|
+
const cfRule1: ConditionalFormat = {
|
|
386
|
+
ranges: ["A1:C7"],
|
|
387
|
+
id: "1",
|
|
388
|
+
rule: {
|
|
389
|
+
values: ["2"],
|
|
390
|
+
operator: "Equal",
|
|
391
|
+
type: "CellIsRule",
|
|
392
|
+
style: { fillColor: "#FF0000" },
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
const cfRule2: ConditionalFormat = {
|
|
396
|
+
ranges: ["A1:C7"],
|
|
397
|
+
id: "2",
|
|
398
|
+
rule: {
|
|
399
|
+
values: ["3"],
|
|
400
|
+
operator: "Equal",
|
|
401
|
+
type: "CellIsRule",
|
|
402
|
+
style: { fillColor: "#FE0001" },
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
model.dispatch("ADD_CONDITIONAL_FORMAT", {
|
|
406
|
+
cf: cfRule1,
|
|
407
|
+
sheet: model.getters.getActiveSheet(),
|
|
408
|
+
});
|
|
409
|
+
model.dispatch("ADD_CONDITIONAL_FORMAT", {
|
|
410
|
+
cf: cfRule2,
|
|
411
|
+
sheet: model.getters.getActiveSheet(),
|
|
412
|
+
});
|
|
413
|
+
const zone = { left: 0, top: 0, bottom: 10, right: 10 };
|
|
414
|
+
model.dispatch("SET_SELECTION", { zones: [zone], anchor: [0, 0] });
|
|
415
|
+
|
|
416
|
+
triggerMouseEvent(".o-topbar-menu[data-id='format']", "click");
|
|
417
|
+
await nextTick();
|
|
418
|
+
triggerMouseEvent(".o-menu-item[data-name='format_cf']", "click");
|
|
419
|
+
await nextTick();
|
|
420
|
+
expect(
|
|
421
|
+
fixture.querySelector(".o-sidePanel .o-sidePanelBody .o-cf .o-cf-preview-list")
|
|
422
|
+
).toBeTruthy();
|
|
423
|
+
expect(
|
|
424
|
+
fixture.querySelector(".o-sidePanel .o-sidePanelBody .o-cf .o-cf-ruleEditor")
|
|
425
|
+
).toBeFalsy();
|
|
426
|
+
});
|
|
427
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { CURRENT_VERSION, load } from "../src/data";
|
|
2
|
+
import { mockUuidV4To } from "./helpers";
|
|
3
|
+
jest.mock("../src/helpers/uuid", () => require("./__mocks__/uuid"));
|
|
4
|
+
|
|
5
|
+
describe("load data", () => {
|
|
6
|
+
test("create empty workbookdata when loading nothing", () => {
|
|
7
|
+
mockUuidV4To(123);
|
|
8
|
+
expect(load()).toEqual({
|
|
9
|
+
version: CURRENT_VERSION,
|
|
10
|
+
borders: {},
|
|
11
|
+
styles: {},
|
|
12
|
+
entities: {},
|
|
13
|
+
sheets: [
|
|
14
|
+
{
|
|
15
|
+
id: "123",
|
|
16
|
+
name: "Sheet1",
|
|
17
|
+
cells: {},
|
|
18
|
+
colNumber: 26,
|
|
19
|
+
rowNumber: 100,
|
|
20
|
+
cols: {},
|
|
21
|
+
rows: {},
|
|
22
|
+
merges: [],
|
|
23
|
+
conditionalFormats: [],
|
|
24
|
+
figures: [],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
activeSheet: "123",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
expect(load({})).toEqual({
|
|
31
|
+
version: CURRENT_VERSION,
|
|
32
|
+
borders: {},
|
|
33
|
+
styles: {},
|
|
34
|
+
entities: {},
|
|
35
|
+
sheets: [
|
|
36
|
+
{
|
|
37
|
+
id: "124",
|
|
38
|
+
name: "Sheet1",
|
|
39
|
+
cells: {},
|
|
40
|
+
colNumber: 26,
|
|
41
|
+
rowNumber: 100,
|
|
42
|
+
cols: {},
|
|
43
|
+
rows: {},
|
|
44
|
+
merges: [],
|
|
45
|
+
conditionalFormats: [],
|
|
46
|
+
figures: [],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
activeSheet: "124",
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("assign sheet name if missing", () => {
|
|
54
|
+
expect(
|
|
55
|
+
load({
|
|
56
|
+
sheets: [{ id: "asdf", merges: ["A1:B2"] }],
|
|
57
|
+
})
|
|
58
|
+
).toEqual({
|
|
59
|
+
version: CURRENT_VERSION,
|
|
60
|
+
borders: {},
|
|
61
|
+
styles: {},
|
|
62
|
+
entities: {},
|
|
63
|
+
sheets: [
|
|
64
|
+
{
|
|
65
|
+
id: "asdf",
|
|
66
|
+
name: "Sheet1",
|
|
67
|
+
cells: {},
|
|
68
|
+
colNumber: 26,
|
|
69
|
+
rowNumber: 100,
|
|
70
|
+
cols: {},
|
|
71
|
+
rows: {},
|
|
72
|
+
merges: ["A1:B2"],
|
|
73
|
+
conditionalFormats: [],
|
|
74
|
+
figures: [],
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
activeSheet: "asdf",
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("assign sheet id if missing", () => {
|
|
82
|
+
mockUuidV4To(12);
|
|
83
|
+
expect(
|
|
84
|
+
load({
|
|
85
|
+
sheets: [{ name: "Sheet1", merges: ["A1:B2"] }],
|
|
86
|
+
})
|
|
87
|
+
).toEqual({
|
|
88
|
+
version: CURRENT_VERSION,
|
|
89
|
+
borders: {},
|
|
90
|
+
styles: {},
|
|
91
|
+
entities: {},
|
|
92
|
+
sheets: [
|
|
93
|
+
{
|
|
94
|
+
id: "13",
|
|
95
|
+
name: "Sheet1",
|
|
96
|
+
cells: {},
|
|
97
|
+
colNumber: 26,
|
|
98
|
+
rowNumber: 100,
|
|
99
|
+
cols: {},
|
|
100
|
+
rows: {},
|
|
101
|
+
merges: ["A1:B2"],
|
|
102
|
+
conditionalFormats: [],
|
|
103
|
+
figures: [],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
activeSheet: "13",
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("assign two different sheet names if missing", () => {
|
|
111
|
+
expect(
|
|
112
|
+
load({
|
|
113
|
+
sheets: [
|
|
114
|
+
{ id: "1", merges: ["A1:B2"] },
|
|
115
|
+
{ id: "asdf", merges: ["C3:D4"] },
|
|
116
|
+
],
|
|
117
|
+
}).sheets
|
|
118
|
+
).toEqual([
|
|
119
|
+
{
|
|
120
|
+
id: "1",
|
|
121
|
+
name: "Sheet1",
|
|
122
|
+
cells: {},
|
|
123
|
+
colNumber: 26,
|
|
124
|
+
rowNumber: 100,
|
|
125
|
+
cols: {},
|
|
126
|
+
rows: {},
|
|
127
|
+
merges: ["A1:B2"],
|
|
128
|
+
conditionalFormats: [],
|
|
129
|
+
figures: [],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "asdf",
|
|
133
|
+
name: "Sheet2",
|
|
134
|
+
cells: {},
|
|
135
|
+
colNumber: 26,
|
|
136
|
+
rowNumber: 100,
|
|
137
|
+
cols: {},
|
|
138
|
+
rows: {},
|
|
139
|
+
merges: ["C3:D4"],
|
|
140
|
+
conditionalFormats: [],
|
|
141
|
+
figures: [],
|
|
142
|
+
},
|
|
143
|
+
]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("sanitize input data, even if versioned", () => {
|
|
147
|
+
mockUuidV4To(133);
|
|
148
|
+
expect(
|
|
149
|
+
load({
|
|
150
|
+
version: 3,
|
|
151
|
+
sheets: [{ merges: ["A1:B2"] }],
|
|
152
|
+
})
|
|
153
|
+
).toEqual({
|
|
154
|
+
version: CURRENT_VERSION,
|
|
155
|
+
borders: {},
|
|
156
|
+
styles: {},
|
|
157
|
+
entities: {},
|
|
158
|
+
sheets: [
|
|
159
|
+
{
|
|
160
|
+
id: "134",
|
|
161
|
+
name: "Sheet1",
|
|
162
|
+
cells: {},
|
|
163
|
+
colNumber: 26,
|
|
164
|
+
rowNumber: 100,
|
|
165
|
+
cols: {},
|
|
166
|
+
rows: {},
|
|
167
|
+
merges: ["A1:B2"],
|
|
168
|
+
conditionalFormats: [],
|
|
169
|
+
figures: [],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
activeSheet: "134",
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { nextTick } from "./helpers";
|
|
2
|
+
|
|
3
|
+
export async function simulateClick(selector: string, x: number = 10, y: number = 10) {
|
|
4
|
+
const target = document.querySelector(selector)! as HTMLElement;
|
|
5
|
+
triggerMouseEvent(selector, "mousedown", x, y);
|
|
6
|
+
if (target !== document.activeElement) {
|
|
7
|
+
(document.activeElement as HTMLElement | null)?.blur();
|
|
8
|
+
target.focus();
|
|
9
|
+
}
|
|
10
|
+
triggerMouseEvent(selector, "mouseup", x, y);
|
|
11
|
+
triggerMouseEvent(selector, "click", x, y);
|
|
12
|
+
await nextTick();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function triggerMouseEvent(
|
|
16
|
+
selector: string | any,
|
|
17
|
+
type: string,
|
|
18
|
+
x?: number,
|
|
19
|
+
y?: number,
|
|
20
|
+
extra: any = { bubbles: true }
|
|
21
|
+
): void {
|
|
22
|
+
const ev = new MouseEvent(type, {
|
|
23
|
+
clientX: x,
|
|
24
|
+
clientY: y,
|
|
25
|
+
...extra,
|
|
26
|
+
});
|
|
27
|
+
(ev as any).offsetX = x;
|
|
28
|
+
(ev as any).offsetY = y;
|
|
29
|
+
(ev as any).pageX = x;
|
|
30
|
+
(ev as any).pageY = y;
|
|
31
|
+
if (typeof selector === "string") {
|
|
32
|
+
document.querySelector(selector)!.dispatchEvent(ev);
|
|
33
|
+
} else {
|
|
34
|
+
selector!.dispatchEvent(ev);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function setInputValueAndTrigger(selector: string, value: string, eventType: string): void {
|
|
39
|
+
const rangeInput = document.querySelector(selector) as HTMLInputElement;
|
|
40
|
+
rangeInput.value = value;
|
|
41
|
+
rangeInput.dispatchEvent(new Event(eventType));
|
|
42
|
+
}
|