@odoo/o-spreadsheet 14.0.1 → 15.0.0

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 (203) hide show
  1. package/dist/o_spreadsheet.cjs.js +31302 -0
  2. package/dist/o_spreadsheet.d.ts +6604 -0
  3. package/dist/o_spreadsheet.esm.js +31257 -0
  4. package/dist/o_spreadsheet.iife.js +31304 -0
  5. package/dist/o_spreadsheet.iife.min.js +3071 -0
  6. package/package.json +57 -15
  7. package/.eslintrc.json +0 -20
  8. package/.husky/post-checkout +0 -9
  9. package/.husky/pre-commit +0 -39
  10. package/.prettierignore +0 -1
  11. package/astToFormula.patch +0 -0
  12. package/demo/data.js +0 -255
  13. package/demo/index.html +0 -9
  14. package/demo/libs/Chart.bundle.js +0 -20755
  15. package/demo/main.js +0 -101
  16. package/doc/readme.md +0 -46
  17. package/rollup.config.js +0 -23
  18. package/src/base_plugin.ts +0 -102
  19. package/src/components/autofill.ts +0 -146
  20. package/src/components/bottom_bar.ts +0 -199
  21. package/src/components/color_picker.ts +0 -150
  22. package/src/components/composer/autocomplete_dropdown.ts +0 -135
  23. package/src/components/composer/composer.ts +0 -487
  24. package/src/components/composer/content_editable_helper.ts +0 -146
  25. package/src/components/figures/chart.ts +0 -70
  26. package/src/components/figures/container.ts +0 -268
  27. package/src/components/figures/text_figure.ts +0 -36
  28. package/src/components/grid.ts +0 -635
  29. package/src/components/helpers/dom_helpers.ts +0 -7
  30. package/src/components/helpers/drag_and_drop.ts +0 -17
  31. package/src/components/icons.ts +0 -36
  32. package/src/components/index.ts +0 -1
  33. package/src/components/menu.ts +0 -288
  34. package/src/components/overlay.ts +0 -457
  35. package/src/components/scrollbar.ts +0 -22
  36. package/src/components/selection_input.ts +0 -168
  37. package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
  38. package/src/components/side_panel/chart_panel.ts +0 -104
  39. package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
  40. package/src/components/side_panel/conditional_formatting.ts +0 -396
  41. package/src/components/side_panel/side_panel.ts +0 -127
  42. package/src/components/side_panel/translations_terms.ts +0 -45
  43. package/src/components/spreadsheet.ts +0 -198
  44. package/src/components/top_bar.ts +0 -535
  45. package/src/constants.ts +0 -26
  46. package/src/data.ts +0 -149
  47. package/src/fonts.ts +0 -41
  48. package/src/formulas/compiler.ts +0 -258
  49. package/src/formulas/composer_tokenizer.ts +0 -70
  50. package/src/formulas/index.ts +0 -15
  51. package/src/formulas/normalize.ts +0 -52
  52. package/src/formulas/parser.ts +0 -280
  53. package/src/formulas/range_tokenizer.ts +0 -97
  54. package/src/formulas/tokenizer.ts +0 -242
  55. package/src/functions/arguments.ts +0 -114
  56. package/src/functions/dates.ts +0 -302
  57. package/src/functions/helpers.ts +0 -592
  58. package/src/functions/index.ts +0 -52
  59. package/src/functions/module_database.ts +0 -282
  60. package/src/functions/module_date.ts +0 -743
  61. package/src/functions/module_info.ts +0 -69
  62. package/src/functions/module_logical.ts +0 -208
  63. package/src/functions/module_lookup.ts +0 -185
  64. package/src/functions/module_math.ts +0 -1252
  65. package/src/functions/module_operators.ts +0 -291
  66. package/src/functions/module_statistical.ts +0 -882
  67. package/src/functions/module_text.ts +0 -370
  68. package/src/helpers/color.ts +0 -30
  69. package/src/helpers/coordinates.ts +0 -71
  70. package/src/helpers/grid_manipulation.ts +0 -68
  71. package/src/helpers/index.ts +0 -7
  72. package/src/helpers/misc.ts +0 -76
  73. package/src/helpers/numbers.ts +0 -117
  74. package/src/helpers/uuid.ts +0 -19
  75. package/src/helpers/zones.ts +0 -263
  76. package/src/history.ts +0 -186
  77. package/src/index.ts +0 -84
  78. package/src/model.ts +0 -261
  79. package/src/plugins/autofill.ts +0 -412
  80. package/src/plugins/chart.ts +0 -404
  81. package/src/plugins/clipboard.ts +0 -461
  82. package/src/plugins/conditional_format.ts +0 -445
  83. package/src/plugins/core.ts +0 -1502
  84. package/src/plugins/edition.ts +0 -157
  85. package/src/plugins/evaluation.ts +0 -428
  86. package/src/plugins/figures.ts +0 -123
  87. package/src/plugins/formatting.ts +0 -630
  88. package/src/plugins/highlight.ts +0 -187
  89. package/src/plugins/index.ts +0 -32
  90. package/src/plugins/merge.ts +0 -524
  91. package/src/plugins/renderer.ts +0 -571
  92. package/src/plugins/selection.ts +0 -562
  93. package/src/plugins/selection_inputs.ts +0 -326
  94. package/src/registries/autofill_modifiers.ts +0 -76
  95. package/src/registries/autofill_rules.ts +0 -98
  96. package/src/registries/figure_registry.ts +0 -30
  97. package/src/registries/index.ts +0 -7
  98. package/src/registries/menu_items_registry.ts +0 -110
  99. package/src/registries/menus/cell_menu_registry.ts +0 -79
  100. package/src/registries/menus/col_menu_registry.ts +0 -63
  101. package/src/registries/menus/index.ts +0 -6
  102. package/src/registries/menus/menu_items_actions.ts +0 -425
  103. package/src/registries/menus/row_menu_registry.ts +0 -63
  104. package/src/registries/menus/sheet_menu_registry.ts +0 -75
  105. package/src/registries/menus/topbar_menu_registry.ts +0 -204
  106. package/src/registries/side_panel_registry.ts +0 -26
  107. package/src/registries/topbar_component_registry.ts +0 -12
  108. package/src/registry.ts +0 -51
  109. package/src/translation.ts +0 -44
  110. package/src/types/autofill.ts +0 -48
  111. package/src/types/chart.ts +0 -26
  112. package/src/types/commands.ts +0 -716
  113. package/src/types/conditional_formatting.ts +0 -124
  114. package/src/types/env.ts +0 -13
  115. package/src/types/functions.ts +0 -35
  116. package/src/types/getters.ts +0 -103
  117. package/src/types/index.ts +0 -20
  118. package/src/types/misc.ts +0 -143
  119. package/src/types/rendering.ts +0 -41
  120. package/src/types/workbook_data.ts +0 -62
  121. package/tests/__mocks__/uuid.ts +0 -7
  122. package/tests/canvas.mock.ts +0 -34
  123. package/tests/components/__mocks__/content_editable_helper.ts +0 -79
  124. package/tests/components/__mocks__/scrollbar.ts +0 -18
  125. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
  126. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
  127. package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
  128. package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
  129. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
  130. package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
  131. package/tests/components/autocomplete_dropdown_test.ts +0 -315
  132. package/tests/components/autofill_test.ts +0 -167
  133. package/tests/components/bottom_bar_test.ts +0 -262
  134. package/tests/components/chart_side_panel_test.ts +0 -123
  135. package/tests/components/composer_test.ts +0 -400
  136. package/tests/components/context_menu_test.ts +0 -825
  137. package/tests/components/grid_manipulation_test.ts +0 -163
  138. package/tests/components/grid_test.ts +0 -581
  139. package/tests/components/overlay_test.ts +0 -541
  140. package/tests/components/selection_input_test.ts +0 -259
  141. package/tests/components/side_panel_test.ts +0 -148
  142. package/tests/components/spreadsheet_test.ts +0 -194
  143. package/tests/components/top_bar_test.ts +0 -427
  144. package/tests/data_test.ts +0 -175
  145. package/tests/dom_helper.ts +0 -42
  146. package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
  147. package/tests/formulas/compiler_test.ts +0 -266
  148. package/tests/formulas/composer_tokenizer_test.ts +0 -137
  149. package/tests/formulas/expressions_test.ts +0 -57
  150. package/tests/formulas/formulas_test.ts +0 -80
  151. package/tests/formulas/normalize_test.ts +0 -82
  152. package/tests/formulas/parser_test.ts +0 -224
  153. package/tests/formulas/range_tokenizer_test.ts +0 -187
  154. package/tests/formulas/tokenizer_test.ts +0 -164
  155. package/tests/functions/arguments_test.ts +0 -141
  156. package/tests/functions/dates_test.ts +0 -1081
  157. package/tests/functions/functions_test.ts +0 -53
  158. package/tests/functions/helper_test.ts +0 -98
  159. package/tests/functions/module_database_test.ts +0 -311
  160. package/tests/functions/module_date_test.ts +0 -941
  161. package/tests/functions/module_info_test.ts +0 -139
  162. package/tests/functions/module_logical_test.ts +0 -369
  163. package/tests/functions/module_lookup_test.ts +0 -541
  164. package/tests/functions/module_math_test.ts +0 -2482
  165. package/tests/functions/module_operators_test.ts +0 -955
  166. package/tests/functions/module_statistical_test.ts +0 -2014
  167. package/tests/functions/module_text_test.ts +0 -667
  168. package/tests/helpers/coordinates_test.ts +0 -25
  169. package/tests/helpers/misc_test.ts +0 -95
  170. package/tests/helpers/numbers_test.ts +0 -196
  171. package/tests/helpers/zones_test.ts +0 -97
  172. package/tests/helpers.ts +0 -384
  173. package/tests/menu_items_registry_test.ts +0 -540
  174. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
  175. package/tests/model/plugins/chart_test.ts +0 -562
  176. package/tests/model_test.ts +0 -82
  177. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
  178. package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
  179. package/tests/plugins/autofill_test.ts +0 -457
  180. package/tests/plugins/borders_test.ts +0 -295
  181. package/tests/plugins/clipboard_test.ts +0 -1180
  182. package/tests/plugins/conditional_formatting_test.ts +0 -1253
  183. package/tests/plugins/core_test.ts +0 -614
  184. package/tests/plugins/edition_test.ts +0 -100
  185. package/tests/plugins/evaluation_async_test.ts +0 -332
  186. package/tests/plugins/evaluation_dates_test.ts +0 -79
  187. package/tests/plugins/evaluation_test.ts +0 -901
  188. package/tests/plugins/figures_test.ts +0 -327
  189. package/tests/plugins/formatting_test.ts +0 -391
  190. package/tests/plugins/grid_manipulation_test.ts +0 -1366
  191. package/tests/plugins/highlight_test.ts +0 -413
  192. package/tests/plugins/history_test.ts +0 -142
  193. package/tests/plugins/import_export_test.ts +0 -276
  194. package/tests/plugins/merges_test.ts +0 -490
  195. package/tests/plugins/navigation_test.ts +0 -181
  196. package/tests/plugins/plugins/evaluation_test.ts +0 -111
  197. package/tests/plugins/renderer_test.ts +0 -598
  198. package/tests/plugins/resizing_test.ts +0 -152
  199. package/tests/plugins/selection_input_test.ts +0 -409
  200. package/tests/plugins/selection_test.ts +0 -442
  201. package/tests/plugins/sheets_test.ts +0 -643
  202. package/tests/plugins/style_test.ts +0 -90
  203. package/tsconfig.json +0 -22
@@ -1,541 +0,0 @@
1
- import { evaluateGrid } from "../helpers";
2
-
3
- describe("lookup", () => {
4
- //----------------------------------------------------------------------------
5
- // LOOKUP
6
- //----------------------------------------------------------------------------
7
-
8
- test("LOOKUP: functional tests on range", () => {
9
- // prettier-ignore
10
- const grid = {
11
- A1: "1", B1: "res 01", C1: "res 11", D1: "res 21", E1: "res 31",
12
- A2: "2", B2: "res 02", C2: "res 12", D2: "res 22", E2: "res 32",
13
- A3: "6", B3: "res 06", C3: "res 16", D3: "res 26", E3: "res 36",
14
- A4: "9", B4: "res 09", C4: "res 19", D4: "res 29", E4: "res 39",
15
-
16
- A5: "=LOOKUP(6, A1:A4)",
17
- A6: "=LOOKUP(6, A1:B4)",
18
- A7: "=LOOKUP(6, A1:C4)",
19
- A8: "=LOOKUP(6, A1:D4)",
20
- A9: "=LOOKUP(6, A1:E4)",
21
-
22
- A10: "=LOOKUP(6, A1:D4, E1:E4)", B10: "=LOOKUP(6, A1:C4, D1:E4)",
23
- A11: "=LOOKUP(6, A1:A2, B3:B4)", B11: "=LOOKUP(6, A1:A2, B2:B4)",
24
- A12: "=LOOKUP(1, A1:A2, B1:C1)", B12: "=LOOKUP(2, A1:A2, B1:C1)",
25
-
26
- A13: "=LOOKUP(6, A1:A3, B2:B3)",
27
- A14: "=LOOKUP(6, A1:A3, B3:C3)",
28
-
29
- A15: "=LOOKUP(0, A1:B4)",
30
- A16: "=LOOKUP(10, A1:B4)"
31
- };
32
-
33
- const evaluatedGrid = evaluateGrid(grid);
34
- expect(evaluatedGrid.A5).toBe(6);
35
- expect(evaluatedGrid.A6).toBe("res 06");
36
- expect(evaluatedGrid.A7).toBe("res 16");
37
- expect(evaluatedGrid.A8).toBe("res 26");
38
- expect(evaluatedGrid.A9).toBe(9);
39
-
40
- expect(evaluatedGrid.A10).toBe("res 36");
41
- expect(evaluatedGrid.B10).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
42
- expect(evaluatedGrid.A11).toBe("res 09");
43
- expect(evaluatedGrid.B11).toBe("res 06");
44
- expect(evaluatedGrid.A12).toBe("res 01");
45
- expect(evaluatedGrid.B12).toBe("res 11");
46
-
47
- expect(evaluatedGrid.A13).toBe("#ERROR"); // @compatibility: on googlesheets, return #NUM!
48
- expect(evaluatedGrid.A14).toBe("#ERROR"); // @compatibility: on googlesheets, return #NUM!
49
-
50
- expect(evaluatedGrid.A15).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
51
- expect(evaluatedGrid.A16).toBe("res 09");
52
- });
53
-
54
- test("LOOKUP: lookup dates", () => {
55
- // prettier-ignore
56
- const grid = {
57
- A1: "01/03/2020", B1: "999", C1: "15", D1: "01/03/2020", E1: "01/04/2000",
58
- A2: "missed1", B2: "missed2", C2: "touché",
59
-
60
- A4: "=LOOKUP(D1, A1:C1, A2:C2)",
61
- A5: "=LOOKUP(E1, A1:C1, A2:C2)",
62
- }
63
- const evaluatedGrid = evaluateGrid(grid);
64
- expect(evaluatedGrid.A4).toBe("touché");
65
- expect(evaluatedGrid.A5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
66
- });
67
-
68
- //----------------------------------------------------------------------------
69
- // MATCH
70
- //----------------------------------------------------------------------------
71
-
72
- // prettier-ignore
73
- const rangeAscending = {
74
- A1: "1", A2: "2", A3: "2", A4: "3", A5: "5", A6: "6"
75
- };
76
-
77
- // prettier-ignore
78
- const rangeUnsorted = {
79
- A1: "1", A2: "5", A3: "3", A4: "3", A5: "2", A6: "7"
80
- };
81
-
82
- // prettier-ignore
83
- const rangeDescending = {
84
- A1: "6", A2: "5", A3: "3", A4: "2", A5: "2", A6: "1"
85
- };
86
-
87
- // prettier-ignore
88
- const evAsAscending = {
89
- B1: "=MATCH( 0, A1:A6, 1)", B2: "=MATCH( 1, A1:A6, 1)",
90
- B3: "=MATCH( 2, A1:A6, 1)", B4: "=MATCH( 3, A1:A6, 1)",
91
- B5: "=MATCH( 4, A1:A6, 1)", B6: "=MATCH( 5, A1:A6, 1)",
92
- B7: "=MATCH( 6, A1:A6, 1)", B8: "=MATCH( 7, A1:A6, 1)"
93
- };
94
-
95
- // prettier-ignore
96
- const evAsUnsorted = {
97
- C1: "=MATCH( 0, A1:A6, 0)", C2: "=MATCH( 1, A1:A6, 0)",
98
- C3: "=MATCH( 2, A1:A6, 0)", C4: "=MATCH( 3, A1:A6, 0)",
99
- C5: "=MATCH( 4, A1:A6, 0)", C6: "=MATCH( 5, A1:A6, 0)",
100
- C7: "=MATCH( 6, A1:A6, 0)", C8: "=MATCH( 7, A1:A6, 0)"
101
- };
102
-
103
- // prettier-ignore
104
- const evAsDescending = {
105
- D1: "=MATCH( 0, A1:A6, -1)", D2: "=MATCH( 1, A1:A6, -1)",
106
- D3: "=MATCH( 2, A1:A6, -1)", D4: "=MATCH( 3, A1:A6, -1)",
107
- D5: "=MATCH( 4, A1:A6, -1)", D6: "=MATCH( 5, A1:A6, -1)",
108
- D7: "=MATCH( 6, A1:A6, -1)", D8: "=MATCH( 7, A1:A6, -1)"
109
- };
110
-
111
- test("MATCH: range evaluate sorted ascending", () => {
112
- const ascendingAsAscending = { ...rangeAscending, ...evAsAscending };
113
- const aAsA = evaluateGrid(ascendingAsAscending);
114
-
115
- expect(aAsA.B1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
116
- expect(aAsA.B2).toBe(1);
117
- expect(aAsA.B3).toBe(3);
118
- expect(aAsA.B4).toBe(4);
119
- expect(aAsA.B5).toBe(4);
120
- expect(aAsA.B6).toBe(5);
121
- expect(aAsA.B7).toBe(6);
122
- expect(aAsA.B8).toBe(6);
123
-
124
- const ascendingAsUnsorted = { ...rangeAscending, ...evAsUnsorted };
125
- const aAsU = evaluateGrid(ascendingAsUnsorted);
126
-
127
- expect(aAsU.C1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
128
- expect(aAsU.C2).toBe(1);
129
- expect(aAsU.C3).toBe(2);
130
- expect(aAsU.C4).toBe(4);
131
- expect(aAsU.C5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
132
- expect(aAsU.C6).toBe(5);
133
- expect(aAsU.C7).toBe(6);
134
- expect(aAsU.C8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
135
-
136
- const ascendingAsDescending = { ...rangeAscending, ...evAsDescending };
137
- const aAsD = evaluateGrid(ascendingAsDescending);
138
-
139
- expect(aAsD.D1).toBe(6);
140
- expect(aAsD.D2).toBe(6);
141
- expect(aAsD.D3).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
142
- expect(aAsD.D4).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
143
- expect(aAsD.D5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
144
- expect(aAsD.D6).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
145
- expect(aAsD.D7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
146
- expect(aAsD.D8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
147
- });
148
-
149
- test("MATCH: range evaluate unsorted", () => {
150
- const unsortedAsAscending = { ...rangeUnsorted, ...evAsAscending };
151
- const uAsA = evaluateGrid(unsortedAsAscending);
152
-
153
- expect(uAsA.B1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
154
- expect(uAsA.B2).toBe(1);
155
- expect(uAsA.B3).toBe(1);
156
- expect(uAsA.B4).toBe(4); // @compatibility: on googlesheets, return 5
157
- expect(uAsA.B5).toBe(4); // @compatibility: on googlesheets, return 5
158
- expect(uAsA.B6).toBe(4); // @compatibility: on googlesheets, return 5
159
- expect(uAsA.B7).toBe(4); // @compatibility: on googlesheets, return 5
160
- expect(uAsA.B8).toBe(6);
161
-
162
- const unsortedAsUnsorted = { ...rangeUnsorted, ...evAsUnsorted };
163
- const uAsU = evaluateGrid(unsortedAsUnsorted);
164
-
165
- expect(uAsU.C1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
166
- expect(uAsU.C2).toBe(1);
167
- expect(uAsU.C3).toBe(5);
168
- expect(uAsU.C4).toBe(3);
169
- expect(uAsU.C5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
170
- expect(uAsU.C6).toBe(2);
171
- expect(uAsU.C7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
172
- expect(uAsU.C8).toBe(6);
173
-
174
- const unsortedAsDescending = { ...rangeUnsorted, ...evAsDescending };
175
- const uAsD = evaluateGrid(unsortedAsDescending);
176
-
177
- expect(uAsD.D1).toBe(6);
178
- expect(uAsD.D2).toBe(6);
179
- expect(uAsD.D3).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
180
- expect(uAsD.D4).toBe("#ERROR"); // @compatibility: on googlesheets, return 3
181
- expect(uAsD.D5).toBe("#ERROR"); // @compatibility: on googlesheets, return 2
182
- expect(uAsD.D6).toBe("#ERROR"); // @compatibility: on googlesheets, return 2
183
- expect(uAsD.D7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
184
- expect(uAsD.D8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
185
- });
186
-
187
- test("MATCH: range evaluate sorted descending", () => {
188
- const descendingAsAscending = { ...rangeDescending, ...evAsAscending };
189
- const dAsA = evaluateGrid(descendingAsAscending);
190
-
191
- expect(dAsA.B1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
192
- expect(dAsA.B2).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
193
- expect(dAsA.B3).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
194
- expect(dAsA.B4).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
195
- expect(dAsA.B5).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
196
- expect(dAsA.B6).toBe("#ERROR"); // @compatibility: on googlesheets, return 6
197
- expect(dAsA.B7).toBe(6);
198
- expect(dAsA.B8).toBe(6);
199
-
200
- const descendingAsUnsorted = { ...rangeDescending, ...evAsUnsorted };
201
- const dAsU = evaluateGrid(descendingAsUnsorted);
202
-
203
- expect(dAsU.C1).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
204
- expect(dAsU.C2).toBe(6);
205
- expect(dAsU.C3).toBe(4);
206
- expect(dAsU.C4).toBe(3);
207
- expect(dAsU.C5).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
208
- expect(dAsU.C6).toBe(2);
209
- expect(dAsU.C7).toBe(1);
210
- expect(dAsU.C8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
211
-
212
- const descendingAsDescending = { ...rangeDescending, ...evAsDescending };
213
- const dAsD = evaluateGrid(descendingAsDescending);
214
-
215
- expect(dAsD.D1).toBe(6);
216
- expect(dAsD.D2).toBe(6);
217
- expect(dAsD.D3).toBe(4);
218
- expect(dAsD.D4).toBe(3);
219
- expect(dAsD.D5).toBe(2);
220
- expect(dAsD.D6).toBe(2);
221
- expect(dAsD.D7).toBe(1);
222
- expect(dAsD.D8).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
223
- });
224
-
225
- test("MATCH: grid of STRING ascending", () => {
226
- // prettier-ignore
227
- const ascendingStringEvAsAscending = {
228
- A1: '="1"', A2: '="10"', A3: '="100"', A4: '="2"', A5: '="2"',
229
- B1: '=MATCH( "1", A1:A5, 1)',
230
- B2: '=MATCH( "2", A1:A5, 1)',
231
- B3: '=MATCH( "5", A1:A5, 1)',
232
- B4: '=MATCH( "10", A1:A5, 1)',
233
- B5: '=MATCH( "100", A1:A5, 1)',
234
- };
235
- const ascendingString = evaluateGrid(ascendingStringEvAsAscending);
236
-
237
- expect(ascendingString.B1).toBe(1);
238
- expect(ascendingString.B2).toBe(5);
239
- expect(ascendingString.B3).toBe(5);
240
- expect(ascendingString.B4).toBe(2);
241
- expect(ascendingString.B5).toBe(3);
242
- });
243
-
244
- test("MATCH: grid of STRING unsorted", () => {
245
- // prettier-ignore
246
- const unsortedStringEvAsUnsorted = {
247
- A1: '="1"', A2: '="2"', A3: '="2"', A4: '="10"', A5: '="100"',
248
- C1: '=MATCH( "1", A1:A5, 0)',
249
- C2: '=MATCH( "2", A1:A5, 0)',
250
- C3: '=MATCH( "5", A1:A5, 0)',
251
- C4: '=MATCH( "10", A1:A5, 0)',
252
- C5: '=MATCH( "100", A1:A5, 0)',
253
- };
254
- const unsortedString = evaluateGrid(unsortedStringEvAsUnsorted);
255
-
256
- expect(unsortedString.C1).toBe(1);
257
- expect(unsortedString.C2).toBe(2);
258
- expect(unsortedString.C3).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
259
- expect(unsortedString.C4).toBe(4);
260
- expect(unsortedString.C5).toBe(5);
261
- });
262
-
263
- test("MATCH: grid of STRING descending", () => {
264
- // prettier-ignore
265
- const descendingStringEvAsDescending = {
266
- A1: '="2"', A2: '="2"', A3: '="100"', A4: '="10"', A5: '="1"',
267
- D1: '=MATCH( "1", A1:A5, -1)',
268
- D2: '=MATCH( "2", A1:A5, -1)',
269
- D3: '=MATCH( "5", A1:A5, -1)',
270
- D4: '=MATCH( "10", A1:A5, -1)',
271
- D5: '=MATCH( "100", A1:A5, -1)',
272
- }
273
- const descendingString = evaluateGrid(descendingStringEvAsDescending);
274
-
275
- expect(descendingString.D1).toBe(5);
276
- expect(descendingString.D2).toBe(1);
277
- expect(descendingString.D3).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
278
- expect(descendingString.D4).toBe(4);
279
- expect(descendingString.D5).toBe(3);
280
- });
281
-
282
- test("MATCH: match dates", () => {
283
- // prettier-ignore
284
- const grid = {
285
- A1: "01/03/2020", B1: "999", C1: "15", D1: "01/03/2020", E1: "01/04/2000",
286
-
287
- A4: "=MATCH(D1, A1:C1, 0)",
288
- A5: "=MATCH(D1, A1:C1, 1)",
289
- A6: "=MATCH(E1, A1:C1, 0)",
290
- A7: "=MATCH(E1, A1:C1, 1)",
291
- }
292
- const evaluatedGrid = evaluateGrid(grid);
293
- expect(evaluatedGrid.A4).toBe(1);
294
- expect(evaluatedGrid.A5).toBe(3);
295
- expect(evaluatedGrid.A6).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
296
- expect(evaluatedGrid.A7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
297
- });
298
-
299
- //----------------------------------------------------------------------------
300
- // VLOOKUP
301
- //----------------------------------------------------------------------------
302
-
303
- describe("VLOOKUP formula", () => {
304
- describe("sorted values with different type", () => {
305
- test("with undefined values", () => {
306
- // prettier-ignore
307
- const rangesGrid = {
308
- A1: "42", B1: "42", C1: undefined, D1: undefined, E1: undefined, Z1: "1",
309
- A2: undefined, B2: undefined, C2: undefined, D2: undefined, E2: undefined, Z2: "2",
310
- A3: undefined, B3: "42", C3: undefined, D3: "42", E3: undefined, Z3: "3",
311
- A4: undefined, B4: undefined, C4: undefined, D4: undefined, E4: undefined, Z4: "4",
312
- A5: undefined, B5: undefined, C5: "42", D5: "42", E5: undefined, Z5: "5",
313
- };
314
- const grid = evaluateGrid({
315
- ...rangesGrid,
316
- A9: "=VLOOKUP(42, A1:Z5, 26, TRUE)",
317
- B9: "=VLOOKUP(42, B1:Z5, 25, TRUE)",
318
- C9: "=VLOOKUP(42, C1:Z5, 24, TRUE)",
319
- D9: "=VLOOKUP(42, D1:Z5, 23, TRUE)",
320
- E9: "=VLOOKUP(42, E1:Z5, 22, TRUE)",
321
- });
322
- expect(grid.A9).toBe(1);
323
- expect(grid.B9).toBe(3);
324
- expect(grid.C9).toBe(5);
325
- expect(grid.D9).toBe(5);
326
- expect(grid.E9).toBe("#ERROR");
327
- });
328
-
329
- test("lookup string with string and number values", () => {
330
- // prettier-ignore
331
- const rangesGrid = {
332
- A1: "coucou", B1: "coucou", C1: "42", D1: "42", E1: "42", F1: "42", Z1: "1",
333
- A2: "42", B2: "42", C2: "42", D2: "42", E2: "42", F2: "42", Z2: "2",
334
- A3: "42", B3: "coucou", C3: "42", D3: "coucou", E3: "42", F3: `="42"`, Z3: "3",
335
- A4: "42", B4: "42", C4: "42", D4: "42", E4: "42", F4: "42", Z4: "4",
336
- A5: "42", B5: "42", C5:"coucou", D5: "coucou", E5: "42", F5: "42", Z5: "5",
337
- };
338
-
339
- const grid = evaluateGrid({
340
- ...rangesGrid,
341
- A9: '=VLOOKUP("coucou", A1:Z5, 26, TRUE)',
342
- B9: '=VLOOKUP("coucou", B1:Z5, 25, TRUE)',
343
- C9: '=VLOOKUP("coucou", C1:Z5, 24, TRUE)',
344
- D9: '=VLOOKUP("coucou", D1:Z5, 23, TRUE)',
345
- E9: '=VLOOKUP("coucou", E1:Z5, 22, TRUE)',
346
- F9: '=VLOOKUP("42", F1:Z5, 21, TRUE)',
347
- });
348
- expect(grid.A9).toBe(1);
349
- expect(grid.B9).toBe(3);
350
- expect(grid.C9).toBe(5);
351
- expect(grid.D9).toBe(5);
352
- expect(grid.E9).toBe("#ERROR");
353
- expect(grid.F9).toBe(3);
354
- });
355
-
356
- test("lookup number with number and string values", () => {
357
- // prettier-ignore
358
- const rangesGrid = {
359
- A1: "666", B1: "666", C1: "abc", D1: "abc", E1: "abc", Z1: "1",
360
- A2: "abc", B2: "abc", C2: "abc", D2: "abc", E2: "abc", Z2: "2",
361
- A3: "abc", B3: "666", C3: "abc", D3: "666", E3: "abc", Z3: "3",
362
- A4: "abc", B4: "abc", C4: "abc", D4: "abc", E4: "abc", Z4: "4",
363
- A5: "abc", B5: "abc", C5: "666", D5: "666", E5: "abc", Z5: "5",
364
- };
365
- const grid = evaluateGrid({
366
- ...rangesGrid,
367
- A9: "=VLOOKUP(666, A1:Z5, 26, TRUE)",
368
- B9: "=VLOOKUP(666, B1:Z5, 25, TRUE)",
369
- C9: "=VLOOKUP(666, C1:Z5, 24, TRUE)",
370
- D9: "=VLOOKUP(666, D1:Z5, 23, TRUE)",
371
- E9: "=VLOOKUP(666, E1:Z5, 22, TRUE)",
372
- });
373
- expect(grid.A9).toBe(1);
374
- expect(grid.B9).toBe(3);
375
- expect(grid.C9).toBe(5);
376
- expect(grid.D9).toBe(5);
377
- expect(grid.E9).toBe("#ERROR");
378
- });
379
- });
380
-
381
- // prettier-ignore
382
- const commonGrid = {
383
- B1: "B1", C1: "C1", D1: "D1", E1: "E1",
384
- B2: "B2", C2: "C2", D2: "D2", E2: "E2",
385
- B3: "B3", C3: "C3", D3: "D3", E3: "E3",
386
- B4: "B4", C4: "C4", D4: "D4", E4: "E4",
387
- B5: "B5", C5: "C5", D5: "D5", E5: "E5",
388
- B6: "B6", C6: "C6", D6: "D6", E6: "E6",
389
- };
390
- test("if index not between 1 and the number of columns --> return #ERROR", () => {
391
- const grid = evaluateGrid({
392
- ...commonGrid,
393
- Z1: '=VLOOKUP( "B4", B1:E5, 0)',
394
- Z2: '=VLOOKUP( "B4", B1:E5, 5)',
395
- });
396
- expect(grid.Z1).toBe("#ERROR"); // @compatibility: on googlesheets, return #VALUE!
397
- expect(grid.Z2).toBe("#ERROR"); // @compatibility: on googlesheets, return #VALUE!
398
- });
399
- test("if float index --> index rounded down", () => {
400
- const grid = evaluateGrid({
401
- ...commonGrid,
402
- Z1: '=VLOOKUP( "B4", B1:E5, 2.9)',
403
- Z2: '=VLOOKUP( "B4", B1:E5, 4.3)',
404
- });
405
- expect(grid.Z1).toBe("C4");
406
- expect(grid.Z2).toBe("E4");
407
- });
408
- // prettier-ignore
409
- const numSorted = {
410
- A1: "1", A2: "2", A3: "=A2", A4: "3", A5: "5", A6: "=A5",
411
- X1: "4", X2: "6", X3: "-3", X4: "0" // other testing values
412
- };
413
- // prettier-ignore
414
- const numUnsorted = {
415
- A1: "1", A2: "2", A3: "5", A4: "3", A5: "=A2", A6: "=A3",
416
- X1: "4", X2: "6" // other testing values
417
- };
418
- // prettier-ignore
419
- const stringSorted = {
420
- A1: 'ab', A2: 'abc', A3: "=A2", A4: 'abcd', A5: 'ba', A6: "=A5",
421
- X1: "abcde", X2: "bac", X3: "a", X4: "aa" // other testing values
422
- };
423
- // prettier-ignore
424
- const stringUnsorted = {
425
- A1: 'ab', A2: 'abc', A3: 'ba', A4: 'abcd', A5: '=A2', A6: '=A3',
426
- X1: "abcde", X2: "bac" // other testing values
427
- };
428
- describe.each([
429
- ["numerical values", numSorted, numUnsorted],
430
- ["string values", stringSorted, stringUnsorted],
431
- ])("search on %s", (typeValues, colSorted, colUnsorted) => {
432
- const gridSorted = { ...colSorted, ...commonGrid };
433
- const gridUnsorted = { ...colUnsorted, ...commonGrid };
434
- describe("if values are evaluated as sorted", () => {
435
- test("if find a value --> return the match value (normal behavior)", () => {
436
- const grid = evaluateGrid({
437
- ...gridSorted,
438
- Z1: "=VLOOKUP( A4, A1:E6, 3, TRUE )",
439
- Z2: "=VLOOKUP( A1, A1:E6, 4, TRUE )",
440
- });
441
- expect(grid.Z1).toBe("C4");
442
- expect(grid.Z2).toBe("D1");
443
- });
444
- test("if find multiple values --> return match to last value", () => {
445
- const grid = evaluateGrid({
446
- ...gridSorted,
447
- Z1: "=VLOOKUP( A2, A1:E6, 3, TRUE )",
448
- Z2: "=VLOOKUP( A5, A1:E6, 3, TRUE )",
449
- });
450
- expect(grid.Z1).toBe("C3");
451
- expect(grid.Z2).toBe("C6");
452
- });
453
- test("if not find value --> return match to the nearest value (less than the search key)", () => {
454
- const grid = evaluateGrid({
455
- ...gridSorted,
456
- Z1: "=VLOOKUP( X1, A1:E6, 3, TRUE )",
457
- Z2: "=VLOOKUP( X2, A1:E6, 3, TRUE )",
458
- Z3: "=VLOOKUP( X2, A10:A16, 1, TRUE )",
459
- });
460
- expect(grid.Z1).toBe("C4");
461
- expect(grid.Z2).toBe("C6");
462
- expect(grid.Z3).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
463
- });
464
-
465
- test("if all values in the search column are greater than the search key --> return #ERROR ", () => {
466
- const grid = evaluateGrid({
467
- ...gridSorted,
468
- Z1: "=VLOOKUP( X3, A1:E6, 3, TRUE )",
469
- Z2: "=VLOOKUP( X4, A1:E6, 3, TRUE )",
470
- });
471
- expect(grid.Z1).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
472
- expect(grid.Z2).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
473
- });
474
- });
475
- describe("if values are evaluated as unsorted", () => {
476
- test("if find a value --> return the match value (normal behavior)", () => {
477
- const gridS = evaluateGrid({
478
- ...gridSorted,
479
- Z1: "=VLOOKUP( A4, A1:E6, 3, FALSE )",
480
- Z2: "=VLOOKUP( A1, A1:E6, 4, FALSE )",
481
- });
482
- expect(gridS.Z1).toBe("C4");
483
- expect(gridS.Z2).toBe("D1");
484
- const gridU = evaluateGrid({
485
- ...gridUnsorted,
486
- Z1: "=VLOOKUP( A4, A1:E6, 3, FALSE )",
487
- Z2: "=VLOOKUP( A1, A1:E6, 4, FALSE )",
488
- });
489
- expect(gridU.Z1).toBe("C4");
490
- expect(gridU.Z2).toBe("D1");
491
- });
492
- test("if find multiple values --> return match to first value", () => {
493
- const gridS = evaluateGrid({
494
- ...gridSorted,
495
- Z1: "=VLOOKUP( A2, A1:E6, 3, FALSE )",
496
- Z2: "=VLOOKUP( A5, A1:E6, 3, FALSE )",
497
- });
498
- expect(gridS.Z1).toBe("C2");
499
- expect(gridS.Z2).toBe("C5");
500
- const gridU = evaluateGrid({
501
- ...gridUnsorted,
502
- Z1: "=VLOOKUP( A2, A1:E6, 3, FALSE )",
503
- Z2: "=VLOOKUP( A3, A1:E6, 3, FALSE )",
504
- });
505
- expect(gridU.Z1).toBe("C2");
506
- expect(gridU.Z2).toBe("C3");
507
- });
508
- test("if not find value --> #ERROR is returned ", () => {
509
- const formulas = {
510
- Z1: "=VLOOKUP( X1, A1:E6, 3, FALSE )",
511
- Z2: "=VLOOKUP( X2, A1:E6, 3, FALSE )",
512
- };
513
- const gridS = evaluateGrid({ ...gridSorted, ...formulas });
514
- expect(gridS.Z1).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
515
- expect(gridS.Z2).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
516
- const gridU = evaluateGrid({ ...gridUnsorted, ...formulas });
517
- expect(gridU.Z1).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
518
- expect(gridU.Z2).toBe("#ERROR"); // @compatibility: on google sheets return #N/A
519
- });
520
- });
521
- });
522
- });
523
-
524
- test("VLOOKUP: lookup dates", () => {
525
- // prettier-ignore
526
- const grid = {
527
- A1: "01/03/2020", B1: "999", C1: "15", D1: "01/03/2020", E1: "01/04/2000",
528
- A2: "touché", B2: "missed1", C2: "missed2",
529
-
530
- A4: "=VLOOKUP(D1, A1:C2, 2, 0)",
531
- A5: "=VLOOKUP(D1, A1:C2, 2, 1)",
532
- A6: "=VLOOKUP(E1, A1:C2, 2, 0)",
533
- A7: "=VLOOKUP(E1, A1:C2, 2, 1)",
534
- }
535
- const evaluatedGrid = evaluateGrid(grid);
536
- expect(evaluatedGrid.A4).toBe(999);
537
- expect(evaluatedGrid.A5).toBe(999);
538
- expect(evaluatedGrid.A6).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
539
- expect(evaluatedGrid.A7).toBe("#ERROR"); // @compatibility: on googlesheets, return #N/A
540
- });
541
- });