@odoo/o-spreadsheet 14.0.1 → 14.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/dist/o_spreadsheet.cjs.js +17836 -0
  2. package/dist/o_spreadsheet.d.ts +4102 -0
  3. package/dist/o_spreadsheet.esm.js +17801 -0
  4. package/dist/o_spreadsheet.iife.js +17838 -0
  5. package/dist/o_spreadsheet.iife.min.js +1440 -0
  6. package/package.json +27 -7
  7. package/readme.md +10 -0
  8. package/.eslintrc.json +0 -20
  9. package/.husky/post-checkout +0 -9
  10. package/.husky/pre-commit +0 -39
  11. package/.prettierignore +0 -1
  12. package/astToFormula.patch +0 -0
  13. package/demo/data.js +0 -255
  14. package/demo/index.html +0 -9
  15. package/demo/libs/Chart.bundle.js +0 -20755
  16. package/demo/main.js +0 -101
  17. package/doc/readme.md +0 -46
  18. package/rollup.config.js +0 -23
  19. package/src/base_plugin.ts +0 -102
  20. package/src/components/autofill.ts +0 -146
  21. package/src/components/bottom_bar.ts +0 -199
  22. package/src/components/color_picker.ts +0 -150
  23. package/src/components/composer/autocomplete_dropdown.ts +0 -135
  24. package/src/components/composer/composer.ts +0 -487
  25. package/src/components/composer/content_editable_helper.ts +0 -146
  26. package/src/components/figures/chart.ts +0 -70
  27. package/src/components/figures/container.ts +0 -268
  28. package/src/components/figures/text_figure.ts +0 -36
  29. package/src/components/grid.ts +0 -635
  30. package/src/components/helpers/dom_helpers.ts +0 -7
  31. package/src/components/helpers/drag_and_drop.ts +0 -17
  32. package/src/components/icons.ts +0 -36
  33. package/src/components/index.ts +0 -1
  34. package/src/components/menu.ts +0 -288
  35. package/src/components/overlay.ts +0 -457
  36. package/src/components/scrollbar.ts +0 -22
  37. package/src/components/selection_input.ts +0 -168
  38. package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
  39. package/src/components/side_panel/chart_panel.ts +0 -104
  40. package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
  41. package/src/components/side_panel/conditional_formatting.ts +0 -396
  42. package/src/components/side_panel/side_panel.ts +0 -127
  43. package/src/components/side_panel/translations_terms.ts +0 -45
  44. package/src/components/spreadsheet.ts +0 -198
  45. package/src/components/top_bar.ts +0 -535
  46. package/src/constants.ts +0 -26
  47. package/src/data.ts +0 -149
  48. package/src/fonts.ts +0 -41
  49. package/src/formulas/compiler.ts +0 -258
  50. package/src/formulas/composer_tokenizer.ts +0 -70
  51. package/src/formulas/index.ts +0 -15
  52. package/src/formulas/normalize.ts +0 -52
  53. package/src/formulas/parser.ts +0 -280
  54. package/src/formulas/range_tokenizer.ts +0 -97
  55. package/src/formulas/tokenizer.ts +0 -242
  56. package/src/functions/arguments.ts +0 -114
  57. package/src/functions/dates.ts +0 -302
  58. package/src/functions/helpers.ts +0 -592
  59. package/src/functions/index.ts +0 -52
  60. package/src/functions/module_database.ts +0 -282
  61. package/src/functions/module_date.ts +0 -743
  62. package/src/functions/module_info.ts +0 -69
  63. package/src/functions/module_logical.ts +0 -208
  64. package/src/functions/module_lookup.ts +0 -185
  65. package/src/functions/module_math.ts +0 -1252
  66. package/src/functions/module_operators.ts +0 -291
  67. package/src/functions/module_statistical.ts +0 -882
  68. package/src/functions/module_text.ts +0 -370
  69. package/src/helpers/color.ts +0 -30
  70. package/src/helpers/coordinates.ts +0 -71
  71. package/src/helpers/grid_manipulation.ts +0 -68
  72. package/src/helpers/index.ts +0 -7
  73. package/src/helpers/misc.ts +0 -76
  74. package/src/helpers/numbers.ts +0 -117
  75. package/src/helpers/uuid.ts +0 -19
  76. package/src/helpers/zones.ts +0 -263
  77. package/src/history.ts +0 -186
  78. package/src/index.ts +0 -84
  79. package/src/model.ts +0 -261
  80. package/src/plugins/autofill.ts +0 -412
  81. package/src/plugins/chart.ts +0 -404
  82. package/src/plugins/clipboard.ts +0 -461
  83. package/src/plugins/conditional_format.ts +0 -445
  84. package/src/plugins/core.ts +0 -1502
  85. package/src/plugins/edition.ts +0 -157
  86. package/src/plugins/evaluation.ts +0 -428
  87. package/src/plugins/figures.ts +0 -123
  88. package/src/plugins/formatting.ts +0 -630
  89. package/src/plugins/highlight.ts +0 -187
  90. package/src/plugins/index.ts +0 -32
  91. package/src/plugins/merge.ts +0 -524
  92. package/src/plugins/renderer.ts +0 -571
  93. package/src/plugins/selection.ts +0 -562
  94. package/src/plugins/selection_inputs.ts +0 -326
  95. package/src/registries/autofill_modifiers.ts +0 -76
  96. package/src/registries/autofill_rules.ts +0 -98
  97. package/src/registries/figure_registry.ts +0 -30
  98. package/src/registries/index.ts +0 -7
  99. package/src/registries/menu_items_registry.ts +0 -110
  100. package/src/registries/menus/cell_menu_registry.ts +0 -79
  101. package/src/registries/menus/col_menu_registry.ts +0 -63
  102. package/src/registries/menus/index.ts +0 -6
  103. package/src/registries/menus/menu_items_actions.ts +0 -425
  104. package/src/registries/menus/row_menu_registry.ts +0 -63
  105. package/src/registries/menus/sheet_menu_registry.ts +0 -75
  106. package/src/registries/menus/topbar_menu_registry.ts +0 -204
  107. package/src/registries/side_panel_registry.ts +0 -26
  108. package/src/registries/topbar_component_registry.ts +0 -12
  109. package/src/registry.ts +0 -51
  110. package/src/translation.ts +0 -44
  111. package/src/types/autofill.ts +0 -48
  112. package/src/types/chart.ts +0 -26
  113. package/src/types/commands.ts +0 -716
  114. package/src/types/conditional_formatting.ts +0 -124
  115. package/src/types/env.ts +0 -13
  116. package/src/types/functions.ts +0 -35
  117. package/src/types/getters.ts +0 -103
  118. package/src/types/index.ts +0 -20
  119. package/src/types/misc.ts +0 -143
  120. package/src/types/rendering.ts +0 -41
  121. package/src/types/workbook_data.ts +0 -62
  122. package/tests/__mocks__/uuid.ts +0 -7
  123. package/tests/canvas.mock.ts +0 -34
  124. package/tests/components/__mocks__/content_editable_helper.ts +0 -79
  125. package/tests/components/__mocks__/scrollbar.ts +0 -18
  126. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
  127. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
  128. package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
  129. package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
  130. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
  131. package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
  132. package/tests/components/autocomplete_dropdown_test.ts +0 -315
  133. package/tests/components/autofill_test.ts +0 -167
  134. package/tests/components/bottom_bar_test.ts +0 -262
  135. package/tests/components/chart_side_panel_test.ts +0 -123
  136. package/tests/components/composer_test.ts +0 -400
  137. package/tests/components/context_menu_test.ts +0 -825
  138. package/tests/components/grid_manipulation_test.ts +0 -163
  139. package/tests/components/grid_test.ts +0 -581
  140. package/tests/components/overlay_test.ts +0 -541
  141. package/tests/components/selection_input_test.ts +0 -259
  142. package/tests/components/side_panel_test.ts +0 -148
  143. package/tests/components/spreadsheet_test.ts +0 -194
  144. package/tests/components/top_bar_test.ts +0 -427
  145. package/tests/data_test.ts +0 -175
  146. package/tests/dom_helper.ts +0 -42
  147. package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
  148. package/tests/formulas/compiler_test.ts +0 -266
  149. package/tests/formulas/composer_tokenizer_test.ts +0 -137
  150. package/tests/formulas/expressions_test.ts +0 -57
  151. package/tests/formulas/formulas_test.ts +0 -80
  152. package/tests/formulas/normalize_test.ts +0 -82
  153. package/tests/formulas/parser_test.ts +0 -224
  154. package/tests/formulas/range_tokenizer_test.ts +0 -187
  155. package/tests/formulas/tokenizer_test.ts +0 -164
  156. package/tests/functions/arguments_test.ts +0 -141
  157. package/tests/functions/dates_test.ts +0 -1081
  158. package/tests/functions/functions_test.ts +0 -53
  159. package/tests/functions/helper_test.ts +0 -98
  160. package/tests/functions/module_database_test.ts +0 -311
  161. package/tests/functions/module_date_test.ts +0 -941
  162. package/tests/functions/module_info_test.ts +0 -139
  163. package/tests/functions/module_logical_test.ts +0 -369
  164. package/tests/functions/module_lookup_test.ts +0 -541
  165. package/tests/functions/module_math_test.ts +0 -2482
  166. package/tests/functions/module_operators_test.ts +0 -955
  167. package/tests/functions/module_statistical_test.ts +0 -2014
  168. package/tests/functions/module_text_test.ts +0 -667
  169. package/tests/helpers/coordinates_test.ts +0 -25
  170. package/tests/helpers/misc_test.ts +0 -95
  171. package/tests/helpers/numbers_test.ts +0 -196
  172. package/tests/helpers/zones_test.ts +0 -97
  173. package/tests/helpers.ts +0 -384
  174. package/tests/menu_items_registry_test.ts +0 -540
  175. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
  176. package/tests/model/plugins/chart_test.ts +0 -562
  177. package/tests/model_test.ts +0 -82
  178. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
  179. package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
  180. package/tests/plugins/autofill_test.ts +0 -457
  181. package/tests/plugins/borders_test.ts +0 -295
  182. package/tests/plugins/clipboard_test.ts +0 -1180
  183. package/tests/plugins/conditional_formatting_test.ts +0 -1253
  184. package/tests/plugins/core_test.ts +0 -614
  185. package/tests/plugins/edition_test.ts +0 -100
  186. package/tests/plugins/evaluation_async_test.ts +0 -332
  187. package/tests/plugins/evaluation_dates_test.ts +0 -79
  188. package/tests/plugins/evaluation_test.ts +0 -901
  189. package/tests/plugins/figures_test.ts +0 -327
  190. package/tests/plugins/formatting_test.ts +0 -391
  191. package/tests/plugins/grid_manipulation_test.ts +0 -1366
  192. package/tests/plugins/highlight_test.ts +0 -413
  193. package/tests/plugins/history_test.ts +0 -142
  194. package/tests/plugins/import_export_test.ts +0 -276
  195. package/tests/plugins/merges_test.ts +0 -490
  196. package/tests/plugins/navigation_test.ts +0 -181
  197. package/tests/plugins/plugins/evaluation_test.ts +0 -111
  198. package/tests/plugins/renderer_test.ts +0 -598
  199. package/tests/plugins/resizing_test.ts +0 -152
  200. package/tests/plugins/selection_input_test.ts +0 -409
  201. package/tests/plugins/selection_test.ts +0 -442
  202. package/tests/plugins/sheets_test.ts +0 -643
  203. package/tests/plugins/style_test.ts +0 -90
  204. package/tsconfig.json +0 -22
@@ -1,391 +0,0 @@
1
- import { Model } from "../../src/model";
2
- import "../canvas.mock";
3
-
4
- function setFormat(model: Model, format: string) {
5
- model.dispatch("SET_FORMATTER", {
6
- sheet: model.getters.getActiveSheet(),
7
- target: model.getters.getSelectedZones(),
8
- formatter: format,
9
- });
10
- }
11
-
12
- function setDecimal(model: Model, step: number) {
13
- model.dispatch("SET_DECIMAL", {
14
- sheet: model.getters.getActiveSheet(),
15
- target: model.getters.getSelectedZones(),
16
- step: step,
17
- });
18
- }
19
-
20
- describe("formatting values (with formatters)", () => {
21
- test("can set a format to a cell", () => {
22
- const model = new Model();
23
- model.dispatch("SET_VALUE", { xc: "A1", text: "3" });
24
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("3");
25
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
26
- setFormat(model, "0.00%");
27
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("0.00%");
28
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("300.00%");
29
- });
30
-
31
- test("can set a date format to a cell containing a date", () => {
32
- const model = new Model();
33
- model.dispatch("SET_VALUE", { xc: "A1", text: "3 14 2014" });
34
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("3 14 2014");
35
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
36
- setFormat(model, "mm/dd/yyyy");
37
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("mm/dd/yyyy");
38
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("03/14/2014");
39
- });
40
-
41
- test("can set a date format to a cell containing a number", () => {
42
- const model = new Model();
43
- model.dispatch("SET_VALUE", { xc: "A1", text: "1" });
44
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("1");
45
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
46
- setFormat(model, "mm/dd/yyyy");
47
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("mm/dd/yyyy");
48
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("12/31/1899");
49
- });
50
-
51
- test("can set a number format to a cell containing a date", () => {
52
- const model = new Model();
53
- model.dispatch("SET_VALUE", { xc: "A1", text: "1/1/2000" });
54
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("1/1/2000");
55
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
56
- setFormat(model, "0.00%");
57
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("0.00%");
58
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("3652600.00%");
59
- });
60
-
61
- test("can set a format to an empty cell", () => {
62
- const model = new Model();
63
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
64
- setFormat(model, "0.00%");
65
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("0.00%");
66
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("");
67
- model.dispatch("SET_VALUE", { xc: "A1", text: "0.431" });
68
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("43.10%");
69
- });
70
-
71
- test("can set the default format to a cell with value = 0", () => {
72
- const model = new Model();
73
- model.dispatch("SET_VALUE", { xc: "A1", text: "0" });
74
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
75
- setFormat(model, "");
76
- expect(model["workbook"].activeSheet.cells.A1.format).not.toBeDefined();
77
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("0");
78
- });
79
-
80
- test("can clear a format in a non empty cell", () => {
81
- const model = new Model();
82
- model.dispatch("SET_VALUE", { xc: "A1", text: "3" });
83
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
84
- setFormat(model, "0.00%");
85
- expect(model["workbook"].activeSheet.cells.A1.format).toBeDefined();
86
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("300.00%");
87
- setFormat(model, "");
88
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("3");
89
- expect(model["workbook"].activeSheet.cells.A1.format).not.toBeDefined();
90
- });
91
-
92
- test("can clear a format in an empty cell", () => {
93
- const model = new Model();
94
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
95
- setFormat(model, "0.00%");
96
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("0.00%");
97
- setFormat(model, "");
98
- expect(model["workbook"].activeSheet.cells.A1).not.toBeDefined();
99
- });
100
-
101
- test("setting an empty format in an empty cell does nothing", () => {
102
- const model = new Model();
103
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
104
- setFormat(model, "");
105
- expect(model["workbook"].activeSheet.cells.A1).not.toBeDefined();
106
- });
107
-
108
- test("does not format errors", () => {
109
- const model = new Model();
110
- model.dispatch("SET_VALUE", { xc: "A1", text: "3" });
111
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
112
- setFormat(model, "0.00%");
113
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("300.00%");
114
- model.dispatch("SET_VALUE", { xc: "A1", text: "=A1" });
115
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("#CYCLE");
116
- });
117
-
118
- test("Can set number format to text value", () => {
119
- const model = new Model();
120
- model.dispatch("SET_VALUE", { xc: "A1", text: "Test" });
121
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
122
- setFormat(model, "0.00%");
123
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("Test");
124
- });
125
-
126
- test("Can set date format to text value", () => {
127
- const model = new Model();
128
- model.dispatch("SET_VALUE", { xc: "A1", text: "Test" });
129
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
130
- setFormat(model, "mm/dd/yyyy");
131
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("Test");
132
- });
133
- });
134
-
135
- describe("formatting values (when change decimal)", () => {
136
- test("Can't change decimal format of a cell that isn't 'number' type", () => {
137
- const model = new Model();
138
- model.dispatch("SET_VALUE", { xc: "A1", text: "kikou" });
139
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("kikou");
140
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
141
- setDecimal(model, 1);
142
- expect(model["workbook"].activeSheet.cells.A1.format).toBe(undefined);
143
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A1)).toBe("kikou");
144
- });
145
-
146
- test("Can't change decimal format of a cell when value not exist", () => {
147
- const model = new Model();
148
- model.dispatch("SET_VALUE", { xc: "A1", text: "42%" });
149
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
150
- model.dispatch("DELETE_CONTENT", {
151
- sheet: model.getters.getActiveSheet(),
152
- target: model.getters.getSelectedZones(),
153
- });
154
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("0%");
155
- setDecimal(model, 1);
156
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("0%");
157
- });
158
-
159
- test("Can change decimal format of a cell that already has format", () => {
160
- const model = new Model();
161
-
162
- model.dispatch("SET_VALUE", { xc: "A1", text: "42" });
163
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
164
- setFormat(model, "0.0%");
165
- setDecimal(model, 1);
166
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("0.00%");
167
-
168
- model.dispatch("SET_VALUE", { xc: "A2", text: "42" });
169
- model.dispatch("SELECT_CELL", { col: 0, row: 1 });
170
- setFormat(model, "0.0%");
171
- setDecimal(model, -1);
172
- expect(model["workbook"].activeSheet.cells.A2.format).toBe("0%");
173
-
174
- model.dispatch("SET_VALUE", { xc: "A3", text: "42" });
175
- model.dispatch("SELECT_CELL", { col: 0, row: 2 });
176
- setFormat(model, "0%");
177
- setDecimal(model, 1);
178
- expect(model["workbook"].activeSheet.cells.A3.format).toBe("0.0%");
179
-
180
- model.dispatch("SET_VALUE", { xc: "A4", text: "42" });
181
- model.dispatch("SELECT_CELL", { col: 0, row: 3 });
182
- setFormat(model, "0%");
183
- setDecimal(model, -1);
184
- expect(model["workbook"].activeSheet.cells.A4.format).toBe("0%");
185
-
186
- model.dispatch("SET_VALUE", { xc: "B1", text: "24" });
187
- model.dispatch("SELECT_CELL", { col: 1, row: 0 });
188
- setFormat(model, "#,##0.0");
189
- setDecimal(model, 1);
190
- expect(model["workbook"].activeSheet.cells.B1.format).toBe("#,##0.00");
191
-
192
- model.dispatch("SET_VALUE", { xc: "B2", text: "24" });
193
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
194
- setFormat(model, "#,##0.0");
195
- setDecimal(model, -1);
196
- expect(model["workbook"].activeSheet.cells.B2.format).toBe("#,##0");
197
-
198
- model.dispatch("SET_VALUE", { xc: "B3", text: "24" });
199
- model.dispatch("SELECT_CELL", { col: 1, row: 2 });
200
- setFormat(model, "#,##0");
201
- setDecimal(model, 1);
202
- expect(model["workbook"].activeSheet.cells.B3.format).toBe("#,##0.0");
203
-
204
- model.dispatch("SET_VALUE", { xc: "B4", text: "24" });
205
- model.dispatch("SELECT_CELL", { col: 1, row: 3 });
206
- setFormat(model, "#,##0");
207
- setDecimal(model, -1);
208
- expect(model["workbook"].activeSheet.cells.B4.format).toBe("#,##0");
209
-
210
- model.dispatch("SET_VALUE", { xc: "C1", text: "707" });
211
- model.dispatch("SELECT_CELL", { col: 2, row: 0 });
212
- setFormat(model, "0.0E+00");
213
- setDecimal(model, 1);
214
- expect(model["workbook"].activeSheet.cells.C1.format).toBe("0.00E+00");
215
-
216
- model.dispatch("SET_VALUE", { xc: "C2", text: "707" });
217
- model.dispatch("SELECT_CELL", { col: 2, row: 1 });
218
- setFormat(model, "0.0E+00");
219
- setDecimal(model, -1);
220
- expect(model["workbook"].activeSheet.cells.C2.format).toBe("0E+00");
221
-
222
- model.dispatch("SET_VALUE", { xc: "C3", text: "707" });
223
- model.dispatch("SELECT_CELL", { col: 2, row: 2 });
224
- setFormat(model, "0E+00");
225
- setDecimal(model, 1);
226
- expect(model["workbook"].activeSheet.cells.C3.format).toBe("0.0E+00");
227
-
228
- model.dispatch("SET_VALUE", { xc: "C4", text: "707" });
229
- model.dispatch("SELECT_CELL", { col: 2, row: 3 });
230
- setFormat(model, "0E+00");
231
- setDecimal(model, -1);
232
- expect(model["workbook"].activeSheet.cells.C4.format).toBe("0E+00");
233
-
234
- model.dispatch("SET_VALUE", { xc: "D1", text: "39738" });
235
- model.dispatch("SELECT_CELL", { col: 3, row: 0 });
236
- setFormat(model, "#,##0;#,##0.00");
237
- setDecimal(model, 1);
238
- expect(model["workbook"].activeSheet.cells.D1.format).toBe("#,##0.0;#,##0.000");
239
-
240
- model.dispatch("SET_VALUE", { xc: "D2", text: "39738" });
241
- model.dispatch("SELECT_CELL", { col: 3, row: 1 });
242
- setFormat(model, "#,##0;#,##0.0");
243
- setDecimal(model, -1);
244
- expect(model["workbook"].activeSheet.cells.D2.format).toBe("#,##0;#,##0");
245
- });
246
-
247
- test("Can change decimal format of a cell that hasn't format (case 'number' type only)", () => {
248
- const model = new Model();
249
-
250
- model.dispatch("SET_VALUE", { xc: "A1", text: "123" });
251
- expect(model["workbook"].activeSheet.cells.A1.format).toBe(undefined);
252
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
253
- setDecimal(model, 1);
254
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("0.0");
255
-
256
- model.dispatch("SET_VALUE", { xc: "A2", text: "456" });
257
- expect(model["workbook"].activeSheet.cells.A2.format).toBe(undefined);
258
- model.dispatch("SELECT_CELL", { col: 0, row: 1 });
259
- setDecimal(model, -1);
260
- expect(model["workbook"].activeSheet.cells.A2.format).toBe("0");
261
-
262
- model.dispatch("SET_VALUE", { xc: "B1", text: "123.456" });
263
- expect(model["workbook"].activeSheet.cells.B1.format).toBe(undefined);
264
- model.dispatch("SELECT_CELL", { col: 1, row: 0 });
265
- setDecimal(model, 1);
266
- expect(model["workbook"].activeSheet.cells.B1.format).toBe("0.0000");
267
-
268
- model.dispatch("SET_VALUE", { xc: "B2", text: "456.789" });
269
- expect(model["workbook"].activeSheet.cells.B2.format).toBe(undefined);
270
- model.dispatch("SELECT_CELL", { col: 1, row: 1 });
271
- setDecimal(model, -1);
272
- expect(model["workbook"].activeSheet.cells.B2.format).toBe("0.00");
273
- });
274
-
275
- test("Decimal format is limited to 20 zeros after the decimal point", () => {
276
- const model = new Model();
277
-
278
- const nineteenZerosA1 = "0.0000000000000000000";
279
- const twentyZerosA1 = "0.00000000000000000000";
280
- model.dispatch("SET_VALUE", { xc: "A1", text: "123" });
281
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
282
- setFormat(model, nineteenZerosA1);
283
- setDecimal(model, 1);
284
- setDecimal(model, 1);
285
- setDecimal(model, 1);
286
- expect(model["workbook"].activeSheet.cells.A1.format).toBe(twentyZerosA1);
287
-
288
- const seventeenZerosB1 = "0.00000000000000000%";
289
- const twentyZerosB1 = "0.00000000000000000000%";
290
- model.dispatch("SET_VALUE", { xc: "B1", text: "9%" });
291
- model.dispatch("SELECT_CELL", { col: 1, row: 0 });
292
- setFormat(model, seventeenZerosB1);
293
- setDecimal(model, 1);
294
- setDecimal(model, 1);
295
- setDecimal(model, 1);
296
- setDecimal(model, 1);
297
- setDecimal(model, 1);
298
- setDecimal(model, 1);
299
- expect(model["workbook"].activeSheet.cells.B1.format).toBe(twentyZerosB1);
300
-
301
- const eighteenZerosC1 = "#,##0.000000000000000000";
302
- const twentyZerosC1 = "#,##0.00000000000000000000";
303
- model.dispatch("SET_VALUE", { xc: "C1", text: "3456.789" });
304
- model.dispatch("SELECT_CELL", { col: 2, row: 0 });
305
- setFormat(model, eighteenZerosC1);
306
- setDecimal(model, 1);
307
- setDecimal(model, 1);
308
- setDecimal(model, 1);
309
- setDecimal(model, 1);
310
- expect(model["workbook"].activeSheet.cells.C1.format).toBe(twentyZerosC1);
311
- });
312
-
313
- test("Change decimal format on a range gives the same format for all cells", () => {
314
- const model = new Model();
315
-
316
- // give values ​​with different formats
317
-
318
- model.dispatch("SET_VALUE", { xc: "A2", text: "9" });
319
- model.dispatch("SELECT_CELL", { col: 0, row: 1 });
320
- setFormat(model, "0.00%");
321
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A2)).toBe("900.00%");
322
-
323
- model.dispatch("SET_VALUE", { xc: "A3", text: "4567.8" });
324
- model.dispatch("SELECT_CELL", { col: 0, row: 2 });
325
- setFormat(model, "#,##0");
326
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A3)).toBe("4,568");
327
-
328
- model.dispatch("SET_VALUE", { xc: "C1", text: "42.42" });
329
- model.dispatch("SELECT_CELL", { col: 2, row: 0 });
330
- setFormat(model, "0.000");
331
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.C1)).toBe("42.420");
332
-
333
- // select A1, then expand selection to A1:C3
334
-
335
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
336
- model.dispatch("ALTER_SELECTION", { cell: [2, 2] });
337
-
338
- // incrase decimalformat on the selection
339
-
340
- setDecimal(model, 1);
341
-
342
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A2)).toBe("9.0000");
343
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A3)).toBe("4567.8000");
344
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.C1)).toBe("42.4200");
345
-
346
- expect(model["workbook"].activeSheet.cells.A1.format).toBe("0.0000");
347
- expect(model["workbook"].activeSheet.cells.A2.format).toBe("0.0000");
348
- expect(model["workbook"].activeSheet.cells.A3.format).toBe("0.0000");
349
- expect(model["workbook"].activeSheet.cells.B1.format).toBe("0.0000");
350
- expect(model["workbook"].activeSheet.cells.B2.format).toBe("0.0000");
351
- expect(model["workbook"].activeSheet.cells.B3.format).toBe("0.0000");
352
- expect(model["workbook"].activeSheet.cells.C1.format).toBe("0.0000");
353
- expect(model["workbook"].activeSheet.cells.C2.format).toBe("0.0000");
354
- expect(model["workbook"].activeSheet.cells.C3.format).toBe("0.0000");
355
- });
356
-
357
- test("Change decimal format on a range does nothing if there is't 'number' type", () => {
358
- const model = new Model();
359
-
360
- // give values ​​with different formats
361
-
362
- model.dispatch("SET_VALUE", { xc: "A2", text: "Hey Jude" });
363
- model.dispatch("SELECT_CELL", { col: 0, row: 1 });
364
- setFormat(model, "0.00%");
365
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A2)).toBe("Hey Jude");
366
-
367
- model.dispatch("SET_VALUE", { xc: "A3", text: "12/12/2012" });
368
- model.dispatch("SELECT_CELL", { col: 0, row: 2 });
369
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A3)).toBe("12/12/2012");
370
-
371
- model.dispatch("SET_VALUE", { xc: "C1", text: "LEBLEBI" });
372
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.C1)).toBe("LEBLEBI");
373
-
374
- // select A1, then expand selection to A1:C3
375
-
376
- model.dispatch("SELECT_CELL", { col: 0, row: 0 });
377
- model.dispatch("ALTER_SELECTION", { cell: [2, 2] });
378
-
379
- // incrase decimalformat on the selection
380
-
381
- setDecimal(model, 1);
382
-
383
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A2)).toBe("Hey Jude");
384
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.A3)).toBe("12/12/2012");
385
- expect(model.getters.getCellText(model["workbook"].activeSheet.cells.C1)).toBe("LEBLEBI");
386
-
387
- expect(model["workbook"].activeSheet.cells.A2.format).toBe("0.00%");
388
- expect(model["workbook"].activeSheet.cells.A3.format).toBe(undefined);
389
- expect(model["workbook"].activeSheet.cells.C1.format).toBe(undefined);
390
- });
391
- });