@pie-lib/editable-html-tip-tap 2.2.0-beta.8 → 2.2.0-beta.9
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/package.json +3 -3
- package/src/__tests__/EditableHtml.test.jsx +0 -588
- package/src/__tests__/constants.test.js +0 -19
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
- package/src/__tests__/extensions.test.js +0 -208
- package/src/__tests__/index.test.jsx +0 -154
- package/src/__tests__/size-utils.test.js +0 -64
- package/src/__tests__/theme.test.js +0 -17
- package/src/components/__tests__/AltDialog.test.jsx +0 -147
- package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
- package/src/components/__tests__/CssIcon.test.jsx +0 -46
- package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
- package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
- package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
- package/src/components/__tests__/InsertImageHandler.test.js +0 -161
- package/src/components/__tests__/MediaDialog.test.jsx +0 -293
- package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
- package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
- package/src/components/__tests__/MenuBar.test.jsx +0 -250
- package/src/components/__tests__/RespArea.test.jsx +0 -122
- package/src/components/__tests__/TableIcons.test.jsx +0 -149
- package/src/components/__tests__/TextAlign.test.jsx +0 -167
- package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
- package/src/components/__tests__/characterUtils.test.js +0 -166
- package/src/components/__tests__/choice.test.jsx +0 -171
- package/src/components/__tests__/custom-popper.test.jsx +0 -82
- package/src/components/__tests__/done-button.test.jsx +0 -54
- package/src/components/__tests__/toolbar-buttons.test.jsx +0 -234
- package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
- package/src/extensions/__tests__/css.test.js +0 -196
- package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
- package/src/extensions/__tests__/divNode.test.js +0 -87
- package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
- package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
- package/src/extensions/__tests__/extended-list-item.test.js +0 -13
- package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
- package/src/extensions/__tests__/extended-table.test.js +0 -183
- package/src/extensions/__tests__/image-component.test.jsx +0 -346
- package/src/extensions/__tests__/image.test.js +0 -237
- package/src/extensions/__tests__/math.test.js +0 -900
- package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
- package/src/extensions/__tests__/media.test.js +0 -271
- package/src/extensions/__tests__/responseArea.test.js +0 -655
- package/src/utils/__tests__/helper.test.js +0 -126
- package/src/utils/__tests__/toolbar.test.js +0 -43
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
3
|
-
import { Button, MarkButton, RawButton, RawMarkButton } from '../common/toolbar-buttons';
|
|
4
|
-
|
|
5
|
-
describe('RawButton', () => {
|
|
6
|
-
it('renders without crashing', () => {
|
|
7
|
-
const { container } = render(<RawButton onClick={jest.fn()}>Click me</RawButton>);
|
|
8
|
-
expect(container).toBeInTheDocument();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('renders children', () => {
|
|
12
|
-
const { getByText } = render(<RawButton onClick={jest.fn()}>Test Button</RawButton>);
|
|
13
|
-
expect(getByText('Test Button')).toBeInTheDocument();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('calls onClick on mouse down', () => {
|
|
17
|
-
const onClick = jest.fn();
|
|
18
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
19
|
-
fireEvent.mouseDown(getByText('Click'));
|
|
20
|
-
expect(onClick).toHaveBeenCalled();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('prevents default on mouse down', () => {
|
|
24
|
-
const onClick = jest.fn();
|
|
25
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
26
|
-
const button = getByText('Click');
|
|
27
|
-
const event = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
|
|
28
|
-
const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
|
|
29
|
-
button.dispatchEvent(event);
|
|
30
|
-
expect(preventDefaultSpy).toHaveBeenCalled();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('calls onClick on Enter key press', () => {
|
|
34
|
-
const onClick = jest.fn();
|
|
35
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
36
|
-
fireEvent.keyDown(getByText('Click'), { key: 'Enter' });
|
|
37
|
-
expect(onClick).toHaveBeenCalled();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('calls onClick on Space key press', () => {
|
|
41
|
-
const onClick = jest.fn();
|
|
42
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
43
|
-
fireEvent.keyDown(getByText('Click'), { key: ' ' });
|
|
44
|
-
expect(onClick).toHaveBeenCalled();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('does not call onClick on other key press', () => {
|
|
48
|
-
const onClick = jest.fn();
|
|
49
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
50
|
-
fireEvent.keyDown(getByText('Click'), { key: 'a' });
|
|
51
|
-
expect(onClick).not.toHaveBeenCalled();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('applies active style when active is true', () => {
|
|
55
|
-
const { getByText } = render(
|
|
56
|
-
<RawButton onClick={jest.fn()} active={true}>
|
|
57
|
-
Active
|
|
58
|
-
</RawButton>,
|
|
59
|
-
);
|
|
60
|
-
const button = getByText('Active');
|
|
61
|
-
expect(button).toHaveStyle({ color: 'black' });
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('applies disabled style when disabled is true', () => {
|
|
65
|
-
const { getByText } = render(
|
|
66
|
-
<RawButton onClick={jest.fn()} disabled={true}>
|
|
67
|
-
Disabled
|
|
68
|
-
</RawButton>,
|
|
69
|
-
);
|
|
70
|
-
const button = getByText('Disabled');
|
|
71
|
-
expect(button).toHaveStyle({ cursor: 'not-allowed' });
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('applies extraStyles when provided', () => {
|
|
75
|
-
const extraStyles = { backgroundColor: 'red' };
|
|
76
|
-
const { getByText } = render(
|
|
77
|
-
<RawButton onClick={jest.fn()} extraStyles={extraStyles}>
|
|
78
|
-
Styled
|
|
79
|
-
</RawButton>,
|
|
80
|
-
);
|
|
81
|
-
const button = getByText('Styled');
|
|
82
|
-
expect(button).toHaveStyle({ backgroundColor: 'red' });
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('has aria-label when provided', () => {
|
|
86
|
-
const { getByLabelText } = render(
|
|
87
|
-
<RawButton onClick={jest.fn()} ariaLabel="Test Button">
|
|
88
|
-
Button
|
|
89
|
-
</RawButton>,
|
|
90
|
-
);
|
|
91
|
-
expect(getByLabelText('Test Button')).toBeInTheDocument();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('has aria-pressed attribute', () => {
|
|
95
|
-
const { getByText } = render(
|
|
96
|
-
<RawButton onClick={jest.fn()} active={true}>
|
|
97
|
-
Button
|
|
98
|
-
</RawButton>,
|
|
99
|
-
);
|
|
100
|
-
expect(getByText('Button')).toHaveAttribute('aria-pressed', 'true');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('is focusable with tabIndex', () => {
|
|
104
|
-
const { getByText } = render(<RawButton onClick={jest.fn()}>Button</RawButton>);
|
|
105
|
-
expect(getByText('Button')).toHaveAttribute('tabIndex', '0');
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('Button', () => {
|
|
110
|
-
it('is the same as RawButton', () => {
|
|
111
|
-
expect(Button).toBe(RawButton);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('RawMarkButton', () => {
|
|
116
|
-
it('renders without crashing', () => {
|
|
117
|
-
const { container } = render(
|
|
118
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold">
|
|
119
|
-
B
|
|
120
|
-
</RawMarkButton>,
|
|
121
|
-
);
|
|
122
|
-
expect(container).toBeInTheDocument();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('renders children', () => {
|
|
126
|
-
const { getByText } = render(
|
|
127
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold">
|
|
128
|
-
Bold
|
|
129
|
-
</RawMarkButton>,
|
|
130
|
-
);
|
|
131
|
-
expect(getByText('Bold')).toBeInTheDocument();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('calls onToggle with mark on mouse down', () => {
|
|
135
|
-
const onToggle = jest.fn();
|
|
136
|
-
const { getByText } = render(
|
|
137
|
-
<RawMarkButton onToggle={onToggle} mark="italic" label="Italic">
|
|
138
|
-
I
|
|
139
|
-
</RawMarkButton>,
|
|
140
|
-
);
|
|
141
|
-
fireEvent.mouseDown(getByText('I'));
|
|
142
|
-
expect(onToggle).toHaveBeenCalledWith('italic');
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('prevents default on mouse down', () => {
|
|
146
|
-
const onToggle = jest.fn();
|
|
147
|
-
const { getByText } = render(
|
|
148
|
-
<RawMarkButton onToggle={onToggle} mark="bold" label="Bold">
|
|
149
|
-
B
|
|
150
|
-
</RawMarkButton>,
|
|
151
|
-
);
|
|
152
|
-
const button = getByText('B');
|
|
153
|
-
const event = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
|
|
154
|
-
const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
|
|
155
|
-
button.dispatchEvent(event);
|
|
156
|
-
expect(preventDefaultSpy).toHaveBeenCalled();
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('calls onToggle on Enter key press', () => {
|
|
160
|
-
const onToggle = jest.fn();
|
|
161
|
-
const { getByText } = render(
|
|
162
|
-
<RawMarkButton onToggle={onToggle} mark="underline" label="Underline">
|
|
163
|
-
U
|
|
164
|
-
</RawMarkButton>,
|
|
165
|
-
);
|
|
166
|
-
fireEvent.keyDown(getByText('U'), { key: 'Enter' });
|
|
167
|
-
expect(onToggle).toHaveBeenCalledWith('underline');
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('calls onToggle on Space key press', () => {
|
|
171
|
-
const onToggle = jest.fn();
|
|
172
|
-
const { getByText } = render(
|
|
173
|
-
<RawMarkButton onToggle={onToggle} mark="strike" label="Strike">
|
|
174
|
-
S
|
|
175
|
-
</RawMarkButton>,
|
|
176
|
-
);
|
|
177
|
-
fireEvent.keyDown(getByText('S'), { key: ' ' });
|
|
178
|
-
expect(onToggle).toHaveBeenCalledWith('strike');
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('does not call onToggle on other key press', () => {
|
|
182
|
-
const onToggle = jest.fn();
|
|
183
|
-
const { getByText } = render(
|
|
184
|
-
<RawMarkButton onToggle={onToggle} mark="bold" label="Bold">
|
|
185
|
-
B
|
|
186
|
-
</RawMarkButton>,
|
|
187
|
-
);
|
|
188
|
-
fireEvent.keyDown(getByText('B'), { key: 'a' });
|
|
189
|
-
expect(onToggle).not.toHaveBeenCalled();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('applies active style when active is true', () => {
|
|
193
|
-
const { getByText } = render(
|
|
194
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold" active={true}>
|
|
195
|
-
B
|
|
196
|
-
</RawMarkButton>,
|
|
197
|
-
);
|
|
198
|
-
const button = getByText('B');
|
|
199
|
-
expect(button).toHaveStyle({ color: 'black' });
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('has aria-label from label prop', () => {
|
|
203
|
-
const { getByLabelText } = render(
|
|
204
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Toggle Bold">
|
|
205
|
-
B
|
|
206
|
-
</RawMarkButton>,
|
|
207
|
-
);
|
|
208
|
-
expect(getByLabelText('Toggle Bold')).toBeInTheDocument();
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('has aria-pressed attribute', () => {
|
|
212
|
-
const { getByText } = render(
|
|
213
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold" active={true}>
|
|
214
|
-
B
|
|
215
|
-
</RawMarkButton>,
|
|
216
|
-
);
|
|
217
|
-
expect(getByText('B')).toHaveAttribute('aria-pressed', 'true');
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('is focusable with tabIndex', () => {
|
|
221
|
-
const { getByText } = render(
|
|
222
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold">
|
|
223
|
-
B
|
|
224
|
-
</RawMarkButton>,
|
|
225
|
-
);
|
|
226
|
-
expect(getByText('B')).toHaveAttribute('tabIndex', '0');
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
describe('MarkButton', () => {
|
|
231
|
-
it('is the same as RawMarkButton', () => {
|
|
232
|
-
expect(MarkButton).toBe(RawMarkButton);
|
|
233
|
-
});
|
|
234
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import DragDropChoice from '../choice';
|
|
4
|
-
|
|
5
|
-
// Mock @dnd-kit hooks to avoid DndContext requirement
|
|
6
|
-
jest.mock('@dnd-kit/core', () => ({
|
|
7
|
-
useDraggable: jest.fn(() => ({
|
|
8
|
-
attributes: {},
|
|
9
|
-
listeners: {},
|
|
10
|
-
setNodeRef: jest.fn(),
|
|
11
|
-
isDragging: false,
|
|
12
|
-
})),
|
|
13
|
-
useDroppable: jest.fn(() => ({
|
|
14
|
-
setNodeRef: jest.fn(),
|
|
15
|
-
isOver: false,
|
|
16
|
-
active: null,
|
|
17
|
-
})),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
jest.mock('@pie-lib/math-rendering', () => ({
|
|
21
|
-
renderMath: jest.fn(),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
// Collect the CSS rules emotion/MUI injected into the document (jsdom uses insertRule).
|
|
25
|
-
const collectEmotionRules = () => {
|
|
26
|
-
const rules = [];
|
|
27
|
-
for (const sheet of Array.from(document.styleSheets)) {
|
|
28
|
-
try {
|
|
29
|
-
for (const rule of Array.from(sheet.cssRules)) {
|
|
30
|
-
rules.push(rule.cssText);
|
|
31
|
-
}
|
|
32
|
-
} catch (e) {
|
|
33
|
-
/* inaccessible stylesheet */
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return rules;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
describe('DragInTheBlank choice', () => {
|
|
40
|
-
const defaultProps = {
|
|
41
|
-
value: { id: '1', value: '<math>1/2</math>' },
|
|
42
|
-
disabled: false,
|
|
43
|
-
instanceId: 'test-instance',
|
|
44
|
-
n: { index: 0 },
|
|
45
|
-
onChange: jest.fn(),
|
|
46
|
-
removeResponse: jest.fn(),
|
|
47
|
-
duplicates: false,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
it('renders without crashing', () => {
|
|
51
|
-
const { container } = render(<DragDropChoice {...defaultProps} />);
|
|
52
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('fraction math styling', () => {
|
|
56
|
-
it('enlarges numerator/denominator digits adjacent to a fraction to 120%', () => {
|
|
57
|
-
render(<DragDropChoice {...defaultProps} />);
|
|
58
|
-
const rule = collectEmotionRules().find((r) => r.includes('mjx-mn') && r.includes('mjx-mfrac'));
|
|
59
|
-
expect(rule).toBeDefined();
|
|
60
|
-
expect(rule).toMatch(/mjx-mn:has\(~\s*mjx-mfrac\)/);
|
|
61
|
-
expect(rule).toMatch(/mjx-mfrac\s*~\s*mjx-mn/);
|
|
62
|
-
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('keeps the existing mjx-frac 120% rule', () => {
|
|
66
|
-
render(<DragDropChoice {...defaultProps} />);
|
|
67
|
-
const rule = collectEmotionRules().find((r) => /(^|[^-])mjx-frac/.test(r) && !r.includes('mjx-mfrac'));
|
|
68
|
-
expect(rule).toBeDefined();
|
|
69
|
-
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import MathTemplated from '../MathTemplated';
|
|
4
|
-
|
|
5
|
-
// Mock the dependencies
|
|
6
|
-
jest.mock('@tiptap/react', () => ({
|
|
7
|
-
NodeViewWrapper: ({ children, ...props }) => (
|
|
8
|
-
<div data-testid="node-view-wrapper" {...props}>
|
|
9
|
-
{children}
|
|
10
|
-
</div>
|
|
11
|
-
),
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
jest.mock('@pie-lib/math-input-mathlive', () => ({
|
|
15
|
-
mq: {
|
|
16
|
-
Static: ({ latex }) => (
|
|
17
|
-
<div data-testid="mq-static" data-latex={latex}>
|
|
18
|
-
{latex}
|
|
19
|
-
</div>
|
|
20
|
-
),
|
|
21
|
-
},
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
describe('MathTemplated', () => {
|
|
25
|
-
const defaultProps = {
|
|
26
|
-
node: {
|
|
27
|
-
attrs: {
|
|
28
|
-
value: 'x^2 + y^2 = r^2',
|
|
29
|
-
index: 0,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
options: {},
|
|
33
|
-
selected: false,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
it('renders without crashing', () => {
|
|
37
|
-
const { container } = render(<MathTemplated {...defaultProps} />);
|
|
38
|
-
expect(container).toBeInTheDocument();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('renders NodeViewWrapper with correct className', () => {
|
|
42
|
-
const { getByTestId } = render(<MathTemplated {...defaultProps} />);
|
|
43
|
-
const wrapper = getByTestId('node-view-wrapper');
|
|
44
|
-
expect(wrapper).toHaveClass('math-templated');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('displays correct response key for index 0', () => {
|
|
48
|
-
const { getByText } = render(<MathTemplated {...defaultProps} />);
|
|
49
|
-
expect(getByText('R 1')).toBeInTheDocument();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('displays correct response key for index 1', () => {
|
|
53
|
-
const props = {
|
|
54
|
-
...defaultProps,
|
|
55
|
-
node: {
|
|
56
|
-
attrs: {
|
|
57
|
-
value: 'a + b',
|
|
58
|
-
index: 1,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
const { getByText } = render(<MathTemplated {...props} />);
|
|
63
|
-
expect(getByText('R 2')).toBeInTheDocument();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('displays correct response key for index 5', () => {
|
|
67
|
-
const props = {
|
|
68
|
-
...defaultProps,
|
|
69
|
-
node: {
|
|
70
|
-
attrs: {
|
|
71
|
-
value: 'c = d',
|
|
72
|
-
index: 5,
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
const { getByText } = render(<MathTemplated {...props} />);
|
|
77
|
-
expect(getByText('R 6')).toBeInTheDocument();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('renders LaTeX value correctly', () => {
|
|
81
|
-
const { getByTestId } = render(<MathTemplated {...defaultProps} />);
|
|
82
|
-
const mqStatic = getByTestId('mq-static');
|
|
83
|
-
expect(mqStatic).toHaveAttribute('data-latex', 'x^2 + y^2 = r^2');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('renders different LaTeX value', () => {
|
|
87
|
-
const props = {
|
|
88
|
-
...defaultProps,
|
|
89
|
-
node: {
|
|
90
|
-
attrs: {
|
|
91
|
-
value: '\\frac{a}{b}',
|
|
92
|
-
index: 2,
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
const { getByTestId } = render(<MathTemplated {...props} />);
|
|
97
|
-
const mqStatic = getByTestId('mq-static');
|
|
98
|
-
expect(mqStatic).toHaveAttribute('data-latex', '\\frac{a}{b}');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('passes selected prop to NodeViewWrapper', () => {
|
|
102
|
-
const props = {
|
|
103
|
-
...defaultProps,
|
|
104
|
-
selected: true,
|
|
105
|
-
};
|
|
106
|
-
const { getByTestId } = render(<MathTemplated {...props} />);
|
|
107
|
-
const wrapper = getByTestId('node-view-wrapper');
|
|
108
|
-
expect(wrapper).toHaveAttribute('data-selected', 'true');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('passes false selected prop to NodeViewWrapper', () => {
|
|
112
|
-
const { getByTestId } = render(<MathTemplated {...defaultProps} />);
|
|
113
|
-
const wrapper = getByTestId('node-view-wrapper');
|
|
114
|
-
expect(wrapper).toHaveAttribute('data-selected', 'false');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('applies correct inline styles to NodeViewWrapper', () => {
|
|
118
|
-
const { getByTestId } = render(<MathTemplated {...defaultProps} />);
|
|
119
|
-
const wrapper = getByTestId('node-view-wrapper');
|
|
120
|
-
expect(wrapper).toHaveStyle({
|
|
121
|
-
display: 'inline-flex',
|
|
122
|
-
minHeight: '36px',
|
|
123
|
-
minWidth: '50px',
|
|
124
|
-
cursor: 'pointer',
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('handles string index correctly', () => {
|
|
129
|
-
const props = {
|
|
130
|
-
...defaultProps,
|
|
131
|
-
node: {
|
|
132
|
-
attrs: {
|
|
133
|
-
value: 'test',
|
|
134
|
-
index: '3',
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
const { getByText } = render(<MathTemplated {...props} />);
|
|
139
|
-
expect(getByText('R 4')).toBeInTheDocument();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('handles empty value', () => {
|
|
143
|
-
const props = {
|
|
144
|
-
...defaultProps,
|
|
145
|
-
node: {
|
|
146
|
-
attrs: {
|
|
147
|
-
value: '',
|
|
148
|
-
index: 0,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
const { getByTestId } = render(<MathTemplated {...props} />);
|
|
153
|
-
const mqStatic = getByTestId('mq-static');
|
|
154
|
-
expect(mqStatic).toHaveAttribute('data-latex', '');
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('renders all styled components', () => {
|
|
158
|
-
const { container, getByText } = render(<MathTemplated {...defaultProps} />);
|
|
159
|
-
|
|
160
|
-
// Check for response box
|
|
161
|
-
expect(getByText('R 1')).toBeInTheDocument();
|
|
162
|
-
|
|
163
|
-
// Check for math block with LaTeX
|
|
164
|
-
const mqStatic = container.querySelector('[data-testid="mq-static"]');
|
|
165
|
-
expect(mqStatic).toBeInTheDocument();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('handles zero index', () => {
|
|
169
|
-
const props = {
|
|
170
|
-
...defaultProps,
|
|
171
|
-
node: {
|
|
172
|
-
attrs: {
|
|
173
|
-
value: 'x = 0',
|
|
174
|
-
index: 0,
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
const { getByText } = render(<MathTemplated {...props} />);
|
|
179
|
-
expect(getByText('R 1')).toBeInTheDocument();
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('handles large index values', () => {
|
|
183
|
-
const props = {
|
|
184
|
-
...defaultProps,
|
|
185
|
-
node: {
|
|
186
|
-
attrs: {
|
|
187
|
-
value: 'x = 100',
|
|
188
|
-
index: 99,
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
const { getByText } = render(<MathTemplated {...props} />);
|
|
193
|
-
expect(getByText('R 100')).toBeInTheDocument();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('renders with complex LaTeX expression', () => {
|
|
197
|
-
const props = {
|
|
198
|
-
...defaultProps,
|
|
199
|
-
node: {
|
|
200
|
-
attrs: {
|
|
201
|
-
value: '\\sqrt{x^2 + y^2}',
|
|
202
|
-
index: 0,
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
const { getByTestId } = render(<MathTemplated {...props} />);
|
|
207
|
-
const mqStatic = getByTestId('mq-static');
|
|
208
|
-
expect(mqStatic).toHaveAttribute('data-latex', '\\sqrt{x^2 + y^2}');
|
|
209
|
-
});
|
|
210
|
-
});
|