@pie-lib/editable-html-tip-tap 2.1.19 → 2.1.20-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 -130
- package/lib/components/EditableHtml.js +0 -56
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/MenuBar.js +12 -81
- package/lib/components/MenuBar.js.map +1 -1
- package/lib/components/TiptapContainer.js +2 -2
- package/lib/components/TiptapContainer.js.map +1 -1
- package/lib/components/common/toolbar-buttons.js +5 -6
- package/lib/components/common/toolbar-buttons.js.map +1 -1
- package/lib/components/icons/TableIcons.js +1 -3
- package/lib/components/icons/TableIcons.js.map +1 -1
- package/lib/components/icons/TextAlign.js +5 -14
- package/lib/components/icons/TextAlign.js.map +1 -1
- package/lib/components/respArea/MathTemplated.js +8 -14
- package/lib/components/respArea/MathTemplated.js.map +1 -1
- package/lib/extensions/math.js +37 -19
- package/lib/extensions/math.js.map +1 -1
- package/lib/styles/editorContainerStyles.js +2 -2
- package/lib/styles/editorContainerStyles.js.map +1 -1
- package/package.json +9 -9
- package/src/components/EditableHtml.jsx +0 -52
- package/src/components/MenuBar.jsx +9 -91
- package/src/components/TiptapContainer.jsx +2 -2
- package/src/components/common/toolbar-buttons.jsx +4 -6
- package/src/components/icons/TableIcons.jsx +1 -9
- package/src/components/icons/TextAlign.jsx +5 -39
- package/src/components/respArea/MathTemplated.jsx +6 -13
- package/src/extensions/math.js +19 -11
- package/src/styles/editorContainerStyles.js +2 -2
- package/LICENSE.md +0 -5
- package/src/__tests__/EditableHtml.test.jsx +0 -668
- package/src/__tests__/constants.test.js +0 -19
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
- package/src/__tests__/editor-attributes.test.jsx +0 -77
- 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__/spellcheck.test.jsx +0 -63
- 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 -338
- 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 -247
- 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 -898
- 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,82 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import CustomPopper from '../characters/custom-popper';
|
|
4
|
-
|
|
5
|
-
jest.mock('@mui/material/Popper', () => ({
|
|
6
|
-
__esModule: true,
|
|
7
|
-
default: ({ children, id, open, ...props }) =>
|
|
8
|
-
open ? (
|
|
9
|
-
<div id={id} data-testid="popper" {...props}>
|
|
10
|
-
{children}
|
|
11
|
-
</div>
|
|
12
|
-
) : null,
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
describe('CustomPopper', () => {
|
|
16
|
-
const mockAnchorEl = document.createElement('div');
|
|
17
|
-
|
|
18
|
-
it('renders without crashing', () => {
|
|
19
|
-
const { container } = render(<CustomPopper anchorEl={mockAnchorEl}>Content</CustomPopper>);
|
|
20
|
-
expect(container).toBeInTheDocument();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('renders children', () => {
|
|
24
|
-
const { getByText } = render(<CustomPopper anchorEl={mockAnchorEl}>Test Content</CustomPopper>);
|
|
25
|
-
expect(getByText('Test Content')).toBeInTheDocument();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('is always open', () => {
|
|
29
|
-
const { getByTestId } = render(<CustomPopper anchorEl={mockAnchorEl}>Content</CustomPopper>);
|
|
30
|
-
expect(getByTestId('popper')).toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('has correct id', () => {
|
|
34
|
-
const { container } = render(<CustomPopper anchorEl={mockAnchorEl}>Content</CustomPopper>);
|
|
35
|
-
const popper = container.querySelector('#mouse-over-popover');
|
|
36
|
-
expect(popper).toBeInTheDocument();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('applies correct styling to typography', () => {
|
|
40
|
-
const { getByText } = render(<CustomPopper anchorEl={mockAnchorEl}>Content</CustomPopper>);
|
|
41
|
-
const typography = getByText('Content');
|
|
42
|
-
expect(typography).toHaveStyle({ fontSize: '50px', textAlign: 'center' });
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('passes additional props to Popper', () => {
|
|
46
|
-
const { container } = render(
|
|
47
|
-
<CustomPopper anchorEl={mockAnchorEl} onClose={jest.fn()}>
|
|
48
|
-
Content
|
|
49
|
-
</CustomPopper>,
|
|
50
|
-
);
|
|
51
|
-
expect(container).toBeInTheDocument();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('renders multiple children', () => {
|
|
55
|
-
const { getByText } = render(
|
|
56
|
-
<CustomPopper anchorEl={mockAnchorEl}>
|
|
57
|
-
<div>First</div>
|
|
58
|
-
<div>Second</div>
|
|
59
|
-
</CustomPopper>,
|
|
60
|
-
);
|
|
61
|
-
expect(getByText('First')).toBeInTheDocument();
|
|
62
|
-
expect(getByText('Second')).toBeInTheDocument();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('has pointer-events disabled', () => {
|
|
66
|
-
const { container } = render(<CustomPopper anchorEl={mockAnchorEl}>Content</CustomPopper>);
|
|
67
|
-
// Styling is applied via styled component, just verify it rendered
|
|
68
|
-
expect(container).toBeInTheDocument();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('has high z-index', () => {
|
|
72
|
-
const { container } = render(<CustomPopper anchorEl={mockAnchorEl}>Content</CustomPopper>);
|
|
73
|
-
// Styling is applied via styled component, just verify it rendered
|
|
74
|
-
expect(container).toBeInTheDocument();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('has correct background color', () => {
|
|
78
|
-
const { container } = render(<CustomPopper anchorEl={mockAnchorEl}>Content</CustomPopper>);
|
|
79
|
-
// Styling is applied via styled component, just verify it rendered
|
|
80
|
-
expect(container).toBeInTheDocument();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
3
|
-
import { DoneButton, RawDoneButton } from '../common/done-button';
|
|
4
|
-
|
|
5
|
-
describe('RawDoneButton', () => {
|
|
6
|
-
it('renders without crashing', () => {
|
|
7
|
-
const { container } = render(<RawDoneButton onClick={jest.fn()} />);
|
|
8
|
-
expect(container).toBeInTheDocument();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('renders with Check icon', () => {
|
|
12
|
-
const { container } = render(<RawDoneButton onClick={jest.fn()} />);
|
|
13
|
-
const button = container.querySelector('button');
|
|
14
|
-
expect(button).toBeInTheDocument();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('calls onClick when clicked', () => {
|
|
18
|
-
const onClick = jest.fn();
|
|
19
|
-
const { container } = render(<RawDoneButton onClick={onClick} />);
|
|
20
|
-
const button = container.querySelector('button');
|
|
21
|
-
fireEvent.click(button);
|
|
22
|
-
expect(onClick).toHaveBeenCalled();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('has aria-label "Done"', () => {
|
|
26
|
-
const { container } = render(<RawDoneButton onClick={jest.fn()} />);
|
|
27
|
-
const button = container.querySelector('button');
|
|
28
|
-
expect(button).toHaveAttribute('aria-label', 'Done');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('accepts doneButtonRef prop', () => {
|
|
32
|
-
const doneButtonRef = jest.fn();
|
|
33
|
-
const { container } = render(<RawDoneButton onClick={jest.fn()} doneButtonRef={doneButtonRef} />);
|
|
34
|
-
// doneButtonRef is passed as buttonRef to IconButton, just verify it's accepted
|
|
35
|
-
expect(container).toBeInTheDocument();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('applies correct styling', () => {
|
|
39
|
-
const { container } = render(<RawDoneButton onClick={jest.fn()} />);
|
|
40
|
-
const button = container.querySelector('button');
|
|
41
|
-
expect(button).toHaveClass('MuiIconButton-root');
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('DoneButton', () => {
|
|
46
|
-
it('is the same as RawDoneButton', () => {
|
|
47
|
-
expect(DoneButton).toBe(RawDoneButton);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('renders correctly', () => {
|
|
51
|
-
const { container } = render(<DoneButton onClick={jest.fn()} />);
|
|
52
|
-
expect(container.querySelector('button')).toBeInTheDocument();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
3
|
-
import { color } from '@pie-lib/render-ui';
|
|
4
|
-
import { Button, MarkButton, RawButton, RawMarkButton } from '../common/toolbar-buttons';
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* jsdom does not resolve custom properties, so toHaveStyle() normalises `var(--x, y)`
|
|
8
|
-
* to the empty string and cannot compare it. These buttons now take their ink from
|
|
9
|
-
* `--pie-text`, so assert against the rule emotion emitted for the element's class.
|
|
10
|
-
*/
|
|
11
|
-
const declaredColor = (el) =>
|
|
12
|
-
Array.from(document.querySelectorAll('style'))
|
|
13
|
-
.flatMap((tag) => Array.from(tag.sheet?.cssRules || []))
|
|
14
|
-
.filter((rule) => Array.from(el.classList).some((c) => rule.selectorText?.includes(`.${c}`)))
|
|
15
|
-
.map((rule) => rule.style?.color)
|
|
16
|
-
.find(Boolean);
|
|
17
|
-
|
|
18
|
-
describe('RawButton', () => {
|
|
19
|
-
it('renders without crashing', () => {
|
|
20
|
-
const { container } = render(<RawButton onClick={jest.fn()}>Click me</RawButton>);
|
|
21
|
-
expect(container).toBeInTheDocument();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('renders children', () => {
|
|
25
|
-
const { getByText } = render(<RawButton onClick={jest.fn()}>Test Button</RawButton>);
|
|
26
|
-
expect(getByText('Test Button')).toBeInTheDocument();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('calls onClick on mouse down', () => {
|
|
30
|
-
const onClick = jest.fn();
|
|
31
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
32
|
-
fireEvent.mouseDown(getByText('Click'));
|
|
33
|
-
expect(onClick).toHaveBeenCalled();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('prevents default on mouse down', () => {
|
|
37
|
-
const onClick = jest.fn();
|
|
38
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
39
|
-
const button = getByText('Click');
|
|
40
|
-
const event = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
|
|
41
|
-
const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
|
|
42
|
-
button.dispatchEvent(event);
|
|
43
|
-
expect(preventDefaultSpy).toHaveBeenCalled();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('calls onClick on Enter key press', () => {
|
|
47
|
-
const onClick = jest.fn();
|
|
48
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
49
|
-
fireEvent.keyDown(getByText('Click'), { key: 'Enter' });
|
|
50
|
-
expect(onClick).toHaveBeenCalled();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('calls onClick on Space key press', () => {
|
|
54
|
-
const onClick = jest.fn();
|
|
55
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
56
|
-
fireEvent.keyDown(getByText('Click'), { key: ' ' });
|
|
57
|
-
expect(onClick).toHaveBeenCalled();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('does not call onClick on other key press', () => {
|
|
61
|
-
const onClick = jest.fn();
|
|
62
|
-
const { getByText } = render(<RawButton onClick={onClick}>Click</RawButton>);
|
|
63
|
-
fireEvent.keyDown(getByText('Click'), { key: 'a' });
|
|
64
|
-
expect(onClick).not.toHaveBeenCalled();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('applies active style when active is true', () => {
|
|
68
|
-
const { getByText } = render(
|
|
69
|
-
<RawButton onClick={jest.fn()} active={true}>
|
|
70
|
-
Active
|
|
71
|
-
</RawButton>,
|
|
72
|
-
);
|
|
73
|
-
const button = getByText('Active');
|
|
74
|
-
expect(declaredColor(button)).toBe(color.text());
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('applies disabled style when disabled is true', () => {
|
|
78
|
-
const { getByText } = render(
|
|
79
|
-
<RawButton onClick={jest.fn()} disabled={true}>
|
|
80
|
-
Disabled
|
|
81
|
-
</RawButton>,
|
|
82
|
-
);
|
|
83
|
-
const button = getByText('Disabled');
|
|
84
|
-
expect(button).toHaveStyle({ cursor: 'not-allowed' });
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('applies extraStyles when provided', () => {
|
|
88
|
-
const extraStyles = { backgroundColor: 'red' };
|
|
89
|
-
const { getByText } = render(
|
|
90
|
-
<RawButton onClick={jest.fn()} extraStyles={extraStyles}>
|
|
91
|
-
Styled
|
|
92
|
-
</RawButton>,
|
|
93
|
-
);
|
|
94
|
-
const button = getByText('Styled');
|
|
95
|
-
expect(button).toHaveStyle({ backgroundColor: 'red' });
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('has aria-label when provided', () => {
|
|
99
|
-
const { getByLabelText } = render(
|
|
100
|
-
<RawButton onClick={jest.fn()} ariaLabel="Test Button">
|
|
101
|
-
Button
|
|
102
|
-
</RawButton>,
|
|
103
|
-
);
|
|
104
|
-
expect(getByLabelText('Test Button')).toBeInTheDocument();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('has aria-pressed attribute', () => {
|
|
108
|
-
const { getByText } = render(
|
|
109
|
-
<RawButton onClick={jest.fn()} active={true}>
|
|
110
|
-
Button
|
|
111
|
-
</RawButton>,
|
|
112
|
-
);
|
|
113
|
-
expect(getByText('Button')).toHaveAttribute('aria-pressed', 'true');
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('is focusable with tabIndex', () => {
|
|
117
|
-
const { getByText } = render(<RawButton onClick={jest.fn()}>Button</RawButton>);
|
|
118
|
-
expect(getByText('Button')).toHaveAttribute('tabIndex', '0');
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('Button', () => {
|
|
123
|
-
it('is the same as RawButton', () => {
|
|
124
|
-
expect(Button).toBe(RawButton);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe('RawMarkButton', () => {
|
|
129
|
-
it('renders without crashing', () => {
|
|
130
|
-
const { container } = render(
|
|
131
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold">
|
|
132
|
-
B
|
|
133
|
-
</RawMarkButton>,
|
|
134
|
-
);
|
|
135
|
-
expect(container).toBeInTheDocument();
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('renders children', () => {
|
|
139
|
-
const { getByText } = render(
|
|
140
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold">
|
|
141
|
-
Bold
|
|
142
|
-
</RawMarkButton>,
|
|
143
|
-
);
|
|
144
|
-
expect(getByText('Bold')).toBeInTheDocument();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('calls onToggle with mark on mouse down', () => {
|
|
148
|
-
const onToggle = jest.fn();
|
|
149
|
-
const { getByText } = render(
|
|
150
|
-
<RawMarkButton onToggle={onToggle} mark="italic" label="Italic">
|
|
151
|
-
I
|
|
152
|
-
</RawMarkButton>,
|
|
153
|
-
);
|
|
154
|
-
fireEvent.mouseDown(getByText('I'));
|
|
155
|
-
expect(onToggle).toHaveBeenCalledWith('italic');
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('prevents default on mouse down', () => {
|
|
159
|
-
const onToggle = jest.fn();
|
|
160
|
-
const { getByText } = render(
|
|
161
|
-
<RawMarkButton onToggle={onToggle} mark="bold" label="Bold">
|
|
162
|
-
B
|
|
163
|
-
</RawMarkButton>,
|
|
164
|
-
);
|
|
165
|
-
const button = getByText('B');
|
|
166
|
-
const event = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
|
|
167
|
-
const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
|
|
168
|
-
button.dispatchEvent(event);
|
|
169
|
-
expect(preventDefaultSpy).toHaveBeenCalled();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('calls onToggle on Enter key press', () => {
|
|
173
|
-
const onToggle = jest.fn();
|
|
174
|
-
const { getByText } = render(
|
|
175
|
-
<RawMarkButton onToggle={onToggle} mark="underline" label="Underline">
|
|
176
|
-
U
|
|
177
|
-
</RawMarkButton>,
|
|
178
|
-
);
|
|
179
|
-
fireEvent.keyDown(getByText('U'), { key: 'Enter' });
|
|
180
|
-
expect(onToggle).toHaveBeenCalledWith('underline');
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('calls onToggle on Space key press', () => {
|
|
184
|
-
const onToggle = jest.fn();
|
|
185
|
-
const { getByText } = render(
|
|
186
|
-
<RawMarkButton onToggle={onToggle} mark="strike" label="Strike">
|
|
187
|
-
S
|
|
188
|
-
</RawMarkButton>,
|
|
189
|
-
);
|
|
190
|
-
fireEvent.keyDown(getByText('S'), { key: ' ' });
|
|
191
|
-
expect(onToggle).toHaveBeenCalledWith('strike');
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('does not call onToggle on other key press', () => {
|
|
195
|
-
const onToggle = jest.fn();
|
|
196
|
-
const { getByText } = render(
|
|
197
|
-
<RawMarkButton onToggle={onToggle} mark="bold" label="Bold">
|
|
198
|
-
B
|
|
199
|
-
</RawMarkButton>,
|
|
200
|
-
);
|
|
201
|
-
fireEvent.keyDown(getByText('B'), { key: 'a' });
|
|
202
|
-
expect(onToggle).not.toHaveBeenCalled();
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('applies active style when active is true', () => {
|
|
206
|
-
const { getByText } = render(
|
|
207
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold" active={true}>
|
|
208
|
-
B
|
|
209
|
-
</RawMarkButton>,
|
|
210
|
-
);
|
|
211
|
-
const button = getByText('B');
|
|
212
|
-
expect(declaredColor(button)).toBe(color.text());
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('has aria-label from label prop', () => {
|
|
216
|
-
const { getByLabelText } = render(
|
|
217
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Toggle Bold">
|
|
218
|
-
B
|
|
219
|
-
</RawMarkButton>,
|
|
220
|
-
);
|
|
221
|
-
expect(getByLabelText('Toggle Bold')).toBeInTheDocument();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('has aria-pressed attribute', () => {
|
|
225
|
-
const { getByText } = render(
|
|
226
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold" active={true}>
|
|
227
|
-
B
|
|
228
|
-
</RawMarkButton>,
|
|
229
|
-
);
|
|
230
|
-
expect(getByText('B')).toHaveAttribute('aria-pressed', 'true');
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('is focusable with tabIndex', () => {
|
|
234
|
-
const { getByText } = render(
|
|
235
|
-
<RawMarkButton onToggle={jest.fn()} mark="bold" label="Bold">
|
|
236
|
-
B
|
|
237
|
-
</RawMarkButton>,
|
|
238
|
-
);
|
|
239
|
-
expect(getByText('B')).toHaveAttribute('tabIndex', '0');
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
describe('MarkButton', () => {
|
|
244
|
-
it('is the same as RawMarkButton', () => {
|
|
245
|
-
expect(MarkButton).toBe(RawMarkButton);
|
|
246
|
-
});
|
|
247
|
-
});
|
|
@@ -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', () => ({
|
|
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
|
-
});
|