@pie-lib/editable-html 13.0.13 → 13.0.14-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -50
- package/lib/editor.js +3 -3
- package/lib/editor.js.map +1 -1
- package/lib/plugins/respArea/math-templated/index.js +2 -2
- package/lib/plugins/respArea/math-templated/index.js.map +1 -1
- package/lib/shared/alert-dialog.js +68 -0
- package/package.json +7 -7
- package/src/editor.jsx +2 -2
- package/src/plugins/respArea/math-templated/index.jsx +1 -1
- package/LICENSE.md +0 -5
- package/src/__tests__/editor-utils.test.js +0 -162
- package/src/__tests__/serialization.test.js +0 -290
- package/src/__tests__/utils.js +0 -36
- package/src/plugins/image/__tests__/component.test.jsx +0 -73
- package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +0 -90
- package/src/plugins/image/__tests__/image-toolbar.test.jsx +0 -12
- package/src/plugins/image/__tests__/index.test.js +0 -92
- package/src/plugins/image/__tests__/insert-image-handler.test.js +0 -113
- package/src/plugins/image/__tests__/mock-change.js +0 -15
- package/src/plugins/list/__tests__/index.test.js +0 -52
- package/src/plugins/math/__tests__/index.test.jsx +0 -264
- package/src/plugins/media/__tests__/index.test.js +0 -75
- package/src/plugins/respArea/drag-in-the-blank/__tests__/choice.test.js +0 -71
- package/src/plugins/table/__tests__/index.test.jsx +0 -401
- package/src/plugins/table/__tests__/table-toolbar.test.jsx +0 -75
- package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +0 -123
- package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +0 -40
- package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +0 -97
- package/src/plugins/toolbar/__tests__/toolbar.test.jsx +0 -112
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import { Value } from 'slate';
|
|
4
|
-
import { DefaultToolbar } from '../default-toolbar';
|
|
5
|
-
|
|
6
|
-
// Mock the DoneButton component directly to avoid styled component issues
|
|
7
|
-
jest.mock('../done-button', () => ({
|
|
8
|
-
DoneButton: (props) => (
|
|
9
|
-
<button aria-label="Done" onClick={props.onClick} data-testid="done-button">
|
|
10
|
-
Done
|
|
11
|
-
</button>
|
|
12
|
-
),
|
|
13
|
-
RawDoneButton: (props) => (
|
|
14
|
-
<button aria-label="Done" onClick={props.onClick} className="RawDoneButton">
|
|
15
|
-
Done
|
|
16
|
-
</button>
|
|
17
|
-
),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
describe('default-toolbar', () => {
|
|
21
|
-
let onDone;
|
|
22
|
-
let onChange;
|
|
23
|
-
let getFocusedValue;
|
|
24
|
-
let defaultProps;
|
|
25
|
-
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
onDone = jest.fn();
|
|
28
|
-
onChange = jest.fn();
|
|
29
|
-
getFocusedValue = jest.fn();
|
|
30
|
-
|
|
31
|
-
defaultProps = {
|
|
32
|
-
classes: {},
|
|
33
|
-
value: Value.fromJSON({}),
|
|
34
|
-
plugins: [],
|
|
35
|
-
className: 'className',
|
|
36
|
-
onDone,
|
|
37
|
-
onChange,
|
|
38
|
-
getFocusedValue,
|
|
39
|
-
deletable: false,
|
|
40
|
-
showDone: true,
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('rendering', () => {
|
|
45
|
-
it('renders toolbar', () => {
|
|
46
|
-
const { container } = render(<DefaultToolbar {...defaultProps} deletable={false} />);
|
|
47
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('renders with 1 plugin', () => {
|
|
51
|
-
const { container } = render(
|
|
52
|
-
<DefaultToolbar {...defaultProps} plugins={[{ toolbar: { icon: <span>Icon1</span> }, name: 'plugin-one' }]} />,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
56
|
-
// Should render plugin toolbar button
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('renders with 2 plugins', () => {
|
|
60
|
-
const { container } = render(
|
|
61
|
-
<DefaultToolbar
|
|
62
|
-
{...defaultProps}
|
|
63
|
-
plugins={[
|
|
64
|
-
{ toolbar: { icon: <span>Icon1</span> }, name: 'plugin-one' },
|
|
65
|
-
{ toolbar: { icon: <span>Icon2</span> }, name: 'plugin-two' },
|
|
66
|
-
]}
|
|
67
|
-
/>,
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
71
|
-
// Should render both plugin toolbar buttons
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('renders only enabled plugins when one is disabled', () => {
|
|
75
|
-
const { container } = render(
|
|
76
|
-
<DefaultToolbar
|
|
77
|
-
{...defaultProps}
|
|
78
|
-
pluginProps={{
|
|
79
|
-
'plugin-one': {
|
|
80
|
-
disabled: true,
|
|
81
|
-
},
|
|
82
|
-
}}
|
|
83
|
-
plugins={[
|
|
84
|
-
{ toolbar: { icon: <span>Icon1</span> }, name: 'plugin-one' },
|
|
85
|
-
{ toolbar: { icon: <span>Icon2</span> }, name: 'plugin-two' },
|
|
86
|
-
]}
|
|
87
|
-
/>,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
91
|
-
// Only plugin-two should be rendered (plugin-one is disabled)
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('renders done button when not deletable', () => {
|
|
95
|
-
render(<DefaultToolbar {...defaultProps} deletable={false} />);
|
|
96
|
-
|
|
97
|
-
expect(screen.getByLabelText('Done')).toBeInTheDocument();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('does not render done button when deletable', () => {
|
|
101
|
-
render(<DefaultToolbar {...defaultProps} deletable={true} />);
|
|
102
|
-
|
|
103
|
-
expect(screen.queryByLabelText('Done')).not.toBeInTheDocument();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('does not render done button when showDone is false', () => {
|
|
107
|
-
render(<DefaultToolbar {...defaultProps} showDone={false} deletable={false} />);
|
|
108
|
-
|
|
109
|
-
expect(screen.queryByLabelText('Done')).not.toBeInTheDocument();
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('interactions', () => {
|
|
114
|
-
it('calls onDone when done button is clicked', async () => {
|
|
115
|
-
render(<DefaultToolbar {...defaultProps} deletable={false} />);
|
|
116
|
-
|
|
117
|
-
const doneButton = screen.getByLabelText('Done');
|
|
118
|
-
fireEvent.click(doneButton);
|
|
119
|
-
|
|
120
|
-
expect(onDone).toHaveBeenCalled();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { classObject, mockIconButton } from '../../../__tests__/utils';
|
|
2
|
-
|
|
3
|
-
import { Value } from 'slate';
|
|
4
|
-
import { EditorAndToolbar } from '../editor-and-toolbar';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import debug from 'debug';
|
|
7
|
-
import { render, screen } from '@testing-library/react';
|
|
8
|
-
|
|
9
|
-
jest.mock('../toolbar', () => () => <div>---- toolbar ------ </div>);
|
|
10
|
-
|
|
11
|
-
mockIconButton();
|
|
12
|
-
|
|
13
|
-
const log = debug('@pie-lib:editable-html:test:editor-and-toolbar');
|
|
14
|
-
|
|
15
|
-
describe('toolbar', () => {
|
|
16
|
-
let onDelete, classes;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
onDelete = jest.fn();
|
|
20
|
-
classes = classObject('root', 'editorHolder', 'editorInFocus');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('renders EditorAndToolbar component', () => {
|
|
24
|
-
const value = Value.fromJSON({});
|
|
25
|
-
Object.defineProperty(value, 'isFocused', { get: jest.fn(() => true) });
|
|
26
|
-
|
|
27
|
-
const { container } = render(
|
|
28
|
-
<EditorAndToolbar classes={classes} value={value} plugins={[]} onDone={jest.fn()} onChange={jest.fn()}>
|
|
29
|
-
children
|
|
30
|
-
</EditorAndToolbar>,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
// Verify component rendered
|
|
34
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
35
|
-
// Verify toolbar is present
|
|
36
|
-
expect(screen.getByText('---- toolbar ------')).toBeInTheDocument();
|
|
37
|
-
// Verify children are rendered
|
|
38
|
-
expect(screen.getByText('children')).toBeInTheDocument();
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { classObject } from '../../../__tests__/utils';
|
|
2
|
-
import { RawButton, RawMarkButton } from '../toolbar-buttons';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { render, screen } from '@testing-library/react';
|
|
5
|
-
import userEvent from '@testing-library/user-event';
|
|
6
|
-
|
|
7
|
-
// Mock IconButton
|
|
8
|
-
jest.mock('@mui/material/IconButton', () => {
|
|
9
|
-
return function IconButton({ children, onClick, className }) {
|
|
10
|
-
return (
|
|
11
|
-
<button onClick={onClick} className={className} data-testid="icon-button">
|
|
12
|
-
{children}
|
|
13
|
-
</button>
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('Button', () => {
|
|
19
|
-
const onClick = jest.fn();
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
onClick.mockClear();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('renders with children', () => {
|
|
26
|
-
const classes = classObject('root');
|
|
27
|
-
render(
|
|
28
|
-
<RawButton onClick={onClick} classes={classes}>
|
|
29
|
-
children
|
|
30
|
-
</RawButton>,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
expect(screen.getByText('children')).toBeInTheDocument();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('calls onClick when clicked', async () => {
|
|
37
|
-
const user = userEvent.setup();
|
|
38
|
-
const classes = classObject('root');
|
|
39
|
-
render(
|
|
40
|
-
<RawButton onClick={onClick} classes={classes}>
|
|
41
|
-
children
|
|
42
|
-
</RawButton>,
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const button = screen.getByText('children');
|
|
46
|
-
await user.click(button);
|
|
47
|
-
|
|
48
|
-
expect(onClick).toHaveBeenCalled();
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('MarkButton', () => {
|
|
53
|
-
const classes = classObject('button', 'root', 'active');
|
|
54
|
-
const onToggle = jest.fn();
|
|
55
|
-
|
|
56
|
-
beforeEach(() => {
|
|
57
|
-
onToggle.mockClear();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('renders when not active', () => {
|
|
61
|
-
render(
|
|
62
|
-
<RawMarkButton mark={'i'} onToggle={onToggle} active={false} classes={classes}>
|
|
63
|
-
children
|
|
64
|
-
</RawMarkButton>,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const button = screen.getByText('children');
|
|
68
|
-
expect(button).toBeInTheDocument();
|
|
69
|
-
expect(button).toHaveAttribute('aria-pressed', 'false');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('renders when active', () => {
|
|
73
|
-
render(
|
|
74
|
-
<RawMarkButton mark={'i'} onToggle={onToggle} active={true} classes={classes}>
|
|
75
|
-
children
|
|
76
|
-
</RawMarkButton>,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const button = screen.getByText('children');
|
|
80
|
-
expect(button).toBeInTheDocument();
|
|
81
|
-
expect(button).toHaveAttribute('aria-pressed', 'true');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('calls onToggle when clicked', async () => {
|
|
85
|
-
const user = userEvent.setup();
|
|
86
|
-
render(
|
|
87
|
-
<RawMarkButton mark={'i'} onToggle={onToggle} active={false} classes={classes}>
|
|
88
|
-
children
|
|
89
|
-
</RawMarkButton>,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const button = screen.getByText('children');
|
|
93
|
-
await user.click(button);
|
|
94
|
-
|
|
95
|
-
expect(onToggle).toHaveBeenCalled();
|
|
96
|
-
});
|
|
97
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { classObject, mockMathInput } from '../../../__tests__/utils';
|
|
2
|
-
import { Inline, Value } from 'slate';
|
|
3
|
-
import { Toolbar } from '../toolbar';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { render, screen } from '@testing-library/react';
|
|
6
|
-
|
|
7
|
-
mockMathInput();
|
|
8
|
-
|
|
9
|
-
jest.mock('@mui/material/IconButton', () => {
|
|
10
|
-
return (props) => {
|
|
11
|
-
const { children, onClick, buttonRef, ...rest } = props;
|
|
12
|
-
return (
|
|
13
|
-
<button onClick={onClick} {...rest}>
|
|
14
|
-
{children}
|
|
15
|
-
</button>
|
|
16
|
-
);
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
let node = Inline.fromJSON({ type: 'i' });
|
|
21
|
-
let parentNode = Inline.fromJSON({
|
|
22
|
-
type: 'i',
|
|
23
|
-
});
|
|
24
|
-
let value;
|
|
25
|
-
|
|
26
|
-
describe('toolbar', () => {
|
|
27
|
-
let onDelete, classes, document, toolbarOpts;
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
onDelete = jest.fn();
|
|
31
|
-
|
|
32
|
-
toolbarOpts = {
|
|
33
|
-
position: 'bottom',
|
|
34
|
-
alwaysVisible: false,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
value = Value.fromJSON({});
|
|
38
|
-
document = {
|
|
39
|
-
getClosestInline: jest.fn().mockReturnValue(node),
|
|
40
|
-
getParent: jest.fn().mockReturnValue(),
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
Object.defineProperties(value, {
|
|
44
|
-
isCollapsed: {
|
|
45
|
-
get: jest.fn(() => true),
|
|
46
|
-
},
|
|
47
|
-
startKey: {
|
|
48
|
-
get: jest.fn(() => '1'),
|
|
49
|
-
},
|
|
50
|
-
document: {
|
|
51
|
-
get: jest.fn(() => document),
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
classes = classObject('iconRoot', 'inline', 'toolbar', 'focused', 'shared', 'inline', 'pie-toolbar');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('renders custom toolbar', () => {
|
|
59
|
-
const plugins = [
|
|
60
|
-
{
|
|
61
|
-
deleteNode: () => true,
|
|
62
|
-
toolbar: {
|
|
63
|
-
supports: () => true,
|
|
64
|
-
customToolbar: () => () => <div>custom toolbar content</div>,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
const { container } = render(
|
|
70
|
-
<Toolbar
|
|
71
|
-
toolbarOpts={toolbarOpts}
|
|
72
|
-
plugins={plugins}
|
|
73
|
-
classes={classes}
|
|
74
|
-
value={value}
|
|
75
|
-
onDone={jest.fn()}
|
|
76
|
-
onChange={jest.fn()}
|
|
77
|
-
/>,
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
// Verify the custom toolbar content is rendered
|
|
81
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
82
|
-
expect(screen.getByText('custom toolbar content')).toBeInTheDocument();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('default', () => {
|
|
86
|
-
let plugins;
|
|
87
|
-
|
|
88
|
-
beforeEach(() => {
|
|
89
|
-
plugins = [];
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('renders default toolbar', () => {
|
|
93
|
-
const { container } = render(
|
|
94
|
-
<Toolbar
|
|
95
|
-
toolbarOpts={toolbarOpts}
|
|
96
|
-
plugins={plugins}
|
|
97
|
-
classes={classes}
|
|
98
|
-
value={value}
|
|
99
|
-
onDone={jest.fn()}
|
|
100
|
-
onChange={jest.fn()}
|
|
101
|
-
/>,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// Verify the toolbar is rendered
|
|
105
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
106
|
-
|
|
107
|
-
// The default toolbar should render the DefaultToolbar component
|
|
108
|
-
// which includes a Done button
|
|
109
|
-
expect(screen.getByLabelText('Done')).toBeInTheDocument();
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|