@odoo/o-spreadsheet 14.0.1 → 14.0.3

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 +17880 -0
  2. package/dist/o-spreadsheet.d.ts +4119 -0
  3. package/dist/o-spreadsheet.esm.js +17845 -0
  4. package/dist/o-spreadsheet.iife.js +17882 -0
  5. package/dist/o-spreadsheet.iife.min.js +1446 -0
  6. package/package.json +32 -9
  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,100 +0,0 @@
1
- import { toZone } from "../../src/helpers";
2
- import { Model } from "../../src/model";
3
- import "../helpers"; // to have getcontext mocks
4
- import { getCell } from "../helpers";
5
-
6
- describe("edition", () => {
7
- test("adding and removing a cell (by setting its content to empty string", () => {
8
- const model = new Model();
9
- // adding
10
- model.dispatch("START_EDITION", { text: "a" });
11
- model.dispatch("STOP_EDITION");
12
- expect(Object.keys(model["workbook"].activeSheet.cells)).toEqual(["A1"]);
13
- expect(model["workbook"].activeSheet.cells["A1"].content).toBe("a");
14
-
15
- // removing
16
- model.dispatch("START_EDITION");
17
- model.dispatch("SET_CURRENT_CONTENT", { content: "" });
18
- model.dispatch("STOP_EDITION");
19
- expect(model["workbook"].activeSheet.cells).toEqual({});
20
- });
21
-
22
- test("deleting a cell with style does not remove it", () => {
23
- const model = new Model({
24
- sheets: [
25
- {
26
- colNumber: 10,
27
- rowNumber: 10,
28
- cells: { A2: { style: 1, content: "a2" } },
29
- },
30
- ],
31
- styles: {
32
- 1: { fillColor: "red" },
33
- },
34
- });
35
-
36
- // removing
37
- expect(model["workbook"].activeSheet.cells["A2"].content).toBe("a2");
38
- model.dispatch("SELECT_CELL", { col: 0, row: 1 });
39
- model.dispatch("DELETE_CONTENT", {
40
- sheet: model.getters.getActiveSheet(),
41
- target: model.getters.getSelectedZones(),
42
- });
43
- expect("A2" in model["workbook"].activeSheet.cells).toBeTruthy();
44
- expect(model["workbook"].activeSheet.cells["A2"].content).toBe("");
45
- });
46
-
47
- test("editing a cell, then activating a new sheet: edition should be stopped", () => {
48
- const model = new Model();
49
- const sheet1 = model["workbook"].visibleSheets[0];
50
- model.dispatch("START_EDITION", { text: "a" });
51
- expect(model.getters.getEditionMode()).toBe("editing");
52
- model.dispatch("CREATE_SHEET", { activate: true, id: "42" });
53
- expect(model.getters.getEditionMode()).toBe("inactive");
54
- expect(getCell(model, "A1")).toBe(null);
55
- model.dispatch("ACTIVATE_SHEET", { from: model.getters.getActiveSheet(), to: sheet1 });
56
- expect(getCell(model, "A1")!.content).toBe("a");
57
- });
58
-
59
- test("editing a cell, start a composer selection, then activating a new sheet: mode should still be selecting", () => {
60
- const model = new Model();
61
- const sheet1 = model["workbook"].visibleSheets[0];
62
- model.dispatch("START_EDITION", { text: "=" });
63
- model.dispatch("START_COMPOSER_SELECTION");
64
- expect(model.getters.getEditionMode()).toBe("selecting");
65
- expect(model.getters.getEditionSheet()).toBe(sheet1);
66
- model.dispatch("CREATE_SHEET", { activate: true, id: "42", name: "Sheet2" });
67
- expect(model.getters.getEditionMode()).toBe("selecting");
68
- expect(model.getters.getEditionSheet()).toBe(sheet1);
69
- model.dispatch("STOP_EDITION");
70
- expect(getCell(model, "A1", model.getters.getActiveSheet())).toBeNull();
71
- model.dispatch("ACTIVATE_SHEET", { from: model.getters.getActiveSheet(), to: sheet1 });
72
- expect(getCell(model, "A1")!.content).toBe("=");
73
- });
74
-
75
- test("ignore stopping composer selection if not selecting", () => {
76
- const model = new Model();
77
- expect(model.getters.getEditionMode()).toBe("inactive");
78
- model.dispatch("STOP_COMPOSER_SELECTION");
79
- expect(model.getters.getEditionMode()).toBe("inactive");
80
- });
81
-
82
- test("start editing where theres a merge on other sheet, change sheet, and stop edition", () => {
83
- const model = new Model();
84
- const sheetId1 = model.getters.getActiveSheet();
85
- const sheetId2 = "42";
86
- model.dispatch("ADD_MERGE", {
87
- sheet: sheetId1,
88
- zone: toZone("A1:D5"),
89
- });
90
- model.dispatch("CREATE_SHEET", { activate: true, id: sheetId2 });
91
- model.dispatch("SELECT_CELL", { col: 2, row: 2 });
92
-
93
- model.dispatch("START_EDITION", { text: "=" });
94
- model.dispatch("START_COMPOSER_SELECTION");
95
- model.dispatch("ACTIVATE_SHEET", { from: sheetId2, to: sheetId1 });
96
- model.dispatch("STOP_EDITION");
97
- expect(model.getters.getCell(2, 2, "Sheet2")?.content).toBe("=");
98
- expect(model.getters.getCell(0, 0, "Sheet2")).toBeNull();
99
- });
100
- });
@@ -1,332 +0,0 @@
1
- import { args, functionRegistry } from "../../src/functions";
2
- import { toCartesian } from "../../src/helpers";
3
- import { Model } from "../../src/model";
4
- import { LOADING } from "../../src/plugins/evaluation";
5
- import { asyncComputations, patch, waitForRecompute } from "../helpers";
6
-
7
- describe("evaluateCells, async formulas", () => {
8
- test("async formula", async () => {
9
- const model = new Model();
10
- model.dispatch("SET_VALUE", { xc: "A1", text: "=3" });
11
- model.dispatch("SET_VALUE", { xc: "A2", text: "=WAIT(3)" });
12
- model.dispatch("SET_VALUE", { xc: "A3", text: "= WAIT(1) + 1" });
13
-
14
- expect(model.getters.getCell(0, 0)!.formula!.compiledFormula.async).toBe(false);
15
- expect(model.getters.getCell(0, 1)!.formula!.compiledFormula.async).toBe(true);
16
- expect(model.getters.getCell(0, 2)!.formula!.compiledFormula.async).toBe(true);
17
- expect(model.getters.getCell(0, 1)!.value).toEqual(LOADING);
18
- expect(patch.calls.length).toBe(2);
19
- await waitForRecompute();
20
- expect(model.getters.getCell(0, 1)!.value).toEqual(3);
21
- expect(model.getters.getCell(0, 2)!.value).toEqual(2);
22
- });
23
-
24
- test("async formulas in base data", async () => {
25
- const model = new Model({
26
- sheets: [
27
- {
28
- colNumber: 10,
29
- rowNumber: 10,
30
- cells: { B2: { content: "=WAIT(3)" } },
31
- },
32
- ],
33
- });
34
-
35
- expect(model.getters.getCell(1, 1)!.formula!.compiledFormula.async).toBe(true);
36
- expect(model.getters.getCell(1, 1)!.value).toEqual(LOADING);
37
- let updates = 0;
38
- model.on("update", null, () => updates++);
39
- expect(updates).toBe(0);
40
- await waitForRecompute();
41
- expect(updates).toBe(1);
42
- expect(model["workbook"].activeSheet.cells["B2"].value).toEqual(3);
43
- });
44
-
45
- test("async formula, on update", async () => {
46
- const model = new Model();
47
- model.dispatch("SET_VALUE", { xc: "A1", text: "=3" });
48
- model.dispatch("SET_VALUE", { xc: "A2", text: "=?WAIT(33)" });
49
- expect(model.getters.getCell(0, 1)!.formula!.compiledFormula.async).toBe(true);
50
- expect(model.getters.getCell(0, 1)!.value).toEqual(LOADING);
51
- expect(patch.calls.length).toBe(1);
52
-
53
- await waitForRecompute();
54
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(33);
55
- });
56
-
57
- test("async formula (async function inside async function)", async () => {
58
- const model = new Model();
59
- model.dispatch("SET_VALUE", { xc: "A2", text: "=WAIT(WAIT(3))" });
60
- expect(model.getters.getCell(0, 1)!.formula!.compiledFormula.async).toBe(true);
61
- expect(model.getters.getCell(0, 1)!.value).toEqual(LOADING);
62
- expect(patch.calls.length).toBe(1);
63
- // Inner wait is resolved
64
- await waitForRecompute();
65
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(LOADING);
66
- expect(patch.calls.length).toBe(1);
67
-
68
- // outer wait is resolved
69
- await waitForRecompute();
70
-
71
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(3);
72
- });
73
-
74
- test("async formula, and value depending on it", async () => {
75
- const model = new Model();
76
- model.dispatch("SET_VALUE", { xc: "A1", text: "=WAIT(3)" });
77
- model.dispatch("SET_VALUE", { xc: "A2", text: "=1 + A1" });
78
- expect(model.getters.getCell(0, 1)!.formula!.compiledFormula.async).toBe(false);
79
- expect(model.getters.getCell(0, 0)!.value).toEqual(LOADING);
80
- expect(model.getters.getCell(0, 1)!.value).toEqual(LOADING);
81
- expect(patch.calls.length).toBe(1);
82
-
83
- await waitForRecompute();
84
- expect(model["workbook"].activeSheet.cells["A1"].value).toEqual(3);
85
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(4);
86
- expect(patch.calls.length).toBe(0);
87
- });
88
-
89
- test("async formula, and multiple values depending on it", async () => {
90
- const model = new Model();
91
- model.dispatch("SET_VALUE", { xc: "A1", text: "=WAIT(3)" });
92
- model.dispatch("SET_VALUE", { xc: "A2", text: "=WAIT(1)" });
93
- model.dispatch("SET_VALUE", { xc: "A3", text: "=A1 + A2" });
94
-
95
- expect(model.getters.getCell(0, 2)!.formula!.compiledFormula.async).toBe(false);
96
- expect(model.getters.getCell(0, 0)!.value).toEqual(LOADING);
97
- expect(model.getters.getCell(0, 1)!.value).toEqual(LOADING);
98
- expect(model.getters.getCell(0, 2)!.value).toEqual(LOADING);
99
- expect(patch.calls.length).toBe(2);
100
- await waitForRecompute();
101
- expect(model["workbook"].activeSheet.cells["A1"].value).toEqual(3);
102
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(1);
103
- expect(model["workbook"].activeSheet.cells["A3"].value).toEqual(4);
104
- expect(patch.calls.length).toBe(0);
105
- });
106
-
107
- test("async formula, another configuration", async () => {
108
- const model = new Model();
109
- model.dispatch("SET_VALUE", { xc: "A1", text: "=1" });
110
- model.dispatch("SET_VALUE", { xc: "A2", text: "=WAIT(A1 + 3)" });
111
- model.dispatch("SET_VALUE", { xc: "A3", text: "=2 + Wait(3 + Wait(A2))" });
112
-
113
- expect(model["workbook"].activeSheet.cells["A1"].value).toEqual(1);
114
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(LOADING);
115
- expect(model["workbook"].activeSheet.cells["A3"].value).toEqual(LOADING);
116
-
117
- await waitForRecompute();
118
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(4);
119
- expect(model["workbook"].activeSheet.cells["A3"].value).toEqual(LOADING);
120
- // We need two resolveAll, one for Wait(A2) and the second for (Wait(3 + 4))
121
- await waitForRecompute();
122
- await waitForRecompute();
123
-
124
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(4);
125
- expect(model["workbook"].activeSheet.cells["A3"].value).toEqual(9);
126
- });
127
-
128
- test("async formula, multi levels", async () => {
129
- const model = new Model();
130
- model.dispatch("SET_VALUE", { xc: "A1", text: "=WAIT(1)" });
131
- model.dispatch("SET_VALUE", { xc: "A2", text: "=SUM(A1)" });
132
- model.dispatch("SET_VALUE", { xc: "A3", text: "=SUM(A2)" });
133
-
134
- expect(model["workbook"].activeSheet.cells["A1"].value).toEqual(LOADING);
135
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(LOADING);
136
- expect(model["workbook"].activeSheet.cells["A3"].value).toEqual(LOADING);
137
-
138
- await waitForRecompute();
139
-
140
- expect(model["workbook"].activeSheet.cells["A1"].value).toEqual(1);
141
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(1);
142
- expect(model["workbook"].activeSheet.cells["A3"].value).toEqual(1);
143
- });
144
-
145
- test("async formula, with another cell in sync error", async () => {
146
- const model = new Model();
147
- model.dispatch("SET_VALUE", { xc: "A1", text: "=A1" });
148
- model.dispatch("SET_VALUE", { xc: "A2", text: "=WAIT(3)" });
149
- let updateNbr = 0;
150
- model.on("update", null, () => updateNbr++);
151
-
152
- expect(model.getters.getCell(0, 1)!.formula!.compiledFormula.async).toBe(true);
153
- expect(model.getters.getCell(0, 0)!.value).toEqual("#CYCLE");
154
- expect(model.getters.getCell(0, 1)!.value).toEqual(LOADING);
155
- expect(patch.calls.length).toBe(1);
156
- updateNbr = 0;
157
- await waitForRecompute();
158
- // next assertion checks that the interface has properly been
159
- // notified that the state did change
160
- expect(updateNbr).toBe(1);
161
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(3);
162
- });
163
-
164
- test("async formula and errors, scenario 1", async () => {
165
- const model = new Model();
166
- model.dispatch("SET_VALUE", { xc: "A1", text: "=WAIT(3)" });
167
- model.dispatch("SET_VALUE", { xc: "A2", text: "=A1 + 1/0" });
168
-
169
- expect(model.getters.getCell(0, 1)!.formula!.compiledFormula.async).toBe(false);
170
- expect(model.getters.getCell(0, 1)!.value).toEqual(LOADING);
171
-
172
- await waitForRecompute();
173
-
174
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual("#ERROR");
175
-
176
- model.dispatch("SET_VALUE", { xc: "A1", text: "=WAIT(4)" });
177
-
178
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual(LOADING);
179
-
180
- await waitForRecompute();
181
-
182
- expect(model["workbook"].activeSheet.cells["A2"].value).toEqual("#ERROR");
183
- });
184
-
185
- test("sync formula depending on error async cell", async () => {
186
- functionRegistry.add("CRASHING", {
187
- async: true,
188
- description: "This async formula crashes",
189
- args: args(``),
190
- compute: () => {
191
- throw new Error("I crashed");
192
- },
193
- returns: ["ANY"],
194
- });
195
- const model = new Model();
196
- model.dispatch("SET_VALUE", { xc: "A1", text: "=CRASHING()" });
197
- model.dispatch("SET_VALUE", { xc: "A2", text: "=SUM(A1)" });
198
- await asyncComputations();
199
- expect(model.getters.getCell(0, 0)!.value).toEqual("#ERROR");
200
- expect(model.getters.getCell(0, 1)!.value).toEqual(LOADING);
201
- await asyncComputations();
202
- expect(model.getters.getCell(0, 0)!.value).toEqual("#ERROR");
203
- expect(model.getters.getCell(0, 1)!.value).toEqual("#ERROR");
204
- });
205
-
206
- test("async formulas in errors are re-evaluated", async () => {
207
- functionRegistry.add("ONLYPOSITIVE", {
208
- async: true,
209
- description: "This async formula crashes for negative numbers",
210
- args: args(`value (number)`),
211
- compute: (value) => {
212
- if (value < 0) {
213
- throw new Error("I only like positive numbers");
214
- }
215
- return value;
216
- },
217
- returns: ["ANY"],
218
- });
219
- const model = new Model();
220
- model.dispatch("SET_VALUE", { xc: "A2", text: "-1" });
221
- model.dispatch("SET_VALUE", { xc: "A1", text: "=ONLYPOSITIVE(A2)" });
222
- await asyncComputations();
223
- expect(model.getters.getCell(0, 0)!.value).toEqual("#ERROR");
224
- model.dispatch("SET_VALUE", { xc: "A2", text: "1" });
225
- await asyncComputations();
226
- expect(model.getters.getCell(0, 0)!.value).toEqual(1);
227
- });
228
-
229
- test("async formulas rejected with a reason", async () => {
230
- functionRegistry.add("REJECT", {
231
- async: true,
232
- description: "This async formula is rejected",
233
- args: args(`value (any, optional)`),
234
- compute: (value: string | undefined) => {
235
- return new Promise((resolve, reject) => reject(value || undefined));
236
- },
237
- returns: ["ANY"],
238
- });
239
- const model = new Model();
240
- model.dispatch("SET_VALUE", { xc: "A1", text: `=REJECT("This is an error")` });
241
- model.dispatch("SET_VALUE", { xc: "A2", text: `=REJECT()` });
242
- model.dispatch("SET_VALUE", { xc: "A3", text: `=REJECT(4)` });
243
- await asyncComputations();
244
- expect(model.getters.getCell(0, 0)!.value).toBe("#ERROR");
245
- expect(model.getters.getCell(0, 1)!.value).toBe("#ERROR");
246
- expect(model.getters.getCell(0, 2)!.value).toBe("#ERROR");
247
- expect(model.getters.getCell(0, 0)!.error).toBe("This is an error");
248
- expect(model.getters.getCell(0, 1)!.error).toBe("");
249
- expect(model.getters.getCell(0, 2)!.error).toBe("4");
250
- });
251
-
252
- test("sync formula that depends on multiple async formula should not require as many evaluation as they have async dependencies", async () => {
253
- const model = new Model({
254
- sheets: [
255
- {
256
- id: "Sheet1",
257
- name: "Sheet1",
258
- cells: {
259
- A1: { content: "=sum(Sheet2!a1:a2)" },
260
- A2: { content: "=Sheet2!a2+Sheet2!a3" },
261
- },
262
- },
263
- {
264
- id: "Sheet2",
265
- name: "Sheet2",
266
- cells: {
267
- A1: { content: "=wait(100)" },
268
- A2: { content: "=wait(100)" },
269
- A3: { content: "=wait(100)" },
270
- },
271
- },
272
- ],
273
- });
274
- await waitForRecompute();
275
- expect(model.getters.getCell(...toCartesian("A1"))!.value).toBe(200);
276
- // this one will not be able to compute in one go because there is no relation between all the depending cells
277
- expect(model.getters.getCell(...toCartesian("A2"))!.value).toBe("Loading...");
278
- await waitForRecompute();
279
- expect(model.getters.getCell(...toCartesian("A2"))!.value).toBe(200);
280
- });
281
-
282
- describe("Async evaluation with cells that are at the same position on different sheets", () => {
283
- test("Sheet at position 1", async () => {
284
- const model = new Model({
285
- sheets: [
286
- {
287
- id: "Sheet1",
288
- name: "Sheet1",
289
- cells: {
290
- B2: { content: "=Sheet2!B2" },
291
- },
292
- },
293
- {
294
- id: "Sheet2",
295
- name: "Sheet2",
296
- cells: {
297
- B1: { content: "=WAIT(50)" },
298
- B2: { content: "=B1" },
299
- },
300
- },
301
- ],
302
- activeSheet: "Sheet1",
303
- });
304
- await waitForRecompute();
305
- expect(model.getters.getCell(1, 1, "Sheet1")!.value).toBe(50);
306
- });
307
- test("Sheet at position 2", async () => {
308
- const model = new Model({
309
- sheets: [
310
- {
311
- id: "Sheet1",
312
- name: "Sheet1",
313
- cells: {
314
- A1: { content: "=WAIT(50)" },
315
- A2: { content: "=A1" },
316
- },
317
- },
318
- {
319
- id: "Sheet2",
320
- name: "Sheet2",
321
- cells: {
322
- A2: { content: "=Sheet1!A2" },
323
- },
324
- },
325
- ],
326
- activeSheet: "Sheet2",
327
- });
328
- await waitForRecompute();
329
- expect(model.getters.getCell(0, 1, "Sheet2")!.value).toBe(50);
330
- });
331
- });
332
- });
@@ -1,79 +0,0 @@
1
- import { Model } from "../../src/model";
2
- import "../canvas.mock";
3
- import { evaluateCell, evaluateCellText, evaluateGrid, getCell } from "../helpers";
4
-
5
- describe("evaluateCells", () => {
6
- test("Various date representations", () => {
7
- const grid = {
8
- A1: "1/2/2020",
9
- A2: "02/26/1920",
10
- A3: "04/3/2010",
11
- B1: "1-2-2020",
12
- B2: "02-26-1920",
13
- B3: "04-3-2010",
14
- C1: "1 2 2020",
15
- C2: "02 26 1920",
16
- C3: "04 3 2010",
17
- D1: "2020/1/2",
18
- D2: "1920/02/26",
19
- D3: "2010/04/3",
20
- E1: "2020-1-2",
21
- E2: "1920-02-26",
22
- E3: "2010-04-3",
23
- F1: "2020 1 2",
24
- F2: "1920 02 26",
25
- F3: "2010 04 3",
26
- };
27
- expect(evaluateGrid(grid)).toEqual({
28
- A1: { format: "m/d/yyyy", jsDate: new Date(2020, 0, 2), value: 43832 },
29
- A2: { format: "mm/dd/yyyy", jsDate: new Date(1920, 1, 26), value: 7362 },
30
- A3: { format: "mm/dd/yyyy", jsDate: new Date(2010, 3, 3), value: 40271 },
31
- B1: { format: "m-d-yyyy", jsDate: new Date(2020, 0, 2), value: 43832 },
32
- B2: { format: "mm-dd-yyyy", jsDate: new Date(1920, 1, 26), value: 7362 },
33
- B3: { format: "mm-dd-yyyy", jsDate: new Date(2010, 3, 3), value: 40271 },
34
- C1: { format: "m d yyyy", jsDate: new Date(2020, 0, 2), value: 43832 },
35
- C2: { format: "mm dd yyyy", jsDate: new Date(1920, 1, 26), value: 7362 },
36
- C3: { format: "mm dd yyyy", jsDate: new Date(2010, 3, 3), value: 40271 },
37
- D1: { format: "yyyy/m/d", jsDate: new Date(2020, 0, 2), value: 43832 },
38
- D2: { format: "yyyy/mm/dd", jsDate: new Date(1920, 1, 26), value: 7362 },
39
- D3: { format: "yyyy/mm/dd", jsDate: new Date(2010, 3, 3), value: 40271 },
40
- E1: { format: "yyyy-m-d", jsDate: new Date(2020, 0, 2), value: 43832 },
41
- E2: { format: "yyyy-mm-dd", jsDate: new Date(1920, 1, 26), value: 7362 },
42
- E3: { format: "yyyy-mm-dd", jsDate: new Date(2010, 3, 3), value: 40271 },
43
- F1: { format: "yyyy m d", jsDate: new Date(2020, 0, 2), value: 43832 },
44
- F2: { format: "yyyy mm dd", jsDate: new Date(1920, 1, 26), value: 7362 },
45
- F3: { format: "yyyy mm dd", jsDate: new Date(2010, 3, 3), value: 40271 },
46
- });
47
- });
48
-
49
- test("date representation is preserved when displayed", () => {
50
- const model = new Model();
51
- model.dispatch("SET_VALUE", { xc: "A1", text: "1/1/2020" });
52
- expect(model.getters.getCellText(getCell(model, "A1")!)).toEqual("1/1/2020");
53
- });
54
-
55
- test("adding a date and a number", () => {
56
- const grid = {
57
- A1: "1/2/2020",
58
- A2: "=A1+1",
59
- };
60
- expect(evaluateCellText("A2", grid)).toEqual("1/3/2020");
61
- });
62
-
63
- test("adding a date in mm/d/yyyy format and a number", () => {
64
- const grid = {
65
- A1: "01/12/2020",
66
- A2: "=A1+1",
67
- };
68
- expect(evaluateCellText("A2", grid)).toEqual("01/13/2020");
69
- });
70
-
71
- test("adding two dates", () => {
72
- const grid = {
73
- A1: "2/3/2020",
74
- A2: "1/2/1940",
75
- A3: "=A1+A2",
76
- };
77
- expect(evaluateCell("A3", grid)).toEqual(58476);
78
- });
79
- });