@object-ui/components 0.5.0 → 3.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 (119) hide show
  1. package/.turbo/turbo-build.log +12 -25
  2. package/CHANGELOG.md +32 -0
  3. package/dist/index.css +1 -1
  4. package/dist/index.js +23987 -22576
  5. package/dist/index.umd.cjs +30 -30
  6. package/dist/src/custom/action-param-dialog.d.ts +21 -0
  7. package/dist/src/custom/index.d.ts +4 -0
  8. package/dist/src/custom/navigation-overlay.d.ts +50 -0
  9. package/dist/src/custom/view-skeleton.d.ts +37 -0
  10. package/dist/src/custom/view-states.d.ts +33 -0
  11. package/dist/src/index.d.ts +1 -0
  12. package/dist/src/renderers/action/action-button.d.ts +11 -0
  13. package/dist/src/renderers/action/action-group.d.ts +25 -0
  14. package/dist/src/renderers/action/action-icon.d.ts +10 -0
  15. package/dist/src/renderers/action/action-menu.d.ts +19 -0
  16. package/dist/src/renderers/action/index.d.ts +0 -0
  17. package/dist/src/renderers/action/resolve-icon.d.ts +6 -0
  18. package/package.json +20 -19
  19. package/src/__tests__/PageRendererRegions.test.tsx +664 -55
  20. package/src/__tests__/__snapshots__/snapshot-critical.test.tsx.snap +811 -0
  21. package/src/__tests__/__snapshots__/snapshot.test.tsx.snap +327 -0
  22. package/src/__tests__/accessibility.test.tsx +137 -0
  23. package/src/__tests__/api-consistency.test.tsx +596 -0
  24. package/src/__tests__/color-contrast.test.tsx +212 -0
  25. package/src/__tests__/compliance.test.tsx +72 -0
  26. package/src/__tests__/edge-cases.test.tsx +285 -0
  27. package/src/__tests__/navigation-overlay.test.tsx +273 -0
  28. package/src/__tests__/snapshot-critical.test.tsx +317 -0
  29. package/src/__tests__/snapshot.test.tsx +205 -0
  30. package/src/__tests__/view-compliance.test.tsx +153 -0
  31. package/src/__tests__/wcag-audit.test.tsx +493 -0
  32. package/src/custom/action-param-dialog.tsx +264 -0
  33. package/src/custom/index.ts +4 -0
  34. package/src/custom/navigation-overlay.tsx +296 -0
  35. package/src/custom/view-skeleton.tsx +243 -0
  36. package/src/custom/view-states.tsx +153 -0
  37. package/src/index.ts +1 -0
  38. package/src/renderers/action/action-button.tsx +147 -0
  39. package/src/renderers/action/action-group.tsx +270 -0
  40. package/src/renderers/action/action-icon.tsx +150 -0
  41. package/src/renderers/action/action-menu.tsx +203 -0
  42. package/src/renderers/action/index.ts +18 -0
  43. package/src/renderers/action/resolve-icon.ts +35 -0
  44. package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +275 -0
  45. package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +120 -0
  46. package/src/renderers/complex/__tests__/data-table-editing.test.tsx +221 -0
  47. package/src/renderers/complex/data-table.tsx +269 -33
  48. package/src/renderers/complex/resizable.tsx +20 -17
  49. package/src/renderers/data-display/list.tsx +1 -1
  50. package/src/renderers/data-display/table.tsx +1 -1
  51. package/src/renderers/data-display/tree-view.tsx +2 -1
  52. package/src/renderers/form/form.tsx +33 -10
  53. package/src/renderers/index.ts +1 -0
  54. package/src/renderers/layout/aspect-ratio.tsx +1 -1
  55. package/src/renderers/layout/page.tsx +416 -52
  56. package/src/renderers/navigation/sidebar.tsx +6 -0
  57. package/src/renderers/placeholders.tsx +2 -2
  58. package/src/stories/MockedData.stories.tsx +87 -37
  59. package/src/stories-json/Accessibility.mdx +297 -0
  60. package/src/stories-json/EdgeCases.stories.tsx +160 -0
  61. package/src/stories-json/GettingStarted.mdx +89 -0
  62. package/src/stories-json/Introduction.mdx +127 -0
  63. package/src/stories-json/accordion.stories.tsx +1 -1
  64. package/src/stories-json/aggrid.stories.tsx +1 -1
  65. package/src/stories-json/alert.stories.tsx +1 -1
  66. package/src/stories-json/aspect-ratio.stories.tsx +1 -1
  67. package/src/stories-json/avatar.stories.tsx +1 -1
  68. package/src/stories-json/badge.stories.tsx +1 -1
  69. package/src/stories-json/breadcrumb.stories.tsx +1 -1
  70. package/src/stories-json/button-group.stories.tsx +1 -1
  71. package/src/stories-json/button.stories.tsx +1 -1
  72. package/src/stories-json/calendar.stories.tsx +1 -1
  73. package/src/stories-json/card.stories.tsx +1 -1
  74. package/src/stories-json/carousel.stories.tsx +1 -1
  75. package/src/stories-json/charts.stories.tsx +1 -1
  76. package/src/stories-json/chatbot.stories.tsx +1 -1
  77. package/src/stories-json/code-editor.stories.tsx +1 -1
  78. package/src/stories-json/collapsible.stories.tsx +1 -1
  79. package/src/stories-json/controls.stories.tsx +1 -1
  80. package/src/stories-json/crm-live-data.stories.tsx +154 -0
  81. package/src/stories-json/data-table.stories.tsx +80 -4
  82. package/src/stories-json/data_display_extras.stories.tsx +1 -1
  83. package/src/stories-json/date-picker.stories.tsx +1 -1
  84. package/src/stories-json/detail-view.stories.tsx +1 -1
  85. package/src/stories-json/dialog.stories.tsx +1 -1
  86. package/src/stories-json/feedback_extras.stories.tsx +1 -1
  87. package/src/stories-json/feedback_others.stories.tsx +1 -1
  88. package/src/stories-json/form-variants.stories.tsx +210 -0
  89. package/src/stories-json/form_advanced.stories.tsx +1 -1
  90. package/src/stories-json/form_extras.stories.tsx +1 -1
  91. package/src/stories-json/grid.stories.tsx +1 -1
  92. package/src/stories-json/icon.stories.tsx +1 -1
  93. package/src/stories-json/input.stories.tsx +1 -1
  94. package/src/stories-json/kanban.stories.tsx +1 -1
  95. package/src/stories-json/layout_extended.stories.tsx +1 -1
  96. package/src/stories-json/layout_flex.stories.tsx +1 -1
  97. package/src/stories-json/list-view.stories.tsx +1 -1
  98. package/src/stories-json/markdown.stories.tsx +1 -1
  99. package/src/stories-json/menus.stories.tsx +1 -1
  100. package/src/stories-json/metric-card.stories.tsx +1 -1
  101. package/src/stories-json/navigation-menu.stories.tsx +1 -1
  102. package/src/stories-json/object-aggrid-advanced.stories.tsx +389 -0
  103. package/src/stories-json/object-aggrid.stories.tsx +1 -1
  104. package/src/stories-json/object-form.stories.tsx +1 -1
  105. package/src/stories-json/object-gantt.stories.tsx +1 -1
  106. package/src/stories-json/object-grid.stories.tsx +159 -1
  107. package/src/stories-json/object-map.stories.tsx +1 -1
  108. package/src/stories-json/object-view.stories.tsx +1 -1
  109. package/src/stories-json/overlay_extras.stories.tsx +1 -1
  110. package/src/stories-json/overlay_others.stories.tsx +1 -1
  111. package/src/stories-json/resizable.stories.tsx +1 -1
  112. package/src/stories-json/select.stories.tsx +1 -1
  113. package/src/stories-json/separator.stories.tsx +1 -1
  114. package/src/stories-json/statistic.stories.tsx +1 -1
  115. package/src/stories-json/tabs.stories.tsx +1 -1
  116. package/src/stories-json/timeline.stories.tsx +1 -1
  117. package/src/stories-json/typography.stories.tsx +1 -1
  118. package/src/ui/slider.tsx +6 -2
  119. package/src/stories/Introduction.mdx +0 -34
@@ -0,0 +1,275 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import { describe, it, expect, vi } from 'vitest';
10
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
11
+ import React from 'react';
12
+ import type { DataTableSchema } from '@object-ui/types';
13
+
14
+ // Import the component
15
+ import '../data-table';
16
+ import { ComponentRegistry } from '@object-ui/core';
17
+
18
+ describe('Data Table - Batch Editing', () => {
19
+ const mockData = [
20
+ { id: 1, name: 'John Doe', email: 'john@example.com', age: 30 },
21
+ { id: 2, name: 'Jane Smith', email: 'jane@example.com', age: 25 },
22
+ { id: 3, name: 'Bob Johnson', email: 'bob@example.com', age: 35 },
23
+ ];
24
+
25
+ const mockColumns = [
26
+ { header: 'ID', accessorKey: 'id', editable: false },
27
+ { header: 'Name', accessorKey: 'name' },
28
+ { header: 'Email', accessorKey: 'email' },
29
+ { header: 'Age', accessorKey: 'age' },
30
+ ];
31
+
32
+ it('should track pending changes across multiple cells', async () => {
33
+ const onRowSave = vi.fn();
34
+
35
+ const schema: DataTableSchema = {
36
+ type: 'data-table',
37
+ columns: mockColumns,
38
+ data: mockData,
39
+ editable: true,
40
+ pagination: false,
41
+ searchable: false,
42
+ rowActions: true,
43
+ onRowSave,
44
+ };
45
+
46
+ const DataTableRenderer = ComponentRegistry.get('data-table');
47
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
48
+
49
+ const { container } = render(<DataTableRenderer schema={schema} />);
50
+
51
+ // Edit first cell in row
52
+ const nameCell = screen.getByText('John Doe').closest('td');
53
+ if (nameCell) {
54
+ fireEvent.doubleClick(nameCell);
55
+
56
+ await waitFor(() => {
57
+ const input = nameCell.querySelector('input');
58
+ expect(input).toBeInTheDocument();
59
+ });
60
+
61
+ const input = nameCell.querySelector('input');
62
+ if (input) {
63
+ fireEvent.change(input, { target: { value: 'John Smith' } });
64
+ fireEvent.keyDown(input, { key: 'Enter' });
65
+ }
66
+ }
67
+
68
+ // Wait for the edit to be saved to pending changes
69
+ await waitFor(() => {
70
+ const modifiedIndicator = screen.getByText(/1 row modified/i);
71
+ expect(modifiedIndicator).toBeInTheDocument();
72
+ });
73
+
74
+ // Edit second cell in same row - find by searching through all cells
75
+ const emailCell = Array.from(container.querySelectorAll('td')).find(el =>
76
+ el.textContent?.includes('john@example.com')
77
+ );
78
+
79
+ expect(emailCell).toBeInTheDocument();
80
+ if (emailCell) {
81
+ fireEvent.doubleClick(emailCell);
82
+
83
+ await waitFor(() => {
84
+ const input = emailCell.querySelector('input');
85
+ expect(input).toBeInTheDocument();
86
+ });
87
+
88
+ const input = emailCell.querySelector('input');
89
+ if (input) {
90
+ fireEvent.change(input, { target: { value: 'johnsmith@example.com' } });
91
+ fireEvent.keyDown(input, { key: 'Enter' });
92
+ }
93
+ }
94
+
95
+ // Row should still show as modified (still just 1 row)
96
+ await waitFor(() => {
97
+ const modifiedIndicator = screen.getByText(/1 row modified/i);
98
+ expect(modifiedIndicator).toBeInTheDocument();
99
+ });
100
+ });
101
+
102
+ it('should save a single row with multiple changes', async () => {
103
+ const onRowSave = vi.fn().mockResolvedValue(undefined);
104
+
105
+ const schema: DataTableSchema = {
106
+ type: 'data-table',
107
+ columns: mockColumns,
108
+ data: mockData,
109
+ editable: true,
110
+ pagination: false,
111
+ searchable: false,
112
+ rowActions: true,
113
+ onRowSave,
114
+ };
115
+
116
+ const DataTableRenderer = ComponentRegistry.get('data-table');
117
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
118
+
119
+ render(<DataTableRenderer schema={schema} />);
120
+
121
+ // Edit name
122
+ const nameCell = screen.getByText('John Doe').closest('td');
123
+ if (nameCell) {
124
+ fireEvent.doubleClick(nameCell);
125
+ await waitFor(() => {
126
+ const input = nameCell.querySelector('input');
127
+ expect(input).toBeInTheDocument();
128
+ });
129
+
130
+ const input = nameCell.querySelector('input');
131
+ if (input) {
132
+ fireEvent.change(input, { target: { value: 'John Smith' } });
133
+ fireEvent.keyDown(input, { key: 'Enter' });
134
+ }
135
+ }
136
+
137
+ // Find and click save button for row
138
+ await waitFor(() => {
139
+ const saveButtons = screen.getAllByTitle('Save row');
140
+ expect(saveButtons.length).toBeGreaterThan(0);
141
+ fireEvent.click(saveButtons[0]);
142
+ });
143
+
144
+ // Verify callback was called with correct data
145
+ await waitFor(() => {
146
+ expect(onRowSave).toHaveBeenCalledWith(
147
+ 0,
148
+ { name: 'John Smith' },
149
+ mockData[0]
150
+ );
151
+ });
152
+ });
153
+
154
+ it('should save all modified rows with batch save', async () => {
155
+ const onBatchSave = vi.fn().mockResolvedValue(undefined);
156
+
157
+ const schema: DataTableSchema = {
158
+ type: 'data-table',
159
+ columns: mockColumns,
160
+ data: mockData,
161
+ editable: true,
162
+ pagination: false,
163
+ searchable: false,
164
+ onBatchSave,
165
+ };
166
+
167
+ const DataTableRenderer = ComponentRegistry.get('data-table');
168
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
169
+
170
+ render(<DataTableRenderer schema={schema} />);
171
+
172
+ // Edit row 1
173
+ const nameCell1 = screen.getByText('John Doe').closest('td');
174
+ if (nameCell1) {
175
+ fireEvent.doubleClick(nameCell1);
176
+ await waitFor(() => {
177
+ const input = nameCell1.querySelector('input');
178
+ expect(input).toBeInTheDocument();
179
+ });
180
+
181
+ const input = nameCell1.querySelector('input');
182
+ if (input) {
183
+ fireEvent.change(input, { target: { value: 'John Smith' } });
184
+ fireEvent.keyDown(input, { key: 'Enter' });
185
+ }
186
+ }
187
+
188
+ // Edit row 2
189
+ await waitFor(() => {
190
+ const nameCell2 = screen.getByText('Jane Smith').closest('td');
191
+ expect(nameCell2).toBeInTheDocument();
192
+ });
193
+
194
+ const nameCell2 = screen.getByText('Jane Smith').closest('td');
195
+ if (nameCell2) {
196
+ fireEvent.doubleClick(nameCell2);
197
+ await waitFor(() => {
198
+ const input = nameCell2.querySelector('input');
199
+ expect(input).toBeInTheDocument();
200
+ });
201
+
202
+ const input = nameCell2.querySelector('input');
203
+ if (input) {
204
+ fireEvent.change(input, { target: { value: 'Jane Doe' } });
205
+ fireEvent.keyDown(input, { key: 'Enter' });
206
+ }
207
+ }
208
+
209
+ // Click save all button
210
+ await waitFor(() => {
211
+ const saveAllButton = screen.getByText(/Save All \(2\)/i);
212
+ expect(saveAllButton).toBeInTheDocument();
213
+ fireEvent.click(saveAllButton);
214
+ });
215
+
216
+ // Verify callback was called
217
+ await waitFor(() => {
218
+ expect(onBatchSave).toHaveBeenCalledWith([
219
+ { rowIndex: 0, changes: { name: 'John Smith' }, row: mockData[0] },
220
+ { rowIndex: 1, changes: { name: 'Jane Doe' }, row: mockData[1] },
221
+ ]);
222
+ });
223
+ });
224
+
225
+ it('should cancel all changes', async () => {
226
+ const onBatchSave = vi.fn();
227
+
228
+ const schema: DataTableSchema = {
229
+ type: 'data-table',
230
+ columns: mockColumns,
231
+ data: mockData,
232
+ editable: true,
233
+ pagination: false,
234
+ searchable: false,
235
+ onBatchSave,
236
+ };
237
+
238
+ const DataTableRenderer = ComponentRegistry.get('data-table');
239
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
240
+
241
+ render(<DataTableRenderer schema={schema} />);
242
+
243
+ // Edit a cell
244
+ const nameCell = screen.getByText('John Doe').closest('td');
245
+ if (nameCell) {
246
+ fireEvent.doubleClick(nameCell);
247
+ await waitFor(() => {
248
+ const input = nameCell.querySelector('input');
249
+ expect(input).toBeInTheDocument();
250
+ });
251
+
252
+ const input = nameCell.querySelector('input');
253
+ if (input) {
254
+ fireEvent.change(input, { target: { value: 'John Smith' } });
255
+ fireEvent.keyDown(input, { key: 'Enter' });
256
+ }
257
+ }
258
+
259
+ // Click cancel all button
260
+ await waitFor(() => {
261
+ const cancelButton = screen.getByText(/Cancel All/i);
262
+ expect(cancelButton).toBeInTheDocument();
263
+ fireEvent.click(cancelButton);
264
+ });
265
+
266
+ // Verify changes indicator is gone
267
+ await waitFor(() => {
268
+ const modifiedIndicator = screen.queryByText(/row modified/i);
269
+ expect(modifiedIndicator).not.toBeInTheDocument();
270
+ });
271
+
272
+ // Original value should be restored
273
+ expect(screen.getByText('John Doe')).toBeInTheDocument();
274
+ });
275
+ });
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Data Table - Custom Cell Renderer Tests
3
+ *
4
+ * Tests that data-table respects col.cell() function for custom cell rendering.
5
+ */
6
+ import { describe, it, expect, vi } from 'vitest';
7
+ import { render, screen, waitFor } from '@testing-library/react';
8
+ import '@testing-library/jest-dom';
9
+ import React from 'react';
10
+ import { SchemaRenderer } from '@object-ui/react';
11
+
12
+ // Import data-table to ensure it's registered
13
+ import '../data-table';
14
+
15
+ describe('Data Table: col.cell() custom renderer', () => {
16
+ it('should invoke col.cell function to render cell content', async () => {
17
+ const cellFn = vi.fn((value: any, _row: any) => (
18
+ <span data-testid="custom-cell">{`Custom: ${value}`}</span>
19
+ ));
20
+
21
+ const schema = {
22
+ type: 'data-table',
23
+ columns: [
24
+ { header: 'Name', accessorKey: 'name', cell: cellFn },
25
+ { header: 'Email', accessorKey: 'email' },
26
+ ],
27
+ data: [
28
+ { name: 'Alice', email: 'alice@test.com' },
29
+ { name: 'Bob', email: 'bob@test.com' },
30
+ ],
31
+ pagination: false,
32
+ searchable: false,
33
+ };
34
+
35
+ render(<SchemaRenderer schema={schema} />);
36
+
37
+ await waitFor(() => {
38
+ expect(screen.getByText('Custom: Alice')).toBeInTheDocument();
39
+ });
40
+
41
+ expect(screen.getByText('Custom: Bob')).toBeInTheDocument();
42
+ expect(cellFn).toHaveBeenCalledTimes(2);
43
+
44
+ // Non-custom cell should render value directly
45
+ expect(screen.getByText('alice@test.com')).toBeInTheDocument();
46
+ });
47
+
48
+ it('should pass both value and row to cell function', async () => {
49
+ const cellFn = vi.fn((value: any, row: any) => (
50
+ <span data-testid="combo-cell">{`${value} (${row.email})`}</span>
51
+ ));
52
+
53
+ const schema = {
54
+ type: 'data-table',
55
+ columns: [
56
+ { header: 'Name', accessorKey: 'name', cell: cellFn },
57
+ ],
58
+ data: [
59
+ { name: 'Alice', email: 'alice@test.com' },
60
+ ],
61
+ pagination: false,
62
+ searchable: false,
63
+ };
64
+
65
+ render(<SchemaRenderer schema={schema} />);
66
+
67
+ await waitFor(() => {
68
+ expect(screen.getByText('Alice (alice@test.com)')).toBeInTheDocument();
69
+ });
70
+
71
+ expect(cellFn).toHaveBeenCalledWith('Alice', expect.objectContaining({ name: 'Alice', email: 'alice@test.com' }));
72
+ });
73
+
74
+ it('should render raw value when no cell function is provided', async () => {
75
+ const schema = {
76
+ type: 'data-table',
77
+ columns: [
78
+ { header: 'Name', accessorKey: 'name' },
79
+ ],
80
+ data: [
81
+ { name: 'Alice' },
82
+ ],
83
+ pagination: false,
84
+ searchable: false,
85
+ };
86
+
87
+ render(<SchemaRenderer schema={schema} />);
88
+
89
+ await waitFor(() => {
90
+ expect(screen.getByText('Alice')).toBeInTheDocument();
91
+ });
92
+ });
93
+
94
+ it('should prefer editing state over cell function when in edit mode', async () => {
95
+ // The editing state should take precedence over custom cell renderer
96
+ // This test verifies the rendering priority: editing > cell > raw value
97
+ const cellFn = vi.fn((value: any) => (
98
+ <span>{`Custom: ${value}`}</span>
99
+ ));
100
+
101
+ const schema = {
102
+ type: 'data-table',
103
+ columns: [
104
+ { header: 'Name', accessorKey: 'name', cell: cellFn },
105
+ ],
106
+ data: [
107
+ { name: 'Alice' },
108
+ ],
109
+ pagination: false,
110
+ searchable: false,
111
+ editable: false,
112
+ };
113
+
114
+ render(<SchemaRenderer schema={schema} />);
115
+
116
+ await waitFor(() => {
117
+ expect(screen.getByText('Custom: Alice')).toBeInTheDocument();
118
+ });
119
+ });
120
+ });
@@ -0,0 +1,221 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import { describe, it, expect, vi } from 'vitest';
10
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
11
+ import React from 'react';
12
+ import type { DataTableSchema } from '@object-ui/types';
13
+
14
+ // Import the component
15
+ import '../data-table';
16
+ import { ComponentRegistry } from '@object-ui/core';
17
+
18
+ describe('Data Table - Inline Editing', () => {
19
+ const mockData = [
20
+ { id: 1, name: 'John Doe', email: 'john@example.com', age: 30 },
21
+ { id: 2, name: 'Jane Smith', email: 'jane@example.com', age: 25 },
22
+ { id: 3, name: 'Bob Johnson', email: 'bob@example.com', age: 35 },
23
+ ];
24
+
25
+ const mockColumns = [
26
+ { header: 'ID', accessorKey: 'id', editable: false },
27
+ { header: 'Name', accessorKey: 'name' },
28
+ { header: 'Email', accessorKey: 'email' },
29
+ { header: 'Age', accessorKey: 'age' },
30
+ ];
31
+
32
+ it('should render table with editable cells when editable is true', () => {
33
+ const schema: DataTableSchema = {
34
+ type: 'data-table',
35
+ columns: mockColumns,
36
+ data: mockData,
37
+ editable: true,
38
+ pagination: false,
39
+ };
40
+
41
+ const DataTableRenderer = ComponentRegistry.get('data-table');
42
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
43
+
44
+ const { container } = render(<DataTableRenderer schema={schema} />);
45
+
46
+ // Check that cells are rendered
47
+ expect(screen.getByText('John Doe')).toBeInTheDocument();
48
+ expect(screen.getByText('jane@example.com')).toBeInTheDocument();
49
+
50
+ // Editable cells should have tabindex
51
+ const cells = container.querySelectorAll('td[tabindex="0"]');
52
+ expect(cells.length).toBeGreaterThan(0);
53
+ });
54
+
55
+ it('should call onCellChange when cell value is edited', async () => {
56
+ const onCellChange = vi.fn();
57
+
58
+ const schema: DataTableSchema = {
59
+ type: 'data-table',
60
+ columns: mockColumns,
61
+ data: mockData,
62
+ editable: true,
63
+ pagination: false,
64
+ searchable: false, // Disable search to avoid confusion with edit input
65
+ onCellChange,
66
+ };
67
+
68
+ const DataTableRenderer = ComponentRegistry.get('data-table');
69
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
70
+
71
+ const { container } = render(<DataTableRenderer schema={schema} />);
72
+
73
+ // Find the first editable cell (name column)
74
+ const nameCell = screen.getByText('John Doe').closest('td');
75
+ expect(nameCell).toBeInTheDocument();
76
+
77
+ // Double-click to enter edit mode
78
+ if (nameCell) {
79
+ fireEvent.doubleClick(nameCell);
80
+
81
+ // Wait for input to appear inside the cell
82
+ await waitFor(() => {
83
+ const input = nameCell.querySelector('input');
84
+ expect(input).toBeInTheDocument();
85
+ });
86
+
87
+ const input = nameCell.querySelector('input');
88
+ if (input) {
89
+ // Change the value
90
+ fireEvent.change(input, { target: { value: 'John Smith' } });
91
+
92
+ // Press Enter to save
93
+ fireEvent.keyDown(input, { key: 'Enter' });
94
+
95
+ // Verify onCellChange was called
96
+ await waitFor(() => {
97
+ expect(onCellChange).toHaveBeenCalledWith(
98
+ 0, // row index
99
+ 'name', // column key
100
+ 'John Smith', // new value
101
+ mockData[0] // row data
102
+ );
103
+ });
104
+ }
105
+ }
106
+ });
107
+
108
+ it('should not allow editing when editable is false', () => {
109
+ const schema: DataTableSchema = {
110
+ type: 'data-table',
111
+ columns: mockColumns,
112
+ data: mockData,
113
+ editable: false,
114
+ pagination: false,
115
+ searchable: false, // Disable search to avoid confusion
116
+ };
117
+
118
+ const DataTableRenderer = ComponentRegistry.get('data-table');
119
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
120
+
121
+ const { container } = render(<DataTableRenderer schema={schema} />);
122
+
123
+ // Find a cell
124
+ const nameCell = screen.getByText('John Doe').closest('td');
125
+ expect(nameCell).toBeInTheDocument();
126
+
127
+ // Double-click should not trigger edit mode
128
+ if (nameCell) {
129
+ fireEvent.doubleClick(nameCell);
130
+
131
+ // Input should not appear in the cell
132
+ const input = nameCell?.querySelector('input');
133
+ expect(input).not.toBeInTheDocument();
134
+ }
135
+ });
136
+
137
+ it('should respect column-level editable flag', () => {
138
+ const onCellChange = vi.fn();
139
+
140
+ const schema: DataTableSchema = {
141
+ type: 'data-table',
142
+ columns: mockColumns,
143
+ data: mockData,
144
+ editable: true,
145
+ pagination: false,
146
+ searchable: false, // Disable search to avoid confusion
147
+ onCellChange,
148
+ };
149
+
150
+ const DataTableRenderer = ComponentRegistry.get('data-table');
151
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
152
+
153
+ const { container } = render(<DataTableRenderer schema={schema} />);
154
+
155
+ // Try to edit ID column (which has editable: false)
156
+ const idCell = screen.getByText('1').closest('td');
157
+ expect(idCell).toBeInTheDocument();
158
+
159
+ if (idCell) {
160
+ fireEvent.doubleClick(idCell);
161
+
162
+ // Input should not appear for non-editable column
163
+ const input = idCell.querySelector('input');
164
+ expect(input).not.toBeInTheDocument();
165
+ }
166
+ });
167
+
168
+ it('should cancel edit on Escape key', async () => {
169
+ const onCellChange = vi.fn();
170
+
171
+ const schema: DataTableSchema = {
172
+ type: 'data-table',
173
+ columns: mockColumns,
174
+ data: mockData,
175
+ editable: true,
176
+ pagination: false,
177
+ searchable: false, // Disable search to avoid confusion
178
+ onCellChange,
179
+ };
180
+
181
+ const DataTableRenderer = ComponentRegistry.get('data-table');
182
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
183
+
184
+ const { container } = render(<DataTableRenderer schema={schema} />);
185
+
186
+ // Find the first editable cell
187
+ const nameCell = screen.getByText('John Doe').closest('td');
188
+ expect(nameCell).toBeInTheDocument();
189
+
190
+ // Double-click to enter edit mode
191
+ if (nameCell) {
192
+ fireEvent.doubleClick(nameCell);
193
+
194
+ // Wait for input to appear
195
+ await waitFor(() => {
196
+ const input = nameCell.querySelector('input');
197
+ expect(input).toBeInTheDocument();
198
+ });
199
+
200
+ const input = nameCell.querySelector('input');
201
+ if (input) {
202
+ // Change the value
203
+ fireEvent.change(input, { target: { value: 'John Smith' } });
204
+
205
+ // Press Escape to cancel
206
+ fireEvent.keyDown(input, { key: 'Escape' });
207
+
208
+ // Verify onCellChange was NOT called
209
+ await waitFor(() => {
210
+ expect(onCellChange).not.toHaveBeenCalled();
211
+ });
212
+
213
+ // Input should be removed
214
+ expect(nameCell.querySelector('input')).not.toBeInTheDocument();
215
+
216
+ // Original value should be preserved
217
+ expect(screen.getByText('John Doe')).toBeInTheDocument();
218
+ }
219
+ }
220
+ });
221
+ });