@svgrid/grid 1.1.2 → 1.2.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 (143) hide show
  1. package/dist/SvGrid.css +294 -16
  2. package/dist/SvGrid.svelte +4 -1
  3. package/dist/SvGridDropdown.svelte +7 -3
  4. package/dist/cdn/svgrid.js +13506 -0
  5. package/dist/cdn/svgrid.svelte-external.js +11190 -0
  6. package/package.json +12 -2
  7. package/src/SvGrid.css +294 -16
  8. package/src/SvGrid.svelte +4 -1
  9. package/src/SvGridDropdown.svelte +7 -3
  10. package/dist/SvGrid.helpers.test.d.ts +0 -1
  11. package/dist/SvGrid.helpers.test.js +0 -298
  12. package/dist/SvGridChart.test.d.ts +0 -1
  13. package/dist/SvGridChart.test.js +0 -62
  14. package/dist/a11y.contract.test.d.ts +0 -1
  15. package/dist/a11y.contract.test.js +0 -39
  16. package/dist/a11y.test.d.ts +0 -1
  17. package/dist/a11y.test.js +0 -44
  18. package/dist/aligned-grids.test.d.ts +0 -1
  19. package/dist/aligned-grids.test.js +0 -75
  20. package/dist/build-api.coverage.test.d.ts +0 -20
  21. package/dist/build-api.coverage.test.js +0 -505
  22. package/dist/cell-formatting.test.d.ts +0 -1
  23. package/dist/cell-formatting.test.js +0 -234
  24. package/dist/cell-render.test.d.ts +0 -1
  25. package/dist/cell-render.test.js +0 -338
  26. package/dist/chart-export.test.d.ts +0 -1
  27. package/dist/chart-export.test.js +0 -302
  28. package/dist/chart.coverage.test.d.ts +0 -1
  29. package/dist/chart.coverage.test.js +0 -748
  30. package/dist/chart.test.d.ts +0 -1
  31. package/dist/chart.test.js +0 -289
  32. package/dist/clipboard.test.d.ts +0 -1
  33. package/dist/clipboard.test.js +0 -700
  34. package/dist/collaboration.coverage.test.d.ts +0 -1
  35. package/dist/collaboration.coverage.test.js +0 -200
  36. package/dist/collaboration.test.d.ts +0 -1
  37. package/dist/collaboration.test.js +0 -65
  38. package/dist/column-groups.test.d.ts +0 -1
  39. package/dist/column-groups.test.js +0 -56
  40. package/dist/column-types.test.d.ts +0 -1
  41. package/dist/column-types.test.js +0 -62
  42. package/dist/columns.test.d.ts +0 -1
  43. package/dist/columns.test.js +0 -625
  44. package/dist/conditional-formatting.test.d.ts +0 -1
  45. package/dist/conditional-formatting.test.js +0 -87
  46. package/dist/core.coverage.test.d.ts +0 -1
  47. package/dist/core.coverage.test.js +0 -186
  48. package/dist/core.performance.test.d.ts +0 -1
  49. package/dist/core.performance.test.js +0 -29
  50. package/dist/createGrid.test.d.ts +0 -1
  51. package/dist/createGrid.test.js +0 -9
  52. package/dist/editing.test.d.ts +0 -1
  53. package/dist/editing.test.js +0 -732
  54. package/dist/editors/cell-editors.coverage.test.d.ts +0 -1
  55. package/dist/editors/cell-editors.coverage.test.js +0 -139
  56. package/dist/editors/cell-editors.test.d.ts +0 -1
  57. package/dist/editors/cell-editors.test.js +0 -75
  58. package/dist/facet-buckets.test.d.ts +0 -1
  59. package/dist/facet-buckets.test.js +0 -296
  60. package/dist/fill-patterns.test.d.ts +0 -1
  61. package/dist/fill-patterns.test.js +0 -81
  62. package/dist/filter-operators.test.d.ts +0 -1
  63. package/dist/filter-operators.test.js +0 -135
  64. package/dist/filtering/excel-filters.test.d.ts +0 -1
  65. package/dist/filtering/excel-filters.test.js +0 -116
  66. package/dist/filtering/locale-filter.test.d.ts +0 -13
  67. package/dist/filtering/locale-filter.test.js +0 -189
  68. package/dist/flex-render.test.d.ts +0 -1
  69. package/dist/flex-render.test.js +0 -142
  70. package/dist/group-aggregate.test.d.ts +0 -1
  71. package/dist/group-aggregate.test.js +0 -32
  72. package/dist/hyperformula-adapter.test.d.ts +0 -1
  73. package/dist/hyperformula-adapter.test.js +0 -205
  74. package/dist/keyboard-handlers.coverage.test.d.ts +0 -1
  75. package/dist/keyboard-handlers.coverage.test.js +0 -495
  76. package/dist/keyboard.test.d.ts +0 -1
  77. package/dist/keyboard.test.js +0 -27
  78. package/dist/menus.test.d.ts +0 -1
  79. package/dist/menus.test.js +0 -560
  80. package/dist/named-views.coverage.test.d.ts +0 -1
  81. package/dist/named-views.coverage.test.js +0 -180
  82. package/dist/named-views.test.d.ts +0 -1
  83. package/dist/named-views.test.js +0 -57
  84. package/dist/new-features.test.d.ts +0 -1
  85. package/dist/new-features.test.js +0 -183
  86. package/dist/render-component.test.d.ts +0 -1
  87. package/dist/render-component.test.js +0 -41
  88. package/dist/row-drag.test.d.ts +0 -1
  89. package/dist/row-drag.test.js +0 -142
  90. package/dist/row-resize.test.d.ts +0 -1
  91. package/dist/row-resize.test.js +0 -329
  92. package/dist/scroll-sync.test.d.ts +0 -1
  93. package/dist/scroll-sync.test.js +0 -290
  94. package/dist/selection.multi-range.test.d.ts +0 -1
  95. package/dist/selection.multi-range.test.js +0 -55
  96. package/dist/selection.test.d.ts +0 -1
  97. package/dist/selection.test.js +0 -647
  98. package/dist/server-data-source.coverage.test.d.ts +0 -1
  99. package/dist/server-data-source.coverage.test.js +0 -154
  100. package/dist/server-data-source.test.d.ts +0 -1
  101. package/dist/server-data-source.test.js +0 -81
  102. package/dist/sparkline.test.d.ts +0 -1
  103. package/dist/sparkline.test.js +0 -52
  104. package/dist/spreadsheet.test.d.ts +0 -1
  105. package/dist/spreadsheet.test.js +0 -446
  106. package/dist/subscribe.test.d.ts +0 -1
  107. package/dist/subscribe.test.js +0 -93
  108. package/dist/svgrid.api-extensions.test.d.ts +0 -14
  109. package/dist/svgrid.api-extensions.test.js +0 -334
  110. package/dist/svgrid.api.test.d.ts +0 -15
  111. package/dist/svgrid.api.test.js +0 -169
  112. package/dist/svgrid.behavior.test.d.ts +0 -15
  113. package/dist/svgrid.behavior.test.js +0 -625
  114. package/dist/svgrid.column-reorder.test.d.ts +0 -15
  115. package/dist/svgrid.column-reorder.test.js +0 -224
  116. package/dist/svgrid.comments-autocomplete.test.d.ts +0 -1
  117. package/dist/svgrid.comments-autocomplete.test.js +0 -96
  118. package/dist/svgrid.context-menu.test.d.ts +0 -1
  119. package/dist/svgrid.context-menu.test.js +0 -102
  120. package/dist/svgrid.features.test.d.ts +0 -1
  121. package/dist/svgrid.features.test.js +0 -129
  122. package/dist/svgrid.interaction.test.d.ts +0 -9
  123. package/dist/svgrid.interaction.test.js +0 -349
  124. package/dist/svgrid.locale-filtering.test.d.ts +0 -15
  125. package/dist/svgrid.locale-filtering.test.js +0 -261
  126. package/dist/svgrid.new-features.wrapper.test.d.ts +0 -1
  127. package/dist/svgrid.new-features.wrapper.test.js +0 -194
  128. package/dist/svgrid.row-pinning.test.d.ts +0 -14
  129. package/dist/svgrid.row-pinning.test.js +0 -250
  130. package/dist/svgrid.set-filter.test.d.ts +0 -17
  131. package/dist/svgrid.set-filter.test.js +0 -268
  132. package/dist/svgrid.wrapper.test.d.ts +0 -1
  133. package/dist/svgrid.wrapper.test.js +0 -59
  134. package/dist/test-setup.d.ts +0 -1
  135. package/dist/test-setup.js +0 -35
  136. package/dist/transaction.test.d.ts +0 -1
  137. package/dist/transaction.test.js +0 -89
  138. package/dist/virtualization/column-virtualizer.test.d.ts +0 -1
  139. package/dist/virtualization/column-virtualizer.test.js +0 -25
  140. package/dist/virtualization/scroll-scaling.test.d.ts +0 -1
  141. package/dist/virtualization/scroll-scaling.test.js +0 -127
  142. package/dist/virtualization/virtualizer.test.d.ts +0 -1
  143. package/dist/virtualization/virtualizer.test.js +0 -41
@@ -1 +0,0 @@
1
- export {};
@@ -1,139 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { normalizeEditorOptions, parseEditorValue } from './cell-editors';
3
- describe('normalizeEditorOptions', () => {
4
- it('returns [] for undefined', () => {
5
- expect(normalizeEditorOptions(undefined)).toEqual([]);
6
- });
7
- it('treats a function (mistakenly passed) as empty', () => {
8
- // The type says functions are resolved earlier, but the guard handles it.
9
- const fn = (() => []);
10
- expect(normalizeEditorOptions(fn)).toEqual([]);
11
- });
12
- it('maps bare strings to { value, label }', () => {
13
- expect(normalizeEditorOptions(['a', 'b'])).toEqual([
14
- { value: 'a', label: 'a' },
15
- { value: 'b', label: 'b' },
16
- ]);
17
- });
18
- it('maps bare numbers to stringified labels', () => {
19
- expect(normalizeEditorOptions([1, 2])).toEqual([
20
- { value: 1, label: '1' },
21
- { value: 2, label: '2' },
22
- ]);
23
- });
24
- it('keeps an explicit label and color', () => {
25
- expect(normalizeEditorOptions([{ value: 'x', label: 'Ex', color: '#f00' }])).toEqual([{ value: 'x', label: 'Ex', color: '#f00' }]);
26
- });
27
- it('defaults a missing label to String(value)', () => {
28
- expect(normalizeEditorOptions([{ value: 7 }])).toEqual([
29
- { value: 7, label: '7', color: undefined },
30
- ]);
31
- });
32
- });
33
- describe('parseEditorValue - rating', () => {
34
- it('rounds and clamps into 0..5', () => {
35
- expect(parseEditorValue('rating', 3.4)).toBe(3);
36
- expect(parseEditorValue('rating', 4.6)).toBe(5);
37
- expect(parseEditorValue('rating', 9)).toBe(5);
38
- expect(parseEditorValue('rating', -2)).toBe(0);
39
- });
40
- it('returns 0 for non-finite input', () => {
41
- expect(parseEditorValue('rating', 'nope')).toBe(0);
42
- expect(parseEditorValue('rating', Infinity)).toBe(0);
43
- });
44
- });
45
- describe('parseEditorValue - color', () => {
46
- it('returns the trimmed color string', () => {
47
- expect(parseEditorValue('color', ' #abcdef ')).toBe('#abcdef');
48
- });
49
- it('passes non-hex color strings through', () => {
50
- expect(parseEditorValue('color', 'rebeccapurple')).toBe('rebeccapurple');
51
- });
52
- it('falls back to #000000 for empty/nullish', () => {
53
- expect(parseEditorValue('color', '')).toBe('#000000');
54
- expect(parseEditorValue('color', null)).toBe('#000000');
55
- expect(parseEditorValue('color', undefined)).toBe('#000000');
56
- });
57
- });
58
- describe('parseEditorValue - time', () => {
59
- it('returns null for empty input', () => {
60
- expect(parseEditorValue('time', '')).toBe(null);
61
- expect(parseEditorValue('time', null)).toBe(null);
62
- });
63
- it('returns null for malformed strings', () => {
64
- expect(parseEditorValue('time', 'noon')).toBe(null);
65
- expect(parseEditorValue('time', '12')).toBe(null);
66
- });
67
- it('normalizes HH:MM', () => {
68
- expect(parseEditorValue('time', '9:05')).toBe('09:05');
69
- });
70
- it('keeps seconds when present', () => {
71
- expect(parseEditorValue('time', '23:59:59')).toBe('23:59:59');
72
- });
73
- it('clamps out-of-range components', () => {
74
- expect(parseEditorValue('time', '99:99:99')).toBe('23:59:59');
75
- });
76
- });
77
- describe('parseEditorValue - password', () => {
78
- it('keeps an empty string instead of nulling it', () => {
79
- expect(parseEditorValue('password', '')).toBe('');
80
- });
81
- it('stringifies and preserves content', () => {
82
- expect(parseEditorValue('password', 'hunter2')).toBe('hunter2');
83
- expect(parseEditorValue('password', null)).toBe('');
84
- });
85
- });
86
- describe('parseEditorValue - select / rich-select', () => {
87
- it('returns scalar value as-is', () => {
88
- expect(parseEditorValue('select', 'one')).toBe('one');
89
- expect(parseEditorValue('rich-select', 5)).toBe(5);
90
- });
91
- it('takes the first element of an array', () => {
92
- expect(parseEditorValue('select', ['a', 'b'])).toBe('a');
93
- });
94
- it('coerces nullish to null', () => {
95
- expect(parseEditorValue('select', null)).toBe(null);
96
- expect(parseEditorValue('select', undefined)).toBe(null);
97
- expect(parseEditorValue('rich-select', [])).toBe(null);
98
- });
99
- });
100
- describe('parseEditorValue - textarea', () => {
101
- it('stringifies, nullish to empty', () => {
102
- expect(parseEditorValue('textarea', 'multi\nline')).toBe('multi\nline');
103
- expect(parseEditorValue('textarea', null)).toBe('');
104
- });
105
- });
106
- describe('parseEditorValue - list / chips (single)', () => {
107
- it('returns scalar as-is', () => {
108
- expect(parseEditorValue('list', 'x')).toBe('x');
109
- expect(parseEditorValue('chips', 7)).toBe(7);
110
- });
111
- it('takes first element of array', () => {
112
- expect(parseEditorValue('list', ['a', 'b'])).toBe('a');
113
- expect(parseEditorValue('chips', [])).toBe(null);
114
- });
115
- it('coerces nullish to null', () => {
116
- expect(parseEditorValue('list', null)).toBe(null);
117
- });
118
- });
119
- describe('parseEditorValue - list / chips (multiple)', () => {
120
- it('clones an array', () => {
121
- const input = ['a', 'b'];
122
- const out = parseEditorValue('list', input, { multiple: true });
123
- expect(out).toEqual(['a', 'b']);
124
- expect(out).not.toBe(input);
125
- });
126
- it('returns [] for empty/nullish', () => {
127
- expect(parseEditorValue('chips', null, { multiple: true })).toEqual([]);
128
- expect(parseEditorValue('chips', '', { multiple: true })).toEqual([]);
129
- });
130
- it('wraps a scalar into a single-element array', () => {
131
- expect(parseEditorValue('list', 'solo', { multiple: true })).toEqual(['solo']);
132
- });
133
- });
134
- describe('parseEditorValue - unknown type fallback', () => {
135
- it('stringifies, nullish to empty', () => {
136
- expect(parseEditorValue('autocomplete', 'hey')).toBe('hey');
137
- expect(parseEditorValue('autocomplete', undefined)).toBe('');
138
- });
139
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,75 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { parseEditorValue } from './cell-editors';
3
- describe('parseEditorValue - number', () => {
4
- it('parses a valid string', () => {
5
- expect(parseEditorValue('number', '42')).toBe(42);
6
- });
7
- it('parses a numeric value as-is', () => {
8
- expect(parseEditorValue('number', 42)).toBe(42);
9
- });
10
- it('returns null for non-numeric input', () => {
11
- expect(parseEditorValue('number', 'bad')).toBe(null);
12
- expect(parseEditorValue('number', NaN)).toBe(null);
13
- });
14
- it('returns null for Infinity', () => {
15
- expect(parseEditorValue('number', Infinity)).toBe(null);
16
- });
17
- it('handles empty string as null', () => {
18
- expect(parseEditorValue('number', '')).toBe(0);
19
- });
20
- });
21
- describe('parseEditorValue - date', () => {
22
- it('returns an ISO string for a valid date', () => {
23
- const result = parseEditorValue('date', '2026-01-01');
24
- expect(typeof result).toBe('string');
25
- expect(String(result)).toContain('2026-01-01');
26
- });
27
- it('returns null for an unparseable string', () => {
28
- expect(parseEditorValue('date', 'not-a-date')).toBe(null);
29
- });
30
- it('accepts a Date object via its string form', () => {
31
- const result = parseEditorValue('date', new Date('2026-05-30T00:00:00Z'));
32
- expect(String(result)).toContain('2026-05-30');
33
- });
34
- });
35
- describe('parseEditorValue - datetime', () => {
36
- it('returns an ISO string for a valid datetime input', () => {
37
- const result = parseEditorValue('datetime', '2026-01-01T10:30');
38
- expect(typeof result).toBe('string');
39
- expect(String(result)).toContain('2026-01-01');
40
- });
41
- it('returns null for invalid datetime input', () => {
42
- expect(parseEditorValue('datetime', 'bogus')).toBe(null);
43
- });
44
- });
45
- describe('parseEditorValue - checkbox', () => {
46
- it('returns booleans as-is', () => {
47
- expect(parseEditorValue('checkbox', true)).toBe(true);
48
- expect(parseEditorValue('checkbox', false)).toBe(false);
49
- });
50
- it('parses "true"/"false" strings case-insensitively', () => {
51
- expect(parseEditorValue('checkbox', 'true')).toBe(true);
52
- expect(parseEditorValue('checkbox', 'TRUE')).toBe(true);
53
- expect(parseEditorValue('checkbox', 'false')).toBe(false);
54
- expect(parseEditorValue('checkbox', 'False')).toBe(false);
55
- });
56
- it('treats other strings as false', () => {
57
- expect(parseEditorValue('checkbox', 'yes')).toBe(false);
58
- expect(parseEditorValue('checkbox', '1')).toBe(false);
59
- expect(parseEditorValue('checkbox', '')).toBe(false);
60
- });
61
- it('coerces numbers via String() (non-"true" → false)', () => {
62
- expect(parseEditorValue('checkbox', 1)).toBe(false);
63
- expect(parseEditorValue('checkbox', 0)).toBe(false);
64
- });
65
- });
66
- describe('parseEditorValue - text (default)', () => {
67
- it('returns the string form of a value', () => {
68
- expect(parseEditorValue('text', 'hello')).toBe('hello');
69
- expect(parseEditorValue('text', 42)).toBe('42');
70
- });
71
- it('coerces null/undefined to empty string', () => {
72
- expect(parseEditorValue('text', null)).toBe('');
73
- expect(parseEditorValue('text', undefined)).toBe('');
74
- });
75
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,296 +0,0 @@
1
- /**
2
- * Unit tests for the facet value-bucketing helpers: isBucketableColumn,
3
- * buildBuckets, isInBucket. These are pure functions - the only grid
4
- * coupling is the Column type (we use createSvGrid to mint real columns
5
- * carrying an `editorType`) and the rawToNumber/format helpers.
6
- */
7
- import { describe, expect, it } from 'vitest';
8
- import { createCoreRowModel, createSvGrid, tableFeatures, rowSortingFeature, } from './index';
9
- import { isBucketableColumn, buildBuckets, isInBucket, } from './facet-buckets';
10
- const features = tableFeatures({ rowSortingFeature });
11
- /** Build a real grid and return its columns keyed by id so tests can grab
12
- * a genuine Column<Row> object (with columnDef.editorType populated). */
13
- function makeColumns() {
14
- const columns = [
15
- { field: 'id', header: 'ID', editorType: 'text' },
16
- { field: 'num', header: 'Number', editorType: 'number' },
17
- { field: 'when', header: 'When', editorType: 'date' },
18
- { field: 'name', header: 'Name' }, // no editorType
19
- { field: 'flag', header: 'Flag', editorType: 'checkbox' },
20
- ];
21
- const grid = createSvGrid({
22
- _features: features,
23
- _rowModels: { coreRowModel: createCoreRowModel() },
24
- columns,
25
- data: [],
26
- });
27
- const byId = {};
28
- for (const c of grid.getAllColumns())
29
- byId[c.id] = c;
30
- return byId;
31
- }
32
- // Field accessor used by buildBuckets in production - read the property
33
- // matching the column id off the row.
34
- function accessor(row, column) {
35
- return row[column.id];
36
- }
37
- describe('isBucketableColumn', () => {
38
- const cols = makeColumns();
39
- it('returns { isDate: false } for a number column', () => {
40
- expect(isBucketableColumn(cols.num)).toEqual({ isDate: false });
41
- });
42
- it('returns { isDate: true } for a date column', () => {
43
- expect(isBucketableColumn(cols.when)).toEqual({ isDate: true });
44
- });
45
- it('returns { isDate: true } for a datetime column', () => {
46
- const grid = createSvGrid({
47
- _features: features,
48
- _rowModels: { coreRowModel: createCoreRowModel() },
49
- columns: [{ field: 'when', header: 'When', editorType: 'datetime' }],
50
- data: [],
51
- });
52
- const col = grid.getAllColumns().find((c) => c.id === 'when');
53
- expect(isBucketableColumn(col)).toEqual({ isDate: true });
54
- });
55
- it('returns null for a text column', () => {
56
- expect(isBucketableColumn(cols.id)).toBeNull();
57
- });
58
- it('returns null for a checkbox column', () => {
59
- expect(isBucketableColumn(cols.flag)).toBeNull();
60
- });
61
- it('returns null for a column with no editorType', () => {
62
- expect(isBucketableColumn(cols.name)).toBeNull();
63
- });
64
- });
65
- describe('buildBuckets - numeric', () => {
66
- const cols = makeColumns();
67
- it('returns null when distinct values do not exceed the threshold (30)', () => {
68
- // 30 distinct values -> not > 30 -> null
69
- const data = Array.from({ length: 30 }, (_, i) => ({
70
- id: String(i),
71
- num: i,
72
- when: '',
73
- name: '',
74
- flag: false,
75
- }));
76
- expect(buildBuckets(cols.num, false, data, accessor)).toBeNull();
77
- });
78
- it('builds 10 buckets when distinct values exceed the threshold', () => {
79
- // 31 distinct values 0..30 -> > 30 -> buckets
80
- const data = Array.from({ length: 31 }, (_, i) => ({
81
- id: String(i),
82
- num: i,
83
- when: '',
84
- name: '',
85
- flag: false,
86
- }));
87
- const buckets = buildBuckets(cols.num, false, data, accessor);
88
- expect(buckets).not.toBeNull();
89
- expect(buckets).toHaveLength(10);
90
- });
91
- it('spans the full numeric range with contiguous edges', () => {
92
- const data = Array.from({ length: 31 }, (_, i) => ({
93
- id: String(i),
94
- num: i, // 0..30
95
- when: '',
96
- name: '',
97
- flag: false,
98
- }));
99
- const buckets = buildBuckets(cols.num, false, data, accessor);
100
- expect(buckets[0].numericMin).toBe(0);
101
- expect(buckets[9].numericMax).toBe(30);
102
- // bucket i's max equals bucket i+1's min (contiguous, no gaps)
103
- for (let i = 0; i < buckets.length - 1; i += 1) {
104
- expect(buckets[i].numericMax).toBeCloseTo(buckets[i + 1].numericMin, 10);
105
- }
106
- });
107
- it('flags only the final bucket as isLast and sets isDate=false', () => {
108
- const data = Array.from({ length: 31 }, (_, i) => ({
109
- id: String(i),
110
- num: i,
111
- when: '',
112
- name: '',
113
- flag: false,
114
- }));
115
- const buckets = buildBuckets(cols.num, false, data, accessor);
116
- expect(buckets.filter((b) => b.isLast)).toHaveLength(1);
117
- expect(buckets[9].isLast).toBe(true);
118
- expect(buckets[0].isLast).toBe(false);
119
- expect(buckets.every((b) => b.isDate === false)).toBe(true);
120
- });
121
- it('uses numeric labels containing an en-dash separator', () => {
122
- const data = Array.from({ length: 31 }, (_, i) => ({
123
- id: String(i),
124
- num: i,
125
- when: '',
126
- name: '',
127
- flag: false,
128
- }));
129
- const buckets = buildBuckets(cols.num, false, data, accessor);
130
- expect(buckets[0].label).toContain('–');
131
- });
132
- it('ignores non-finite / blank values when computing min/max and distinct', () => {
133
- // 31 numeric values plus a pile of null/undefined/empty/NaN-ish ones
134
- const data = [
135
- ...Array.from({ length: 31 }, (_, i) => ({
136
- id: String(i),
137
- num: i,
138
- when: '',
139
- name: '',
140
- flag: false,
141
- })),
142
- { id: 'a', num: null, when: '', name: '', flag: false },
143
- { id: 'b', num: undefined, when: '', name: '', flag: false },
144
- { id: 'c', num: 'not-a-number', when: '', name: '', flag: false },
145
- ];
146
- const buckets = buildBuckets(cols.num, false, data, accessor);
147
- // range is still 0..30 - the junk rows were skipped
148
- expect(buckets[0].numericMin).toBe(0);
149
- expect(buckets[9].numericMax).toBe(30);
150
- });
151
- it('returns null when all finite values are identical (min === max)', () => {
152
- // 40 rows but every num is 5 -> distinct.size === 1 -> <= threshold -> null.
153
- // (Also exercises the min === max guard via a distinct-but-uniform case below.)
154
- const data = Array.from({ length: 40 }, (_, i) => ({
155
- id: String(i),
156
- num: 5,
157
- when: '',
158
- name: '',
159
- flag: false,
160
- }));
161
- expect(buildBuckets(cols.num, false, data, accessor)).toBeNull();
162
- });
163
- it('returns null when there is no finite data at all', () => {
164
- const data = Array.from({ length: 40 }, (_, i) => ({
165
- id: String(i),
166
- num: null,
167
- when: '',
168
- name: '',
169
- flag: false,
170
- }));
171
- expect(buildBuckets(cols.num, false, data, accessor)).toBeNull();
172
- });
173
- it('returns null for an empty dataset', () => {
174
- expect(buildBuckets(cols.num, false, [], accessor)).toBeNull();
175
- });
176
- it('handles negative ranges', () => {
177
- const data = Array.from({ length: 41 }, (_, i) => ({
178
- id: String(i),
179
- num: i - 20, // -20..20, 41 distinct
180
- when: '',
181
- name: '',
182
- flag: false,
183
- }));
184
- const buckets = buildBuckets(cols.num, false, data, accessor);
185
- expect(buckets[0].numericMin).toBe(-20);
186
- expect(buckets[9].numericMax).toBe(20);
187
- });
188
- });
189
- describe('buildBuckets - date', () => {
190
- const cols = makeColumns();
191
- it('builds buckets from date strings with isDate=true and date labels', () => {
192
- const start = Date.UTC(2020, 0, 1);
193
- const day = 24 * 60 * 60 * 1000;
194
- const data = Array.from({ length: 40 }, (_, i) => ({
195
- id: String(i),
196
- num: 0,
197
- when: new Date(start + i * day).toISOString(),
198
- name: '',
199
- flag: false,
200
- }));
201
- const buckets = buildBuckets(cols.when, true, data, accessor);
202
- expect(buckets).toHaveLength(10);
203
- expect(buckets.every((b) => b.isDate === true)).toBe(true);
204
- // labels should look like dates (contain a 4-digit year)
205
- expect(buckets[0].label).toMatch(/\d{4}/);
206
- });
207
- it('accepts Date instances directly', () => {
208
- const start = Date.UTC(2020, 0, 1);
209
- const day = 24 * 60 * 60 * 1000;
210
- const data = Array.from({ length: 40 }, (_, i) => ({ id: 'when' + i, when: new Date(start + i * day) }));
211
- // accessor reads row[column.id]; column id is 'when'
212
- const rows = data.map((d) => ({ when: d.when }));
213
- const buckets = buildBuckets(cols.when, true, rows, accessor);
214
- expect(buckets).toHaveLength(10);
215
- expect(buckets[0].numericMin).toBe(start);
216
- });
217
- it('returns null when date values are too few', () => {
218
- const data = Array.from({ length: 5 }, (_, i) => ({
219
- id: String(i),
220
- num: 0,
221
- when: new Date(Date.UTC(2020, 0, 1 + i)).toISOString(),
222
- name: '',
223
- flag: false,
224
- }));
225
- expect(buildBuckets(cols.when, true, data, accessor)).toBeNull();
226
- });
227
- it('skips invalid date strings', () => {
228
- const start = Date.UTC(2021, 0, 1);
229
- const day = 24 * 60 * 60 * 1000;
230
- const data = [
231
- ...Array.from({ length: 40 }, (_, i) => ({
232
- id: String(i),
233
- num: 0,
234
- when: new Date(start + i * day).toISOString(),
235
- name: '',
236
- flag: false,
237
- })),
238
- { id: 'bad', num: 0, when: 'not-a-date', name: '', flag: false },
239
- ];
240
- const buckets = buildBuckets(cols.when, true, data, accessor);
241
- expect(buckets).toHaveLength(10);
242
- expect(buckets[0].numericMin).toBe(start);
243
- });
244
- });
245
- describe('isInBucket', () => {
246
- const mid = {
247
- label: '10 - 20',
248
- numericMin: 10,
249
- numericMax: 20,
250
- isLast: false,
251
- isDate: false,
252
- };
253
- const last = {
254
- label: '20 - 30',
255
- numericMin: 20,
256
- numericMax: 30,
257
- isLast: true,
258
- isDate: false,
259
- };
260
- it('returns false for non-finite numbers', () => {
261
- expect(isInBucket(Number.NaN, mid)).toBe(false);
262
- expect(isInBucket(Number.POSITIVE_INFINITY, mid)).toBe(false);
263
- });
264
- it('returns false below the lower bound', () => {
265
- expect(isInBucket(9.999, mid)).toBe(false);
266
- });
267
- it('includes the lower bound', () => {
268
- expect(isInBucket(10, mid)).toBe(true);
269
- });
270
- it('excludes the upper bound for a non-last bucket (half-open interval)', () => {
271
- expect(isInBucket(20, mid)).toBe(false);
272
- expect(isInBucket(19.999, mid)).toBe(true);
273
- });
274
- it('includes the upper bound for the last bucket (closed interval)', () => {
275
- expect(isInBucket(30, last)).toBe(true);
276
- expect(isInBucket(20, last)).toBe(true);
277
- });
278
- it('rejects values past the upper bound even on the last bucket', () => {
279
- expect(isInBucket(30.0001, last)).toBe(false);
280
- });
281
- it('partitions a value into exactly one bucket across a built set', () => {
282
- const cols = makeColumns();
283
- const data = Array.from({ length: 101 }, (_, i) => ({
284
- id: String(i),
285
- num: i, // 0..100
286
- when: '',
287
- name: '',
288
- flag: false,
289
- }));
290
- const buckets = buildBuckets(cols.num, false, data, accessor);
291
- for (const v of [0, 1, 15, 50, 99, 100]) {
292
- const hits = buckets.filter((b) => isInBucket(v, b));
293
- expect(hits).toHaveLength(1);
294
- }
295
- });
296
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,81 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { buildFillPattern } from './fill-patterns';
3
- describe('buildFillPattern - numeric', () => {
4
- it('extrapolates an arithmetic progression', () => {
5
- expect(buildFillPattern([1, 2, 3], 3)).toEqual([4, 5, 6]);
6
- expect(buildFillPattern([10, 20, 30], 2)).toEqual([40, 50]);
7
- expect(buildFillPattern([100, 90, 80], 3)).toEqual([70, 60, 50]);
8
- });
9
- it('repeats a single numeric value (Excel default)', () => {
10
- expect(buildFillPattern([42], 4)).toEqual([42, 42, 42, 42]);
11
- });
12
- });
13
- describe('buildFillPattern - known sequences', () => {
14
- it('extends days of the week with wrap', () => {
15
- expect(buildFillPattern(['Monday', 'Tuesday'], 3)).toEqual([
16
- 'Wednesday',
17
- 'Thursday',
18
- 'Friday',
19
- ]);
20
- });
21
- it('preserves source casing', () => {
22
- expect(buildFillPattern(['JAN', 'FEB'], 2)).toEqual(['MAR', 'APR']);
23
- expect(buildFillPattern(['jan', 'feb'], 2)).toEqual(['mar', 'apr']);
24
- });
25
- it('extends quarters with wrap', () => {
26
- expect(buildFillPattern(['Q3', 'Q4'], 3)).toEqual(['Q1', 'Q2', 'Q3']);
27
- });
28
- });
29
- describe('buildFillPattern - chips / array values', () => {
30
- it('cycles array values across target cells', () => {
31
- const source = [['feature', 'editors']];
32
- const result = buildFillPattern(source, 3);
33
- expect(result).toEqual([
34
- ['feature', 'editors'],
35
- ['feature', 'editors'],
36
- ['feature', 'editors'],
37
- ]);
38
- });
39
- it('returns INDEPENDENT copies of arrays so a later mutation to one filled cell does not bleed into siblings', () => {
40
- const source = [['feature', 'editors']];
41
- const result = buildFillPattern(source, 3);
42
- // Mutate one - siblings must not change.
43
- result[0].push('bug');
44
- expect(result[1]).toEqual(['feature', 'editors']);
45
- expect(result[2]).toEqual(['feature', 'editors']);
46
- });
47
- it('cycles multi-cell array source', () => {
48
- const source = [['a'], ['b'], ['c']];
49
- const result = buildFillPattern(source, 4);
50
- expect(result).toEqual([['a'], ['b'], ['c'], ['a']]);
51
- });
52
- });
53
- describe('buildFillPattern - prefix/number/suffix', () => {
54
- it('extrapolates "Item N" series', () => {
55
- expect(buildFillPattern(['Item 1', 'Item 2'], 3)).toEqual([
56
- 'Item 3',
57
- 'Item 4',
58
- 'Item 5',
59
- ]);
60
- });
61
- it('preserves zero-padding width', () => {
62
- expect(buildFillPattern(['Run-001', 'Run-002'], 2)).toEqual([
63
- 'Run-003',
64
- 'Run-004',
65
- ]);
66
- });
67
- });
68
- describe('buildFillPattern - fallback cycle', () => {
69
- it('cycles plain string list when no sequence/progression detected', () => {
70
- expect(buildFillPattern(['red', 'green', 'blue'], 5)).toEqual([
71
- 'red',
72
- 'green',
73
- 'blue',
74
- 'red',
75
- 'green',
76
- ]);
77
- });
78
- it('repeats a single non-numeric string', () => {
79
- expect(buildFillPattern(['hello'], 3)).toEqual(['hello', 'hello', 'hello']);
80
- });
81
- });
@@ -1 +0,0 @@
1
- export {};