@odoo/o-spreadsheet 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/.eslintrc.json +20 -0
  2. package/.husky/post-checkout +9 -0
  3. package/.husky/pre-commit +39 -0
  4. package/.prettierignore +1 -0
  5. package/astToFormula.patch +0 -0
  6. package/demo/data.js +255 -0
  7. package/demo/index.html +9 -0
  8. package/demo/libs/Chart.bundle.js +20755 -0
  9. package/demo/main.js +101 -0
  10. package/doc/readme.md +46 -0
  11. package/package.json +78 -0
  12. package/readme.md +39 -0
  13. package/rollup.config.js +23 -0
  14. package/src/base_plugin.ts +102 -0
  15. package/src/components/autofill.ts +146 -0
  16. package/src/components/bottom_bar.ts +199 -0
  17. package/src/components/color_picker.ts +150 -0
  18. package/src/components/composer/autocomplete_dropdown.ts +135 -0
  19. package/src/components/composer/composer.ts +487 -0
  20. package/src/components/composer/content_editable_helper.ts +146 -0
  21. package/src/components/figures/chart.ts +70 -0
  22. package/src/components/figures/container.ts +268 -0
  23. package/src/components/figures/text_figure.ts +36 -0
  24. package/src/components/grid.ts +635 -0
  25. package/src/components/helpers/dom_helpers.ts +7 -0
  26. package/src/components/helpers/drag_and_drop.ts +17 -0
  27. package/src/components/icons.ts +36 -0
  28. package/src/components/index.ts +1 -0
  29. package/src/components/menu.ts +288 -0
  30. package/src/components/overlay.ts +457 -0
  31. package/src/components/scrollbar.ts +22 -0
  32. package/src/components/selection_input.ts +168 -0
  33. package/src/components/side_panel/cell_is_rule_editor.ts +169 -0
  34. package/src/components/side_panel/chart_panel.ts +104 -0
  35. package/src/components/side_panel/color_scale_rule_editor.ts +145 -0
  36. package/src/components/side_panel/conditional_formatting.ts +396 -0
  37. package/src/components/side_panel/side_panel.ts +127 -0
  38. package/src/components/side_panel/translations_terms.ts +45 -0
  39. package/src/components/spreadsheet.ts +198 -0
  40. package/src/components/top_bar.ts +535 -0
  41. package/src/constants.ts +26 -0
  42. package/src/data.ts +149 -0
  43. package/src/fonts.ts +41 -0
  44. package/src/formulas/compiler.ts +258 -0
  45. package/src/formulas/composer_tokenizer.ts +70 -0
  46. package/src/formulas/index.ts +15 -0
  47. package/src/formulas/normalize.ts +52 -0
  48. package/src/formulas/parser.ts +280 -0
  49. package/src/formulas/range_tokenizer.ts +97 -0
  50. package/src/formulas/tokenizer.ts +242 -0
  51. package/src/functions/arguments.ts +114 -0
  52. package/src/functions/dates.ts +302 -0
  53. package/src/functions/helpers.ts +592 -0
  54. package/src/functions/index.ts +52 -0
  55. package/src/functions/module_database.ts +282 -0
  56. package/src/functions/module_date.ts +743 -0
  57. package/src/functions/module_info.ts +69 -0
  58. package/src/functions/module_logical.ts +208 -0
  59. package/src/functions/module_lookup.ts +185 -0
  60. package/src/functions/module_math.ts +1252 -0
  61. package/src/functions/module_operators.ts +291 -0
  62. package/src/functions/module_statistical.ts +882 -0
  63. package/src/functions/module_text.ts +370 -0
  64. package/src/helpers/color.ts +30 -0
  65. package/src/helpers/coordinates.ts +71 -0
  66. package/src/helpers/grid_manipulation.ts +68 -0
  67. package/src/helpers/index.ts +7 -0
  68. package/src/helpers/misc.ts +76 -0
  69. package/src/helpers/numbers.ts +117 -0
  70. package/src/helpers/uuid.ts +19 -0
  71. package/src/helpers/zones.ts +263 -0
  72. package/src/history.ts +186 -0
  73. package/src/index.ts +84 -0
  74. package/src/model.ts +261 -0
  75. package/src/plugins/autofill.ts +412 -0
  76. package/src/plugins/chart.ts +404 -0
  77. package/src/plugins/clipboard.ts +461 -0
  78. package/src/plugins/conditional_format.ts +445 -0
  79. package/src/plugins/core.ts +1502 -0
  80. package/src/plugins/edition.ts +157 -0
  81. package/src/plugins/evaluation.ts +428 -0
  82. package/src/plugins/figures.ts +123 -0
  83. package/src/plugins/formatting.ts +630 -0
  84. package/src/plugins/highlight.ts +187 -0
  85. package/src/plugins/index.ts +32 -0
  86. package/src/plugins/merge.ts +524 -0
  87. package/src/plugins/renderer.ts +571 -0
  88. package/src/plugins/selection.ts +562 -0
  89. package/src/plugins/selection_inputs.ts +326 -0
  90. package/src/registries/autofill_modifiers.ts +76 -0
  91. package/src/registries/autofill_rules.ts +98 -0
  92. package/src/registries/figure_registry.ts +30 -0
  93. package/src/registries/index.ts +7 -0
  94. package/src/registries/menu_items_registry.ts +110 -0
  95. package/src/registries/menus/cell_menu_registry.ts +79 -0
  96. package/src/registries/menus/col_menu_registry.ts +63 -0
  97. package/src/registries/menus/index.ts +6 -0
  98. package/src/registries/menus/menu_items_actions.ts +425 -0
  99. package/src/registries/menus/row_menu_registry.ts +63 -0
  100. package/src/registries/menus/sheet_menu_registry.ts +75 -0
  101. package/src/registries/menus/topbar_menu_registry.ts +204 -0
  102. package/src/registries/side_panel_registry.ts +26 -0
  103. package/src/registries/topbar_component_registry.ts +12 -0
  104. package/src/registry.ts +51 -0
  105. package/src/translation.ts +44 -0
  106. package/src/types/autofill.ts +48 -0
  107. package/src/types/chart.ts +26 -0
  108. package/src/types/commands.ts +716 -0
  109. package/src/types/conditional_formatting.ts +124 -0
  110. package/src/types/env.ts +13 -0
  111. package/src/types/functions.ts +35 -0
  112. package/src/types/getters.ts +103 -0
  113. package/src/types/index.ts +20 -0
  114. package/src/types/misc.ts +143 -0
  115. package/src/types/rendering.ts +41 -0
  116. package/src/types/workbook_data.ts +62 -0
  117. package/tests/__mocks__/uuid.ts +7 -0
  118. package/tests/canvas.mock.ts +34 -0
  119. package/tests/components/__mocks__/content_editable_helper.ts +79 -0
  120. package/tests/components/__mocks__/scrollbar.ts +18 -0
  121. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +29 -0
  122. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +75 -0
  123. package/tests/components/__snapshots__/context_menu_test.ts.snap +88 -0
  124. package/tests/components/__snapshots__/grid_test.ts.snap +60 -0
  125. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +455 -0
  126. package/tests/components/__snapshots__/top_bar_test.ts.snap +705 -0
  127. package/tests/components/autocomplete_dropdown_test.ts +315 -0
  128. package/tests/components/autofill_test.ts +167 -0
  129. package/tests/components/bottom_bar_test.ts +262 -0
  130. package/tests/components/chart_side_panel_test.ts +123 -0
  131. package/tests/components/composer_test.ts +400 -0
  132. package/tests/components/context_menu_test.ts +825 -0
  133. package/tests/components/grid_manipulation_test.ts +163 -0
  134. package/tests/components/grid_test.ts +581 -0
  135. package/tests/components/overlay_test.ts +541 -0
  136. package/tests/components/selection_input_test.ts +259 -0
  137. package/tests/components/side_panel_test.ts +148 -0
  138. package/tests/components/spreadsheet_test.ts +194 -0
  139. package/tests/components/top_bar_test.ts +427 -0
  140. package/tests/data_test.ts +175 -0
  141. package/tests/dom_helper.ts +42 -0
  142. package/tests/formulas/__snapshots__/compiler_test.ts.snap +302 -0
  143. package/tests/formulas/compiler_test.ts +266 -0
  144. package/tests/formulas/composer_tokenizer_test.ts +137 -0
  145. package/tests/formulas/expressions_test.ts +57 -0
  146. package/tests/formulas/formulas_test.ts +80 -0
  147. package/tests/formulas/normalize_test.ts +82 -0
  148. package/tests/formulas/parser_test.ts +224 -0
  149. package/tests/formulas/range_tokenizer_test.ts +187 -0
  150. package/tests/formulas/tokenizer_test.ts +164 -0
  151. package/tests/functions/arguments_test.ts +141 -0
  152. package/tests/functions/dates_test.ts +1081 -0
  153. package/tests/functions/functions_test.ts +53 -0
  154. package/tests/functions/helper_test.ts +98 -0
  155. package/tests/functions/module_database_test.ts +311 -0
  156. package/tests/functions/module_date_test.ts +941 -0
  157. package/tests/functions/module_info_test.ts +139 -0
  158. package/tests/functions/module_logical_test.ts +369 -0
  159. package/tests/functions/module_lookup_test.ts +541 -0
  160. package/tests/functions/module_math_test.ts +2482 -0
  161. package/tests/functions/module_operators_test.ts +955 -0
  162. package/tests/functions/module_statistical_test.ts +2014 -0
  163. package/tests/functions/module_text_test.ts +667 -0
  164. package/tests/helpers/coordinates_test.ts +25 -0
  165. package/tests/helpers/misc_test.ts +95 -0
  166. package/tests/helpers/numbers_test.ts +196 -0
  167. package/tests/helpers/zones_test.ts +97 -0
  168. package/tests/helpers.ts +384 -0
  169. package/tests/menu_items_registry_test.ts +540 -0
  170. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +90 -0
  171. package/tests/model/plugins/chart_test.ts +562 -0
  172. package/tests/model_test.ts +82 -0
  173. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +131 -0
  174. package/tests/plugins/__snapshots__/renderer_test.ts.snap +371 -0
  175. package/tests/plugins/autofill_test.ts +457 -0
  176. package/tests/plugins/borders_test.ts +295 -0
  177. package/tests/plugins/clipboard_test.ts +1180 -0
  178. package/tests/plugins/conditional_formatting_test.ts +1253 -0
  179. package/tests/plugins/core_test.ts +614 -0
  180. package/tests/plugins/edition_test.ts +100 -0
  181. package/tests/plugins/evaluation_async_test.ts +332 -0
  182. package/tests/plugins/evaluation_dates_test.ts +79 -0
  183. package/tests/plugins/evaluation_test.ts +901 -0
  184. package/tests/plugins/figures_test.ts +327 -0
  185. package/tests/plugins/formatting_test.ts +391 -0
  186. package/tests/plugins/grid_manipulation_test.ts +1366 -0
  187. package/tests/plugins/highlight_test.ts +413 -0
  188. package/tests/plugins/history_test.ts +142 -0
  189. package/tests/plugins/import_export_test.ts +276 -0
  190. package/tests/plugins/merges_test.ts +490 -0
  191. package/tests/plugins/navigation_test.ts +181 -0
  192. package/tests/plugins/plugins/evaluation_test.ts +111 -0
  193. package/tests/plugins/renderer_test.ts +598 -0
  194. package/tests/plugins/resizing_test.ts +152 -0
  195. package/tests/plugins/selection_input_test.ts +409 -0
  196. package/tests/plugins/selection_test.ts +442 -0
  197. package/tests/plugins/sheets_test.ts +643 -0
  198. package/tests/plugins/style_test.ts +90 -0
  199. package/tsconfig.json +22 -0
@@ -0,0 +1,53 @@
1
+ import { Model } from "../../src";
2
+ import { args, functionRegistry } from "../../src/functions/index";
3
+ import { evaluateCell, getCell } from "../helpers";
4
+
5
+ describe("addFunction", () => {
6
+ test("can add a function", () => {
7
+ const val = evaluateCell("A1", { A1: "=DOUBLEDOUBLE(3)" });
8
+ expect(val).toBe("#BAD_EXPR");
9
+ functionRegistry.add("DOUBLEDOUBLE", {
10
+ description: "Double the first argument",
11
+ compute: (arg: number) => (2 * arg) as any,
12
+ args: args(`number (number) my number`),
13
+ returns: ["NUMBER"],
14
+ });
15
+ expect(evaluateCell("A1", { A1: "=DOUBLEDOUBLE(3)" })).toBe(6);
16
+ });
17
+
18
+ test("Can use a custom evaluation context in a function", () => {
19
+ const model = new Model(
20
+ {},
21
+ {
22
+ evalContext: {
23
+ coucou: "Raoul",
24
+ },
25
+ }
26
+ );
27
+ functionRegistry.add("GETCOUCOU", {
28
+ description: "Get coucou's name",
29
+ compute: function () {
30
+ return (this as any).coucou;
31
+ },
32
+ args: args(``),
33
+ returns: ["STRING"],
34
+ });
35
+ model.dispatch("SET_VALUE", { xc: "A1", text: "=GETCOUCOU()" });
36
+ expect(getCell(model, "A1")!.value).toBe("Raoul");
37
+ });
38
+
39
+ test("Can use a getter in a function", () => {
40
+ const model = new Model();
41
+ functionRegistry.add("GETNUMBERCOLS", {
42
+ description: "Get the number of columns",
43
+ compute: function () {
44
+ return (this as any).getters.getNumberCols(this.getters.getActiveSheet());
45
+ },
46
+ args: args(``),
47
+ returns: ["STRING"],
48
+ });
49
+ expect(evaluateCell("A1", { A1: "=GETNUMBERCOLS()" })).toBe(
50
+ model.getters.getNumberCols(model.getters.getActiveSheet())
51
+ );
52
+ });
53
+ });
@@ -0,0 +1,98 @@
1
+ import {
2
+ dichotomicPredecessorSearch,
3
+ dichotomicSuccessorSearch,
4
+ } from "../../src/functions/helpers";
5
+
6
+ describe("Function helpers", () => {
7
+ describe("dichotomicPredecessorSearch", () => {
8
+ test("with numbers only", () => {
9
+ expect(dichotomicPredecessorSearch([0, 1, 2, 3, 4], 0)).toBe(0);
10
+ expect(dichotomicPredecessorSearch([0, 1, 2, 3, 4], 4)).toBe(4);
11
+ expect(dichotomicPredecessorSearch([0, 1, 2, 3, 4], 2)).toBe(2);
12
+ expect(dichotomicPredecessorSearch([0, 1, 2, 3, 4], 22)).toBe(4);
13
+ expect(dichotomicPredecessorSearch([0, 1, 2, 3, 4], -22)).toBe(-1);
14
+ expect(dichotomicPredecessorSearch([0, 1, 2, 3, 3], 3)).toBe(4);
15
+ });
16
+
17
+ test("with strings only", () => {
18
+ expect(dichotomicPredecessorSearch(["0", "1", "2", "3", "4"], "0")).toBe(0);
19
+ expect(dichotomicPredecessorSearch(["0", "1", "2", "3", "4"], "4")).toBe(4);
20
+ expect(dichotomicPredecessorSearch(["0", "1", "2", "3", "4"], "2")).toBe(2);
21
+ expect(dichotomicPredecessorSearch(["0", "1", "2", "3", "4"], "22")).toBe(2);
22
+ expect(dichotomicPredecessorSearch(["0", "1", "2", "3", "4"], "9")).toBe(4);
23
+ expect(dichotomicPredecessorSearch(["0", "1", "2", "3", "4"], "-22")).toBe(-1);
24
+ expect(dichotomicPredecessorSearch(["0", "1", "3", "3", "4"], "3")).toBe(3);
25
+ });
26
+
27
+ test("search number in strings and numbers", () => {
28
+ expect(dichotomicPredecessorSearch([0, "a", "a", "a", "a"], 0)).toBe(0);
29
+ expect(dichotomicPredecessorSearch(["a", "a", "a", "a", 0], 0)).toBe(4);
30
+ expect(dichotomicPredecessorSearch(["a", "a", 0, "a", "a"], 0)).toBe(2);
31
+ expect(dichotomicPredecessorSearch(["a", "a", "a", "a", "a"], 0)).toBe(-1);
32
+ expect(dichotomicPredecessorSearch(["0", "0", "a", 0, "0"], 0)).toBe(3);
33
+ });
34
+
35
+ test("search string in strings and numbers", () => {
36
+ const u = undefined;
37
+ expect(dichotomicPredecessorSearch(["a", u, u, u, u], "a")).toBe(0);
38
+ expect(dichotomicPredecessorSearch([u, u, u, u, "a"], "a")).toBe(4);
39
+ expect(dichotomicPredecessorSearch([u, u, "a", u, u], "a")).toBe(2);
40
+ expect(dichotomicPredecessorSearch([u, u, u, u, u], "a")).toBe(-1);
41
+ expect(dichotomicPredecessorSearch([u, "0", u, u, u], "0")).toBe(1);
42
+ });
43
+
44
+ test("search string in strings and numbers", () => {
45
+ expect(dichotomicPredecessorSearch(["a", 0, 0, 0, 0], "a")).toBe(0);
46
+ expect(dichotomicPredecessorSearch([0, 0, 0, 0, "a"], "a")).toBe(4);
47
+ expect(dichotomicPredecessorSearch([0, 0, "a", 0, 0], "a")).toBe(2);
48
+ expect(dichotomicPredecessorSearch([0, 0, 0, 0, 0], "a")).toBe(-1);
49
+ expect(dichotomicPredecessorSearch([0, "0", 0, 0, 0], "0")).toBe(1);
50
+ });
51
+ });
52
+
53
+ describe("dichotomicSuccessorSearch", () => {
54
+ test("with numbers only", () => {
55
+ expect(dichotomicSuccessorSearch([4, 3, 2, 1, 0], 4)).toBe(0);
56
+ expect(dichotomicSuccessorSearch([4, 3, 2, 1, 0], 0)).toBe(4);
57
+ expect(dichotomicSuccessorSearch([4, 3, 2, 1, 0], 2)).toBe(2);
58
+ expect(dichotomicSuccessorSearch([4, 3, 2, 1, 0], 22)).toBe(-1);
59
+ expect(dichotomicSuccessorSearch([4, 3, 2, 1, 0], -22)).toBe(4);
60
+ expect(dichotomicSuccessorSearch([3, 3, 2, 1, 0], 3)).toBe(0);
61
+ });
62
+
63
+ test("with strings only", () => {
64
+ expect(dichotomicSuccessorSearch(["4", "3", "2", "1", "0"], "0")).toBe(4);
65
+ expect(dichotomicSuccessorSearch(["4", "3", "2", "1", "0"], "4")).toBe(0);
66
+ expect(dichotomicSuccessorSearch(["4", "3", "2", "1", "0"], "2")).toBe(2);
67
+ expect(dichotomicSuccessorSearch(["4", "3", "2", "1", "0"], "22")).toBe(1);
68
+ expect(dichotomicSuccessorSearch(["4", "3", "2", "1", "0"], "9")).toBe(-1);
69
+ expect(dichotomicSuccessorSearch(["4", "3", "2", "1", "0"], "-22")).toBe(4);
70
+ expect(dichotomicSuccessorSearch(["4", "3", "2", "1", "0"], "3")).toBe(1);
71
+ });
72
+
73
+ test("search number in strings and numbers", () => {
74
+ expect(dichotomicSuccessorSearch([0, "a", "a", "a", "a"], 0)).toBe(0);
75
+ expect(dichotomicSuccessorSearch(["a", "a", "a", "a", 0], 0)).toBe(4);
76
+ expect(dichotomicSuccessorSearch(["a", "a", 0, "a", "a"], 0)).toBe(2);
77
+ expect(dichotomicSuccessorSearch(["a", "a", "a", "a", "a"], 0)).toBe(-1);
78
+ expect(dichotomicSuccessorSearch(["0", "0", "a", 0, "0"], 0)).toBe(3);
79
+ });
80
+
81
+ test("search string in strings and numbers", () => {
82
+ const u = undefined;
83
+ expect(dichotomicSuccessorSearch(["a", u, u, u, u], "a")).toBe(0);
84
+ expect(dichotomicSuccessorSearch([u, u, u, u, "a"], "a")).toBe(4);
85
+ expect(dichotomicSuccessorSearch([u, u, "a", u, u], "a")).toBe(2);
86
+ expect(dichotomicSuccessorSearch([u, u, u, u, u], "a")).toBe(-1);
87
+ expect(dichotomicSuccessorSearch([u, "0", u, u, u], "0")).toBe(1);
88
+ });
89
+
90
+ test("search string in strings and numbers", () => {
91
+ expect(dichotomicSuccessorSearch(["a", 0, 0, 0, 0], "a")).toBe(0);
92
+ expect(dichotomicSuccessorSearch([0, 0, 0, 0, "a"], "a")).toBe(4);
93
+ expect(dichotomicSuccessorSearch([0, 0, "a", 0, 0], "a")).toBe(2);
94
+ expect(dichotomicSuccessorSearch([0, 0, 0, 0, 0], "a")).toBe(-1);
95
+ expect(dichotomicSuccessorSearch([0, "0", 0, 0, 0], "0")).toBe(1);
96
+ });
97
+ });
98
+ });
@@ -0,0 +1,311 @@
1
+ import { evaluateGrid } from "../helpers";
2
+
3
+ describe("database", () => {
4
+ // prettier-ignore
5
+ const database = {
6
+ A1: "NAME" , B1: "FILM" , C1: "YEAR", D1: "SCORE",
7
+ A2: "Jean Rochefort", B2: "Un éléphant ça ..." , C2: "1976", D2: "0.71" ,
8
+ A3: "Jean Benguigui", B3: "Bufffet froid" , C3: "1976", D3: "0.75" ,
9
+ A4: "Jean Dujardin" , B4: "The Artist" , C4: "2011", D4: "0.95" ,
10
+ A5: "Jean Ferrat" , B5: "Vivre sa vie" , C5: "1962", D5: "0.8" ,
11
+ A6: "Jean Gabin" , B6: "Le jour se lève" , C6: "1939", D6: "0.78" ,
12
+ A7: "Jean Marais" , B7: "Fantômas" , C7: "1964", D7: "0.7" ,
13
+ A8: "Jean Reno" , B8: "Le Grand Bleu" , C8: "1988", D8: "0.76" ,
14
+ A9: "Jean Rochefort", B9: "Le Mari de la coi...", C9: "1990", D9: "0.73" ,
15
+ A10: "Jean Benguigui", B10: "Coco" , C10: "2009", D10: "0.28" ,
16
+ A11: "Jean Reno" , B11: "Léon" , C11: "1994", D11: "0.75" ,
17
+ A12: "Jean Lassalle" ,
18
+ A13: "Jean Benguigui", B13: "Astérix et Obélix...", C13: "2002", D13: "0.86" ,
19
+ A14: "Jean Benguigui", B14: "Les Fugitifs" , C14: "1986", D14: "0.64" ,
20
+ A15: "Jean Reno" , B15: "Les Visiteurs" , C15: "1993", D15: "0.71" ,
21
+ A16: "Jean Gabin" , B16: "La Bête humaine" , C16: "1938", D16: "0.76" ,
22
+ A17: "Jean Ferrat" , B17: "La Vieille dame ..." , C17: "1965", D17: "0.7"
23
+ }
24
+
25
+ test("DCOUNT: functional tests on cell arguments", () => {
26
+ // prettier-ignore
27
+ const gridDcount = {
28
+ A20: "YEAR",
29
+ A21: "1976", B21: '=DCOUNT(A1:D17, "YEAR", A20:A21)',
30
+
31
+ B24: '=DCOUNT(A1:D17, "YEAR", A23:A24)',
32
+
33
+ A27: "1976", B27: '=DCOUNT(A1:D17, "YEAR", A26:A27)',
34
+
35
+ A29: "YEAR",
36
+ B30: '=DCOUNT(A1:D17, "YEAR", A29:A30)',
37
+
38
+ A32: "TEST",
39
+ A33: "2" , B33: '=DCOUNT(A1:D17, "YEAR", A32:A33)',
40
+
41
+ A35: "TEST",
42
+ B36: '=DCOUNT(A1:D17, "YEAR", A35:A36)',
43
+
44
+ A39: "2" , B39: '=DCOUNT(A1:D17, "YEAR", A38:A39)',
45
+
46
+ A41: "FILM",
47
+ A42: "Léon", B42: '=DCOUNT(A1:D17, "FILM", A41:A42)',
48
+
49
+ A44: "year" , B44: "year" ,
50
+ A45: "<>1965", B45: ">1940", C45: '=DCOUNT(A1:D17, "YEAR", A44:B45)',
51
+
52
+ A47: "NAME" ,
53
+ A48: "Jean R", B48: '=DCOUNT(A1:D17, "YEAR", A47:A48)',
54
+
55
+ A50: "NAME" ,
56
+ A51: "Jean Re", B51: '=DCOUNT(A1:D17, "YEAR", A50:A51)',
57
+
58
+ A53: "NAME" ,
59
+ A54: "Jean R", B54: '=DCOUNT(A1:D17, C1, A53:A54)',
60
+
61
+ A56: "NAME" ,
62
+ A57: "Jean R", B57: '=DCOUNT(A1:D17, 3, A56:A57)',
63
+
64
+ A59: "1" ,
65
+ A60: "Jean R", B60: '=DCOUNT(A1:D17, "YEAR", A59:A60)',
66
+
67
+ A62: "SCORE", B62: "SCORE",
68
+ A63: "0.71" , B63: "0.7" , C63: '=DCOUNT(A1:D17, "YEAR", A62:B63)',
69
+
70
+ A65: "SCORE",
71
+ A66: "0.71" ,
72
+ A67: "0.7" , B67: '=DCOUNT(A1:D17, "YEAR", A65:A67)',
73
+
74
+ A69: "SCORE",
75
+ A70: ">0.7" , B70: '=DCOUNT(A1:D17, "YEAR", A69:A70)',
76
+
77
+ A72: "SCORE",
78
+ A73: ">0.7" ,
79
+ A74: ">0.71", B74: '=DCOUNT(A1:D17, "YEAR", A72:A74)',
80
+
81
+ A76: "NAME" ,
82
+ A77: "JEAN R", B77: '=DCOUNT(A1:D17, 4.9, A76:A77)',
83
+
84
+ A79: "SCORE", B79: "YEAR"
85
+ , B80: "1976",
86
+ A81: "0.7" , C81: '=DCOUNT(A1:D17, "YEAR", A79:B81)',
87
+
88
+ A83: "SCORE", B83: "TEST"
89
+ , B84: "1976",
90
+ A85: "0.7" , C85: '=DCOUNT(A1:D17, "YEAR", A83:B85)',
91
+
92
+ };
93
+
94
+ const gridResult = evaluateGrid({ ...database, ...gridDcount });
95
+
96
+ expect(gridResult.B21).toBe(2);
97
+ expect(gridResult.B24).toBe(15);
98
+ expect(gridResult.B27).toBe(0);
99
+ expect(gridResult.B30).toBe(15);
100
+ expect(gridResult.B33).toBe(0);
101
+ expect(gridResult.B36).toBe(15);
102
+ expect(gridResult.B39).toBe(0);
103
+ expect(gridResult.B42).toBe(0);
104
+ expect(gridResult.C45).toBe(12);
105
+ expect(gridResult.B48).toBe(5);
106
+ expect(gridResult.B51).toBe(3);
107
+ expect(gridResult.B54).toBe(5);
108
+ expect(gridResult.B57).toBe(5);
109
+ expect(gridResult.B60).toBe(0);
110
+ expect(gridResult.C63).toBe(0);
111
+ expect(gridResult.B67).toBe(4);
112
+ expect(gridResult.B70).toBe(11);
113
+ expect(gridResult.B74).toBe(11);
114
+ expect(gridResult.B77).toBe(5);
115
+ expect(gridResult.C81).toBe(4);
116
+ expect(gridResult.C85).toBe(2);
117
+ });
118
+
119
+ // prettier-ignore
120
+ const criteria = {
121
+ F1: "YEAR",
122
+ F2: "1976",
123
+
124
+ F4: "FILM",
125
+ F5: "Léon",
126
+
127
+ F7: "SCORE",
128
+ F8: ">0.7",
129
+ F9: "0.28",
130
+
131
+ F11: "SCORE", G11: "YEAR",
132
+ G12: "1976",
133
+ F13: "0.7" , G13: "1964",
134
+ }
135
+
136
+ test("DAVERAGE: functional tests on cell arguments", () => {
137
+ // prettier-ignore
138
+ const grid = {
139
+ A20: '=DAVERAGE(A1:D17, "SCORE", F1:F2)',
140
+ A21: '=DAVERAGE(A1:D17, "SCORE", F4:F5)',
141
+ A22: '=DAVERAGE(A1:D17, "YEAR", F7:F9)',
142
+ A23: '=DAVERAGE(A1:D17, "YEAR", F11:G13)',
143
+ };
144
+
145
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
146
+ expect(gridResult.A20).toBe(0.73);
147
+ expect(gridResult.A21).toBe(0.75);
148
+ expect(gridResult.A22).toBe(1981.5);
149
+ expect(gridResult.A23).toBe(1972);
150
+ });
151
+
152
+ test("DCOUNTA: functional tests on cell arguments", () => {
153
+ // prettier-ignore
154
+ const grid = {
155
+ A20: '=DCOUNTA(A1:D17, "SCORE", F1:F2)',
156
+ A21: '=DCOUNTA(A1:D17, "SCORE", F4:F5)',
157
+ A22: '=DCOUNTA(A1:D17, "NAME", F7:F9)',
158
+ A23: '=DCOUNTA(A1:D17, "NAME", F11:G13)',
159
+ };
160
+
161
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
162
+ expect(gridResult.A20).toBe(2);
163
+ expect(gridResult.A21).toBe(1);
164
+ expect(gridResult.A22).toBe(12);
165
+ expect(gridResult.A23).toBe(3);
166
+ });
167
+
168
+ test("DGET: functional tests on cell arguments", () => {
169
+ // prettier-ignore
170
+ const grid = {
171
+ A20: '=DGET(A1:D17, "SCORE", F1:F2)',
172
+ A21: '=DGET(A1:D17, "SCORE", F4:F5)',
173
+ A22: '=DGET(A1:D17, "YEAR", F7:F9)',
174
+ A23: '=DGET(A1:D17, "YEAR", F11:G13)',
175
+ };
176
+
177
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
178
+ expect(gridResult.A20).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
179
+ expect(gridResult.A21).toBe(0.75);
180
+ expect(gridResult.A22).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
181
+ expect(gridResult.A23).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
182
+ });
183
+
184
+ test("DMAX: functional tests on cell arguments", () => {
185
+ // prettier-ignore
186
+ const grid = {
187
+ A20: '=DMAX(A1:D17, "SCORE", F1:F2)',
188
+ A21: '=DMAX(A1:D17, "SCORE", F4:F5)',
189
+ A22: '=DMAX(A1:D17, "YEAR", F7:F9)',
190
+ A23: '=DMAX(A1:D17, "YEAR", F11:G13)',
191
+ };
192
+
193
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
194
+ expect(gridResult.A20).toBe(0.75);
195
+ expect(gridResult.A21).toBe(0.75);
196
+ expect(gridResult.A22).toBe(2011);
197
+ expect(gridResult.A23).toBe(1976);
198
+ });
199
+
200
+ test("DMIN: functional tests on cell arguments", () => {
201
+ // prettier-ignore
202
+ const grid = {
203
+ A20: '=DMIN(A1:D17, "SCORE", F1:F2)',
204
+ A21: '=DMIN(A1:D17, "SCORE", F4:F5)',
205
+ A22: '=DMIN(A1:D17, "YEAR", F7:F9)',
206
+ A23: '=DMIN(A1:D17, "YEAR", F11:G13)',
207
+ };
208
+
209
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
210
+ expect(gridResult.A20).toBe(0.71);
211
+ expect(gridResult.A21).toBe(0.75);
212
+ expect(gridResult.A22).toBe(1938);
213
+ expect(gridResult.A23).toBe(1964);
214
+ });
215
+
216
+ test("DPRODUCT: functional tests on cell arguments", () => {
217
+ // prettier-ignore
218
+ const grid = {
219
+ A20: '=DPRODUCT(A1:D17, "SCORE", F1:F2)',
220
+ A21: '=DPRODUCT(A1:D17, "SCORE", F4:F5)',
221
+ A22: '=DPRODUCT(A1:D17, "SCORE", F7:F9)',
222
+ A23: '=DPRODUCT(A1:D17, "YEAR", F11:G13)',
223
+ };
224
+
225
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
226
+ expect(gridResult.A20).toBe(0.5325);
227
+ expect(gridResult.A21).toBe(0.75);
228
+ expect(gridResult.A22).toBeCloseTo(0.01707, 5);
229
+ expect(gridResult.A23).toBe(7668587264);
230
+ });
231
+
232
+ test("DSTDEV: functional tests on cell arguments", () => {
233
+ // prettier-ignore
234
+ const grid = {
235
+ A20: '=DSTDEV(A1:D17, "SCORE", F1:F2)',
236
+ A21: '=DSTDEV(A1:D17, "SCORE", F4:F5)',
237
+ A22: '=DSTDEV(A1:D17, "YEAR", F7:F9)',
238
+ A23: '=DSTDEV(A1:D17, "YEAR", F11:G13)',
239
+ };
240
+
241
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
242
+ expect(gridResult.A20).toBeCloseTo(0.02828, 5);
243
+ expect(gridResult.A21).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
244
+ expect(gridResult.A22).toBeCloseTo(24.47448, 5);
245
+ expect(gridResult.A23).toBeCloseTo(6.9282, 5);
246
+ });
247
+
248
+ test("DSTDEVP: functional tests on cell arguments", () => {
249
+ // prettier-ignore
250
+ const grid = {
251
+ A20: '=DSTDEVP(A1:D17, "SCORE", F1:F2)',
252
+ A21: '=DSTDEVP(A1:D17, "SCORE", F4:F5)',
253
+ A22: '=DSTDEVP(A1:D17, "YEAR", F7:F9)',
254
+ A23: '=DSTDEVP(A1:D17, "YEAR", F11:G13)',
255
+ };
256
+
257
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
258
+ expect(gridResult.A20).toBeCloseTo(0.02);
259
+ expect(gridResult.A21).toBe(0);
260
+ expect(gridResult.A22).toBeCloseTo(23.43253, 5);
261
+ expect(gridResult.A23).toBeCloseTo(5.65685, 5);
262
+ });
263
+
264
+ test("DSUM: functional tests on cell arguments", () => {
265
+ // prettier-ignore
266
+ const grid = {
267
+ A20: '=DSUM(A1:D17, "SCORE", F1:F2)',
268
+ A21: '=DSUM(A1:D17, "SCORE", F4:F5)',
269
+ A22: '=DSUM(A1:D17, "YEAR", F7:F9)',
270
+ A23: '=DSUM(A1:D17, "YEAR", F11:G13)',
271
+ };
272
+
273
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
274
+ expect(gridResult.A20).toBe(1.46);
275
+ expect(gridResult.A21).toBe(0.75);
276
+ expect(gridResult.A22).toBe(23778);
277
+ expect(gridResult.A23).toBe(5916);
278
+ });
279
+
280
+ test("DVAR: functional tests on cell arguments", () => {
281
+ // prettier-ignore
282
+ const grid = {
283
+ A20: '=DVAR(A1:D17, "SCORE", F1:F2)',
284
+ A21: '=DVAR(A1:D17, "SCORE", F4:F5)',
285
+ A22: '=DVAR(A1:D17, "YEAR", F7:F9)',
286
+ A23: '=DVAR(A1:D17, "YEAR", F11:G13)',
287
+ };
288
+
289
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
290
+ expect(gridResult.A20).toBeCloseTo(0.0008, 4);
291
+ expect(gridResult.A21).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
292
+ expect(gridResult.A22).toBe(599);
293
+ expect(gridResult.A23).toBe(48);
294
+ });
295
+
296
+ test("DVARP: functional tests on cell arguments", () => {
297
+ // prettier-ignore
298
+ const grid = {
299
+ A20: '=DVARP(A1:D17, "SCORE", F1:F2)',
300
+ A21: '=DVARP(A1:D17, "SCORE", F4:F5)',
301
+ A22: '=DVARP(A1:D17, "YEAR", F7:F9)',
302
+ A23: '=DVARP(A1:D17, "YEAR", F11:G13)',
303
+ };
304
+
305
+ const gridResult = evaluateGrid({ ...database, ...criteria, ...grid });
306
+ expect(gridResult.A20).toBeCloseTo(0.0004, 4);
307
+ expect(gridResult.A21).toBe(0);
308
+ expect(gridResult.A22).toBeCloseTo(549.08333, 5);
309
+ expect(gridResult.A23).toBe(32);
310
+ });
311
+ });