@uiw/react-md-editor 3.23.4 → 3.23.6
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/README.md +27 -34
- package/dist/mdeditor.js +66 -56
- package/dist/mdeditor.min.js +1 -1
- package/esm/components/DragBar/index.js +7 -7
- package/lib/components/DragBar/index.js +7 -7
- package/package.json +2 -2
- package/src/__test__/commands.test.tsx +0 -512
- package/src/__test__/editor.test.tsx +0 -88
- package/src/__test__/utils/getSurroundingWord.test.tsx +0 -22
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
/* eslint-disable jest/no-conditional-expect */
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import TestRenderer from 'react-test-renderer';
|
|
7
|
-
import { render, fireEvent, screen } from '@testing-library/react';
|
|
8
|
-
import userEvent from '@testing-library/user-event';
|
|
9
|
-
import '@testing-library/jest-dom';
|
|
10
|
-
import MDEditor from '../';
|
|
11
|
-
|
|
12
|
-
it('MDEditor', () => {
|
|
13
|
-
const component = TestRenderer.create(<MDEditor value="**Hello world!!!**" />);
|
|
14
|
-
let tree = component.toJSON();
|
|
15
|
-
if (tree && !Array.isArray(tree)) {
|
|
16
|
-
expect(tree.type).toEqual('div');
|
|
17
|
-
expect(tree.props.className).toEqual('wmde-markdown-var w-md-editor w-md-editor-show-live');
|
|
18
|
-
expect(tree.props.style).toMatchObject({
|
|
19
|
-
height: 200,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('MDEditor onChange', async () => {
|
|
25
|
-
const MyComponent = () => {
|
|
26
|
-
const [value, setValue] = React.useState('**Hello world!!!**');
|
|
27
|
-
return (
|
|
28
|
-
<MDEditor
|
|
29
|
-
value={value}
|
|
30
|
-
textareaProps={{
|
|
31
|
-
title: 'test',
|
|
32
|
-
}}
|
|
33
|
-
onChange={(value) => {
|
|
34
|
-
expect(value).toEqual('# title');
|
|
35
|
-
setValue(value || '');
|
|
36
|
-
}}
|
|
37
|
-
/>
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
render(<MyComponent />);
|
|
41
|
-
const inputNode = screen.getByTitle('test');
|
|
42
|
-
inputNode.focus();
|
|
43
|
-
fireEvent.change(inputNode, { target: { value: '# title' } });
|
|
44
|
-
inputNode.blur();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('MDEditor KeyboardEvent onChange', async () => {
|
|
48
|
-
const handleChange = jest.fn((value, evn, state) => value);
|
|
49
|
-
render(
|
|
50
|
-
<MDEditor
|
|
51
|
-
value=""
|
|
52
|
-
textareaProps={{
|
|
53
|
-
title: 'test',
|
|
54
|
-
}}
|
|
55
|
-
onChange={handleChange}
|
|
56
|
-
/>,
|
|
57
|
-
);
|
|
58
|
-
const input = screen.getByTitle('test');
|
|
59
|
-
userEvent.type(input, 'Hello,{enter}World!');
|
|
60
|
-
expect(handleChange).toHaveLength(3);
|
|
61
|
-
// expect(handleChange).lastReturnedWith('!');
|
|
62
|
-
// expect(handleChange).nthCalledWith(7, '\n');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('MDEditor KeyboardEvent onHeightChange', async () => {
|
|
66
|
-
const handleChange = jest.fn((value, propsValue, state) => {
|
|
67
|
-
return propsValue;
|
|
68
|
-
});
|
|
69
|
-
const MyComponent = () => {
|
|
70
|
-
const [height, setHeight] = React.useState(300);
|
|
71
|
-
React.useEffect(() => {
|
|
72
|
-
setHeight(500);
|
|
73
|
-
}, []);
|
|
74
|
-
return (
|
|
75
|
-
<MDEditor
|
|
76
|
-
value=""
|
|
77
|
-
height={height}
|
|
78
|
-
textareaProps={{
|
|
79
|
-
title: 'test',
|
|
80
|
-
}}
|
|
81
|
-
onHeightChange={handleChange}
|
|
82
|
-
/>
|
|
83
|
-
);
|
|
84
|
-
};
|
|
85
|
-
render(<MyComponent />);
|
|
86
|
-
expect(handleChange).lastReturnedWith(500);
|
|
87
|
-
expect(handleChange).toHaveLength(3);
|
|
88
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
/* eslint-disable jest/no-conditional-expect */
|
|
5
|
-
import '@testing-library/jest-dom';
|
|
6
|
-
import { getSurroundingWord } from '../../utils/markdownUtils';
|
|
7
|
-
|
|
8
|
-
it('getSurroundingWord', () => {
|
|
9
|
-
expect(getSurroundingWord('hello world', 0)).toMatchObject({
|
|
10
|
-
start: 0,
|
|
11
|
-
end: 5,
|
|
12
|
-
});
|
|
13
|
-
expect(getSurroundingWord('hello world', 3)).toMatchObject({
|
|
14
|
-
start: 0,
|
|
15
|
-
end: 5,
|
|
16
|
-
});
|
|
17
|
-
expect(getSurroundingWord('hello world', 6)).toMatchObject({
|
|
18
|
-
start: 6,
|
|
19
|
-
end: 11,
|
|
20
|
-
});
|
|
21
|
-
// expect(getSurroundingWord('', 3)).toThrowError(new Error(`Argument 'text' should be truthy`));
|
|
22
|
-
});
|