@pie-lib/editable-html-tip-tap 2.1.2-next.31 → 2.1.2-next.36
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.json +32 -0
- package/CHANGELOG.md +2532 -0
- package/LICENSE.md +5 -0
- package/lib/components/CharacterPicker.js +201 -0
- package/lib/components/CharacterPicker.js.map +1 -0
- package/lib/components/EditableHtml.js +376 -0
- package/lib/components/EditableHtml.js.map +1 -0
- package/lib/components/MenuBar.js +697 -0
- package/lib/components/MenuBar.js.map +1 -0
- package/lib/components/TiptapContainer.js +234 -0
- package/lib/components/TiptapContainer.js.map +1 -0
- package/lib/components/characters/characterUtils.js +378 -0
- package/lib/components/characters/characterUtils.js.map +1 -0
- package/lib/components/characters/custom-popper.js +44 -0
- package/lib/components/characters/custom-popper.js.map +1 -0
- package/lib/components/common/done-button.js +34 -0
- package/lib/components/common/done-button.js.map +1 -0
- package/lib/components/common/toolbar-buttons.js +144 -0
- package/lib/components/common/toolbar-buttons.js.map +1 -0
- package/lib/components/icons/CssIcon.js +25 -0
- package/lib/components/icons/CssIcon.js.map +1 -0
- package/lib/components/icons/RespArea.js +72 -0
- package/lib/components/icons/RespArea.js.map +1 -0
- package/lib/components/icons/TableIcons.js +53 -0
- package/lib/components/icons/TableIcons.js.map +1 -0
- package/lib/components/icons/TextAlign.js +157 -0
- package/lib/components/icons/TextAlign.js.map +1 -0
- package/lib/components/image/AltDialog.js +98 -0
- package/lib/components/image/AltDialog.js.map +1 -0
- package/lib/components/image/ImageToolbar.js +137 -0
- package/lib/components/image/ImageToolbar.js.map +1 -0
- package/lib/components/image/InsertImageHandler.js +135 -0
- package/lib/components/image/InsertImageHandler.js.map +1 -0
- package/lib/components/media/MediaDialog.js +594 -0
- package/lib/components/media/MediaDialog.js.map +1 -0
- package/lib/components/media/MediaToolbar.js +74 -0
- package/lib/components/media/MediaToolbar.js.map +1 -0
- package/lib/components/media/MediaWrapper.js +67 -0
- package/lib/components/media/MediaWrapper.js.map +1 -0
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +84 -0
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -0
- package/lib/components/respArea/DragInTheBlank/choice.js +250 -0
- package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -0
- package/lib/components/respArea/ExplicitConstructedResponse.js +137 -0
- package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -0
- package/lib/components/respArea/InlineDropdown.js +210 -0
- package/lib/components/respArea/InlineDropdown.js.map +1 -0
- package/lib/components/respArea/MathTemplated.js +130 -0
- package/lib/components/respArea/MathTemplated.js.map +1 -0
- package/lib/components/respArea/ToolbarIcon.js +81 -0
- package/lib/components/respArea/ToolbarIcon.js.map +1 -0
- package/lib/components/respArea/inlineDropdownUtils.js +67 -0
- package/lib/components/respArea/inlineDropdownUtils.js.map +1 -0
- package/lib/constants.js +11 -0
- package/lib/constants.js.map +1 -0
- package/lib/extensions/css.js +217 -0
- package/lib/extensions/css.js.map +1 -0
- package/lib/extensions/custom-toolbar-wrapper.js +92 -0
- package/lib/extensions/custom-toolbar-wrapper.js.map +1 -0
- package/lib/extensions/div-node.js +83 -0
- package/lib/extensions/div-node.js.map +1 -0
- package/lib/extensions/ensure-empty-root-div.js +48 -0
- package/lib/extensions/ensure-empty-root-div.js.map +1 -0
- package/lib/extensions/ensure-list-item-content-is-div.js +64 -0
- package/lib/extensions/ensure-list-item-content-is-div.js.map +1 -0
- package/lib/extensions/extended-list-item.js +15 -0
- package/lib/extensions/extended-list-item.js.map +1 -0
- package/lib/extensions/extended-table-cell.js +22 -0
- package/lib/extensions/extended-table-cell.js.map +1 -0
- package/lib/extensions/extended-table.js +75 -0
- package/lib/extensions/extended-table.js.map +1 -0
- package/lib/extensions/heading-paragraph.js +61 -0
- package/lib/extensions/heading-paragraph.js.map +1 -0
- package/lib/extensions/image-component.js +348 -0
- package/lib/extensions/image-component.js.map +1 -0
- package/lib/extensions/image.js +134 -0
- package/lib/extensions/image.js.map +1 -0
- package/lib/extensions/index.js +46 -0
- package/lib/extensions/index.js.map +1 -0
- package/lib/extensions/math.js +342 -0
- package/lib/extensions/math.js.map +1 -0
- package/lib/extensions/media.js +243 -0
- package/lib/extensions/media.js.map +1 -0
- package/lib/extensions/responseArea.js +446 -0
- package/lib/extensions/responseArea.js.map +1 -0
- package/lib/index.js +37 -0
- package/lib/index.js.map +1 -0
- package/lib/styles/editorContainerStyles.js +137 -0
- package/lib/styles/editorContainerStyles.js.map +1 -0
- package/lib/theme.js +8 -0
- package/lib/theme.js.map +1 -0
- package/lib/utils/helper.js +73 -0
- package/lib/utils/helper.js.map +1 -0
- package/lib/utils/size.js +26 -0
- package/lib/utils/size.js.map +1 -0
- package/lib/utils/toolbar.js +19 -0
- package/lib/utils/toolbar.js.map +1 -0
- package/package.json +24 -40
- package/src/__tests__/EditableHtml.test.jsx +554 -0
- package/src/__tests__/constants.test.js +19 -0
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +125 -0
- package/src/__tests__/extensions.test.js +208 -0
- package/src/__tests__/index.test.jsx +154 -0
- package/src/__tests__/size-utils.test.js +64 -0
- package/src/__tests__/theme.test.js +17 -0
- package/src/components/CharacterPicker.jsx +207 -0
- package/src/components/EditableHtml.jsx +440 -0
- package/src/components/MenuBar.jsx +556 -0
- package/src/components/TiptapContainer.jsx +219 -0
- package/src/components/__tests__/AltDialog.test.jsx +147 -0
- package/src/components/__tests__/CharacterPicker.test.jsx +261 -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 +209 -0
- package/src/components/__tests__/ImageToolbar.test.jsx +128 -0
- package/src/components/__tests__/InlineDropdown.test.jsx +393 -0
- package/src/components/__tests__/InsertImageHandler.test.js +161 -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 +250 -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/components/characters/characterUtils.js +447 -0
- package/src/components/characters/custom-popper.js +38 -0
- package/src/components/common/done-button.jsx +27 -0
- package/src/components/common/toolbar-buttons.jsx +122 -0
- package/src/components/icons/CssIcon.jsx +15 -0
- package/src/components/icons/RespArea.jsx +71 -0
- package/src/components/icons/TableIcons.jsx +52 -0
- package/src/components/icons/TextAlign.jsx +114 -0
- package/src/components/image/AltDialog.jsx +82 -0
- package/src/components/image/ImageToolbar.jsx +99 -0
- package/src/components/image/InsertImageHandler.js +107 -0
- package/src/components/media/MediaDialog.jsx +596 -0
- package/src/components/media/MediaToolbar.jsx +49 -0
- package/src/components/media/MediaWrapper.jsx +39 -0
- package/src/components/respArea/DragInTheBlank/DragInTheBlank.jsx +76 -0
- package/src/components/respArea/DragInTheBlank/choice.jsx +256 -0
- package/src/components/respArea/ExplicitConstructedResponse.jsx +136 -0
- package/src/components/respArea/InlineDropdown.jsx +221 -0
- package/src/components/respArea/MathTemplated.jsx +124 -0
- package/src/components/respArea/ToolbarIcon.jsx +66 -0
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +210 -0
- package/src/components/respArea/inlineDropdownUtils.js +79 -0
- package/src/constants.js +5 -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__/divNode.test.js +87 -0
- package/src/extensions/__tests__/ensure-empty-root-div.test.js +57 -0
- package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +44 -0
- package/src/extensions/__tests__/extended-list-item.test.js +13 -0
- package/src/extensions/__tests__/extended-table-cell.test.js +22 -0
- package/src/extensions/__tests__/extended-table.test.js +183 -0
- package/src/extensions/__tests__/image-component.test.jsx +345 -0
- package/src/extensions/__tests__/image.test.js +237 -0
- package/src/extensions/__tests__/math.test.js +604 -0
- package/src/extensions/__tests__/media-node-view.test.jsx +298 -0
- package/src/extensions/__tests__/media.test.js +271 -0
- package/src/extensions/__tests__/responseArea.test.js +601 -0
- package/src/extensions/css.js +220 -0
- package/src/extensions/custom-toolbar-wrapper.jsx +78 -0
- package/src/extensions/div-node.js +86 -0
- package/src/extensions/ensure-empty-root-div.js +47 -0
- package/src/extensions/ensure-list-item-content-is-div.js +62 -0
- package/src/extensions/extended-list-item.js +10 -0
- package/src/extensions/extended-table-cell.js +19 -0
- package/src/extensions/extended-table.js +60 -0
- package/src/extensions/heading-paragraph.js +53 -0
- package/src/extensions/image-component.jsx +338 -0
- package/src/extensions/image.js +109 -0
- package/src/extensions/index.js +81 -0
- package/src/extensions/math.js +325 -0
- package/src/extensions/media.js +188 -0
- package/src/extensions/responseArea.js +401 -0
- package/src/index.jsx +5 -0
- package/src/styles/editorContainerStyles.js +145 -0
- package/src/theme.js +1 -0
- package/src/utils/__tests__/helper.test.js +126 -0
- package/src/utils/__tests__/toolbar.test.js +43 -0
- package/src/utils/helper.js +69 -0
- package/src/utils/size.js +32 -0
- package/src/utils/toolbar.js +15 -0
- package/dist/components/CharacterPicker.d.ts +0 -31
- package/dist/components/CharacterPicker.js +0 -131
- package/dist/components/EditableHtml.d.ts +0 -11
- package/dist/components/EditableHtml.js +0 -291
- package/dist/components/MenuBar.d.ts +0 -11
- package/dist/components/MenuBar.js +0 -462
- package/dist/components/TiptapContainer.d.ts +0 -11
- package/dist/components/TiptapContainer.js +0 -154
- package/dist/components/characters/characterUtils.d.ts +0 -35
- package/dist/components/characters/characterUtils.js +0 -465
- package/dist/components/characters/custom-popper.d.ts +0 -14
- package/dist/components/characters/custom-popper.js +0 -32
- package/dist/components/common/done-button.d.ts +0 -30
- package/dist/components/common/done-button.js +0 -26
- package/dist/components/common/toolbar-buttons.d.ts +0 -38
- package/dist/components/common/toolbar-buttons.js +0 -91
- package/dist/components/icons/CssIcon.d.ts +0 -11
- package/dist/components/icons/CssIcon.js +0 -14
- package/dist/components/icons/RespArea.d.ts +0 -26
- package/dist/components/icons/RespArea.js +0 -42
- package/dist/components/icons/TableIcons.d.ts +0 -14
- package/dist/components/icons/TableIcons.js +0 -32
- package/dist/components/icons/TextAlign.d.ts +0 -18
- package/dist/components/icons/TextAlign.js +0 -134
- package/dist/components/image/AltDialog.d.ts +0 -22
- package/dist/components/image/AltDialog.js +0 -61
- package/dist/components/image/ImageToolbar.d.ts +0 -24
- package/dist/components/image/ImageToolbar.js +0 -80
- package/dist/components/image/InsertImageHandler.d.ts +0 -32
- package/dist/components/image/InsertImageHandler.js +0 -53
- package/dist/components/media/MediaDialog.d.ts +0 -43
- package/dist/components/media/MediaDialog.js +0 -389
- package/dist/components/media/MediaToolbar.d.ts +0 -19
- package/dist/components/media/MediaToolbar.js +0 -41
- package/dist/components/media/MediaWrapper.d.ts +0 -19
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +0 -23
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +0 -58
- package/dist/components/respArea/DragInTheBlank/choice.d.ts +0 -56
- package/dist/components/respArea/DragInTheBlank/choice.js +0 -156
- package/dist/components/respArea/ExplicitConstructedResponse.d.ts +0 -20
- package/dist/components/respArea/ExplicitConstructedResponse.js +0 -83
- package/dist/components/respArea/InlineDropdown.d.ts +0 -18
- package/dist/components/respArea/InlineDropdown.js +0 -119
- package/dist/components/respArea/MathTemplated.d.ts +0 -19
- package/dist/components/respArea/MathTemplated.js +0 -97
- package/dist/components/respArea/ToolbarIcon.d.ts +0 -14
- package/dist/components/respArea/ToolbarIcon.js +0 -17
- package/dist/components/respArea/inlineDropdownUtils.d.ts +0 -15
- package/dist/components/respArea/inlineDropdownUtils.js +0 -15
- package/dist/constants.d.ts +0 -13
- package/dist/constants.js +0 -4
- package/dist/extensions/css.d.ts +0 -11
- package/dist/extensions/css.js +0 -115
- package/dist/extensions/custom-toolbar-wrapper.d.ts +0 -11
- package/dist/extensions/custom-toolbar-wrapper.js +0 -61
- package/dist/extensions/div-node.d.ts +0 -10
- package/dist/extensions/div-node.js +0 -42
- package/dist/extensions/ensure-empty-root-div.d.ts +0 -14
- package/dist/extensions/ensure-empty-root-div.js +0 -24
- package/dist/extensions/ensure-list-item-content-is-div.d.ts +0 -15
- package/dist/extensions/ensure-list-item-content-is-div.js +0 -31
- package/dist/extensions/extended-list-item.d.ts +0 -13
- package/dist/extensions/extended-list-item.js +0 -5
- package/dist/extensions/extended-table-cell.d.ts +0 -10
- package/dist/extensions/extended-table-cell.js +0 -6
- package/dist/extensions/extended-table.d.ts +0 -17
- package/dist/extensions/extended-table.js +0 -34
- package/dist/extensions/heading-paragraph.d.ts +0 -17
- package/dist/extensions/heading-paragraph.js +0 -30
- package/dist/extensions/image-component.d.ts +0 -22
- package/dist/extensions/image-component.js +0 -220
- package/dist/extensions/image.d.ts +0 -10
- package/dist/extensions/image.js +0 -68
- package/dist/extensions/index.d.ts +0 -16
- package/dist/extensions/index.js +0 -64
- package/dist/extensions/math.d.ts +0 -15
- package/dist/extensions/math.js +0 -158
- package/dist/extensions/media.d.ts +0 -19
- package/dist/extensions/media.js +0 -149
- package/dist/extensions/responseArea.d.ts +0 -27
- package/dist/extensions/responseArea.js +0 -259
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -7
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +0 -16
- package/dist/styles/editorContainerStyles.d.ts +0 -134
- package/dist/theme.d.ts +0 -9
- package/dist/utils/helper.d.ts +0 -9
- package/dist/utils/helper.js +0 -27
- package/dist/utils/size.d.ts +0 -9
- package/dist/utils/size.js +0 -14
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState, useRef } from 'react';
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
|
+
import { color } from '@pie-lib/render-ui';
|
|
4
|
+
import { valueToSize } from '../utils/size';
|
|
5
|
+
|
|
6
|
+
import StyledMenuBar from './MenuBar';
|
|
7
|
+
|
|
8
|
+
const StyledRoot = styled('div', {
|
|
9
|
+
shouldForwardProp: (prop) => !['noBorder', 'error'].includes(prop),
|
|
10
|
+
})(({ theme, noBorder, error }) => ({
|
|
11
|
+
position: 'relative',
|
|
12
|
+
padding: '0px',
|
|
13
|
+
border: noBorder ? 'none' : '1px solid #ccc',
|
|
14
|
+
borderRadius: '4px',
|
|
15
|
+
cursor: 'text',
|
|
16
|
+
'& [data-slate-editor="true"]': {
|
|
17
|
+
wordBreak: 'break-word',
|
|
18
|
+
overflow: 'visible',
|
|
19
|
+
maxHeight: '500px',
|
|
20
|
+
padding: '5px',
|
|
21
|
+
},
|
|
22
|
+
'&:first-child': {
|
|
23
|
+
marginTop: 0,
|
|
24
|
+
},
|
|
25
|
+
'& ul, & ol': {
|
|
26
|
+
padding: '0 1rem',
|
|
27
|
+
margin: '1.25rem 1rem 1.25rem 0.4rem',
|
|
28
|
+
},
|
|
29
|
+
'& ul li p, & ol li p': {
|
|
30
|
+
marginTop: '0.25em',
|
|
31
|
+
marginBottom: '0.25em',
|
|
32
|
+
},
|
|
33
|
+
'& h1, & h2, & h3, & h4, & h5, & h6': {
|
|
34
|
+
lineHeight: 1.1,
|
|
35
|
+
marginTop: '2.5rem',
|
|
36
|
+
textWrap: 'pretty',
|
|
37
|
+
},
|
|
38
|
+
'& h1, & h2': {
|
|
39
|
+
marginTop: '3.5rem',
|
|
40
|
+
marginBottom: '1.5rem',
|
|
41
|
+
},
|
|
42
|
+
'& h1': {
|
|
43
|
+
fontSize: '1.4rem',
|
|
44
|
+
},
|
|
45
|
+
'& h2': {
|
|
46
|
+
fontSize: '1.2rem',
|
|
47
|
+
},
|
|
48
|
+
'& h3': {
|
|
49
|
+
fontSize: '1.1rem',
|
|
50
|
+
},
|
|
51
|
+
'& h4, & h5, & h6': {
|
|
52
|
+
fontSize: '1rem',
|
|
53
|
+
},
|
|
54
|
+
'& code': {
|
|
55
|
+
backgroundColor: 'var(--purple-light)',
|
|
56
|
+
borderRadius: '0.4rem',
|
|
57
|
+
color: 'var(--black)',
|
|
58
|
+
fontSize: '0.85rem',
|
|
59
|
+
padding: '0.25em 0.3em',
|
|
60
|
+
},
|
|
61
|
+
'& pre': {
|
|
62
|
+
background: 'var(--black)',
|
|
63
|
+
borderRadius: '0.5rem',
|
|
64
|
+
color: 'var(--white)',
|
|
65
|
+
fontFamily: '\'JetBrainsMono\', monospace',
|
|
66
|
+
margin: '1.5rem 0',
|
|
67
|
+
padding: '0.75rem 1rem',
|
|
68
|
+
'& code': {
|
|
69
|
+
background: 'none',
|
|
70
|
+
color: 'inherit',
|
|
71
|
+
fontSize: '0.8rem',
|
|
72
|
+
padding: 0,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
'& blockquote': {
|
|
76
|
+
background: '#f9f9f9',
|
|
77
|
+
borderLeft: '5px solid #ccc',
|
|
78
|
+
margin: '1.5em 10px',
|
|
79
|
+
padding: '.5em 10px',
|
|
80
|
+
},
|
|
81
|
+
'& p': {
|
|
82
|
+
margin: '0',
|
|
83
|
+
},
|
|
84
|
+
'& table': {
|
|
85
|
+
tableLayout: 'fixed',
|
|
86
|
+
width: '100%',
|
|
87
|
+
borderCollapse: 'collapse',
|
|
88
|
+
color: color.text(),
|
|
89
|
+
backgroundColor: color.background(),
|
|
90
|
+
},
|
|
91
|
+
'& table:not([border="1"]) tr': {
|
|
92
|
+
borderTop: '1px solid #dfe2e5',
|
|
93
|
+
},
|
|
94
|
+
'& td, th': {
|
|
95
|
+
padding: '.6em 1em',
|
|
96
|
+
textAlign: 'center',
|
|
97
|
+
},
|
|
98
|
+
'& table:not([border="1"]) td, th': {
|
|
99
|
+
border: '1px solid #dfe2e5',
|
|
100
|
+
},
|
|
101
|
+
...(error && {
|
|
102
|
+
border: `2px solid ${theme.palette.error.main} !important`,
|
|
103
|
+
}),
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
const StyledEditorHolder = styled('div', {
|
|
107
|
+
shouldForwardProp: (prop) => !['disableScrollbar', 'highlightShape'].includes(prop),
|
|
108
|
+
})(({ theme, disableScrollbar, highlightShape }) => ({
|
|
109
|
+
position: 'relative',
|
|
110
|
+
padding: '0px',
|
|
111
|
+
overflowY: 'auto',
|
|
112
|
+
color: color.text(),
|
|
113
|
+
backgroundColor: highlightShape ? theme.palette.action.selected : color.background(),
|
|
114
|
+
...(disableScrollbar && {
|
|
115
|
+
'&::-webkit-scrollbar': {
|
|
116
|
+
display: 'none',
|
|
117
|
+
},
|
|
118
|
+
scrollbarWidth: 'none',
|
|
119
|
+
'-ms-overflow-style': 'none',
|
|
120
|
+
}),
|
|
121
|
+
}));
|
|
122
|
+
|
|
123
|
+
const StyledChildren = styled('div', {
|
|
124
|
+
shouldForwardProp: (prop) => prop !== 'noPadding',
|
|
125
|
+
})(({ noPadding }) => ({
|
|
126
|
+
padding: noPadding ? 0 : '10px 8px',
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
function TiptapContainer(props) {
|
|
130
|
+
const [adjustedWidth, setAdjustedWidth] = useState(null);
|
|
131
|
+
const rootRef = useRef(null);
|
|
132
|
+
const {
|
|
133
|
+
editor,
|
|
134
|
+
disabled,
|
|
135
|
+
children,
|
|
136
|
+
disableScrollbar,
|
|
137
|
+
activePlugins,
|
|
138
|
+
toolbarOpts,
|
|
139
|
+
responseAreaProps,
|
|
140
|
+
autoFocus,
|
|
141
|
+
minWidth,
|
|
142
|
+
width,
|
|
143
|
+
maxWidth,
|
|
144
|
+
minHeight,
|
|
145
|
+
height,
|
|
146
|
+
maxHeight,
|
|
147
|
+
highlightShape,
|
|
148
|
+
ref,
|
|
149
|
+
} = props;
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (editor && rootRef.current) {
|
|
153
|
+
editor._tiptapContainerEl = rootRef.current;
|
|
154
|
+
}
|
|
155
|
+
}, [editor, rootRef.current]);
|
|
156
|
+
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (editor && autoFocus) {
|
|
159
|
+
Promise.resolve().then(() => {
|
|
160
|
+
editor.commands.focus('end');
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}, [editor, autoFocus]);
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (props.adjustWidthForLimit) {
|
|
167
|
+
const el = document.createElement('p');
|
|
168
|
+
|
|
169
|
+
el.style.visibility = 'hidden';
|
|
170
|
+
el.style.position = 'absolute';
|
|
171
|
+
el.textContent = 'W'.repeat(props.charactersLimit);
|
|
172
|
+
|
|
173
|
+
rootRef.current.appendChild(el);
|
|
174
|
+
|
|
175
|
+
setAdjustedWidth(`${el.offsetWidth + 27}px`);
|
|
176
|
+
|
|
177
|
+
el.remove();
|
|
178
|
+
}
|
|
179
|
+
}, [props.adjustWidthForLimit, props.charactersLimit]);
|
|
180
|
+
|
|
181
|
+
const sizeStyle = useMemo(
|
|
182
|
+
() => ({
|
|
183
|
+
width: valueToSize(adjustedWidth || width),
|
|
184
|
+
minWidth: valueToSize(minWidth),
|
|
185
|
+
maxWidth: valueToSize(maxWidth),
|
|
186
|
+
height: valueToSize(height),
|
|
187
|
+
minHeight: valueToSize(minHeight),
|
|
188
|
+
maxHeight: valueToSize(maxHeight),
|
|
189
|
+
}),
|
|
190
|
+
[adjustedWidth, minWidth, width, maxWidth, minHeight, height, maxHeight],
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<StyledRoot
|
|
195
|
+
noBorder={toolbarOpts && toolbarOpts.noBorder}
|
|
196
|
+
error={toolbarOpts && toolbarOpts.error}
|
|
197
|
+
className={props.className}
|
|
198
|
+
style={{ width: sizeStyle.width, minWidth: sizeStyle.minWidth, maxWidth: sizeStyle.maxWidth }}
|
|
199
|
+
ref={rootRef}
|
|
200
|
+
>
|
|
201
|
+
<StyledEditorHolder disableScrollbar={disableScrollbar} highlightShape={highlightShape}>
|
|
202
|
+
<StyledChildren noPadding={toolbarOpts && toolbarOpts.noPadding}>{children}</StyledChildren>
|
|
203
|
+
</StyledEditorHolder>
|
|
204
|
+
|
|
205
|
+
{editor && (
|
|
206
|
+
<StyledMenuBar
|
|
207
|
+
editor={editor}
|
|
208
|
+
responseAreaProps={responseAreaProps}
|
|
209
|
+
toolbarOpts={toolbarOpts}
|
|
210
|
+
activePlugins={activePlugins}
|
|
211
|
+
onChange={props.onChange}
|
|
212
|
+
autoWidthToolbar={props.autoWidthToolbar}
|
|
213
|
+
/>
|
|
214
|
+
)}
|
|
215
|
+
</StyledRoot>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export default TiptapContainer;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render } 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,261 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { act, fireEvent, render, waitFor } from '@testing-library/react';
|
|
3
|
+
import { CharacterIcon, CharacterPicker } 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 act(async () => {
|
|
132
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
133
|
+
});
|
|
134
|
+
fireEvent.click(document.body);
|
|
135
|
+
|
|
136
|
+
await waitFor(() => {
|
|
137
|
+
expect(onClose).toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('does not re-run positioning when only onClose reference changes', async () => {
|
|
142
|
+
const opts = {
|
|
143
|
+
characters: [['á', 'é']],
|
|
144
|
+
};
|
|
145
|
+
const getRect = mockEditor.options.element.getBoundingClientRect;
|
|
146
|
+
const { rerender } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
147
|
+
|
|
148
|
+
await act(async () => {
|
|
149
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const callsAfterMount = getRect.mock.calls.length;
|
|
153
|
+
expect(callsAfterMount).toBeGreaterThan(0);
|
|
154
|
+
|
|
155
|
+
rerender(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
156
|
+
|
|
157
|
+
expect(getRect.mock.calls.length).toBe(callsAfterMount);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('outside click invokes the latest onClose after rerender', async () => {
|
|
161
|
+
const opts = {
|
|
162
|
+
characters: [['á', 'é']],
|
|
163
|
+
};
|
|
164
|
+
const onCloseFirst = jest.fn();
|
|
165
|
+
const { rerender } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={onCloseFirst} />);
|
|
166
|
+
|
|
167
|
+
await act(async () => {
|
|
168
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const onCloseSecond = jest.fn();
|
|
172
|
+
rerender(<CharacterPicker editor={mockEditor} opts={opts} onClose={onCloseSecond} />);
|
|
173
|
+
|
|
174
|
+
fireEvent.click(document.body);
|
|
175
|
+
|
|
176
|
+
await waitFor(() => {
|
|
177
|
+
expect(onCloseSecond).toHaveBeenCalled();
|
|
178
|
+
});
|
|
179
|
+
expect(onCloseFirst).not.toHaveBeenCalled();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('does not close when clicking inside picker', async () => {
|
|
183
|
+
const onClose = jest.fn();
|
|
184
|
+
const opts = {
|
|
185
|
+
characters: [['á', 'é']],
|
|
186
|
+
};
|
|
187
|
+
const { container } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={onClose} />);
|
|
188
|
+
|
|
189
|
+
await waitFor(() => {
|
|
190
|
+
const picker = container.querySelector('.insert-character-dialog');
|
|
191
|
+
if (picker) {
|
|
192
|
+
fireEvent.mouseDown(picker);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('renders with custom opts structure', () => {
|
|
200
|
+
const opts = {
|
|
201
|
+
characters: [
|
|
202
|
+
[
|
|
203
|
+
{ name: 'a', write: 'á', label: 'á' },
|
|
204
|
+
{ name: 'e', write: 'é', label: 'é' },
|
|
205
|
+
],
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
const { getByTestId } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
209
|
+
expect(getByTestId('pure-toolbar')).toBeInTheDocument();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('renders with hasPreview option', () => {
|
|
213
|
+
const opts = {
|
|
214
|
+
hasPreview: true,
|
|
215
|
+
characters: [
|
|
216
|
+
[
|
|
217
|
+
{
|
|
218
|
+
name: 'euro',
|
|
219
|
+
write: '€',
|
|
220
|
+
label: '€',
|
|
221
|
+
description: 'Euro sign',
|
|
222
|
+
unicode: 'U+20AC',
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
],
|
|
226
|
+
};
|
|
227
|
+
const { getByTestId } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
228
|
+
expect(getByTestId('pure-toolbar')).toBeInTheDocument();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('calculates position correctly', () => {
|
|
232
|
+
const opts = {
|
|
233
|
+
characters: [['á']],
|
|
234
|
+
};
|
|
235
|
+
const { container } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
236
|
+
const dialog = container.querySelector('.insert-character-dialog');
|
|
237
|
+
expect(dialog).toHaveStyle({ position: 'absolute' });
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('adds data-toolbar-for attribute with editor instanceId', () => {
|
|
241
|
+
const editorWithInstanceId = {
|
|
242
|
+
...mockEditor,
|
|
243
|
+
instanceId: 'editor-123',
|
|
244
|
+
};
|
|
245
|
+
const opts = {
|
|
246
|
+
characters: [['á', 'é']],
|
|
247
|
+
};
|
|
248
|
+
const { container } = render(<CharacterPicker editor={editorWithInstanceId} opts={opts} onClose={jest.fn()} />);
|
|
249
|
+
const dialog = container.querySelector('.insert-character-dialog');
|
|
250
|
+
expect(dialog).toHaveAttribute('data-toolbar-for', 'editor-123');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('renders without instanceId gracefully', () => {
|
|
254
|
+
const opts = {
|
|
255
|
+
characters: [['á', 'é']],
|
|
256
|
+
};
|
|
257
|
+
const { container } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
258
|
+
const dialog = container.querySelector('.insert-character-dialog');
|
|
259
|
+
expect(dialog).toBeInTheDocument();
|
|
260
|
+
});
|
|
261
|
+
});
|
|
@@ -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
|
+
});
|