@pie-lib/mask-markup 3.1.4 → 3.1.6-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -101
- package/lib/choices/choice.js +6 -24
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +9 -32
- package/lib/choices/index.js.map +1 -1
- package/lib/components/blank.js +29 -106
- package/lib/components/blank.js.map +1 -1
- package/lib/components/dropdown.js +9 -6
- package/lib/components/dropdown.js.map +1 -1
- package/lib/drag-in-the-blank.js +30 -139
- package/lib/drag-in-the-blank.js.map +1 -1
- package/lib/keyboard-coordinates.js +1 -1
- package/lib/mask.js +15 -20
- package/lib/mask.js.map +1 -1
- package/package.json +6 -6
- package/src/choices/choice.jsx +3 -16
- package/src/choices/index.jsx +3 -27
- package/src/components/blank.jsx +35 -108
- package/src/components/dropdown.jsx +9 -7
- package/src/drag-in-the-blank.jsx +22 -132
- package/src/mask.jsx +11 -13
- package/LICENSE.md +0 -5
- package/lib/keyboard-coordinates.js.map +0 -1
- package/src/__tests__/drag-in-the-blank.test.js +0 -256
- package/src/__tests__/index.test.js +0 -38
- package/src/__tests__/keyboard-coordinates.test.js +0 -202
- package/src/__tests__/mask.test.js +0 -479
- package/src/__tests__/serialization.test.js +0 -54
- package/src/__tests__/utils.js +0 -1
- package/src/__tests__/with-mask.test.js +0 -76
- package/src/choices/__tests__/index.test.js +0 -212
- package/src/components/__tests__/blank.test.js +0 -413
- package/src/components/__tests__/correct-input.test.js +0 -90
- package/src/components/__tests__/dropdown.test.js +0 -129
- package/src/components/__tests__/input.test.js +0 -102
- package/src/keyboard-coordinates.js +0 -147
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
-
import Choice from '../choice';
|
|
4
|
-
import { choice } from '../../__tests__/utils';
|
|
5
|
-
import Choices from '../index';
|
|
6
|
-
|
|
7
|
-
// Collect the CSS rules emotion/MUI injected into the document (jsdom uses insertRule).
|
|
8
|
-
const collectEmotionRules = () => {
|
|
9
|
-
const rules = [];
|
|
10
|
-
for (const sheet of Array.from(document.styleSheets)) {
|
|
11
|
-
try {
|
|
12
|
-
for (const rule of Array.from(sheet.cssRules)) {
|
|
13
|
-
rules.push(rule.cssText);
|
|
14
|
-
}
|
|
15
|
-
} catch (e) {
|
|
16
|
-
/* inaccessible stylesheet */
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return rules;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// Mock @dnd-kit hooks to avoid DndContext requirement
|
|
23
|
-
jest.mock('@dnd-kit/core', () => ({
|
|
24
|
-
useDraggable: jest.fn(() => ({
|
|
25
|
-
attributes: {},
|
|
26
|
-
listeners: {},
|
|
27
|
-
setNodeRef: jest.fn(),
|
|
28
|
-
isDragging: false,
|
|
29
|
-
})),
|
|
30
|
-
useDroppable: jest.fn(() => ({
|
|
31
|
-
setNodeRef: jest.fn(),
|
|
32
|
-
isOver: false,
|
|
33
|
-
active: null,
|
|
34
|
-
})),
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
describe('index', () => {
|
|
38
|
-
describe('Choices', () => {
|
|
39
|
-
const defaultProps = {
|
|
40
|
-
disabled: false,
|
|
41
|
-
choices: [choice('Jumped', '0'), choice('Laughed', '1'), choice('Spoon', '2')],
|
|
42
|
-
choicePosition: 'below',
|
|
43
|
-
instanceId: 'test-instance',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
it('renders correctly with default props', () => {
|
|
47
|
-
const { container } = render(<Choices {...defaultProps} />);
|
|
48
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
49
|
-
expect(screen.getByText('Jumped')).toBeInTheDocument();
|
|
50
|
-
expect(screen.getByText('Laughed')).toBeInTheDocument();
|
|
51
|
-
expect(screen.getByText('Spoon')).toBeInTheDocument();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('renders correctly with disabled prop as true', () => {
|
|
55
|
-
const { container } = render(<Choices {...defaultProps} disabled={true} />);
|
|
56
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('renders without duplicates', () => {
|
|
60
|
-
const { container } = render(<Choices {...defaultProps} duplicates={undefined} value={{ 0: '0', 1: '1' }} />);
|
|
61
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('renders with duplicates', () => {
|
|
65
|
-
const { container } = render(<Choices {...defaultProps} duplicates={true} value={{ 0: '0', 1: '1' }} />);
|
|
66
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('click-to-place into the pool', () => {
|
|
70
|
-
it('places the selection into the pool when clicking the pool background', () => {
|
|
71
|
-
const onPlacementClick = jest.fn();
|
|
72
|
-
const selectedItem = { id: 'some-blank', fromChoice: false, type: 'MaskBlank' };
|
|
73
|
-
const { container } = render(
|
|
74
|
-
<Choices {...defaultProps} selectedItem={selectedItem} onPlacementClick={onPlacementClick} />,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
fireEvent.click(container.firstChild);
|
|
78
|
-
|
|
79
|
-
expect(onPlacementClick).toHaveBeenCalledWith(undefined);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('does nothing when clicking the pool background with nothing selected', () => {
|
|
83
|
-
const onPlacementClick = jest.fn();
|
|
84
|
-
const { container } = render(<Choices {...defaultProps} onPlacementClick={onPlacementClick} />);
|
|
85
|
-
|
|
86
|
-
fireEvent.click(container.firstChild);
|
|
87
|
-
|
|
88
|
-
expect(onPlacementClick).not.toHaveBeenCalled();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('clicking a specific choice selects it, not the pool background handler', () => {
|
|
92
|
-
const onPlacementClick = jest.fn();
|
|
93
|
-
const onSelectClick = jest.fn();
|
|
94
|
-
const selectedItem = { id: 'some-blank', fromChoice: false, type: 'MaskBlank' };
|
|
95
|
-
render(
|
|
96
|
-
<Choices
|
|
97
|
-
{...defaultProps}
|
|
98
|
-
selectedItem={selectedItem}
|
|
99
|
-
onSelectClick={onSelectClick}
|
|
100
|
-
onPlacementClick={onPlacementClick}
|
|
101
|
-
/>,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
fireEvent.click(screen.getByText('Jumped'));
|
|
105
|
-
|
|
106
|
-
expect(onSelectClick).toHaveBeenCalled();
|
|
107
|
-
expect(onPlacementClick).not.toHaveBeenCalled();
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe('Choice', () => {
|
|
113
|
-
const defaultProps = {
|
|
114
|
-
disabled: false,
|
|
115
|
-
choice: choice('Label', '1'),
|
|
116
|
-
instanceId: 'test-instance',
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
describe('render', () => {
|
|
120
|
-
it('renders correctly with default props', () => {
|
|
121
|
-
const { container } = render(<Choice {...defaultProps} />);
|
|
122
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
123
|
-
expect(screen.getByText('Label')).toBeInTheDocument();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('renders correctly with disabled prop as true', () => {
|
|
127
|
-
const { container } = render(<Choice {...defaultProps} disabled={true} />);
|
|
128
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('fraction math styling', () => {
|
|
133
|
-
it('enlarges numerator/denominator digits adjacent to a fraction to 120%', () => {
|
|
134
|
-
render(<Choice {...defaultProps} />);
|
|
135
|
-
// The new rule targets mjx-mn digits that sit next to an mjx-mfrac.
|
|
136
|
-
const rule = collectEmotionRules().find((r) => r.includes('mjx-mn') && r.includes('mjx-mfrac'));
|
|
137
|
-
expect(rule).toBeDefined();
|
|
138
|
-
expect(rule).toMatch(/mjx-mn:has\(~\s*mjx-mfrac\)/);
|
|
139
|
-
expect(rule).toMatch(/mjx-mfrac\s*~\s*mjx-mn/);
|
|
140
|
-
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('keeps the existing mjx-frac 120% rule', () => {
|
|
144
|
-
render(<Choice {...defaultProps} />);
|
|
145
|
-
const rule = collectEmotionRules().find((r) => /(^|[^-])mjx-frac/.test(r) && !r.includes('mjx-mfrac'));
|
|
146
|
-
expect(rule).toBeDefined();
|
|
147
|
-
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('click-to-select', () => {
|
|
152
|
-
it('selects this choice on click when nothing else is selected', () => {
|
|
153
|
-
const onSelectClick = jest.fn();
|
|
154
|
-
const { container } = render(<Choice {...defaultProps} selectedItem={null} onSelectClick={onSelectClick} />);
|
|
155
|
-
|
|
156
|
-
fireEvent.click(container.firstChild);
|
|
157
|
-
|
|
158
|
-
expect(onSelectClick).toHaveBeenCalledWith({
|
|
159
|
-
choice: defaultProps.choice,
|
|
160
|
-
instanceId: defaultProps.instanceId,
|
|
161
|
-
fromChoice: true,
|
|
162
|
-
type: 'MaskBlank',
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('toggles off (calls onSelectClick again) when clicking the already-selected choice', () => {
|
|
167
|
-
const onSelectClick = jest.fn();
|
|
168
|
-
const selectedItem = { choice: defaultProps.choice, instanceId: defaultProps.instanceId, fromChoice: true, type: 'MaskBlank' };
|
|
169
|
-
const { container } = render(
|
|
170
|
-
<Choice {...defaultProps} selectedItem={selectedItem} onSelectClick={onSelectClick} />,
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
fireEvent.click(container.firstChild);
|
|
174
|
-
|
|
175
|
-
expect(onSelectClick).toHaveBeenCalledWith({
|
|
176
|
-
choice: defaultProps.choice,
|
|
177
|
-
instanceId: defaultProps.instanceId,
|
|
178
|
-
fromChoice: true,
|
|
179
|
-
type: 'MaskBlank',
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('selects this choice even while a different item is already selected (pool items are never placement targets)', () => {
|
|
184
|
-
const onSelectClick = jest.fn();
|
|
185
|
-
const selectedItem = { id: 'some-blank', fromChoice: false, type: 'MaskBlank' };
|
|
186
|
-
const { container } = render(
|
|
187
|
-
<Choice {...defaultProps} selectedItem={selectedItem} onSelectClick={onSelectClick} />,
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
fireEvent.click(container.firstChild);
|
|
191
|
-
|
|
192
|
-
expect(onSelectClick).toHaveBeenCalledWith({
|
|
193
|
-
choice: defaultProps.choice,
|
|
194
|
-
instanceId: defaultProps.instanceId,
|
|
195
|
-
fromChoice: true,
|
|
196
|
-
type: 'MaskBlank',
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('does nothing on click when disabled', () => {
|
|
201
|
-
const onSelectClick = jest.fn();
|
|
202
|
-
const { container } = render(
|
|
203
|
-
<Choice {...defaultProps} disabled={true} selectedItem={null} onSelectClick={onSelectClick} />,
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
fireEvent.click(container.firstChild);
|
|
207
|
-
|
|
208
|
-
expect(onSelectClick).not.toHaveBeenCalled();
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
});
|
|
@@ -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
|
-
});
|