@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.
Files changed (47) hide show
  1. package/package.json +3 -3
  2. package/src/__tests__/EditableHtml.test.jsx +0 -588
  3. package/src/__tests__/constants.test.js +0 -19
  4. package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
  5. package/src/__tests__/extensions.test.js +0 -208
  6. package/src/__tests__/index.test.jsx +0 -154
  7. package/src/__tests__/size-utils.test.js +0 -64
  8. package/src/__tests__/theme.test.js +0 -17
  9. package/src/components/__tests__/AltDialog.test.jsx +0 -147
  10. package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
  11. package/src/components/__tests__/CssIcon.test.jsx +0 -46
  12. package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
  13. package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
  14. package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
  15. package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
  16. package/src/components/__tests__/InsertImageHandler.test.js +0 -161
  17. package/src/components/__tests__/MediaDialog.test.jsx +0 -293
  18. package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
  19. package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
  20. package/src/components/__tests__/MenuBar.test.jsx +0 -250
  21. package/src/components/__tests__/RespArea.test.jsx +0 -122
  22. package/src/components/__tests__/TableIcons.test.jsx +0 -149
  23. package/src/components/__tests__/TextAlign.test.jsx +0 -167
  24. package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
  25. package/src/components/__tests__/characterUtils.test.js +0 -166
  26. package/src/components/__tests__/choice.test.jsx +0 -171
  27. package/src/components/__tests__/custom-popper.test.jsx +0 -82
  28. package/src/components/__tests__/done-button.test.jsx +0 -54
  29. package/src/components/__tests__/toolbar-buttons.test.jsx +0 -234
  30. package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
  31. package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
  32. package/src/extensions/__tests__/css.test.js +0 -196
  33. package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
  34. package/src/extensions/__tests__/divNode.test.js +0 -87
  35. package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
  36. package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
  37. package/src/extensions/__tests__/extended-list-item.test.js +0 -13
  38. package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
  39. package/src/extensions/__tests__/extended-table.test.js +0 -183
  40. package/src/extensions/__tests__/image-component.test.jsx +0 -346
  41. package/src/extensions/__tests__/image.test.js +0 -237
  42. package/src/extensions/__tests__/math.test.js +0 -900
  43. package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
  44. package/src/extensions/__tests__/media.test.js +0 -271
  45. package/src/extensions/__tests__/responseArea.test.js +0 -655
  46. package/src/utils/__tests__/helper.test.js +0 -126
  47. package/src/utils/__tests__/toolbar.test.js +0 -43
@@ -1,250 +0,0 @@
1
- import React from 'react';
2
- import { fireEvent, render } from '@testing-library/react';
3
- import StyledMenuBar from '../MenuBar';
4
-
5
- jest.mock('@tiptap/react', () => ({
6
- EditorContent: ({ editor }) => <div data-testid="editor-content" />,
7
- useEditorState: ({ selector }) => {
8
- const mockEditor = {
9
- isActive: jest.fn(() => false),
10
- can: jest.fn(() => ({
11
- chain: jest.fn(() => ({
12
- toggleBold: jest.fn(() => ({ run: jest.fn(() => true) })),
13
- insertTable: jest.fn(() => ({ run: jest.fn(() => true) })),
14
- toggleItalic: jest.fn(() => ({ run: jest.fn(() => true) })),
15
- toggleStrike: jest.fn(() => ({ run: jest.fn(() => true) })),
16
- toggleCode: jest.fn(() => ({ run: jest.fn(() => true) })),
17
- unsetAllMarks: jest.fn(() => ({ run: jest.fn(() => true) })),
18
- undo: jest.fn(() => ({ run: jest.fn(() => true) })),
19
- redo: jest.fn(() => ({ run: jest.fn(() => true) })),
20
- })),
21
- })),
22
- getAttributes: jest.fn(() => ({ border: '1' })),
23
- commandManager: {},
24
- isFocused: true,
25
- state: {
26
- selection: {},
27
- },
28
- };
29
-
30
- return selector({ editor: mockEditor });
31
- },
32
- }));
33
-
34
- jest.mock('prosemirror-state', () => ({
35
- NodeSelection: jest.fn(),
36
- }));
37
-
38
- jest.mock('../CharacterPicker', () => ({
39
- CharacterIcon: ({ letter }) => <div data-testid="character-icon">{letter}</div>,
40
- CharacterPicker: ({ onClose }) => (
41
- <div data-testid="character-picker">
42
- <button onClick={onClose} data-testid="close-picker">
43
- Close
44
- </button>
45
- </div>
46
- ),
47
- }));
48
-
49
- jest.mock('../common/done-button', () => ({
50
- DoneButton: ({ onClick }) => (
51
- <button onClick={onClick} data-testid="done-button">
52
- Done
53
- </button>
54
- ),
55
- }));
56
-
57
- describe('StyledMenuBar', () => {
58
- const mockEditor = {
59
- chain: jest.fn(() => ({
60
- focus: jest.fn(() => ({
61
- insertTable: jest.fn(() => ({ run: jest.fn() })),
62
- toggleBold: jest.fn(() => ({ run: jest.fn() })),
63
- toggleItalic: jest.fn(() => ({ run: jest.fn() })),
64
- toggleStrike: jest.fn(() => ({ run: jest.fn() })),
65
- toggleCode: jest.fn(() => ({ run: jest.fn() })),
66
- toggleUnderline: jest.fn(() => ({ run: jest.fn() })),
67
- toggleSubscript: jest.fn(() => ({ run: jest.fn() })),
68
- toggleSuperscript: jest.fn(() => ({ run: jest.fn() })),
69
- setImageUploadNode: jest.fn(() => ({ run: jest.fn() })),
70
- insertMedia: jest.fn(() => ({ run: jest.fn() })),
71
- toggleHeading: jest.fn(() => ({ run: jest.fn() })),
72
- insertMath: jest.fn(() => ({ run: jest.fn() })),
73
- toggleBulletList: jest.fn(() => ({ run: jest.fn() })),
74
- toggleOrderedList: jest.fn(() => ({ run: jest.fn() })),
75
- undo: jest.fn(() => ({ run: jest.fn() })),
76
- redo: jest.fn(() => ({ run: jest.fn() })),
77
- addRowAfter: jest.fn(() => ({ run: jest.fn() })),
78
- deleteRow: jest.fn(() => ({ run: jest.fn() })),
79
- addColumnAfter: jest.fn(() => ({ run: jest.fn() })),
80
- deleteColumn: jest.fn(() => ({ run: jest.fn() })),
81
- deleteTable: jest.fn(() => ({ run: jest.fn() })),
82
- insertResponseArea: jest.fn(() => ({ run: jest.fn() })),
83
- })),
84
- })),
85
- can: jest.fn(() => ({
86
- chain: jest.fn(() => ({
87
- toggleBold: jest.fn(() => ({ run: jest.fn(() => true) })),
88
- insertTable: jest.fn(() => ({ run: jest.fn(() => true) })),
89
- undo: jest.fn(() => ({ run: jest.fn(() => true) })),
90
- redo: jest.fn(() => ({ run: jest.fn(() => true) })),
91
- })),
92
- })),
93
- isActive: jest.fn((name) => {
94
- if (name === 'bold') return true;
95
- if (name === 'italic') return false;
96
- return false;
97
- }),
98
- getAttributes: jest.fn(() => ({ border: '1' })),
99
- getHTML: jest.fn(() => '<p>Test</p>'),
100
- commands: {
101
- blur: jest.fn(),
102
- openCSSClassDialog: jest.fn(),
103
- updateAttributes: jest.fn(),
104
- },
105
- isFocused: true,
106
- state: {
107
- selection: {},
108
- },
109
- _toolbarOpened: false,
110
- };
111
-
112
- const defaultProps = {
113
- editor: mockEditor,
114
- activePlugins: ['bold', 'italic', 'underline', 'table'],
115
- toolbarOpts: {},
116
- responseAreaProps: { type: 'explicit-constructed-response' },
117
- };
118
-
119
- beforeEach(() => {
120
- jest.clearAllMocks();
121
- });
122
-
123
- it('renders without crashing', () => {
124
- const { container } = render(<StyledMenuBar {...defaultProps} />);
125
- expect(container).toBeInTheDocument();
126
- });
127
-
128
- it('renders toolbar with buttons', () => {
129
- const { container } = render(<StyledMenuBar {...defaultProps} />);
130
- const buttons = container.querySelectorAll('button');
131
- expect(buttons.length).toBeGreaterThan(0);
132
- });
133
-
134
- it('shows bold button when bold plugin is active', () => {
135
- const { container } = render(<StyledMenuBar {...defaultProps} />);
136
- expect(container).toBeInTheDocument();
137
- });
138
-
139
- it('hides buttons when isTable is true', () => {
140
- const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table']} />);
141
- expect(container).toBeInTheDocument();
142
- });
143
-
144
- it('shows table buttons when in table context', () => {
145
- const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table']} />);
146
- expect(container).toBeInTheDocument();
147
- });
148
-
149
- it('handles button clicks', () => {
150
- const { container } = render(<StyledMenuBar {...defaultProps} />);
151
- const button = container.querySelector('button');
152
- if (button) {
153
- fireEvent.click(button);
154
- }
155
- expect(container).toBeInTheDocument();
156
- });
157
-
158
- it('shows done button when toolbarOpts.showDone is true', () => {
159
- const { getByTestId } = render(
160
- <StyledMenuBar {...defaultProps} toolbarOpts={{ showDone: true }} onChange={jest.fn()} />,
161
- );
162
- expect(getByTestId('done-button')).toBeInTheDocument();
163
- });
164
-
165
- it('does not show done button when toolbarOpts.showDone is false', () => {
166
- const { queryByTestId } = render(<StyledMenuBar {...defaultProps} toolbarOpts={{ showDone: false }} />);
167
- expect(queryByTestId('done-button')).not.toBeInTheDocument();
168
- });
169
-
170
- it('handles done button click', () => {
171
- const onChange = jest.fn();
172
- const { getByTestId } = render(
173
- <StyledMenuBar {...defaultProps} toolbarOpts={{ showDone: true }} onChange={onChange} />,
174
- );
175
- fireEvent.click(getByTestId('done-button'));
176
- expect(onChange).toHaveBeenCalledWith('<p>Test</p>');
177
- expect(mockEditor.commands.blur).toHaveBeenCalled();
178
- });
179
-
180
- it('applies custom minWidth from toolbarOpts', () => {
181
- const { container } = render(<StyledMenuBar {...defaultProps} toolbarOpts={{ minWidth: 500 }} />);
182
- const toolbar = container.querySelector('.toolbar');
183
- expect(toolbar).toHaveStyle({ minWidth: '500px' });
184
- });
185
-
186
- it('applies hidden class when toolbarOpts.isHidden is true', () => {
187
- const { container } = render(<StyledMenuBar {...defaultProps} toolbarOpts={{ isHidden: true }} />);
188
- const toolbar = container.querySelector('.toolbar');
189
- expect(toolbar).toHaveClass('hidden');
190
- });
191
-
192
- it('shows character picker when language character button is clicked', () => {
193
- const { container, queryByTestId } = render(
194
- <StyledMenuBar {...defaultProps} activePlugins={['languageCharacters']} />,
195
- );
196
- expect(queryByTestId('character-picker')).not.toBeInTheDocument();
197
- });
198
-
199
- it('applies focused class when editor is focused', () => {
200
- const { container } = render(<StyledMenuBar {...defaultProps} toolbarOpts={{ alwaysVisible: false }} />);
201
- const toolbar = container.querySelector('.toolbar');
202
- expect(toolbar).toHaveClass('focused');
203
- });
204
-
205
- it('shows response area button when responseArea plugin is active', () => {
206
- const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['responseArea']} />);
207
- expect(container).toBeInTheDocument();
208
- });
209
-
210
- it('prevents default on mouse down', () => {
211
- const { container } = render(<StyledMenuBar {...defaultProps} />);
212
- const toolbar = container.querySelector('.toolbar');
213
- const event = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
214
- const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
215
- toolbar?.dispatchEvent(event);
216
- expect(preventDefaultSpy).toHaveBeenCalled();
217
- });
218
-
219
- it('calculates hasTextSelectionInTable correctly when selection is not empty in table', () => {
220
- // This test verifies the hasTextSelectionInTable state computation
221
- const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table', 'bold', 'italic']} />);
222
- expect(container).toBeInTheDocument();
223
- });
224
-
225
- it('hides table manipulation buttons when text is selected in table', () => {
226
- // When hasTextSelectionInTable is true, table row/column buttons should be hidden
227
- const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table']} />);
228
- // The component should render but table manipulation buttons should be conditional
229
- expect(container).toBeInTheDocument();
230
- });
231
-
232
- it('shows table manipulation buttons when no text is selected in table', () => {
233
- // When hasTextSelectionInTable is false, table row/column buttons should be visible
234
- const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table']} />);
235
- expect(container).toBeInTheDocument();
236
- });
237
-
238
- it('shows text formatting buttons regardless of table state', () => {
239
- // Bold, italic, etc. should always be visible when their plugin is active
240
- const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['bold', 'italic', 'underline']} />);
241
- const buttons = container.querySelectorAll('button');
242
- expect(buttons.length).toBeGreaterThan(0);
243
- });
244
-
245
- it('does not hide text formatting buttons when in table', () => {
246
- // Verify that the removal of "|| state.isTable" condition works correctly
247
- const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table', 'bold', 'italic']} />);
248
- expect(container).toBeInTheDocument();
249
- });
250
- });
@@ -1,122 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import { Chevron, GripIcon, ToolbarIcon } from '../icons/RespArea';
4
-
5
- describe('Chevron', () => {
6
- it('renders without crashing', () => {
7
- const { container } = render(<Chevron />);
8
- expect(container).toBeInTheDocument();
9
- });
10
-
11
- it('rotates 0 degrees for right direction (default)', () => {
12
- const { container } = render(<Chevron direction="right" />);
13
- const svg = container.querySelector('svg');
14
- expect(svg).toHaveStyle({ transform: 'rotate(0deg)' });
15
- });
16
-
17
- it('rotates 90 degrees for down direction', () => {
18
- const { container } = render(<Chevron direction="down" />);
19
- const svg = container.querySelector('svg');
20
- expect(svg).toHaveStyle({ transform: 'rotate(90deg)' });
21
- });
22
-
23
- it('rotates -90 degrees for up direction', () => {
24
- const { container } = render(<Chevron direction="up" />);
25
- const svg = container.querySelector('svg');
26
- expect(svg).toHaveStyle({ transform: 'rotate(-90deg)' });
27
- });
28
-
29
- it('rotates 180 degrees for left direction', () => {
30
- const { container } = render(<Chevron direction="left" />);
31
- const svg = container.querySelector('svg');
32
- expect(svg).toHaveStyle({ transform: 'rotate(180deg)' });
33
- });
34
-
35
- it('applies custom style prop', () => {
36
- const customStyle = { color: 'red', fontSize: '20px' };
37
- const { container } = render(<Chevron style={customStyle} />);
38
- const svg = container.querySelector('svg');
39
- expect(svg).toHaveStyle({ color: 'red', fontSize: '20px' });
40
- });
41
-
42
- it('defaults to 0 rotation when no direction specified', () => {
43
- const { container } = render(<Chevron />);
44
- const svg = container.querySelector('svg');
45
- expect(svg).toHaveStyle({ transform: 'rotate(0deg)' });
46
- });
47
- });
48
-
49
- describe('GripIcon', () => {
50
- it('renders without crashing', () => {
51
- const { container } = render(<GripIcon />);
52
- expect(container).toBeInTheDocument();
53
- });
54
-
55
- it('renders two MoreVert icons', () => {
56
- const { container } = render(<GripIcon />);
57
- const moreVertIcons = container.querySelectorAll('svg');
58
- expect(moreVertIcons.length).toBe(2);
59
- });
60
-
61
- it('applies custom style prop', () => {
62
- const customStyle = { color: 'blue' };
63
- const { container } = render(<GripIcon style={customStyle} />);
64
- const span = container.querySelector('span');
65
- expect(span).toHaveStyle({ color: 'blue' });
66
- });
67
-
68
- it('applies negative margin to first icon', () => {
69
- const { container } = render(<GripIcon />);
70
- const firstIcon = container.querySelector('svg');
71
- expect(firstIcon).toHaveStyle({ margin: '0 -16px' });
72
- });
73
- });
74
-
75
- describe('ToolbarIcon', () => {
76
- it('renders without crashing', () => {
77
- const { container } = render(<ToolbarIcon />);
78
- expect(container).toBeInTheDocument();
79
- });
80
-
81
- it('renders "+ Response Area" text', () => {
82
- const { getByText } = render(<ToolbarIcon />);
83
- expect(getByText('+ Response Area')).toBeInTheDocument();
84
- });
85
-
86
- it('applies correct font family', () => {
87
- const { getByText } = render(<ToolbarIcon />);
88
- const element = getByText('+ Response Area');
89
- // Font family is applied via styled component, just verify text renders
90
- expect(element).toBeInTheDocument();
91
- });
92
-
93
- it('applies bold font weight', () => {
94
- const { getByText } = render(<ToolbarIcon />);
95
- const element = getByText('+ Response Area');
96
- expect(element).toHaveStyle({ fontWeight: 'bold' });
97
- });
98
-
99
- it('has correct dimensions', () => {
100
- const { getByText } = render(<ToolbarIcon />);
101
- const element = getByText('+ Response Area');
102
- expect(element).toHaveStyle({ width: '110px', height: '28px' });
103
- });
104
-
105
- it('has relative positioning', () => {
106
- const { getByText } = render(<ToolbarIcon />);
107
- const element = getByText('+ Response Area');
108
- expect(element).toHaveStyle({ position: 'relative' });
109
- });
110
-
111
- it('has nowrap white space', () => {
112
- const { getByText } = render(<ToolbarIcon />);
113
- const element = getByText('+ Response Area');
114
- expect(element).toHaveStyle({ whiteSpace: 'nowrap' });
115
- });
116
-
117
- it('has top offset', () => {
118
- const { getByText } = render(<ToolbarIcon />);
119
- const element = getByText('+ Response Area');
120
- expect(element).toHaveStyle({ top: '7px' });
121
- });
122
- });
@@ -1,149 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import { AddColumn, AddRow, RemoveColumn, RemoveRow, RemoveTable } from '../icons/TableIcons';
4
-
5
- describe('AddRow', () => {
6
- it('renders without crashing', () => {
7
- const { container } = render(<AddRow />);
8
- expect(container).toBeInTheDocument();
9
- });
10
-
11
- it('renders SVG', () => {
12
- const { container } = render(<AddRow />);
13
- const svg = container.querySelector('svg');
14
- expect(svg).toBeInTheDocument();
15
- });
16
-
17
- it('has correct viewBox', () => {
18
- const { container } = render(<AddRow />);
19
- const svg = container.querySelector('svg');
20
- expect(svg).toHaveAttribute('viewBox', '0 0 24 24');
21
- });
22
-
23
- it('has correct dimensions', () => {
24
- const { container } = render(<AddRow />);
25
- const svg = container.querySelector('svg');
26
- expect(svg).toHaveAttribute('width', '24');
27
- expect(svg).toHaveAttribute('height', '24');
28
- });
29
-
30
- it('contains path element', () => {
31
- const { container } = render(<AddRow />);
32
- const path = container.querySelector('path');
33
- expect(path).toBeInTheDocument();
34
- });
35
- });
36
-
37
- describe('RemoveRow', () => {
38
- it('renders without crashing', () => {
39
- const { container } = render(<RemoveRow />);
40
- expect(container).toBeInTheDocument();
41
- });
42
-
43
- it('renders SVG', () => {
44
- const { container } = render(<RemoveRow />);
45
- const svg = container.querySelector('svg');
46
- expect(svg).toBeInTheDocument();
47
- });
48
-
49
- it('has correct viewBox', () => {
50
- const { container } = render(<RemoveRow />);
51
- const svg = container.querySelector('svg');
52
- expect(svg).toHaveAttribute('viewBox', '0 0 24 24');
53
- });
54
-
55
- it('contains path element', () => {
56
- const { container } = render(<RemoveRow />);
57
- const path = container.querySelector('path');
58
- expect(path).toBeInTheDocument();
59
- });
60
- });
61
-
62
- describe('AddColumn', () => {
63
- it('renders without crashing', () => {
64
- const { container } = render(<AddColumn />);
65
- expect(container).toBeInTheDocument();
66
- });
67
-
68
- it('renders SVG', () => {
69
- const { container } = render(<AddColumn />);
70
- const svg = container.querySelector('svg');
71
- expect(svg).toBeInTheDocument();
72
- });
73
-
74
- it('has correct viewBox', () => {
75
- const { container } = render(<AddColumn />);
76
- const svg = container.querySelector('svg');
77
- expect(svg).toHaveAttribute('viewBox', '0 0 24 24');
78
- });
79
-
80
- it('has correct dimensions', () => {
81
- const { container } = render(<AddColumn />);
82
- const svg = container.querySelector('svg');
83
- expect(svg).toHaveAttribute('width', '24');
84
- expect(svg).toHaveAttribute('height', '24');
85
- });
86
-
87
- it('contains path element', () => {
88
- const { container } = render(<AddColumn />);
89
- const path = container.querySelector('path');
90
- expect(path).toBeInTheDocument();
91
- });
92
- });
93
-
94
- describe('RemoveColumn', () => {
95
- it('renders without crashing', () => {
96
- const { container } = render(<RemoveColumn />);
97
- expect(container).toBeInTheDocument();
98
- });
99
-
100
- it('renders SVG', () => {
101
- const { container } = render(<RemoveColumn />);
102
- const svg = container.querySelector('svg');
103
- expect(svg).toBeInTheDocument();
104
- });
105
-
106
- it('has correct viewBox', () => {
107
- const { container } = render(<RemoveColumn />);
108
- const svg = container.querySelector('svg');
109
- expect(svg).toHaveAttribute('viewBox', '0 0 24 24');
110
- });
111
-
112
- it('contains path element', () => {
113
- const { container } = render(<RemoveColumn />);
114
- const path = container.querySelector('path');
115
- expect(path).toBeInTheDocument();
116
- });
117
- });
118
-
119
- describe('RemoveTable', () => {
120
- it('renders without crashing', () => {
121
- const { container } = render(<RemoveTable />);
122
- expect(container).toBeInTheDocument();
123
- });
124
-
125
- it('renders SVG', () => {
126
- const { container } = render(<RemoveTable />);
127
- const svg = container.querySelector('svg');
128
- expect(svg).toBeInTheDocument();
129
- });
130
-
131
- it('has correct viewBox', () => {
132
- const { container } = render(<RemoveTable />);
133
- const svg = container.querySelector('svg');
134
- expect(svg).toHaveAttribute('viewBox', '0 0 24 24');
135
- });
136
-
137
- it('has correct dimensions', () => {
138
- const { container } = render(<RemoveTable />);
139
- const svg = container.querySelector('svg');
140
- expect(svg).toHaveAttribute('width', '24');
141
- expect(svg).toHaveAttribute('height', '24');
142
- });
143
-
144
- it('contains path element', () => {
145
- const { container } = render(<RemoveTable />);
146
- const path = container.querySelector('path');
147
- expect(path).toBeInTheDocument();
148
- });
149
- });
@@ -1,167 +0,0 @@
1
- import React from 'react';
2
- import { fireEvent, render } from '@testing-library/react';
3
- import TextAlignIcon, { AlignCenter, AlignJustify, AlignLeft, AlignRight } from '../icons/TextAlign';
4
-
5
- jest.mock('@mui/material/ListItem', () => ({
6
- __esModule: true,
7
- default: ({ children, onClick, value, ...props }) => (
8
- <div {...props} value={value} onClick={onClick} role="listitem">
9
- {children}
10
- </div>
11
- ),
12
- }));
13
-
14
- describe('AlignLeft', () => {
15
- it('renders SVG', () => {
16
- const { container } = render(<AlignLeft />);
17
- expect(container.querySelector('svg')).toBeInTheDocument();
18
- });
19
-
20
- it('has correct viewBox', () => {
21
- const { container } = render(<AlignLeft />);
22
- const svg = container.querySelector('svg');
23
- expect(svg).toHaveAttribute('viewBox', '0 0 66 66');
24
- });
25
- });
26
-
27
- describe('AlignRight', () => {
28
- it('renders SVG', () => {
29
- const { container } = render(<AlignRight />);
30
- expect(container.querySelector('svg')).toBeInTheDocument();
31
- });
32
-
33
- it('has correct viewBox', () => {
34
- const { container } = render(<AlignRight />);
35
- const svg = container.querySelector('svg');
36
- expect(svg).toHaveAttribute('viewBox', '0 0 66 66');
37
- });
38
- });
39
-
40
- describe('AlignCenter', () => {
41
- it('renders SVG', () => {
42
- const { container } = render(<AlignCenter />);
43
- expect(container.querySelector('svg')).toBeInTheDocument();
44
- });
45
-
46
- it('has correct viewBox', () => {
47
- const { container } = render(<AlignCenter />);
48
- const svg = container.querySelector('svg');
49
- expect(svg).toHaveAttribute('viewBox', '0 0 66 66');
50
- });
51
- });
52
-
53
- describe('AlignJustify', () => {
54
- it('renders SVG', () => {
55
- const { container } = render(<AlignJustify />);
56
- expect(container.querySelector('svg')).toBeInTheDocument();
57
- });
58
-
59
- it('has correct viewBox', () => {
60
- const { container } = render(<AlignJustify />);
61
- const svg = container.querySelector('svg');
62
- expect(svg).toHaveAttribute('viewBox', '0 0 66 66');
63
- });
64
- });
65
-
66
- describe('TextAlignIcon', () => {
67
- const mockEditor = {
68
- isActive: jest.fn(),
69
- commands: {
70
- setTextAlign: jest.fn(),
71
- },
72
- };
73
-
74
- beforeEach(() => {
75
- jest.clearAllMocks();
76
- });
77
-
78
- it('renders without crashing', () => {
79
- const { container } = render(<TextAlignIcon editor={mockEditor} />);
80
- expect(container).toBeInTheDocument();
81
- });
82
-
83
- it('shows AlignLeft icon by default', () => {
84
- mockEditor.isActive.mockReturnValue(false);
85
- const { container } = render(<TextAlignIcon editor={mockEditor} />);
86
- expect(container.querySelector('svg')).toBeInTheDocument();
87
- });
88
-
89
- it('shows AlignRight icon when right alignment is active', () => {
90
- mockEditor.isActive.mockImplementation((options) => options?.textAlign === 'right');
91
- const { container } = render(<TextAlignIcon editor={mockEditor} />);
92
- expect(container.querySelector('svg')).toBeInTheDocument();
93
- });
94
-
95
- it('shows AlignCenter icon when center alignment is active', () => {
96
- mockEditor.isActive.mockImplementation((options) => options?.textAlign === 'center');
97
- const { container } = render(<TextAlignIcon editor={mockEditor} />);
98
- expect(container.querySelector('svg')).toBeInTheDocument();
99
- });
100
-
101
- it('shows AlignJustify icon when justify alignment is active', () => {
102
- mockEditor.isActive.mockImplementation((options) => options?.textAlign === 'justify');
103
- const { container } = render(<TextAlignIcon editor={mockEditor} />);
104
- expect(container.querySelector('svg')).toBeInTheDocument();
105
- });
106
-
107
- it('toggles dropdown on click', () => {
108
- const { container } = render(<TextAlignIcon editor={mockEditor} />);
109
- const button = container.querySelector('div[style*="display: flex"]');
110
- fireEvent.click(button);
111
- expect(container).toBeInTheDocument();
112
- });
113
-
114
- it('applies alignment when list item is clicked', () => {
115
- const { container, getByLabelText } = render(<TextAlignIcon editor={mockEditor} />);
116
- const button = container.querySelector('div[style*="display: flex"]');
117
- fireEvent.click(button);
118
-
119
- const leftButton = getByLabelText('Align text left');
120
- fireEvent.click(leftButton);
121
- expect(mockEditor.commands.setTextAlign).toHaveBeenCalledWith('left');
122
- });
123
-
124
- it('prevents default and stops propagation on mouse down', () => {
125
- const { container } = render(<TextAlignIcon editor={mockEditor} />);
126
- const button = container.querySelector('div[style*="display"]');
127
- if (button) {
128
- fireEvent.mouseDown(button);
129
- // Just verify the event handler didn't throw
130
- expect(container).toBeInTheDocument();
131
- } else {
132
- expect(container).toBeInTheDocument();
133
- }
134
- });
135
-
136
- it('shows dropdown arrow', () => {
137
- const { container } = render(<TextAlignIcon editor={mockEditor} />);
138
- const span = container.querySelector('span[style*="marginLeft"]');
139
- if (span) {
140
- expect(span).toBeInTheDocument();
141
- } else {
142
- // Arrow might be rendered differently in test environment
143
- expect(container).toBeInTheDocument();
144
- }
145
- });
146
-
147
- it('closes dropdown after selecting alignment', () => {
148
- const { container, getByLabelText } = render(<TextAlignIcon editor={mockEditor} />);
149
- const button = container.querySelector('div[style*="display: flex"]');
150
- fireEvent.click(button);
151
-
152
- const centerButton = getByLabelText('Align text center');
153
- fireEvent.click(centerButton);
154
- expect(mockEditor.commands.setTextAlign).toHaveBeenCalledWith('center');
155
- });
156
-
157
- it('renders all alignment options in dropdown', () => {
158
- const { container, getByLabelText } = render(<TextAlignIcon editor={mockEditor} />);
159
- const button = container.querySelector('div[style*="display: flex"]');
160
- fireEvent.click(button);
161
-
162
- expect(getByLabelText('Align text left')).toBeInTheDocument();
163
- expect(getByLabelText('Align text center')).toBeInTheDocument();
164
- expect(getByLabelText('Align text right')).toBeInTheDocument();
165
- expect(getByLabelText('Justify text')).toBeInTheDocument();
166
- });
167
- });