@pie-lib/editable-html-tip-tap 1.1.0-next.6059 → 1.1.1-next.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 +44 -0
- package/lib/__tests__/EditableHtml.test.js +374 -0
- package/lib/__tests__/constants.test.js +28 -0
- package/lib/__tests__/extensions.test.js +214 -0
- package/lib/__tests__/index.test.js +246 -0
- package/lib/__tests__/size-utils.test.js +57 -0
- package/lib/__tests__/theme.test.js +17 -0
- package/lib/components/CharacterPicker.js +18 -0
- package/lib/components/CharacterPicker.js.map +1 -1
- package/lib/components/EditableHtml.js +22 -5
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/MenuBar.js +17 -0
- package/lib/components/MenuBar.js.map +1 -1
- package/lib/components/TiptapContainer.js +16 -0
- package/lib/components/TiptapContainer.js.map +1 -1
- package/lib/components/__tests__/AltDialog.test.js +201 -0
- package/lib/components/__tests__/CharacterPicker.test.js +313 -0
- package/lib/components/__tests__/CssIcon.test.js +58 -0
- package/lib/components/__tests__/DragInTheBlank.test.js +309 -0
- package/lib/components/__tests__/ExplicitConstructedResponse.test.js +263 -0
- package/lib/components/__tests__/ImageToolbar.test.js +195 -0
- package/lib/components/__tests__/InlineDropdown.test.js +297 -0
- package/lib/components/__tests__/InsertImageHandler.test.js +162 -0
- package/lib/components/__tests__/MediaDialog.test.js +435 -0
- package/lib/components/__tests__/MediaToolbar.test.js +126 -0
- package/lib/components/__tests__/MediaWrapper.test.js +96 -0
- package/lib/components/__tests__/MenuBar.test.js +459 -0
- package/lib/components/__tests__/RespArea.test.js +171 -0
- package/lib/components/__tests__/TableIcons.test.js +153 -0
- package/lib/components/__tests__/TextAlign.test.js +216 -0
- package/lib/components/__tests__/TiptapContainer.test.js +196 -0
- package/lib/components/__tests__/characterUtils.test.js +189 -0
- package/lib/components/__tests__/choice.test.js +213 -0
- package/lib/components/__tests__/custom-popper.test.js +108 -0
- package/lib/components/__tests__/done-button.test.js +72 -0
- package/lib/components/__tests__/toolbar-buttons.test.js +277 -0
- package/lib/components/characters/characterUtils.js +2 -0
- package/lib/components/characters/characterUtils.js.map +1 -1
- package/lib/components/characters/custom-popper.js +1 -0
- package/lib/components/characters/custom-popper.js.map +1 -1
- package/lib/components/common/done-button.js +1 -0
- package/lib/components/common/done-button.js.map +1 -1
- package/lib/components/common/toolbar-buttons.js +12 -0
- package/lib/components/common/toolbar-buttons.js.map +1 -1
- package/lib/components/icons/CssIcon.js +1 -0
- package/lib/components/icons/CssIcon.js.map +1 -1
- package/lib/components/icons/RespArea.js +10 -0
- package/lib/components/icons/RespArea.js.map +1 -1
- package/lib/components/icons/TableIcons.js +1 -0
- package/lib/components/icons/TableIcons.js.map +1 -1
- package/lib/components/icons/TextAlign.js +7 -0
- package/lib/components/icons/TextAlign.js.map +1 -1
- package/lib/components/image/AltDialog.js +5 -0
- package/lib/components/image/AltDialog.js.map +1 -1
- package/lib/components/image/ImageToolbar.js +13 -0
- package/lib/components/image/ImageToolbar.js.map +1 -1
- package/lib/components/image/InsertImageHandler.js +10 -0
- package/lib/components/image/InsertImageHandler.js.map +1 -1
- package/lib/components/media/MediaDialog.js +18 -0
- package/lib/components/media/MediaDialog.js.map +1 -1
- package/lib/components/media/MediaToolbar.js +2 -0
- package/lib/components/media/MediaToolbar.js.map +1 -1
- package/lib/components/media/MediaWrapper.js +11 -0
- package/lib/components/media/MediaWrapper.js.map +1 -1
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +10 -0
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -1
- package/lib/components/respArea/DragInTheBlank/choice.js +8 -0
- package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -1
- package/lib/components/respArea/ExplicitConstructedResponse.js +8 -0
- package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -1
- package/lib/components/respArea/InlineDropdown.js +7 -0
- package/lib/components/respArea/InlineDropdown.js.map +1 -1
- package/lib/components/respArea/ToolbarIcon.js +10 -0
- package/lib/components/respArea/ToolbarIcon.js.map +1 -1
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -1
- package/lib/extensions/__tests__/component.test.js +314 -0
- package/lib/extensions/__tests__/css.test.js +218 -0
- package/lib/extensions/__tests__/custom-toolbar-wrapper.test.js +185 -0
- package/lib/extensions/__tests__/extended-table.test.js +114 -0
- package/lib/extensions/__tests__/image.test.js +178 -0
- package/lib/extensions/__tests__/media.test.js +296 -0
- package/lib/extensions/__tests__/responseArea.test.js +332 -0
- package/lib/extensions/component.js +22 -2
- package/lib/extensions/css.js +11 -0
- package/lib/extensions/css.js.map +1 -1
- package/lib/extensions/custom-toolbar-wrapper.js +15 -0
- package/lib/extensions/custom-toolbar-wrapper.js.map +1 -1
- package/lib/extensions/extended-table.js +4 -0
- package/lib/extensions/extended-table.js.map +1 -1
- package/lib/extensions/image-component.js +314 -0
- package/lib/extensions/image-component.js.map +1 -0
- package/lib/extensions/image.js +13 -2
- package/lib/extensions/image.js.map +1 -1
- package/lib/extensions/index.js +12 -2
- package/lib/extensions/index.js.map +1 -1
- package/lib/extensions/math.js +16 -0
- package/lib/extensions/math.js.map +1 -1
- package/lib/extensions/media.js +15 -0
- package/lib/extensions/media.js.map +1 -1
- package/lib/extensions/responseArea.js +22 -0
- package/lib/extensions/responseArea.js.map +1 -1
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -1
- package/lib/styles/editorContainerStyles.js +1 -0
- package/lib/styles/editorContainerStyles.js.map +1 -1
- package/lib/theme.js +1 -0
- package/lib/theme.js.map +1 -1
- package/lib/utils/size.js +6 -0
- package/lib/utils/size.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/EditableHtml.test.jsx +266 -0
- package/src/__tests__/constants.test.js +20 -0
- package/src/__tests__/extensions.test.js +208 -0
- package/src/__tests__/index.test.jsx +146 -0
- package/src/__tests__/size-utils.test.js +64 -0
- package/src/__tests__/theme.test.js +17 -0
- package/src/components/EditableHtml.jsx +8 -6
- package/src/components/__tests__/AltDialog.test.jsx +147 -0
- package/src/components/__tests__/CharacterPicker.test.jsx +195 -0
- package/src/components/__tests__/CssIcon.test.jsx +46 -0
- package/src/components/__tests__/DragInTheBlank.test.jsx +255 -0
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +161 -0
- package/src/components/__tests__/ImageToolbar.test.jsx +128 -0
- package/src/components/__tests__/InlineDropdown.test.jsx +187 -0
- package/src/components/__tests__/InsertImageHandler.test.js +154 -0
- package/src/components/__tests__/MediaDialog.test.jsx +293 -0
- package/src/components/__tests__/MediaToolbar.test.jsx +74 -0
- package/src/components/__tests__/MediaWrapper.test.jsx +81 -0
- package/src/components/__tests__/MenuBar.test.jsx +217 -0
- package/src/components/__tests__/RespArea.test.jsx +122 -0
- package/src/components/__tests__/TableIcons.test.jsx +149 -0
- package/src/components/__tests__/TextAlign.test.jsx +167 -0
- package/src/components/__tests__/TiptapContainer.test.jsx +138 -0
- package/src/components/__tests__/characterUtils.test.js +166 -0
- package/src/components/__tests__/choice.test.jsx +171 -0
- package/src/components/__tests__/custom-popper.test.jsx +82 -0
- package/src/components/__tests__/done-button.test.jsx +54 -0
- package/src/components/__tests__/toolbar-buttons.test.jsx +234 -0
- package/src/extensions/__tests__/css.test.js +196 -0
- package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +180 -0
- package/src/extensions/__tests__/extended-table.test.js +107 -0
- package/src/extensions/__tests__/image-component.test.jsx +249 -0
- package/src/extensions/__tests__/image.test.js +136 -0
- package/src/extensions/__tests__/media.test.js +270 -0
- package/src/extensions/__tests__/responseArea.test.js +310 -0
- package/src/extensions/{component.jsx → image-component.jsx} +11 -1
- package/src/extensions/image.js +1 -1
- package/src/extensions/index.js +5 -1
- package/LICENSE.md +0 -5
- package/NEXT.CHANGELOG.json +0 -1
- package/lib/extensions/component.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { valueToSize } from '../utils/size';
|
|
2
|
+
|
|
3
|
+
describe('Size Utilities', () => {
|
|
4
|
+
describe('valueToSize', () => {
|
|
5
|
+
it('returns undefined for falsy values', () => {
|
|
6
|
+
expect(valueToSize(null)).toBeUndefined();
|
|
7
|
+
expect(valueToSize(undefined)).toBeUndefined();
|
|
8
|
+
expect(valueToSize('')).toBeUndefined();
|
|
9
|
+
expect(valueToSize(0)).toBeUndefined();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('converts number to px string', () => {
|
|
13
|
+
expect(valueToSize(100)).toBe('100px');
|
|
14
|
+
expect(valueToSize(50)).toBe('50px');
|
|
15
|
+
expect(valueToSize(0)).toBeUndefined();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('returns undefined for percentage strings', () => {
|
|
19
|
+
expect(valueToSize('100%')).toBeUndefined();
|
|
20
|
+
expect(valueToSize('50%')).toBeUndefined();
|
|
21
|
+
expect(valueToSize('0%')).toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('preserves valid CSS unit strings', () => {
|
|
25
|
+
expect(valueToSize('100px')).toBe('100px');
|
|
26
|
+
expect(valueToSize('10vh')).toBe('10vh');
|
|
27
|
+
expect(valueToSize('50vw')).toBe('50vw');
|
|
28
|
+
expect(valueToSize('9ch')).toBe('9ch');
|
|
29
|
+
expect(valueToSize('2em')).toBe('2em');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('preserves calc() expressions', () => {
|
|
33
|
+
expect(valueToSize('calc(10em + 42px)')).toBe('calc(10em + 42px)');
|
|
34
|
+
expect(valueToSize('calc(100% - 20px)')).toBe('calc(100% - 20px)');
|
|
35
|
+
expect(valueToSize('calc(50vh + 10px)')).toBe('calc(50vh + 10px)');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('converts numeric strings to px', () => {
|
|
39
|
+
expect(valueToSize('100')).toBe('100px');
|
|
40
|
+
expect(valueToSize('50')).toBe('50px');
|
|
41
|
+
expect(valueToSize('250')).toBe('250px');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('handles invalid numeric strings', () => {
|
|
45
|
+
const result = valueToSize('invalid');
|
|
46
|
+
expect(isNaN(result)).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('handles edge cases with whitespace', () => {
|
|
50
|
+
const result = valueToSize(' ');
|
|
51
|
+
expect(isNaN(result)).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('handles negative numbers', () => {
|
|
55
|
+
expect(valueToSize(-100)).toBe('-100px');
|
|
56
|
+
expect(valueToSize('-50')).toBe('-50px');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('handles decimal numbers', () => {
|
|
60
|
+
expect(valueToSize(100.5)).toBe('100.5px');
|
|
61
|
+
expect(valueToSize('100.5')).toBe('100px'); // parseInt truncates
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { primary } from '../theme';
|
|
2
|
+
|
|
3
|
+
describe('Theme', () => {
|
|
4
|
+
describe('primary color', () => {
|
|
5
|
+
it('is defined', () => {
|
|
6
|
+
expect(primary).toBeDefined();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('has the correct hex value', () => {
|
|
10
|
+
expect(primary).toBe('#304ffe');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('is a valid hex color', () => {
|
|
14
|
+
expect(primary).toMatch(/^#[0-9A-Fa-f]{6}$/);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -26,7 +26,7 @@ import { CSSMark } from '../extensions/css';
|
|
|
26
26
|
|
|
27
27
|
import EditorContainer from './TiptapContainer';
|
|
28
28
|
import { valueToSize } from '../utils/size';
|
|
29
|
-
import { buildExtensions } from '../extensions';
|
|
29
|
+
import { buildExtensions, PLUGINS_MAP } from '../extensions';
|
|
30
30
|
|
|
31
31
|
const defaultToolbarOpts = {
|
|
32
32
|
position: 'bottom',
|
|
@@ -105,17 +105,20 @@ export const EditableHtml = (props) => {
|
|
|
105
105
|
customPlugins = customPlugins || [];
|
|
106
106
|
|
|
107
107
|
const filteredActivePlugins = (props.activePlugins || DEFAULT_ACTIVE_PLUGINS)?.filter((pluginName) => {
|
|
108
|
-
const
|
|
108
|
+
const nameToUse = PLUGINS_MAP[pluginName] || pluginName;
|
|
109
|
+
const pluginInfo = otherPluginProps[nameToUse] || {};
|
|
109
110
|
|
|
110
111
|
return !pluginInfo || !pluginInfo.disabled;
|
|
111
112
|
});
|
|
112
113
|
|
|
113
114
|
return buildExtensions(filteredActivePlugins, customPlugins, {
|
|
114
115
|
math: {},
|
|
115
|
-
textAlign:
|
|
116
|
+
textAlign: props.textAlign,
|
|
116
117
|
html: {},
|
|
117
118
|
extraCSSRules: props.extraCSSRules || {},
|
|
118
|
-
image: {
|
|
119
|
+
image: {
|
|
120
|
+
...props.imageSupport,
|
|
121
|
+
},
|
|
119
122
|
toolbar: {},
|
|
120
123
|
table: {},
|
|
121
124
|
responseArea: {
|
|
@@ -160,7 +163,7 @@ export const EditableHtml = (props) => {
|
|
|
160
163
|
onDelete:
|
|
161
164
|
props.imageSupport &&
|
|
162
165
|
props.imageSupport.delete &&
|
|
163
|
-
(
|
|
166
|
+
(node => {
|
|
164
167
|
const { src } = node.attrs;
|
|
165
168
|
|
|
166
169
|
props.imageSupport.delete(src, (e) => {
|
|
@@ -172,7 +175,6 @@ export const EditableHtml = (props) => {
|
|
|
172
175
|
|
|
173
176
|
setPendingImages(newState.pendingImages);
|
|
174
177
|
setScheduled(newState.scheduled);
|
|
175
|
-
done();
|
|
176
178
|
});
|
|
177
179
|
}),
|
|
178
180
|
insertImageRequested:
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { AltDialog } from '../image/AltDialog';
|
|
4
|
+
|
|
5
|
+
jest.mock('@mui/material/Dialog', () => ({
|
|
6
|
+
__esModule: true,
|
|
7
|
+
default: ({ children, open, id }) => open && <div id={id}>{children}</div>,
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
jest.mock('@mui/material/DialogContent', () => ({
|
|
11
|
+
__esModule: true,
|
|
12
|
+
default: ({ children }) => <div>{children}</div>,
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock('@mui/material/DialogActions', () => ({
|
|
16
|
+
__esModule: true,
|
|
17
|
+
default: ({ children }) => <div>{children}</div>,
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
jest.mock('@mui/material/Button', () => ({
|
|
21
|
+
__esModule: true,
|
|
22
|
+
default: ({ children, onClick }) => <button onClick={onClick}>{children}</button>,
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
jest.mock('@mui/material/TextField', () => ({
|
|
26
|
+
__esModule: true,
|
|
27
|
+
default: ({ value, onChange, placeholder, helperText, FormHelperTextProps, multiline }) => (
|
|
28
|
+
<div className="MuiTextField-root">
|
|
29
|
+
<textarea value={value || ''} onChange={onChange} placeholder={placeholder} data-multiline={multiline} />
|
|
30
|
+
{helperText && <div style={FormHelperTextProps?.style}>{helperText}</div>}
|
|
31
|
+
</div>
|
|
32
|
+
),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
jest.mock('@mui/icons-material/ArrowBackIos', () => ({
|
|
36
|
+
__esModule: true,
|
|
37
|
+
default: () => <svg data-testid="arrow-back-icon" />,
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
describe('AltDialog', () => {
|
|
41
|
+
const defaultProps = {
|
|
42
|
+
onDone: jest.fn(),
|
|
43
|
+
alt: 'Initial alt text',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
jest.clearAllMocks();
|
|
48
|
+
document.body.innerHTML = '';
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('renders without crashing', () => {
|
|
52
|
+
const { container } = render(<AltDialog {...defaultProps} />);
|
|
53
|
+
expect(container).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('renders with initial alt text', () => {
|
|
57
|
+
const { container } = render(<AltDialog {...defaultProps} />);
|
|
58
|
+
const textarea = container.querySelector('textarea');
|
|
59
|
+
expect(textarea.value).toBe('Initial alt text');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders placeholder text', () => {
|
|
63
|
+
const { getByPlaceholderText } = render(<AltDialog {...defaultProps} alt="" />);
|
|
64
|
+
expect(getByPlaceholderText('Enter an Alt Text description of this image')).toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('renders helper text', () => {
|
|
68
|
+
const { getByText } = render(<AltDialog {...defaultProps} />);
|
|
69
|
+
expect(
|
|
70
|
+
getByText(
|
|
71
|
+
'Users with visual limitations rely on Alt Text, since screen readers cannot otherwise describe the contents of an image.',
|
|
72
|
+
),
|
|
73
|
+
).toBeInTheDocument();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('renders Done button', () => {
|
|
77
|
+
const { getByText } = render(<AltDialog {...defaultProps} />);
|
|
78
|
+
expect(getByText('Done')).toBeInTheDocument();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('renders ArrowBackIos icon', () => {
|
|
82
|
+
const { getByTestId } = render(<AltDialog {...defaultProps} />);
|
|
83
|
+
expect(getByTestId('arrow-back-icon')).toBeInTheDocument();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('updates value on text field change', () => {
|
|
87
|
+
const { container } = render(<AltDialog {...defaultProps} />);
|
|
88
|
+
const textarea = container.querySelector('textarea');
|
|
89
|
+
fireEvent.change(textarea, { target: { value: 'New alt text' } });
|
|
90
|
+
expect(textarea.value).toBe('New alt text');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('calls onDone with value when Done button is clicked', () => {
|
|
94
|
+
const onDone = jest.fn();
|
|
95
|
+
// Mock document.querySelectorAll to avoid DOM manipulation issues
|
|
96
|
+
const mockQuerySelectorAll = jest.spyOn(document, 'querySelectorAll').mockReturnValue([]);
|
|
97
|
+
|
|
98
|
+
const { getByText, container } = render(<AltDialog {...defaultProps} onDone={onDone} />);
|
|
99
|
+
const textarea = container.querySelector('textarea');
|
|
100
|
+
fireEvent.change(textarea, { target: { value: 'Updated alt text' } });
|
|
101
|
+
fireEvent.click(getByText('Done'));
|
|
102
|
+
expect(onDone).toHaveBeenCalledWith('Updated alt text');
|
|
103
|
+
|
|
104
|
+
mockQuerySelectorAll.mockRestore();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('closes dialog when Done button is clicked', () => {
|
|
108
|
+
// Mock document.querySelectorAll to avoid DOM manipulation issues
|
|
109
|
+
const mockQuerySelectorAll = jest.spyOn(document, 'querySelectorAll').mockReturnValue([]);
|
|
110
|
+
|
|
111
|
+
const { getByText, container } = render(<AltDialog {...defaultProps} />);
|
|
112
|
+
const dialog = container.querySelector('#text-dialog');
|
|
113
|
+
expect(dialog).toBeInTheDocument();
|
|
114
|
+
fireEvent.click(getByText('Done'));
|
|
115
|
+
|
|
116
|
+
mockQuerySelectorAll.mockRestore();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('dialog is open', () => {
|
|
120
|
+
const { container } = render(<AltDialog {...defaultProps} />);
|
|
121
|
+
const dialog = container.querySelector('[id="text-dialog"]');
|
|
122
|
+
expect(dialog).toBeInTheDocument();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('has correct dialog props', () => {
|
|
126
|
+
const { container } = render(<AltDialog {...defaultProps} />);
|
|
127
|
+
const dialog = container.querySelector('[id="text-dialog"]');
|
|
128
|
+
expect(dialog).toBeInTheDocument();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('text field is multiline', () => {
|
|
132
|
+
const { container } = render(<AltDialog {...defaultProps} />);
|
|
133
|
+
const textarea = container.querySelector('textarea');
|
|
134
|
+
expect(textarea.getAttribute('data-multiline')).toBe('true');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('renders without alt text', () => {
|
|
138
|
+
const { getByPlaceholderText } = render(<AltDialog {...defaultProps} alt={undefined} />);
|
|
139
|
+
expect(getByPlaceholderText('Enter an Alt Text description of this image')).toBeInTheDocument();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('handles empty alt text', () => {
|
|
143
|
+
const { container } = render(<AltDialog {...defaultProps} alt="" />);
|
|
144
|
+
const textarea = container.querySelector('textarea');
|
|
145
|
+
expect(textarea.value).toBe('');
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent, waitFor } from '@testing-library/react';
|
|
3
|
+
import { CharacterPicker, CharacterIcon } from '../CharacterPicker';
|
|
4
|
+
|
|
5
|
+
jest.mock('react-dom', () => ({
|
|
6
|
+
...jest.requireActual('react-dom'),
|
|
7
|
+
createPortal: (node) => node,
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
jest.mock('@pie-lib/math-toolbar', () => ({
|
|
11
|
+
PureToolbar: ({ onChange, onDone, additionalKeys }) => (
|
|
12
|
+
<div data-testid="pure-toolbar">
|
|
13
|
+
<button onClick={() => onChange('á')} data-testid="char-button">
|
|
14
|
+
á
|
|
15
|
+
</button>
|
|
16
|
+
<button onClick={onDone} data-testid="done-button">
|
|
17
|
+
Done
|
|
18
|
+
</button>
|
|
19
|
+
</div>
|
|
20
|
+
),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
jest.mock('../characters/custom-popper', () => ({
|
|
24
|
+
__esModule: true,
|
|
25
|
+
default: ({ children, onClose }) => (
|
|
26
|
+
<div data-testid="custom-popper">
|
|
27
|
+
{children}
|
|
28
|
+
<button onClick={onClose} data-testid="close-popper">
|
|
29
|
+
Close
|
|
30
|
+
</button>
|
|
31
|
+
</div>
|
|
32
|
+
),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
describe('CharacterIcon', () => {
|
|
36
|
+
it('renders with letter', () => {
|
|
37
|
+
const { getByText } = render(<CharacterIcon letter="ñ" />);
|
|
38
|
+
expect(getByText('ñ')).toBeInTheDocument();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('renders with correct styling', () => {
|
|
42
|
+
const { container } = render(<CharacterIcon letter="€" />);
|
|
43
|
+
const div = container.firstChild;
|
|
44
|
+
expect(div).toHaveStyle({ fontSize: '24px', lineHeight: '24px' });
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('CharacterPicker', () => {
|
|
49
|
+
const mockEditor = {
|
|
50
|
+
chain: jest.fn(() => ({
|
|
51
|
+
focus: jest.fn(() => ({
|
|
52
|
+
insertContent: jest.fn(() => ({ run: jest.fn() })),
|
|
53
|
+
})),
|
|
54
|
+
})),
|
|
55
|
+
options: {
|
|
56
|
+
element: document.createElement('div'),
|
|
57
|
+
},
|
|
58
|
+
view: {
|
|
59
|
+
coordsAtPos: jest.fn(() => ({ top: 100, left: 50 })),
|
|
60
|
+
dom: document.createElement('div'),
|
|
61
|
+
},
|
|
62
|
+
state: {
|
|
63
|
+
selection: { from: 0 },
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
jest.clearAllMocks();
|
|
69
|
+
// Reset the element to avoid "Cannot redefine property" error
|
|
70
|
+
mockEditor.options.element = document.createElement('div');
|
|
71
|
+
Object.defineProperty(mockEditor.options.element, 'getBoundingClientRect', {
|
|
72
|
+
value: jest.fn(() => ({ top: 0, left: 0, height: 100 })),
|
|
73
|
+
configurable: true,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('returns null when opts has no characters', () => {
|
|
78
|
+
const { container } = render(<CharacterPicker editor={mockEditor} opts={{}} onClose={jest.fn()} />);
|
|
79
|
+
expect(container.firstChild).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('returns null when opts is not provided', () => {
|
|
83
|
+
const { container } = render(<CharacterPicker editor={mockEditor} opts={null} onClose={jest.fn()} />);
|
|
84
|
+
expect(container.firstChild).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('renders character picker with spanish config', () => {
|
|
88
|
+
const opts = {
|
|
89
|
+
language: 'spanish',
|
|
90
|
+
characters: [['á', 'é', 'í']],
|
|
91
|
+
};
|
|
92
|
+
const { getByTestId } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
93
|
+
expect(getByTestId('pure-toolbar')).toBeInTheDocument();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('renders character picker with special config', () => {
|
|
97
|
+
const opts = {
|
|
98
|
+
language: 'special',
|
|
99
|
+
characters: [['€', '£']],
|
|
100
|
+
};
|
|
101
|
+
const { getByTestId } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
102
|
+
expect(getByTestId('pure-toolbar')).toBeInTheDocument();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('handles character insertion', () => {
|
|
106
|
+
const opts = {
|
|
107
|
+
characters: [['á', 'é']],
|
|
108
|
+
};
|
|
109
|
+
const { getByTestId } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
110
|
+
fireEvent.click(getByTestId('char-button'));
|
|
111
|
+
expect(mockEditor.chain).toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('calls onClose when done button is clicked', () => {
|
|
115
|
+
const onClose = jest.fn();
|
|
116
|
+
const opts = {
|
|
117
|
+
characters: [['á', 'é']],
|
|
118
|
+
};
|
|
119
|
+
const { getByTestId } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={onClose} />);
|
|
120
|
+
fireEvent.click(getByTestId('done-button'));
|
|
121
|
+
expect(onClose).toHaveBeenCalled();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('closes on outside click', async () => {
|
|
125
|
+
const onClose = jest.fn();
|
|
126
|
+
const opts = {
|
|
127
|
+
characters: [['á', 'é']],
|
|
128
|
+
};
|
|
129
|
+
render(<CharacterPicker editor={mockEditor} opts={opts} onClose={onClose} />);
|
|
130
|
+
|
|
131
|
+
await waitFor(() => {
|
|
132
|
+
fireEvent.mouseDown(document.body);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
expect(onClose).toHaveBeenCalled();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('does not close when clicking inside picker', async () => {
|
|
139
|
+
const onClose = jest.fn();
|
|
140
|
+
const opts = {
|
|
141
|
+
characters: [['á', 'é']],
|
|
142
|
+
};
|
|
143
|
+
const { container } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={onClose} />);
|
|
144
|
+
|
|
145
|
+
await waitFor(() => {
|
|
146
|
+
const picker = container.querySelector('.insert-character-dialog');
|
|
147
|
+
if (picker) {
|
|
148
|
+
fireEvent.mouseDown(picker);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('renders with custom opts structure', () => {
|
|
156
|
+
const opts = {
|
|
157
|
+
characters: [
|
|
158
|
+
[
|
|
159
|
+
{ name: 'a', write: 'á', label: 'á' },
|
|
160
|
+
{ name: 'e', write: 'é', label: 'é' },
|
|
161
|
+
],
|
|
162
|
+
],
|
|
163
|
+
};
|
|
164
|
+
const { getByTestId } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
165
|
+
expect(getByTestId('pure-toolbar')).toBeInTheDocument();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('renders with hasPreview option', () => {
|
|
169
|
+
const opts = {
|
|
170
|
+
hasPreview: true,
|
|
171
|
+
characters: [
|
|
172
|
+
[
|
|
173
|
+
{
|
|
174
|
+
name: 'euro',
|
|
175
|
+
write: '€',
|
|
176
|
+
label: '€',
|
|
177
|
+
description: 'Euro sign',
|
|
178
|
+
unicode: 'U+20AC',
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
const { getByTestId } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
184
|
+
expect(getByTestId('pure-toolbar')).toBeInTheDocument();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('calculates position correctly', () => {
|
|
188
|
+
const opts = {
|
|
189
|
+
characters: [['á']],
|
|
190
|
+
};
|
|
191
|
+
const { container } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
192
|
+
const dialog = container.querySelector('.insert-character-dialog');
|
|
193
|
+
expect(dialog).toHaveStyle({ position: 'absolute' });
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import CssIcon from '../icons/CssIcon';
|
|
4
|
+
|
|
5
|
+
describe('CssIcon', () => {
|
|
6
|
+
it('renders without crashing', () => {
|
|
7
|
+
const { container } = render(<CssIcon />);
|
|
8
|
+
expect(container).toBeInTheDocument();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('renders CSS text', () => {
|
|
12
|
+
const { getByText } = render(<CssIcon />);
|
|
13
|
+
expect(getByText('CSS')).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('applies correct font family', () => {
|
|
17
|
+
const { getByText } = render(<CssIcon />);
|
|
18
|
+
const element = getByText('CSS');
|
|
19
|
+
// Font family is applied via styled component, just verify text renders
|
|
20
|
+
expect(element).toBeInTheDocument();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('applies bold font weight', () => {
|
|
24
|
+
const { getByText } = render(<CssIcon />);
|
|
25
|
+
const element = getByText('CSS');
|
|
26
|
+
expect(element).toHaveStyle({ fontWeight: 'bold' });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('has correct line height', () => {
|
|
30
|
+
const { getByText } = render(<CssIcon />);
|
|
31
|
+
const element = getByText('CSS');
|
|
32
|
+
expect(element).toHaveStyle({ lineHeight: '14px' });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('has relative positioning', () => {
|
|
36
|
+
const { getByText } = render(<CssIcon />);
|
|
37
|
+
const element = getByText('CSS');
|
|
38
|
+
expect(element).toHaveStyle({ position: 'relative' });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('has nowrap white space', () => {
|
|
42
|
+
const { getByText } = render(<CssIcon />);
|
|
43
|
+
const element = getByText('CSS');
|
|
44
|
+
expect(element).toHaveStyle({ whiteSpace: 'nowrap' });
|
|
45
|
+
});
|
|
46
|
+
});
|