@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,125 +0,0 @@
1
- import React from 'react';
2
- import { render, waitFor } from '@testing-library/react';
3
- import { EditableHtml } from '../components/EditableHtml';
4
-
5
- describe('Div to Paragraph Conversion', () => {
6
- it('converts consecutive divs to paragraph with br tags', async () => {
7
- const markup = '<div>A</div><div>B</div>';
8
- const { container } = render(<EditableHtml markup={markup} onChange={() => {}} pluginProps={{}} />);
9
-
10
- // Wait for the editor to initialize
11
- await waitFor(() => {
12
- const prosemirror = container.querySelector('.ProseMirror');
13
- expect(prosemirror).toBeInTheDocument();
14
- });
15
-
16
- // Check that the content was converted to a paragraph
17
- const paragraph = container.querySelector('.ProseMirror p');
18
- expect(paragraph).toBeInTheDocument();
19
-
20
- // Check that br tag is present
21
- const br = container.querySelector('.ProseMirror p br');
22
- expect(br).toBeInTheDocument();
23
-
24
- // Verify the text content
25
- expect(paragraph.textContent).toBe('AB');
26
- });
27
-
28
- it('converts three consecutive divs correctly', async () => {
29
- const markup = '<div>First</div><div>Second</div><div>Third</div>';
30
- const { container } = render(<EditableHtml markup={markup} onChange={() => {}} pluginProps={{}} />);
31
-
32
- await waitFor(() => {
33
- const prosemirror = container.querySelector('.ProseMirror');
34
- expect(prosemirror).toBeInTheDocument();
35
- });
36
-
37
- const paragraph = container.querySelector('.ProseMirror p');
38
- expect(paragraph).toBeInTheDocument();
39
-
40
- // Should have 2 br tags (between 3 items)
41
- const brTags = container.querySelectorAll('.ProseMirror p br');
42
- expect(brTags.length).toBe(2);
43
-
44
- expect(paragraph.textContent).toBe('FirstSecondThird');
45
- });
46
-
47
- it('does not convert single div', async () => {
48
- const markup = '<div>Single</div>';
49
- const { container } = render(<EditableHtml markup={markup} onChange={() => {}} pluginProps={{}} />);
50
-
51
- await waitFor(() => {
52
- const prosemirror = container.querySelector('.ProseMirror');
53
- expect(prosemirror).toBeInTheDocument();
54
- });
55
-
56
- // Should remain as a div
57
- const div = container.querySelector('.ProseMirror div');
58
- expect(div).toBeInTheDocument();
59
- expect(div.textContent).toBe('Single');
60
- });
61
-
62
- it('does not convert divs with attributes', async () => {
63
- const markup = '<div class="test">A</div><div>B</div>';
64
- const { container } = render(<EditableHtml markup={markup} onChange={() => {}} pluginProps={{}} />);
65
-
66
- await waitFor(() => {
67
- const prosemirror = container.querySelector('.ProseMirror');
68
- expect(prosemirror).toBeInTheDocument();
69
- });
70
-
71
- // Should remain as divs since one has an attribute
72
- const divs = container.querySelectorAll('.ProseMirror div');
73
- expect(divs.length).toBeGreaterThanOrEqual(2);
74
- });
75
-
76
- it('handles divs with inline formatting', async () => {
77
- const markup = '<div><strong>Bold</strong></div><div><em>Italic</em></div>';
78
- const { container } = render(<EditableHtml markup={markup} onChange={() => {}} pluginProps={{}} />);
79
-
80
- await waitFor(() => {
81
- const prosemirror = container.querySelector('.ProseMirror');
82
- expect(prosemirror).toBeInTheDocument();
83
- });
84
-
85
- // Should be converted to paragraph
86
- const paragraph = container.querySelector('.ProseMirror p');
87
- expect(paragraph).toBeInTheDocument();
88
-
89
- // Check that formatting is preserved
90
- const strong = container.querySelector('.ProseMirror p strong');
91
- const em = container.querySelector('.ProseMirror p em');
92
- expect(strong).toBeInTheDocument();
93
- expect(em).toBeInTheDocument();
94
- });
95
-
96
- it('does not convert mixed element types', async () => {
97
- const markup = '<div>A</div><p>B</p>';
98
- const { container } = render(<EditableHtml markup={markup} onChange={() => {}} pluginProps={{}} />);
99
-
100
- await waitFor(() => {
101
- const prosemirror = container.querySelector('.ProseMirror');
102
- expect(prosemirror).toBeInTheDocument();
103
- });
104
-
105
- // Should have both div and paragraph
106
- const div = container.querySelector('.ProseMirror div');
107
- const p = container.querySelector('.ProseMirror p');
108
- expect(div).toBeInTheDocument();
109
- expect(p).toBeInTheDocument();
110
- });
111
-
112
- it('does not convert divs with nested block elements', async () => {
113
- const markup = '<div><div>Nested</div></div><div>B</div>';
114
- const { container } = render(<EditableHtml markup={markup} onChange={() => {}} pluginProps={{}} />);
115
-
116
- await waitFor(() => {
117
- const prosemirror = container.querySelector('.ProseMirror');
118
- expect(prosemirror).toBeInTheDocument();
119
- });
120
-
121
- // Should remain as divs
122
- const divs = container.querySelectorAll('.ProseMirror > div');
123
- expect(divs.length).toBeGreaterThanOrEqual(1);
124
- });
125
- });
@@ -1,208 +0,0 @@
1
- import { ALL_PLUGINS, buildExtensions, DEFAULT_PLUGINS } from '../extensions';
2
-
3
- describe('Extensions', () => {
4
- describe('ALL_PLUGINS', () => {
5
- it('contains all expected plugins', () => {
6
- expect(ALL_PLUGINS).toContain('bold');
7
- expect(ALL_PLUGINS).toContain('italic');
8
- expect(ALL_PLUGINS).toContain('underline');
9
- expect(ALL_PLUGINS).toContain('strikethrough');
10
- expect(ALL_PLUGINS).toContain('bulleted-list');
11
- expect(ALL_PLUGINS).toContain('numbered-list');
12
- expect(ALL_PLUGINS).toContain('image');
13
- expect(ALL_PLUGINS).toContain('math');
14
- expect(ALL_PLUGINS).toContain('languageCharacters');
15
- expect(ALL_PLUGINS).toContain('text-align');
16
- expect(ALL_PLUGINS).toContain('table');
17
- expect(ALL_PLUGINS).toContain('video');
18
- expect(ALL_PLUGINS).toContain('audio');
19
- expect(ALL_PLUGINS).toContain('responseArea');
20
- expect(ALL_PLUGINS).toContain('superscript');
21
- expect(ALL_PLUGINS).toContain('subscript');
22
- expect(ALL_PLUGINS).toContain('h3');
23
- expect(ALL_PLUGINS).toContain('blockquote');
24
- expect(ALL_PLUGINS).toContain('undo');
25
- expect(ALL_PLUGINS).toContain('redo');
26
- });
27
- });
28
-
29
- describe('DEFAULT_PLUGINS', () => {
30
- it('excludes responseArea, h3, and blockquote', () => {
31
- expect(DEFAULT_PLUGINS).not.toContain('responseArea');
32
- expect(DEFAULT_PLUGINS).not.toContain('h3');
33
- expect(DEFAULT_PLUGINS).not.toContain('blockquote');
34
- });
35
-
36
- it('contains basic formatting plugins', () => {
37
- expect(DEFAULT_PLUGINS).toContain('bold');
38
- expect(DEFAULT_PLUGINS).toContain('italic');
39
- expect(DEFAULT_PLUGINS).toContain('underline');
40
- });
41
- });
42
-
43
- describe('buildExtensions', () => {
44
- it('returns an array when called with default parameters', () => {
45
- const result = buildExtensions(DEFAULT_PLUGINS, [], {});
46
- expect(Array.isArray(result)).toBe(true);
47
- });
48
-
49
- it('includes only active extensions', () => {
50
- const activeExtensions = ['bold', 'italic'];
51
- const result = buildExtensions(activeExtensions, [], {});
52
- expect(result).toEqual(['bold', 'italic']);
53
- });
54
-
55
- it('filters out undefined values', () => {
56
- const result = buildExtensions(['bold', 'italic'], [], {});
57
- expect(result.every((item) => item !== undefined)).toBe(true);
58
- });
59
-
60
- it('excludes image plugin when opts.image.onDelete is not provided', () => {
61
- const activeExtensions = ['image'];
62
- const result = buildExtensions(activeExtensions, [], {});
63
- expect(result).not.toContain('image');
64
- });
65
-
66
- it('includes image plugin when opts.image.delete is provided', () => {
67
- const activeExtensions = ['image'];
68
- const opts = { image: { delete: jest.fn() } };
69
- const result = buildExtensions(activeExtensions, [], opts);
70
- expect(result).toContain('image');
71
- });
72
-
73
- it('excludes math plugin when opts.math is not provided', () => {
74
- const activeExtensions = ['math'];
75
- const result = buildExtensions(activeExtensions, [], {});
76
- expect(result).not.toContain('math');
77
- });
78
-
79
- it('includes math plugin when opts.math is provided', () => {
80
- const activeExtensions = ['math'];
81
- const opts = { math: {} };
82
- const result = buildExtensions(activeExtensions, [], opts);
83
- expect(result).toContain('math');
84
- });
85
-
86
- it('excludes responseArea plugin when opts.responseArea.type is not provided', () => {
87
- const activeExtensions = ['responseArea'];
88
- const result = buildExtensions(activeExtensions, [], {});
89
- expect(result).not.toContain('responseArea');
90
- });
91
-
92
- it('includes responseArea plugin when opts.responseArea.type is provided', () => {
93
- const activeExtensions = ['responseArea'];
94
- const opts = { responseArea: { type: 'explicit-constructed-response' } };
95
- const result = buildExtensions(activeExtensions, [], opts);
96
- expect(result).toContain('responseArea');
97
- });
98
-
99
- it('excludes css plugin when opts.extraCSSRules is empty', () => {
100
- const activeExtensions = ['css'];
101
- const result = buildExtensions(activeExtensions, [], { extraCSSRules: {} });
102
- expect(result).not.toContain('css');
103
- });
104
-
105
- it('includes css plugin when opts.extraCSSRules has values', () => {
106
- const activeExtensions = ['css'];
107
- const opts = { extraCSSRules: { color: 'red' } };
108
- const result = buildExtensions(activeExtensions, [], opts);
109
- expect(result).toContain('css');
110
- });
111
-
112
- it('excludes html plugin when opts.html is not provided', () => {
113
- const activeExtensions = ['html'];
114
- const result = buildExtensions(activeExtensions, [], {});
115
- expect(result).not.toContain('html');
116
- });
117
-
118
- it('includes html plugin when opts.html is provided', () => {
119
- const activeExtensions = ['html'];
120
- const opts = { html: true };
121
- const result = buildExtensions(activeExtensions, [], opts);
122
- expect(result).toContain('html');
123
- });
124
-
125
- it('handles languageCharacters plugins array', () => {
126
- const activeExtensions = ['languageCharacters'];
127
- const opts = {
128
- languageCharacters: [
129
- { label: 'Greek', value: 'greek' },
130
- { label: 'Cyrillic', value: 'cyrillic' },
131
- ],
132
- };
133
- const result = buildExtensions(activeExtensions, [], opts);
134
- // Should include languageCharacters for each item in the array
135
- const languageCharsCount = result.filter((item) => item === 'languageCharacters').length;
136
- expect(languageCharsCount).toBe(2);
137
- });
138
-
139
- it('uses DEFAULT_PLUGINS when activeExtensions is not provided', () => {
140
- const result = buildExtensions(null, [], {});
141
- expect(Array.isArray(result)).toBe(true);
142
- expect(result.length).toBeGreaterThan(0);
143
- });
144
-
145
- it('includes list plugins', () => {
146
- const activeExtensions = ['bulleted-list', 'numbered-list'];
147
- const result = buildExtensions(activeExtensions, [], {});
148
- expect(result).toContain('bulleted-list');
149
- expect(result).toContain('numbered-list');
150
- });
151
-
152
- it('includes undo and redo plugins', () => {
153
- const activeExtensions = ['undo', 'redo'];
154
- const result = buildExtensions(activeExtensions, [], {});
155
- expect(result).toContain('undo');
156
- expect(result).toContain('redo');
157
- });
158
-
159
- it('includes text formatting plugins', () => {
160
- const activeExtensions = ['superscript', 'subscript', 'strikethrough', 'underline'];
161
- const result = buildExtensions(activeExtensions, [], {});
162
- expect(result).toContain('superscript');
163
- expect(result).toContain('subscript');
164
- expect(result).toContain('strikethrough');
165
- expect(result).toContain('underline');
166
- });
167
-
168
- it('includes media plugins', () => {
169
- const activeExtensions = ['video', 'audio'];
170
- const result = buildExtensions(activeExtensions, [], {});
171
- expect(result).toContain('video');
172
- expect(result).toContain('audio');
173
- });
174
-
175
- it('includes table plugin', () => {
176
- const activeExtensions = ['table'];
177
- const result = buildExtensions(activeExtensions, [], {});
178
- expect(result).toContain('table');
179
- });
180
-
181
- it('includes text-align plugin', () => {
182
- const activeExtensions = ['text-align'];
183
- const result = buildExtensions(activeExtensions, [], {});
184
- expect(result).toContain('text-align');
185
- });
186
-
187
- it('includes blockquote and h3 plugins when in active list', () => {
188
- const activeExtensions = ['blockquote', 'h3'];
189
- const result = buildExtensions(activeExtensions, [], {});
190
- expect(result).toContain('blockquote');
191
- expect(result).toContain('h3');
192
- });
193
-
194
- it('filters out inactive extensions', () => {
195
- const activeExtensions = ['bold'];
196
- const result = buildExtensions(activeExtensions, [], {});
197
- expect(result).not.toContain('italic');
198
- expect(result).not.toContain('underline');
199
- });
200
-
201
- it('maintains order of extensions', () => {
202
- const activeExtensions = ['table', 'bold', 'italic'];
203
- const result = buildExtensions(activeExtensions, [], {});
204
- expect(result.indexOf('table')).toBeLessThan(result.indexOf('bold'));
205
- expect(result.indexOf('bold')).toBeLessThan(result.indexOf('italic'));
206
- });
207
- });
208
- });
@@ -1,154 +0,0 @@
1
- import StyledEditor, { ALL_PLUGINS, DEFAULT_PLUGINS, EditableHtml } from '../index';
2
-
3
- // Mock TipTap and dependencies
4
- jest.mock('@tiptap/react', () => ({
5
- EditorContent: () => <div data-testid="editor-content" />,
6
- useEditor: jest.fn(() => ({
7
- getHTML: jest.fn(() => '<p>test content</p>'),
8
- setEditable: jest.fn(),
9
- commands: { setContent: jest.fn() },
10
- isActive: jest.fn(() => false),
11
- isFocused: false,
12
- })),
13
- useEditorState: jest.fn(() => ({ isFocused: false })),
14
- }));
15
-
16
- jest.mock('@tiptap/starter-kit', () => ({
17
- __esModule: true,
18
- default: { configure: jest.fn(() => ({})) },
19
- }));
20
- jest.mock('@tiptap/extension-text-style', () => ({ TextStyleKit: {} }));
21
- jest.mock('@tiptap/extension-character-count', () => ({
22
- CharacterCount: { configure: jest.fn(() => ({})) },
23
- }));
24
- jest.mock('@tiptap/extension-superscript', () => ({ __esModule: true, default: {} }));
25
- jest.mock('@tiptap/extension-subscript', () => ({ __esModule: true, default: {} }));
26
- jest.mock('@tiptap/extension-text-align', () => ({
27
- __esModule: true,
28
- default: { configure: jest.fn(() => ({})) },
29
- }));
30
- jest.mock('@tiptap/extension-image', () => ({ __esModule: true, default: {} }));
31
- jest.mock('@tiptap/extension-table', () => ({ __esModule: true, default: {} }));
32
- jest.mock('@tiptap/extension-table-row', () => ({ TableRow: {} }));
33
- jest.mock('../extensions/extended-table-cell', () => ({
34
- ExtendedTableCell: {},
35
- ExtendedTableHeader: {},
36
- }));
37
- jest.mock('../extensions/extended-table', () => ({ __esModule: true, default: {} }));
38
- jest.mock('../extensions/ensure-empty-root-div', () => ({ EnsureEmptyRootIsDiv: {} }));
39
- jest.mock('../extensions/extended-list-item', () => ({ ExtendedListItem: {} }));
40
- jest.mock('../extensions/ensure-list-item-content-is-div', () => ({ EnsureListItemContentIsDiv: {} }));
41
- jest.mock('../extensions/responseArea', () => ({
42
- ExplicitConstructedResponseNode: { configure: jest.fn(() => ({})) },
43
- DragInTheBlankNode: { configure: jest.fn(() => ({})) },
44
- InlineDropdownNode: { configure: jest.fn(() => ({})) },
45
- ResponseAreaExtension: { configure: jest.fn(() => ({})) },
46
- }));
47
- jest.mock('../extensions/math', () => ({ MathNode: { configure: jest.fn(() => ({})) } }));
48
- jest.mock('../extensions/image', () => ({ ImageUploadNode: { configure: jest.fn(() => ({})) } }));
49
- jest.mock('../extensions/media', () => ({ Media: { configure: jest.fn(() => ({})) } }));
50
- jest.mock('../extensions/css', () => ({ CSSMark: { configure: jest.fn(() => ({})) } }));
51
- jest.mock('../components/TiptapContainer', () => ({
52
- __esModule: true,
53
- default: ({ children }) => <div data-testid="editor-container">{children}</div>,
54
- }));
55
- jest.mock('../extensions', () => ({
56
- buildExtensions: jest.fn(() => []),
57
- ALL_PLUGINS: [
58
- 'bold',
59
- 'html',
60
- 'extraCSSRules',
61
- 'italic',
62
- 'underline',
63
- 'strikethrough',
64
- 'bulleted-list',
65
- 'numbered-list',
66
- 'image',
67
- 'math',
68
- 'languageCharacters',
69
- 'text-align',
70
- 'blockquote',
71
- 'h3',
72
- 'table',
73
- 'video',
74
- 'audio',
75
- 'responseArea',
76
- 'redo',
77
- 'undo',
78
- 'superscript',
79
- 'subscript',
80
- ],
81
- DEFAULT_PLUGINS: [
82
- 'bold',
83
- 'html',
84
- 'extraCSSRules',
85
- 'italic',
86
- 'underline',
87
- 'strikethrough',
88
- 'bulleted-list',
89
- 'numbered-list',
90
- 'image',
91
- 'math',
92
- 'languageCharacters',
93
- 'text-align',
94
- 'table',
95
- 'video',
96
- 'audio',
97
- 'redo',
98
- 'undo',
99
- 'superscript',
100
- 'subscript',
101
- ],
102
- }));
103
-
104
- describe('editable-html-tip-tap module', () => {
105
- describe('exports', () => {
106
- it('exports StyledEditor as default', () => {
107
- expect(StyledEditor).toBeDefined();
108
- });
109
-
110
- it('exports EditableHtml as named export', () => {
111
- expect(EditableHtml).toBeDefined();
112
- });
113
-
114
- it('exports ALL_PLUGINS as named export', () => {
115
- expect(ALL_PLUGINS).toBeDefined();
116
- expect(Array.isArray(ALL_PLUGINS)).toBe(true);
117
- });
118
-
119
- it('exports DEFAULT_PLUGINS as named export', () => {
120
- expect(DEFAULT_PLUGINS).toBeDefined();
121
- expect(Array.isArray(DEFAULT_PLUGINS)).toBe(true);
122
- });
123
-
124
- it('StyledEditor and EditableHtml refer to the same component', () => {
125
- expect(StyledEditor).toBe(EditableHtml);
126
- });
127
- });
128
-
129
- describe('ALL_PLUGINS', () => {
130
- it('contains expected plugins', () => {
131
- expect(ALL_PLUGINS).toContain('bold');
132
- expect(ALL_PLUGINS).toContain('italic');
133
- expect(ALL_PLUGINS).toContain('underline');
134
- expect(ALL_PLUGINS).toContain('math');
135
- expect(ALL_PLUGINS).toContain('table');
136
- expect(ALL_PLUGINS).toContain('responseArea');
137
- });
138
- });
139
-
140
- describe('DEFAULT_PLUGINS', () => {
141
- it('is a subset of ALL_PLUGINS', () => {
142
- const allPluginsSet = new Set(ALL_PLUGINS);
143
- DEFAULT_PLUGINS.forEach((plugin) => {
144
- expect(allPluginsSet.has(plugin)).toBe(true);
145
- });
146
- });
147
-
148
- it('contains basic formatting plugins', () => {
149
- expect(DEFAULT_PLUGINS).toContain('bold');
150
- expect(DEFAULT_PLUGINS).toContain('italic');
151
- expect(DEFAULT_PLUGINS).toContain('underline');
152
- });
153
- });
154
- });
@@ -1,64 +0,0 @@
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
- });
@@ -1,17 +0,0 @@
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
- });