@pie-lib/mask-markup 3.1.3 → 4.0.0-next.37

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 (113) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +4 -0
  2. package/dist/choices/choice.d.ts +28 -0
  3. package/dist/choices/choice.js +92 -0
  4. package/dist/choices/index.d.ts +29 -0
  5. package/dist/choices/index.js +59 -0
  6. package/dist/componentize.d.ts +12 -0
  7. package/dist/componentize.js +4 -0
  8. package/dist/components/blank.d.ts +45 -0
  9. package/dist/components/blank.js +273 -0
  10. package/dist/components/correct-input.d.ts +11 -0
  11. package/dist/components/dropdown.d.ts +37 -0
  12. package/dist/components/dropdown.js +311 -0
  13. package/dist/components/input.d.ts +37 -0
  14. package/dist/constructed-response.d.ts +44 -0
  15. package/dist/constructed-response.js +56 -0
  16. package/dist/customizable.d.ts +43 -0
  17. package/dist/customizable.js +8 -0
  18. package/dist/drag-in-the-blank.d.ts +47 -0
  19. package/dist/drag-in-the-blank.js +220 -0
  20. package/dist/index.d.ts +15 -0
  21. package/dist/index.js +7 -0
  22. package/dist/inline-dropdown.d.ts +44 -0
  23. package/dist/inline-dropdown.js +24 -0
  24. package/dist/keyboard-coordinates.d.ts +25 -0
  25. package/dist/keyboard-coordinates.js +49 -0
  26. package/dist/mask.d.ts +30 -0
  27. package/dist/mask.js +95 -0
  28. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  29. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +17 -0
  30. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +9 -0
  31. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +26 -0
  32. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +11 -0
  33. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +11 -0
  34. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +11 -0
  35. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +24 -0
  36. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +32 -0
  37. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +29 -0
  38. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +14 -0
  39. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +8 -0
  40. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +12 -0
  41. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +11 -0
  42. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +10 -0
  43. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +10 -0
  44. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +55 -0
  45. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +16 -0
  46. package/dist/serialization.d.ts +34 -0
  47. package/dist/serialization.js +132 -0
  48. package/dist/with-mask.d.ts +55 -0
  49. package/dist/with-mask.js +45 -0
  50. package/package.json +35 -19
  51. package/CHANGELOG.json +0 -17
  52. package/CHANGELOG.md +0 -1353
  53. package/LICENSE.md +0 -5
  54. package/lib/choices/choice.js +0 -138
  55. package/lib/choices/choice.js.map +0 -1
  56. package/lib/choices/index.js +0 -126
  57. package/lib/choices/index.js.map +0 -1
  58. package/lib/componentize.js +0 -21
  59. package/lib/componentize.js.map +0 -1
  60. package/lib/components/blank.js +0 -489
  61. package/lib/components/blank.js.map +0 -1
  62. package/lib/components/correct-input.js +0 -94
  63. package/lib/components/correct-input.js.map +0 -1
  64. package/lib/components/dropdown.js +0 -480
  65. package/lib/components/dropdown.js.map +0 -1
  66. package/lib/components/input.js +0 -50
  67. package/lib/components/input.js.map +0 -1
  68. package/lib/constructed-response.js +0 -101
  69. package/lib/constructed-response.js.map +0 -1
  70. package/lib/customizable.js +0 -42
  71. package/lib/customizable.js.map +0 -1
  72. package/lib/drag-in-the-blank.js +0 -363
  73. package/lib/drag-in-the-blank.js.map +0 -1
  74. package/lib/index.js +0 -55
  75. package/lib/index.js.map +0 -1
  76. package/lib/inline-dropdown.js +0 -40
  77. package/lib/inline-dropdown.js.map +0 -1
  78. package/lib/keyboard-coordinates.js +0 -156
  79. package/lib/keyboard-coordinates.js.map +0 -1
  80. package/lib/mask.js +0 -203
  81. package/lib/mask.js.map +0 -1
  82. package/lib/serialization.js +0 -261
  83. package/lib/serialization.js.map +0 -1
  84. package/lib/with-mask.js +0 -97
  85. package/lib/with-mask.js.map +0 -1
  86. package/src/__tests__/drag-in-the-blank.test.js +0 -256
  87. package/src/__tests__/index.test.js +0 -38
  88. package/src/__tests__/keyboard-coordinates.test.js +0 -202
  89. package/src/__tests__/mask.test.js +0 -479
  90. package/src/__tests__/serialization.test.js +0 -54
  91. package/src/__tests__/utils.js +0 -1
  92. package/src/__tests__/with-mask.test.js +0 -76
  93. package/src/choices/__tests__/index.test.js +0 -212
  94. package/src/choices/choice.jsx +0 -113
  95. package/src/choices/index.jsx +0 -88
  96. package/src/componentize.js +0 -13
  97. package/src/components/__tests__/blank.test.js +0 -413
  98. package/src/components/__tests__/correct-input.test.js +0 -90
  99. package/src/components/__tests__/dropdown.test.js +0 -129
  100. package/src/components/__tests__/input.test.js +0 -102
  101. package/src/components/blank.jsx +0 -504
  102. package/src/components/correct-input.jsx +0 -82
  103. package/src/components/dropdown.jsx +0 -421
  104. package/src/components/input.jsx +0 -48
  105. package/src/constructed-response.jsx +0 -87
  106. package/src/customizable.jsx +0 -34
  107. package/src/drag-in-the-blank.jsx +0 -351
  108. package/src/index.js +0 -16
  109. package/src/inline-dropdown.jsx +0 -29
  110. package/src/keyboard-coordinates.js +0 -147
  111. package/src/mask.jsx +0 -174
  112. package/src/serialization.js +0 -260
  113. package/src/with-mask.jsx +0 -75
@@ -1,413 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen, act, fireEvent } from '@testing-library/react';
3
- import Blank from '../blank';
4
-
5
- // Mock @dnd-kit hooks to avoid DndContext requirement
6
- jest.mock('@dnd-kit/core', () => ({
7
- useDraggable: jest.fn((options) => ({
8
- attributes: options?.attributes || {},
9
- listeners: {},
10
- setNodeRef: jest.fn(),
11
- transform: null,
12
- isDragging: false,
13
- })),
14
- useDroppable: jest.fn(() => ({
15
- setNodeRef: jest.fn(),
16
- isOver: false,
17
- active: null,
18
- })),
19
- }));
20
-
21
- jest.mock('@dnd-kit/utilities', () => ({
22
- CSS: {
23
- Translate: {
24
- toString: jest.fn(() => 'translate3d(0, 0, 0)'),
25
- },
26
- },
27
- }));
28
-
29
- jest.mock('@pie-lib/math-rendering', () => ({
30
- renderMath: jest.fn(),
31
- }));
32
-
33
- // Collect the CSS rules emotion/MUI injected into the document (jsdom uses insertRule).
34
- const collectEmotionRules = () => {
35
- const rules = [];
36
- for (const sheet of Array.from(document.styleSheets)) {
37
- try {
38
- for (const rule of Array.from(sheet.cssRules)) {
39
- rules.push(rule.cssText);
40
- }
41
- } catch (e) {
42
- /* inaccessible stylesheet */
43
- }
44
- }
45
- return rules;
46
- };
47
-
48
- describe('Blank', () => {
49
- const { renderMath } = require('@pie-lib/math-rendering');
50
- const onChange = jest.fn();
51
- const defaultProps = {
52
- disabled: false,
53
- choice: { value: 'Cow' },
54
- isOver: false,
55
- dragItem: {},
56
- correct: false,
57
- onChange,
58
- };
59
-
60
- beforeEach(() => {
61
- onChange.mockClear();
62
- renderMath.mockClear();
63
- });
64
-
65
- describe('rendering', () => {
66
- it('renders with default props', () => {
67
- const { container } = render(<Blank {...defaultProps} />);
68
- expect(container.firstChild).toBeInTheDocument();
69
- });
70
-
71
- it('displays the value when provided', () => {
72
- render(<Blank {...defaultProps} />);
73
- expect(screen.getByText('Cow')).toBeInTheDocument();
74
- });
75
-
76
- it('renders as disabled when disabled prop is true', () => {
77
- render(<Blank {...defaultProps} disabled={true} />);
78
- // Check that delete button is not present when disabled
79
- expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
80
- });
81
-
82
- it('renders with dragged item preview', () => {
83
- render(<Blank {...defaultProps} dragItem={{ choice: { value: 'Dog' } }} />);
84
- // Blank component should render
85
- expect(screen.getByText('Cow')).toBeInTheDocument();
86
- });
87
-
88
- it('shows hover state when isOver is true', () => {
89
- const { container } = render(<Blank {...defaultProps} dragItem={{ choice: { value: 'Dog' } }} isOver={true} />);
90
- // Component should have hover styling
91
- expect(container.firstChild).toBeInTheDocument();
92
- });
93
-
94
- it('shows correct state when correct is true', () => {
95
- const { container } = render(<Blank {...defaultProps} correct={true} />);
96
- // Component should indicate correctness
97
- expect(container.firstChild).toBeInTheDocument();
98
- });
99
- });
100
-
101
- describe('delete functionality', () => {
102
- it('does not show delete button when disabled', () => {
103
- render(<Blank {...defaultProps} disabled={true} />);
104
- expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
105
- });
106
-
107
- it('does not show delete button when no value is set', () => {
108
- render(<Blank {...defaultProps} choice={undefined} />);
109
- expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
110
- });
111
-
112
- it('shows delete button when value is present and not disabled', () => {
113
- render(<Blank {...defaultProps} />);
114
- // If delete button is present, it should be clickable
115
- const deleteButton = screen.queryByRole('button');
116
- if (deleteButton) {
117
- expect(deleteButton).toBeInTheDocument();
118
- }
119
- });
120
- });
121
-
122
- describe('dimensions', () => {
123
- it('renders with custom dimensions when provided', () => {
124
- const { container } = render(
125
- <Blank {...defaultProps} emptyResponseAreaHeight={100} emptyResponseAreaWidth={200} />,
126
- );
127
- const element = container.firstChild;
128
- expect(element).toBeInTheDocument();
129
- });
130
-
131
- it('renders with min dimensions by default', () => {
132
- const { container } = render(<Blank {...defaultProps} />);
133
- const element = container.firstChild;
134
- expect(element).toBeInTheDocument();
135
- // Component should have minimum dimensions applied
136
- });
137
-
138
- it('handles non-numeric dimension props gracefully', () => {
139
- const { container } = render(
140
- <Blank {...defaultProps} emptyResponseAreaHeight="non-numeric" emptyResponseAreaWidth="non-numeric" />,
141
- );
142
- expect(container.firstChild).toBeInTheDocument();
143
- });
144
-
145
- it('computes chip dimensions based on content when no emptyResponseArea size is provided', () => {
146
- jest.useFakeTimers();
147
- // Mock getBoundingClientRect to simulate measured content size
148
- const rectSpy = jest
149
- .spyOn(HTMLElement.prototype, 'getBoundingClientRect')
150
- .mockReturnValue({ width: 100, height: 20, top: 0, left: 0, right: 100, bottom: 20 });
151
-
152
- const { container } = render(
153
- <Blank
154
- {...defaultProps}
155
- // Force measurement path that uses getMeasureNode / updateDimensions
156
- emptyResponseAreaHeight={0}
157
- emptyResponseAreaWidth={0}
158
- />,
159
- );
160
-
161
- // Let the internal timeout in handleElements / updateDimensions run
162
- act(() => {
163
- jest.runAllTimers();
164
- });
165
-
166
- const wrapper = container.firstChild; // StyledContent (outer droppable/click node)
167
- const dragHandle = wrapper && wrapper.firstChild; // StyledDragHandle (inner draggable node)
168
- const chip = dragHandle && dragHandle.firstChild; // StyledChip (rootRef)
169
-
170
- // Width and height should include padding (24px) around measured content
171
- expect(chip.style.width).toBe('129px');
172
- expect(chip.style.height).toBe('49px');
173
-
174
- rectSpy.mockRestore();
175
- jest.useRealTimers();
176
- });
177
- });
178
-
179
- describe('math rendering', () => {
180
- it('calls renderMath on mount when choice has content', () => {
181
- render(<Blank {...defaultProps} />);
182
- expect(renderMath).toHaveBeenCalled();
183
- });
184
-
185
- it('calls renderMath again when correct changes', () => {
186
- const { rerender } = render(<Blank {...defaultProps} correct={false} />);
187
- const callsAfterMount = renderMath.mock.calls.length;
188
- expect(callsAfterMount).toBeGreaterThan(0);
189
-
190
- rerender(<Blank {...defaultProps} correct={true} />);
191
- expect(renderMath.mock.calls.length).toBeGreaterThan(callsAfterMount);
192
- });
193
-
194
- it('does not call renderMath again when correct is unchanged', () => {
195
- const { rerender } = render(<Blank {...defaultProps} correct={true} />);
196
- const callsAfterMount = renderMath.mock.calls.length;
197
-
198
- rerender(<Blank {...defaultProps} correct={true} />);
199
- expect(renderMath.mock.calls.length).toBe(callsAfterMount);
200
- });
201
- });
202
-
203
- describe('fraction math styling', () => {
204
- it('enlarges numerator/denominator digits adjacent to a fraction to 120%', () => {
205
- render(<Blank {...defaultProps} />);
206
- const rule = collectEmotionRules().find((r) => r.includes('mjx-mn') && r.includes('mjx-mfrac'));
207
- expect(rule).toBeDefined();
208
- expect(rule).toMatch(/mjx-mn:has\(~\s*mjx-mfrac\)/);
209
- expect(rule).toMatch(/mjx-mfrac\s*~\s*mjx-mn/);
210
- expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
211
- });
212
-
213
- it('keeps the existing mjx-frac 120% rule', () => {
214
- render(<Blank {...defaultProps} />);
215
- const rule = collectEmotionRules().find((r) => /(^|[^-])mjx-frac/.test(r) && !r.includes('mjx-mfrac'));
216
- expect(rule).toBeDefined();
217
- expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
218
- });
219
- });
220
-
221
- describe('drag and drop', () => {
222
- it('accepts drag item when not disabled', () => {
223
- render(<Blank {...defaultProps} isOver={true} dragItem={{ choice: { value: 'Dog' } }} />);
224
- expect(screen.getByText('Cow')).toBeInTheDocument();
225
- });
226
-
227
- it('shows drag preview when dragging over', () => {
228
- const { container } = render(<Blank {...defaultProps} isOver={true} dragItem={{ choice: { value: 'Dog' } }} />);
229
- expect(container.firstChild).toBeInTheDocument();
230
- // Should show visual feedback for drag over
231
- });
232
- });
233
-
234
- describe('click-to-select and click-to-place', () => {
235
- const { useDroppable } = require('@dnd-kit/core');
236
-
237
- afterEach(() => {
238
- useDroppable.mockReturnValue({ setNodeRef: jest.fn(), isOver: false, active: null });
239
- });
240
-
241
- it('is a native tab stop (role=button, tabIndex=0) when empty and not disabled', () => {
242
- const { container } = render(<Blank {...defaultProps} choice={undefined} />);
243
- const outer = container.firstChild;
244
-
245
- expect(outer.getAttribute('role')).toBe('button');
246
- expect(outer.getAttribute('tabindex')).toBe('0');
247
- });
248
-
249
- it('is not a tab stop when it already holds a choice (relies on the inner draggable node)', () => {
250
- const { container } = render(<Blank {...defaultProps} />);
251
- const outer = container.firstChild;
252
-
253
- expect(outer.getAttribute('role')).toBeNull();
254
- expect(outer.getAttribute('tabindex')).toBe('-1');
255
- });
256
-
257
- it('is not a tab stop when disabled, even if empty', () => {
258
- const { container } = render(<Blank {...defaultProps} choice={undefined} disabled={true} />);
259
- const outer = container.firstChild;
260
-
261
- expect(outer.getAttribute('tabindex')).toBe('-1');
262
- });
263
-
264
- it('does not make the inner draggable node a second tab stop when the blank is empty', () => {
265
- const { container } = render(<Blank {...defaultProps} choice={undefined} selectedItem={null} />);
266
- const outer = container.firstChild;
267
- const inner = outer.firstElementChild;
268
-
269
- expect(outer.getAttribute('tabindex')).toBe('0');
270
- // dragAttributes (which carries tabIndex) is only spread onto the inner node when
271
- // it's the live tab stop (filled and not disabled) — otherwise it's omitted
272
- // entirely, so no tabindex attribute is present at all here.
273
- expect(inner.getAttribute('tabindex')).toBeNull();
274
- });
275
-
276
- it('makes the inner draggable node the tab stop when the blank is filled and not disabled', () => {
277
- const { container } = render(<Blank {...defaultProps} selectedItem={null} />);
278
- const outer = container.firstChild;
279
- const inner = outer.firstElementChild;
280
-
281
- expect(inner.getAttribute('tabindex')).toBe('0');
282
- });
283
-
284
- it('selects this blank\'s content on click when nothing else is selected', () => {
285
- const onSelectClick = jest.fn();
286
- const { container } = render(
287
- <Blank {...defaultProps} id="3" selectedItem={null} onSelectClick={onSelectClick} />,
288
- );
289
-
290
- fireEvent.click(container.firstChild);
291
-
292
- expect(onSelectClick).toHaveBeenCalledWith({
293
- id: '3',
294
- choice: defaultProps.choice,
295
- instanceId: undefined,
296
- fromChoice: false,
297
- type: 'MaskBlank',
298
- });
299
- });
300
-
301
- it('toggles off when clicking its own already-selected content', () => {
302
- const onSelectClick = jest.fn();
303
- const selectedItem = { id: '3', choice: defaultProps.choice, instanceId: undefined, fromChoice: false, type: 'MaskBlank' };
304
- const { container } = render(
305
- <Blank {...defaultProps} id="3" selectedItem={selectedItem} onSelectClick={onSelectClick} />,
306
- );
307
-
308
- fireEvent.click(container.firstChild);
309
-
310
- expect(onSelectClick).toHaveBeenCalledWith(selectedItem);
311
- });
312
-
313
- it('places the current selection here when clicking a different, already-filled blank', () => {
314
- const onPlacementClick = jest.fn();
315
- const selectedItem = { choice: { value: 'Other' }, instanceId: undefined, fromChoice: true, type: 'MaskBlank' };
316
- const { container } = render(
317
- <Blank {...defaultProps} id="3" selectedItem={selectedItem} onPlacementClick={onPlacementClick} />,
318
- );
319
-
320
- fireEvent.click(container.firstChild);
321
-
322
- expect(onPlacementClick).toHaveBeenCalledWith('3');
323
- });
324
-
325
- it('places the current selection here on Space/Enter when empty', () => {
326
- const onPlacementClick = jest.fn();
327
- const selectedItem = { choice: { value: 'Other' }, instanceId: undefined, fromChoice: true, type: 'MaskBlank' };
328
- const { container } = render(
329
- <Blank {...defaultProps} id="3" choice={undefined} selectedItem={selectedItem} onPlacementClick={onPlacementClick} />,
330
- );
331
-
332
- fireEvent.keyDown(container.firstChild, { code: 'Space' });
333
-
334
- expect(onPlacementClick).toHaveBeenCalledWith('3');
335
- });
336
-
337
- it('does nothing on click when empty and nothing is selected', () => {
338
- const onSelectClick = jest.fn();
339
- const onPlacementClick = jest.fn();
340
- const { container } = render(
341
- <Blank {...defaultProps} choice={undefined} selectedItem={null} onSelectClick={onSelectClick} onPlacementClick={onPlacementClick} />,
342
- );
343
-
344
- fireEvent.click(container.firstChild);
345
-
346
- expect(onSelectClick).not.toHaveBeenCalled();
347
- expect(onPlacementClick).not.toHaveBeenCalled();
348
- });
349
-
350
- it('does nothing on click when disabled', () => {
351
- const onSelectClick = jest.fn();
352
- const selectedItem = { choice: { value: 'Other' }, instanceId: undefined, fromChoice: true, type: 'MaskBlank' };
353
- const { container } = render(
354
- <Blank {...defaultProps} disabled={true} selectedItem={selectedItem} onSelectClick={onSelectClick} />,
355
- );
356
-
357
- fireEvent.click(container.firstChild);
358
-
359
- expect(onSelectClick).not.toHaveBeenCalled();
360
- });
361
-
362
- it('folds click-selection hover into the same highlight a live drag-over shows', () => {
363
- const selectedItem = { choice: { value: 'Other' }, instanceId: undefined, fromChoice: true, type: 'MaskBlank' };
364
- const { container } = render(<Blank {...defaultProps} id="3" selectedItem={selectedItem} />);
365
- const outer = container.firstChild;
366
-
367
- fireEvent.mouseEnter(outer);
368
- // The "over" prop drives the same CSS the real isOver-driven highlight uses —
369
- // assert via the rendered chip's className, since StyledContent forwards `over`.
370
- // Re-render check: BlankContent receives the folded isOver as true while hovered
371
- // with a selection active — verified indirectly via the "over" chip class it sets.
372
- expect(screen.getByText('Cow').closest('.over')).not.toBeNull();
373
-
374
- fireEvent.mouseLeave(outer);
375
- expect(screen.getByText('Cow').closest('.over')).toBeNull();
376
- });
377
-
378
- it('shows a pointer cursor on hover when something is selected', () => {
379
- const selectedItem = { choice: { value: 'Other' }, instanceId: undefined, fromChoice: true, type: 'MaskBlank' };
380
- const { container } = render(<Blank {...defaultProps} id="3" selectedItem={selectedItem} />);
381
- const outer = container.firstChild;
382
- const className = Array.from(outer.classList).find((c) => c.startsWith('css-'));
383
-
384
- const hoverRule = collectEmotionRules().find((r) => r.includes(`.${className}:hover`));
385
-
386
- expect(hoverRule).toBeDefined();
387
- expect(hoverRule).toMatch(/cursor:\s*pointer/);
388
- });
389
-
390
- it('keeps the default cursor on hover when nothing is selected', () => {
391
- const { container } = render(<Blank {...defaultProps} id="3" selectedItem={null} />);
392
- const outer = container.firstChild;
393
- const className = Array.from(outer.classList).find((c) => c.startsWith('css-'));
394
-
395
- const hoverRule = collectEmotionRules().find((r) => r.includes(`.${className}:hover`));
396
-
397
- expect(hoverRule).toBeUndefined();
398
- });
399
-
400
- it('keeps the default cursor on hover when disabled, even with something selected', () => {
401
- const selectedItem = { choice: { value: 'Other' }, instanceId: undefined, fromChoice: true, type: 'MaskBlank' };
402
- const { container } = render(
403
- <Blank {...defaultProps} id="3" disabled={true} selectedItem={selectedItem} />,
404
- );
405
- const outer = container.firstChild;
406
- const className = Array.from(outer.classList).find((c) => c.startsWith('css-'));
407
-
408
- const hoverRule = collectEmotionRules().find((r) => r.includes(`.${className}:hover`));
409
-
410
- expect(hoverRule).toBeUndefined();
411
- });
412
- });
413
- });
@@ -1,90 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import CorrectInput from '../correct-input';
5
-
6
- describe('CorrectInput', () => {
7
- const onChange = jest.fn();
8
- const defaultProps = {
9
- disabled: false,
10
- correct: false,
11
- variant: 'outlined',
12
- value: 'Cow',
13
- onChange,
14
- };
15
-
16
- beforeEach(() => {
17
- onChange.mockClear();
18
- });
19
-
20
- describe('rendering', () => {
21
- it('renders input with default props', () => {
22
- render(<CorrectInput {...defaultProps} />);
23
- const input = screen.getByRole('textbox');
24
- expect(input).toBeInTheDocument();
25
- expect(input).toHaveValue('Cow');
26
- });
27
-
28
- it('renders as disabled when disabled prop is true', () => {
29
- render(<CorrectInput {...defaultProps} disabled={true} />);
30
- const input = screen.getByRole('textbox');
31
- expect(input).toBeDisabled();
32
- });
33
-
34
- it('renders with correct state as false', () => {
35
- const { container } = render(<CorrectInput {...defaultProps} correct={false} />);
36
- const input = screen.getByRole('textbox');
37
- expect(input).toBeInTheDocument();
38
- });
39
-
40
- it('renders with correct state as true', () => {
41
- const { container } = render(<CorrectInput {...defaultProps} correct={true} />);
42
- const input = screen.getByRole('textbox');
43
- expect(input).toBeInTheDocument();
44
- // Should show visual indication of correctness
45
- });
46
-
47
- it('renders with outlined variant', () => {
48
- render(<CorrectInput {...defaultProps} variant="outlined" />);
49
- const input = screen.getByRole('textbox');
50
- expect(input).toBeInTheDocument();
51
- });
52
- });
53
-
54
- describe('user interactions', () => {
55
- it('calls onChange when user types', async () => {
56
- const user = userEvent.setup();
57
- render(<CorrectInput {...defaultProps} />);
58
-
59
- const input = screen.getByRole('textbox');
60
- await user.clear(input);
61
- await user.type(input, '1');
62
-
63
- expect(onChange).toHaveBeenCalled();
64
- });
65
-
66
- it('calls onChange with event object', async () => {
67
- const user = userEvent.setup();
68
- render(<CorrectInput {...defaultProps} value="" />);
69
-
70
- const input = screen.getByRole('textbox');
71
- await user.type(input, 'test');
72
-
73
- expect(onChange).toHaveBeenCalled();
74
- // Check that onChange receives an event-like object
75
- const lastCall = onChange.mock.calls[onChange.mock.calls.length - 1][0];
76
- expect(lastCall).toHaveProperty('target');
77
- });
78
-
79
- it('updates value when user changes input', async () => {
80
- const user = userEvent.setup();
81
- render(<CorrectInput {...defaultProps} />);
82
-
83
- const input = screen.getByRole('textbox');
84
- await user.clear(input);
85
- await user.type(input, 'Dog');
86
-
87
- expect(onChange).toHaveBeenCalled();
88
- });
89
- });
90
- });
@@ -1,129 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen, waitFor } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { choice } from '../../__tests__/utils';
5
- import Dropdown from '../dropdown';
6
-
7
- describe('Dropdown', () => {
8
- const onChange = jest.fn();
9
- const defaultProps = {
10
- onChange,
11
- id: '1',
12
- correct: false,
13
- disabled: false,
14
- value: 'Jumped',
15
- choices: [choice('Jumped'), choice('Laughed'), choice('Smiled')],
16
- };
17
-
18
- beforeEach(() => {
19
- onChange.mockClear();
20
- });
21
-
22
- describe('rendering', () => {
23
- it('renders dropdown with default props', () => {
24
- render(<Dropdown {...defaultProps} />);
25
- const button = screen.getByRole('combobox');
26
- expect(button).toBeInTheDocument();
27
- // Button displays the selected value
28
- expect(button).toHaveTextContent('Jumped');
29
- });
30
-
31
- it('renders with all choices as options when opened', async () => {
32
- const user = userEvent.setup();
33
- render(<Dropdown {...defaultProps} />);
34
-
35
- const button = screen.getByRole('combobox');
36
- await user.click(button);
37
-
38
- // Options should now be visible - find them by role
39
- const options = screen.getAllByRole('option');
40
- expect(options).toHaveLength(3);
41
- // Verify the text content of options using specific elements
42
- expect(options[0]).toHaveTextContent('Jumped');
43
- expect(options[1]).toHaveTextContent('Laughed');
44
- expect(options[2]).toHaveTextContent('Smiled');
45
- });
46
-
47
- it('focuses the selected option when the menu opens', async () => {
48
- const user = userEvent.setup();
49
- render(<Dropdown {...defaultProps} />);
50
-
51
- const button = screen.getByRole('combobox');
52
- await user.click(button);
53
-
54
- await waitFor(() => {
55
- expect(document.getElementById('dropdown-option-1-0')).toHaveFocus();
56
- });
57
- expect(button).toHaveAttribute('aria-activedescendant', 'dropdown-option-1-0');
58
- });
59
-
60
- it('focuses a non-first selected option when the menu opens', async () => {
61
- const user = userEvent.setup();
62
- render(<Dropdown {...defaultProps} value="Laughed" />);
63
-
64
- const button = screen.getByRole('combobox');
65
- await user.click(button);
66
-
67
- await waitFor(() => {
68
- expect(document.getElementById('dropdown-option-1-1')).toHaveFocus();
69
- });
70
- expect(button).toHaveAttribute('aria-activedescendant', 'dropdown-option-1-1');
71
- });
72
-
73
- it('does not highlight an option when no value is selected', async () => {
74
- const user = userEvent.setup();
75
- render(<Dropdown {...defaultProps} value={undefined} />);
76
-
77
- const button = screen.getByRole('combobox');
78
- await user.click(button);
79
-
80
- expect(button).not.toHaveAttribute('aria-activedescendant');
81
- });
82
-
83
- it('renders as disabled when disabled prop is true', () => {
84
- render(<Dropdown {...defaultProps} disabled={true} />);
85
- const button = screen.getByRole('combobox');
86
- expect(button).toBeDisabled();
87
- });
88
-
89
- it('shows correct state when correct is true', () => {
90
- const { container } = render(<Dropdown {...defaultProps} correct={true} />);
91
- const button = screen.getByRole('combobox');
92
- expect(button).toBeInTheDocument();
93
- });
94
- });
95
-
96
- describe('user interactions', () => {
97
- it('calls onChange when user selects a different option', async () => {
98
- const user = userEvent.setup();
99
- render(<Dropdown {...defaultProps} />);
100
-
101
- // Click button to open menu
102
- const button = screen.getByRole('combobox');
103
- await user.click(button);
104
-
105
- // Find the option by getting all options and selecting the one with "Laughed" text
106
- const options = screen.getAllByRole('option');
107
- const laughedOption = options.find((opt) => opt.textContent.includes('Laughed'));
108
- await user.click(laughedOption);
109
-
110
- expect(onChange).toHaveBeenCalledWith('1', 'Laughed');
111
- });
112
-
113
- it('calls onChange with correct value', async () => {
114
- const user = userEvent.setup();
115
- render(<Dropdown {...defaultProps} />);
116
-
117
- // Click button to open menu
118
- const button = screen.getByRole('combobox');
119
- await user.click(button);
120
-
121
- // Find the option by getting all options and selecting the one with "Smiled" text
122
- const options = screen.getAllByRole('option');
123
- const smiledOption = options.find((opt) => opt.textContent.includes('Smiled'));
124
- await user.click(smiledOption);
125
-
126
- expect(onChange).toHaveBeenCalledWith('1', 'Smiled');
127
- });
128
- });
129
- });