@odoo/o-spreadsheet 14.0.1 → 14.0.2

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.
Files changed (204) hide show
  1. package/dist/o_spreadsheet.cjs.js +17836 -0
  2. package/dist/o_spreadsheet.d.ts +4102 -0
  3. package/dist/o_spreadsheet.esm.js +17801 -0
  4. package/dist/o_spreadsheet.iife.js +17838 -0
  5. package/dist/o_spreadsheet.iife.min.js +1440 -0
  6. package/package.json +27 -7
  7. package/readme.md +10 -0
  8. package/.eslintrc.json +0 -20
  9. package/.husky/post-checkout +0 -9
  10. package/.husky/pre-commit +0 -39
  11. package/.prettierignore +0 -1
  12. package/astToFormula.patch +0 -0
  13. package/demo/data.js +0 -255
  14. package/demo/index.html +0 -9
  15. package/demo/libs/Chart.bundle.js +0 -20755
  16. package/demo/main.js +0 -101
  17. package/doc/readme.md +0 -46
  18. package/rollup.config.js +0 -23
  19. package/src/base_plugin.ts +0 -102
  20. package/src/components/autofill.ts +0 -146
  21. package/src/components/bottom_bar.ts +0 -199
  22. package/src/components/color_picker.ts +0 -150
  23. package/src/components/composer/autocomplete_dropdown.ts +0 -135
  24. package/src/components/composer/composer.ts +0 -487
  25. package/src/components/composer/content_editable_helper.ts +0 -146
  26. package/src/components/figures/chart.ts +0 -70
  27. package/src/components/figures/container.ts +0 -268
  28. package/src/components/figures/text_figure.ts +0 -36
  29. package/src/components/grid.ts +0 -635
  30. package/src/components/helpers/dom_helpers.ts +0 -7
  31. package/src/components/helpers/drag_and_drop.ts +0 -17
  32. package/src/components/icons.ts +0 -36
  33. package/src/components/index.ts +0 -1
  34. package/src/components/menu.ts +0 -288
  35. package/src/components/overlay.ts +0 -457
  36. package/src/components/scrollbar.ts +0 -22
  37. package/src/components/selection_input.ts +0 -168
  38. package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
  39. package/src/components/side_panel/chart_panel.ts +0 -104
  40. package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
  41. package/src/components/side_panel/conditional_formatting.ts +0 -396
  42. package/src/components/side_panel/side_panel.ts +0 -127
  43. package/src/components/side_panel/translations_terms.ts +0 -45
  44. package/src/components/spreadsheet.ts +0 -198
  45. package/src/components/top_bar.ts +0 -535
  46. package/src/constants.ts +0 -26
  47. package/src/data.ts +0 -149
  48. package/src/fonts.ts +0 -41
  49. package/src/formulas/compiler.ts +0 -258
  50. package/src/formulas/composer_tokenizer.ts +0 -70
  51. package/src/formulas/index.ts +0 -15
  52. package/src/formulas/normalize.ts +0 -52
  53. package/src/formulas/parser.ts +0 -280
  54. package/src/formulas/range_tokenizer.ts +0 -97
  55. package/src/formulas/tokenizer.ts +0 -242
  56. package/src/functions/arguments.ts +0 -114
  57. package/src/functions/dates.ts +0 -302
  58. package/src/functions/helpers.ts +0 -592
  59. package/src/functions/index.ts +0 -52
  60. package/src/functions/module_database.ts +0 -282
  61. package/src/functions/module_date.ts +0 -743
  62. package/src/functions/module_info.ts +0 -69
  63. package/src/functions/module_logical.ts +0 -208
  64. package/src/functions/module_lookup.ts +0 -185
  65. package/src/functions/module_math.ts +0 -1252
  66. package/src/functions/module_operators.ts +0 -291
  67. package/src/functions/module_statistical.ts +0 -882
  68. package/src/functions/module_text.ts +0 -370
  69. package/src/helpers/color.ts +0 -30
  70. package/src/helpers/coordinates.ts +0 -71
  71. package/src/helpers/grid_manipulation.ts +0 -68
  72. package/src/helpers/index.ts +0 -7
  73. package/src/helpers/misc.ts +0 -76
  74. package/src/helpers/numbers.ts +0 -117
  75. package/src/helpers/uuid.ts +0 -19
  76. package/src/helpers/zones.ts +0 -263
  77. package/src/history.ts +0 -186
  78. package/src/index.ts +0 -84
  79. package/src/model.ts +0 -261
  80. package/src/plugins/autofill.ts +0 -412
  81. package/src/plugins/chart.ts +0 -404
  82. package/src/plugins/clipboard.ts +0 -461
  83. package/src/plugins/conditional_format.ts +0 -445
  84. package/src/plugins/core.ts +0 -1502
  85. package/src/plugins/edition.ts +0 -157
  86. package/src/plugins/evaluation.ts +0 -428
  87. package/src/plugins/figures.ts +0 -123
  88. package/src/plugins/formatting.ts +0 -630
  89. package/src/plugins/highlight.ts +0 -187
  90. package/src/plugins/index.ts +0 -32
  91. package/src/plugins/merge.ts +0 -524
  92. package/src/plugins/renderer.ts +0 -571
  93. package/src/plugins/selection.ts +0 -562
  94. package/src/plugins/selection_inputs.ts +0 -326
  95. package/src/registries/autofill_modifiers.ts +0 -76
  96. package/src/registries/autofill_rules.ts +0 -98
  97. package/src/registries/figure_registry.ts +0 -30
  98. package/src/registries/index.ts +0 -7
  99. package/src/registries/menu_items_registry.ts +0 -110
  100. package/src/registries/menus/cell_menu_registry.ts +0 -79
  101. package/src/registries/menus/col_menu_registry.ts +0 -63
  102. package/src/registries/menus/index.ts +0 -6
  103. package/src/registries/menus/menu_items_actions.ts +0 -425
  104. package/src/registries/menus/row_menu_registry.ts +0 -63
  105. package/src/registries/menus/sheet_menu_registry.ts +0 -75
  106. package/src/registries/menus/topbar_menu_registry.ts +0 -204
  107. package/src/registries/side_panel_registry.ts +0 -26
  108. package/src/registries/topbar_component_registry.ts +0 -12
  109. package/src/registry.ts +0 -51
  110. package/src/translation.ts +0 -44
  111. package/src/types/autofill.ts +0 -48
  112. package/src/types/chart.ts +0 -26
  113. package/src/types/commands.ts +0 -716
  114. package/src/types/conditional_formatting.ts +0 -124
  115. package/src/types/env.ts +0 -13
  116. package/src/types/functions.ts +0 -35
  117. package/src/types/getters.ts +0 -103
  118. package/src/types/index.ts +0 -20
  119. package/src/types/misc.ts +0 -143
  120. package/src/types/rendering.ts +0 -41
  121. package/src/types/workbook_data.ts +0 -62
  122. package/tests/__mocks__/uuid.ts +0 -7
  123. package/tests/canvas.mock.ts +0 -34
  124. package/tests/components/__mocks__/content_editable_helper.ts +0 -79
  125. package/tests/components/__mocks__/scrollbar.ts +0 -18
  126. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
  127. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
  128. package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
  129. package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
  130. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
  131. package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
  132. package/tests/components/autocomplete_dropdown_test.ts +0 -315
  133. package/tests/components/autofill_test.ts +0 -167
  134. package/tests/components/bottom_bar_test.ts +0 -262
  135. package/tests/components/chart_side_panel_test.ts +0 -123
  136. package/tests/components/composer_test.ts +0 -400
  137. package/tests/components/context_menu_test.ts +0 -825
  138. package/tests/components/grid_manipulation_test.ts +0 -163
  139. package/tests/components/grid_test.ts +0 -581
  140. package/tests/components/overlay_test.ts +0 -541
  141. package/tests/components/selection_input_test.ts +0 -259
  142. package/tests/components/side_panel_test.ts +0 -148
  143. package/tests/components/spreadsheet_test.ts +0 -194
  144. package/tests/components/top_bar_test.ts +0 -427
  145. package/tests/data_test.ts +0 -175
  146. package/tests/dom_helper.ts +0 -42
  147. package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
  148. package/tests/formulas/compiler_test.ts +0 -266
  149. package/tests/formulas/composer_tokenizer_test.ts +0 -137
  150. package/tests/formulas/expressions_test.ts +0 -57
  151. package/tests/formulas/formulas_test.ts +0 -80
  152. package/tests/formulas/normalize_test.ts +0 -82
  153. package/tests/formulas/parser_test.ts +0 -224
  154. package/tests/formulas/range_tokenizer_test.ts +0 -187
  155. package/tests/formulas/tokenizer_test.ts +0 -164
  156. package/tests/functions/arguments_test.ts +0 -141
  157. package/tests/functions/dates_test.ts +0 -1081
  158. package/tests/functions/functions_test.ts +0 -53
  159. package/tests/functions/helper_test.ts +0 -98
  160. package/tests/functions/module_database_test.ts +0 -311
  161. package/tests/functions/module_date_test.ts +0 -941
  162. package/tests/functions/module_info_test.ts +0 -139
  163. package/tests/functions/module_logical_test.ts +0 -369
  164. package/tests/functions/module_lookup_test.ts +0 -541
  165. package/tests/functions/module_math_test.ts +0 -2482
  166. package/tests/functions/module_operators_test.ts +0 -955
  167. package/tests/functions/module_statistical_test.ts +0 -2014
  168. package/tests/functions/module_text_test.ts +0 -667
  169. package/tests/helpers/coordinates_test.ts +0 -25
  170. package/tests/helpers/misc_test.ts +0 -95
  171. package/tests/helpers/numbers_test.ts +0 -196
  172. package/tests/helpers/zones_test.ts +0 -97
  173. package/tests/helpers.ts +0 -384
  174. package/tests/menu_items_registry_test.ts +0 -540
  175. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
  176. package/tests/model/plugins/chart_test.ts +0 -562
  177. package/tests/model_test.ts +0 -82
  178. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
  179. package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
  180. package/tests/plugins/autofill_test.ts +0 -457
  181. package/tests/plugins/borders_test.ts +0 -295
  182. package/tests/plugins/clipboard_test.ts +0 -1180
  183. package/tests/plugins/conditional_formatting_test.ts +0 -1253
  184. package/tests/plugins/core_test.ts +0 -614
  185. package/tests/plugins/edition_test.ts +0 -100
  186. package/tests/plugins/evaluation_async_test.ts +0 -332
  187. package/tests/plugins/evaluation_dates_test.ts +0 -79
  188. package/tests/plugins/evaluation_test.ts +0 -901
  189. package/tests/plugins/figures_test.ts +0 -327
  190. package/tests/plugins/formatting_test.ts +0 -391
  191. package/tests/plugins/grid_manipulation_test.ts +0 -1366
  192. package/tests/plugins/highlight_test.ts +0 -413
  193. package/tests/plugins/history_test.ts +0 -142
  194. package/tests/plugins/import_export_test.ts +0 -276
  195. package/tests/plugins/merges_test.ts +0 -490
  196. package/tests/plugins/navigation_test.ts +0 -181
  197. package/tests/plugins/plugins/evaluation_test.ts +0 -111
  198. package/tests/plugins/renderer_test.ts +0 -598
  199. package/tests/plugins/resizing_test.ts +0 -152
  200. package/tests/plugins/selection_input_test.ts +0 -409
  201. package/tests/plugins/selection_test.ts +0 -442
  202. package/tests/plugins/sheets_test.ts +0 -643
  203. package/tests/plugins/style_test.ts +0 -90
  204. package/tsconfig.json +0 -22
@@ -1,259 +0,0 @@
1
- import { Component, hooks, tags } from "@odoo/owl";
2
- import { Model } from "../../src";
3
- import { SelectionInput } from "../../src/components/selection_input";
4
- import { simulateClick } from "../dom_helper";
5
- import { makeTestFixture, nextTick } from "../helpers";
6
-
7
- const { xml } = tags;
8
- const { useSubEnv, useRef } = hooks;
9
-
10
- let model: Model;
11
- let fixture: HTMLElement;
12
-
13
- function focus(index = 0) {
14
- fixture.querySelectorAll("input")[index].dispatchEvent(new Event("focus"));
15
- }
16
-
17
- async function writeInput(index: number, text: string) {
18
- focus(index);
19
- await nextTick();
20
- const input = fixture.querySelectorAll("input")[index];
21
- input.value = text;
22
- input.dispatchEvent(new Event("input"));
23
- input.dispatchEvent(new Event("change"));
24
- }
25
-
26
- interface SelectionInputTestConfig {
27
- initialRanges?: string[];
28
- maximumRanges?: number;
29
- onChanged?: jest.Mock<void, [any]>;
30
- }
31
-
32
- class Parent extends Component<any> {
33
- static template = xml/* xml */ `
34
- <SelectionInput
35
- t-ref="selection-input"
36
- ranges="initialRanges"
37
- maximumRanges="maximumRanges"
38
- t-on-selection-changed="onChanged"/>
39
- `;
40
- static components = { SelectionInput };
41
- model: Model;
42
- initialRanges: string[] | undefined;
43
- maximumRanges: number | undefined;
44
- ref = useRef("selection-input");
45
- onChanged: jest.Mock<void, [any]>;
46
-
47
- constructor(model: Model, config: SelectionInputTestConfig) {
48
- super();
49
- useSubEnv({
50
- dispatch: model.dispatch,
51
- getters: model.getters,
52
- });
53
- this.initialRanges = config.initialRanges;
54
- this.maximumRanges = config.maximumRanges;
55
- this.model = model;
56
- this.onChanged = config.onChanged || jest.fn();
57
- }
58
-
59
- get id(): string {
60
- return (this.ref.comp as any).id;
61
- }
62
-
63
- mounted() {
64
- this.model.on("update", this, this.render);
65
- this.render();
66
- }
67
-
68
- willUnmount() {
69
- this.model.off("update", this);
70
- }
71
- }
72
-
73
- class MutliParent extends Component<any> {
74
- static template = xml/* xml */ `
75
- <div>
76
- <div class="input-1">
77
- <SelectionInput/>
78
- </div>
79
- <div class="input-2">
80
- <SelectionInput/>
81
- </div>
82
- </div>
83
- `;
84
- static components = { SelectionInput };
85
- model: Model;
86
-
87
- constructor(model: Model) {
88
- super();
89
- useSubEnv({
90
- dispatch: model.dispatch,
91
- getters: model.getters,
92
- });
93
- this.model = model;
94
- }
95
-
96
- mounted() {
97
- this.model.on("update", this, this.render);
98
- this.render();
99
- }
100
-
101
- willUnmount() {
102
- this.model.off("update", this);
103
- }
104
- }
105
-
106
- async function createSelectionInput(config: SelectionInputTestConfig = {}) {
107
- model = new Model();
108
- const parent = new Parent(model, config);
109
- await parent.mount(fixture);
110
- await nextTick();
111
- const id = parent.id;
112
- return { parent, model, id };
113
- }
114
-
115
- describe("Selection Input", () => {
116
- beforeEach(async () => {
117
- fixture = makeTestFixture();
118
- });
119
-
120
- afterEach(() => {
121
- fixture.remove();
122
- });
123
-
124
- test("remove button is not displayed with a single input", async () => {
125
- await createSelectionInput();
126
- expect(fixture.querySelectorAll(".o-remove-selection").length).toBeFalsy();
127
- });
128
-
129
- test("remove button is displayed with more than one input", async () => {
130
- await createSelectionInput();
131
- await simulateClick(".o-add-selection");
132
- expect(fixture.querySelectorAll(".o-remove-selection").length).toBe(2);
133
- });
134
-
135
- test("input is filled when new highlight is added", async () => {
136
- const { model } = await createSelectionInput();
137
- model.dispatch("ADD_HIGHLIGHTS", {
138
- ranges: {
139
- B4: "#454545",
140
- },
141
- });
142
- await nextTick();
143
- expect(fixture.querySelector("input")!.value).toBe("B4");
144
- expect(fixture.querySelector("input")!.getAttribute("style")).toBe("color: #454545");
145
- simulateClick(".o-add-selection");
146
- model.dispatch("ADD_HIGHLIGHTS", {
147
- ranges: {
148
- B5: "#787878",
149
- },
150
- });
151
- await nextTick();
152
- expect(fixture.querySelectorAll("input")[0].value).toBe("B4");
153
- expect(fixture.querySelectorAll("input")[0].getAttribute("style")).toBe("color: #454545");
154
- expect(fixture.querySelectorAll("input")[1].value).toBe("B5");
155
- expect(fixture.querySelectorAll("input")[1].getAttribute("style")).toBe("color: #787878");
156
- });
157
-
158
- test("input is not filled with highlight when maximum ranges reached", async () => {
159
- const { model } = await createSelectionInput({ maximumRanges: 1 });
160
- expect(fixture.querySelectorAll("input")).toHaveLength(1);
161
- model.dispatch("PREPARE_SELECTION_EXPANSION");
162
- model.dispatch("START_SELECTION_EXPANSION");
163
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
164
- await nextTick();
165
- expect(fixture.querySelectorAll("input")).toHaveLength(1);
166
- expect(fixture.querySelector("input")!.value).toBe("A1");
167
- expect(fixture.querySelector(".o-add-selection")).toBeNull();
168
- });
169
-
170
- test("new range is added when button clicked", async () => {
171
- await createSelectionInput();
172
- expect(fixture.querySelectorAll("input").length).toBe(1);
173
- await simulateClick(".o-add-selection");
174
- expect(fixture.querySelectorAll("input").length).toBe(2);
175
- });
176
-
177
- test("cannot add more ranges than the maximum", async () => {
178
- await createSelectionInput({ maximumRanges: 2 });
179
- expect(fixture.querySelectorAll("input").length).toBe(1);
180
- await simulateClick(".o-add-selection");
181
- expect(fixture.querySelectorAll("input").length).toBe(2);
182
- expect(fixture.querySelector(".o-add-selection")).toBeNull();
183
- await simulateClick(".o-remove-selection");
184
- expect(fixture.querySelector(".o-add-selection")).toBeDefined();
185
- });
186
-
187
- test("can set initial ranges", async () => {
188
- await createSelectionInput({ initialRanges: ["C4", "A1"] });
189
- expect(fixture.querySelectorAll("input").length).toBe(2);
190
- expect(fixture.querySelectorAll("input")[0].value).toBe("C4");
191
- expect(fixture.querySelectorAll("input")[1].value).toBe("A1");
192
- });
193
-
194
- test("can focus a range", async () => {
195
- await createSelectionInput();
196
- await simulateClick(".o-add-selection"); // last input is now focused
197
- expect([...fixture.querySelectorAll("input")].map((i) => i.className)).toEqual([
198
- "",
199
- "o-focused",
200
- ]);
201
- await simulateClick("input"); // focus the first input
202
- expect([...fixture.querySelectorAll("input")].map((i) => i.className)).toEqual([
203
- "o-focused",
204
- "",
205
- ]);
206
- });
207
-
208
- test("unmounting deletes the state", async () => {
209
- const { parent, model, id } = await createSelectionInput();
210
- expect(model.getters.getSelectionInput(id).length).toBe(1);
211
- parent.unmount();
212
- expect(model.getters.getSelectionInput(id).length).toBe(0);
213
- });
214
-
215
- test("can unfocus all inputs with the OK button", async () => {
216
- await createSelectionInput();
217
- expect(fixture.querySelector(".o-focused")).toBeTruthy();
218
- await simulateClick(".o-selection-ok");
219
- });
220
-
221
- test("changed event is triggered when input changed", async () => {
222
- let newRanges;
223
- const onChanged = jest.fn(({ detail }) => {
224
- newRanges = detail.ranges;
225
- });
226
- await createSelectionInput({ onChanged });
227
- await writeInput(0, "C2");
228
- expect(onChanged).toHaveBeenCalled();
229
- expect(newRanges).toStrictEqual(["C2"]);
230
- });
231
-
232
- test("changed event is triggered when highlight added", async () => {
233
- let newRanges;
234
- const onChanged = jest.fn(({ detail }) => {
235
- newRanges = detail.ranges;
236
- });
237
- const { model } = await createSelectionInput({ onChanged });
238
- model.dispatch("ADD_HIGHLIGHTS", {
239
- ranges: {
240
- B4: "#454545",
241
- },
242
- });
243
- await nextTick();
244
- expect(onChanged).toHaveBeenCalled();
245
- expect(newRanges).toStrictEqual(["B4"]);
246
- });
247
-
248
- test("focus is transfered from one input to another", async () => {
249
- model = new Model();
250
- const parent = new MutliParent(model);
251
- await parent.mount(fixture);
252
- await nextTick();
253
- expect(fixture.querySelector(".input-1 .o-focused")).toBeTruthy();
254
- expect(fixture.querySelector(".input-2 .o-focused")).toBeFalsy();
255
- await simulateClick(".input-2 input");
256
- expect(fixture.querySelector(".input-1 .o-focused")).toBeFalsy();
257
- expect(fixture.querySelector(".input-2 .o-focused")).toBeTruthy();
258
- });
259
- });
@@ -1,148 +0,0 @@
1
- import { Component, hooks, tags } from "@odoo/owl";
2
- import { Spreadsheet } from "../../src/components";
3
- import { Model } from "../../src/model";
4
- import { sidePanelRegistry } from "../../src/registries/index";
5
- import { SidePanelContent } from "../../src/registries/side_panel_registry";
6
- import { SpreadsheetEnv } from "../../src/types";
7
- import { simulateClick } from "../dom_helper";
8
- import { makeTestFixture, nextTick } from "../helpers";
9
-
10
- const { useRef } = hooks;
11
- const { xml } = tags;
12
-
13
- class Parent extends Component<any> {
14
- static template = xml`<Spreadsheet t-ref="spreadsheet" data="data"/>`;
15
- static components = { Spreadsheet };
16
- private spreadsheet: any = useRef("spreadsheet");
17
- get spreadsheetEnv(): SpreadsheetEnv {
18
- return this.spreadsheet.comp.env;
19
- }
20
- get model(): Model {
21
- return this.spreadsheet.comp.model;
22
- }
23
- }
24
-
25
- let fixture: HTMLElement;
26
- let parent: Parent;
27
- let sidePanelContent: { [key: string]: SidePanelContent };
28
-
29
- class Body extends Component<any, any> {
30
- static template = xml`
31
- <div>
32
- <div class="main_body">test</div>
33
- <div class="props_body" t-if="props.text"><t t-esc="props.text"/></div>
34
- </div>`;
35
- }
36
-
37
- class Body2 extends Component<any, any> {
38
- static template = xml`
39
- <div>
40
- <div class="main_body_2">Hello</div>
41
- <div class="props_body_2" t-if="props.field"><t t-esc="props.field"/></div>
42
- </div>`;
43
- }
44
-
45
- beforeEach(async () => {
46
- fixture = makeTestFixture();
47
- parent = new Parent();
48
- await parent.mount(fixture);
49
- sidePanelContent = Object.assign({}, sidePanelRegistry.content);
50
- });
51
-
52
- afterEach(() => {
53
- fixture.remove();
54
- sidePanelRegistry.content = sidePanelContent;
55
- });
56
-
57
- describe("Side Panel", () => {
58
- test("Can open a custom side panel", async () => {
59
- sidePanelRegistry.add("CUSTOM_PANEL", {
60
- title: "Custom Panel",
61
- Body: Body,
62
- });
63
- parent.spreadsheetEnv.openSidePanel("CUSTOM_PANEL");
64
- await nextTick();
65
- expect(document.querySelectorAll(".o-sidePanel")).toHaveLength(1);
66
- expect(document.querySelector(".o-sidePanelTitle")!.textContent).toBe("Custom Panel");
67
- expect(document.querySelector(".main_body")!.textContent).toBe("test");
68
- expect(document.querySelector(".props_body")).toBeNull();
69
- });
70
-
71
- test("Can close a side panel", async () => {
72
- sidePanelRegistry.add("CUSTOM_PANEL", {
73
- title: "Custom Panel",
74
- Body: Body,
75
- });
76
- parent.spreadsheetEnv.openSidePanel("CUSTOM_PANEL");
77
- await nextTick();
78
- expect(document.querySelectorAll(".o-sidePanel")).toHaveLength(1);
79
- simulateClick(".o-sidePanelClose");
80
- await nextTick();
81
- expect(document.querySelectorAll(".o-sidePanel")).toHaveLength(0);
82
- });
83
-
84
- test("Can toggle a side panel", async () => {
85
- sidePanelRegistry.add("CUSTOM_PANEL", {
86
- title: "Custom Panel",
87
- Body: Body,
88
- });
89
- parent.spreadsheetEnv.toggleSidePanel("CUSTOM_PANEL");
90
- await nextTick();
91
- expect(document.querySelectorAll(".o-sidePanel")).toHaveLength(1);
92
- parent.spreadsheetEnv.toggleSidePanel("CUSTOM_PANEL");
93
- await nextTick();
94
- expect(document.querySelectorAll(".o-sidePanel")).toHaveLength(0);
95
- });
96
-
97
- test("Can toggle a side panel when another is already opened", async () => {
98
- sidePanelRegistry.add("CUSTOM_PANEL_1", {
99
- title: "Custom Panel 1",
100
- Body: Body,
101
- });
102
- sidePanelRegistry.add("CUSTOM_PANEL_2", {
103
- title: "Custom Panel 2",
104
- Body: Body,
105
- });
106
- parent.spreadsheetEnv.toggleSidePanel("CUSTOM_PANEL_1");
107
- await nextTick();
108
- expect(document.querySelector(".o-sidePanelTitle")!.textContent).toBe("Custom Panel 1");
109
- parent.spreadsheetEnv.toggleSidePanel("CUSTOM_PANEL_2");
110
- await nextTick();
111
- expect(document.querySelector(".o-sidePanelTitle")!.textContent).toBe("Custom Panel 2");
112
- });
113
-
114
- test("Can open a custom side panel with custom title and panelProps", async () => {
115
- sidePanelRegistry.add("CUSTOM_PANEL", {
116
- title: () => "Computed Title",
117
- Body: Body,
118
- });
119
- parent.spreadsheetEnv.openSidePanel("CUSTOM_PANEL", { text: "context" });
120
- await nextTick();
121
- expect(document.querySelectorAll(".o-sidePanel")).toHaveLength(1);
122
- expect(document.querySelector(".o-sidePanelTitle")!.textContent).toBe("Computed Title");
123
- expect(document.querySelector(".main_body")!.textContent).toBe("test");
124
- expect(document.querySelector(".props_body")).toBeDefined();
125
- expect(document.querySelector(".props_body")!.textContent).toBe("context");
126
- });
127
-
128
- test("Can open a side panel when another one is open", async () => {
129
- sidePanelRegistry.add("PANEL_1", {
130
- title: "PANEL_1",
131
- Body: Body,
132
- });
133
- sidePanelRegistry.add("PANEL_2", {
134
- title: "PANEL_2",
135
- Body: Body2,
136
- });
137
- parent.spreadsheetEnv.openSidePanel("PANEL_1", { text: "test" });
138
- await nextTick();
139
- parent.spreadsheetEnv.openSidePanel("PANEL_2", { field: "field" });
140
- await nextTick();
141
- expect(document.querySelectorAll(".o-sidePanel")).toHaveLength(1);
142
- expect(document.querySelector(".o-sidePanelTitle")!.textContent).toBe("PANEL_2");
143
- expect(document.querySelector(".main_body_2")).toBeDefined();
144
- expect(document.querySelector(".main_body_2")!.textContent).toBe("Hello");
145
- expect(document.querySelector(".props_body_2")).toBeDefined();
146
- expect(document.querySelector(".props_body_2")!.textContent).toBe("field");
147
- });
148
- });
@@ -1,194 +0,0 @@
1
- import { Component, hooks, tags } from "@odoo/owl";
2
- import { Model } from "../../src";
3
- import { Spreadsheet } from "../../src/components";
4
- import { args, functionRegistry } from "../../src/functions";
5
- import { DEBUG } from "../../src/helpers";
6
- import { SelectionMode } from "../../src/plugins/selection";
7
- import { simulateClick, triggerMouseEvent } from "../dom_helper";
8
- import { makeTestFixture, MockClipboard, nextTick } from "../helpers";
9
-
10
- const { xml } = tags;
11
- const { useRef } = hooks;
12
-
13
- let fixture: HTMLElement;
14
- let parent: Parent;
15
- const clipboard = new MockClipboard();
16
-
17
- Object.defineProperty(navigator, "clipboard", {
18
- get() {
19
- return clipboard;
20
- },
21
- configurable: true,
22
- });
23
-
24
- class Parent extends Component<any> {
25
- static template = xml`<Spreadsheet t-ref="spreadsheet" data="data"/>`;
26
- static components = { Spreadsheet };
27
- private spreadsheet: any = useRef("spreadsheet");
28
- readonly data: any;
29
- get model(): Model {
30
- return this.spreadsheet.comp.model;
31
- }
32
-
33
- constructor(data?) {
34
- super();
35
- this.data = data;
36
- }
37
- }
38
-
39
- beforeEach(async () => {
40
- fixture = makeTestFixture();
41
- parent = new Parent({
42
- sheets: [
43
- {
44
- id: 1,
45
- },
46
- ],
47
- });
48
- await parent.mount(fixture);
49
- });
50
-
51
- afterEach(() => {
52
- fixture.remove();
53
- });
54
-
55
- describe("Spreadsheet", () => {
56
- test("simple rendering snapshot", async () => {
57
- await nextTick();
58
- expect(fixture.querySelector(".o-spreadsheet")).toMatchSnapshot();
59
- });
60
-
61
- test("focus is properly set, initially and after switching sheet", async () => {
62
- expect(document.activeElement!.tagName).toEqual("CANVAS");
63
- document.querySelector(".o-add-sheet")!.dispatchEvent(new Event("click"));
64
- // simulate the fact that a user clicking on the add sheet button will
65
- // move the focus to the document.body
66
- (document.activeElement as any).blur();
67
- await nextTick();
68
- expect(document.querySelectorAll(".o-sheet").length).toBe(2);
69
- expect(document.activeElement!.tagName).toEqual("CANVAS");
70
- });
71
-
72
- test("Can use the env in a function", () => {
73
- let env;
74
- functionRegistry.add("GETACTIVESHEET", {
75
- description: "Get the name of the current sheet",
76
- compute: function () {
77
- env = this.env;
78
- return "Sheet";
79
- },
80
- args: args(``),
81
- returns: ["STRING"],
82
- });
83
- parent.model.dispatch("SET_VALUE", { xc: "A1", text: "=GETACTIVESHEET()" });
84
- expect(env).toBeTruthy();
85
- });
86
-
87
- test("Can use the env in a function at model start", async () => {
88
- let env;
89
- functionRegistry.add("GETACTIVESHEET", {
90
- description: "Get the name of the current sheet",
91
- compute: function () {
92
- env = this.env;
93
- return "Sheet";
94
- },
95
- args: args(``),
96
- returns: ["STRING"],
97
- });
98
- const parent = new Parent({
99
- version: 2,
100
- sheets: [
101
- {
102
- name: "Sheet1",
103
- colNumber: 26,
104
- rowNumber: 100,
105
- cells: {
106
- A1: { content: "=GETACTIVESHEET()" },
107
- },
108
- conditionalFormats: [],
109
- },
110
- ],
111
- activeSheet: "Sheet1",
112
- });
113
- await parent.mount(fixture);
114
- expect(env).toBeTruthy();
115
- });
116
-
117
- test("Clipboard is in spreadsheet env", () => {
118
- expect((parent as any).spreadsheet.comp.env.clipboard).toBe(clipboard);
119
- });
120
-
121
- test("selection mode is changed with a simple select", async () => {
122
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.idle);
123
- triggerMouseEvent("canvas", "mousedown", 300, 200);
124
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.selecting);
125
- triggerMouseEvent(window, "mouseup", 300, 200);
126
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.idle);
127
- });
128
-
129
- test("selection mode is changed when selecting with CTRL pressed", async () => {
130
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.idle);
131
- document.activeElement!.dispatchEvent(
132
- new KeyboardEvent("keydown", { key: "Control", ctrlKey: true, bubbles: true })
133
- );
134
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.readyToExpand);
135
- triggerMouseEvent("canvas", "mousedown", 300, 200, { ctrlKey: true });
136
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.expanding);
137
- triggerMouseEvent(window, "mouseup", 300, 200, { ctrlKey: true });
138
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.readyToExpand);
139
- document.activeElement!.dispatchEvent(
140
- new KeyboardEvent("keyup", { key: "Control", bubbles: true })
141
- );
142
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.idle);
143
- });
144
-
145
- test("selection mode is changed when releasing CTRL while selecting", async () => {
146
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.idle);
147
- document.activeElement!.dispatchEvent(
148
- new KeyboardEvent("keydown", { key: "Control", ctrlKey: true, bubbles: true })
149
- );
150
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.readyToExpand);
151
- triggerMouseEvent("canvas", "mousedown", 300, 200, { ctrlKey: true });
152
- document.activeElement!.dispatchEvent(
153
- new KeyboardEvent("keyup", { key: "Control", bubbles: true })
154
- );
155
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.expanding);
156
- triggerMouseEvent(window, "mouseup", 300, 200);
157
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.idle);
158
- });
159
-
160
- test("selection mode is changed when pressing CTRL while selecting", async () => {
161
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.idle);
162
- triggerMouseEvent("canvas", "mousedown", 300, 200);
163
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.selecting);
164
- document.activeElement!.dispatchEvent(
165
- new KeyboardEvent("keydown", { key: "Control", ctrlKey: true, bubbles: true })
166
- );
167
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.expanding);
168
- triggerMouseEvent(window, "mouseup", 300, 200, { ctrlKey: true });
169
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.readyToExpand);
170
- });
171
-
172
- test("repeating CTRL keydown events does not trigger command", async () => {
173
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.idle);
174
- document.activeElement!.dispatchEvent(
175
- new KeyboardEvent("keydown", { key: "Control", ctrlKey: true, bubbles: true, repeat: true })
176
- );
177
- expect(parent.model.getters.getSelectionMode()).toBe(SelectionMode.idle);
178
- });
179
-
180
- test("Debug informations are removed when Spreadsheet is destroyed", async () => {
181
- parent["spreadsheet"].comp.destroy();
182
- expect(Object.keys(DEBUG)).toHaveLength(0);
183
- });
184
-
185
- test("typing opens composer after toolbar clicked", async () => {
186
- await simulateClick(`div[title="Bold"]`);
187
- expect(document.activeElement).not.toBeNull();
188
- document.activeElement?.dispatchEvent(
189
- new KeyboardEvent("keydown", { key: "d", bubbles: true })
190
- );
191
- expect(parent.model.getters.getEditionMode()).toBe("editing");
192
- expect(parent.model.getters.getCurrentContent()).toBe("d");
193
- });
194
- });