@uiw/react-md-editor 3.9.3 → 3.9.4

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.
@@ -0,0 +1,49 @@
1
+ /*
2
+ object-assign
3
+ (c) Sindre Sorhus
4
+ @license MIT
5
+ */
6
+
7
+ /*!
8
+ * @uiw/copy-to-clipboard v1.0.12
9
+ * Copy to clipboard.
10
+ *
11
+ * Copyright (c) 2021 Kenny Wang
12
+ * https://github.com/uiwjs/copy-to-clipboard.git
13
+ *
14
+ * Licensed under the MIT license.
15
+ */
16
+
17
+ /*!
18
+ * Determine if an object is a Buffer
19
+ *
20
+ * @author Feross Aboukhadijeh <https://feross.org>
21
+ * @license MIT
22
+ */
23
+
24
+ /**
25
+ * Prism: Lightweight, robust, elegant syntax highlighting
26
+ *
27
+ * @license MIT <https://opensource.org/licenses/MIT>
28
+ * @author Lea Verou <https://lea.verou.me>
29
+ * @namespace
30
+ * @public
31
+ */
32
+
33
+ /** @license React v17.0.2
34
+ * react-is.production.min.js
35
+ *
36
+ * Copyright (c) Facebook, Inc. and its affiliates.
37
+ *
38
+ * This source code is licensed under the MIT license found in the
39
+ * LICENSE file in the root directory of this source tree.
40
+ */
41
+
42
+ /** @license React v17.0.2
43
+ * react-jsx-runtime.production.min.js
44
+ *
45
+ * Copyright (c) Facebook, Inc. and its affiliates.
46
+ *
47
+ * This source code is licensed under the MIT license found in the
48
+ * LICENSE file in the root directory of this source tree.
49
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-md-editor",
3
- "version": "3.9.3",
3
+ "version": "3.9.4",
4
4
  "description": "A markdown editor with preview, implemented with React.js and TypeScript.",
5
5
  "homepage": "https://uiwjs.github.io/react-md-editor/",
6
6
  "author": "kenny wang <wowohoo@qq.com>",
@@ -19,7 +19,7 @@
19
19
  "watch": "tsbb watch & npm run css:watch",
20
20
  "build": "tsbb build && npm run css:build && npm run css:build:dist",
21
21
  "test": "tsbb test --env=jsdom",
22
- "coverage": "tsbb test --env=jsdom --coverage",
22
+ "coverage": "tsbb test --env=jsdom --coverage --bail",
23
23
  "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
24
24
  "map": "source-map-explorer build/static/js/*.js --html build/website-result.html"
25
25
  },
@@ -30,6 +30,7 @@
30
30
  "files": [
31
31
  "markdown-editor.css",
32
32
  "lib",
33
+ "dist",
33
34
  "esm",
34
35
  "src"
35
36
  ],
@@ -39,10 +40,10 @@
39
40
  "react-dom": ">=16.8.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@kkt/less-modules": "7.0.4",
43
- "@kkt/raw-modules": "7.0.4",
44
- "@kkt/react-library": "7.0.4",
45
- "@kkt/scope-plugin-options": "7.0.4",
43
+ "@kkt/less-modules": "7.0.7",
44
+ "@kkt/raw-modules": "7.0.7",
45
+ "@kkt/react-library": "7.0.7",
46
+ "@kkt/scope-plugin-options": "7.0.7",
46
47
  "@types/katex": "0.11.1",
47
48
  "@types/react": "17.0.38",
48
49
  "@types/react-dom": "17.0.11",
@@ -51,17 +52,16 @@
51
52
  "@uiw/react-codesandbox": "1.1.4",
52
53
  "@uiw/react-shields": "1.1.2",
53
54
  "compile-less-cli": "1.8.11",
54
- "katex": "0.15.1",
55
+ "katex": "0.15.2",
55
56
  "husky": "7.0.4",
56
- "jest-environment-jsdom": "27.4.4",
57
- "kkt": "7.0.4",
58
- "lint-staged": "12.1.5",
57
+ "kkt": "7.0.7",
58
+ "lint-staged": "12.3.2",
59
59
  "prettier": "2.5.1",
60
60
  "react": "17.0.2",
61
61
  "react-dom": "17.0.2",
62
62
  "react-test-renderer": "17.0.2",
63
63
  "source-map-explorer": "2.5.2",
64
- "tsbb": "3.5.4"
64
+ "tsbb": "3.5.5"
65
65
  },
66
66
  "dependencies": {
67
67
  "@babel/runtime": "^7.14.6",
@@ -84,10 +84,6 @@
84
84
  "code"
85
85
  ],
86
86
  "jest": {
87
- "testMatch": [
88
- "<rootDir>/test/*.{ts,tsx}",
89
- "<rootDir>/test/**/*.{ts,tsx}"
90
- ],
91
87
  "transformIgnorePatterns": [
92
88
  "<rootDir>/node_modules/?!(.*)"
93
89
  ]
@@ -0,0 +1,512 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import React from 'react';
5
+ import { render, screen, fireEvent } from '@testing-library/react';
6
+ import userEvent from '@testing-library/user-event';
7
+ import '@testing-library/jest-dom';
8
+ import MDEditor, { commands } from '../';
9
+
10
+ it('MDEditor commands bold', async () => {
11
+ const MyComponent = () => {
12
+ const [value, setValue] = React.useState('title');
13
+ return (
14
+ <MDEditor
15
+ value={value}
16
+ textareaProps={{ title: 'test' }}
17
+ onChange={(value) => {
18
+ setValue(value || '');
19
+ }}
20
+ />
21
+ );
22
+ };
23
+ render(<MyComponent />);
24
+ const btn = screen.getByTitle('Add bold text');
25
+ btn.focus();
26
+ fireEvent(
27
+ btn,
28
+ new MouseEvent('click', {
29
+ bubbles: true,
30
+ cancelable: true,
31
+ }),
32
+ );
33
+ const inputNode = screen.getByTitle('test');
34
+ expect(inputNode).toHaveValue('**title**');
35
+ });
36
+
37
+ it('MDEditor commands italic', async () => {
38
+ const MyComponent = () => {
39
+ const [value, setValue] = React.useState('title');
40
+ return (
41
+ <MDEditor
42
+ value={value}
43
+ textareaProps={{ title: 'test' }}
44
+ onChange={(value) => {
45
+ setValue(value || '');
46
+ }}
47
+ />
48
+ );
49
+ };
50
+ render(<MyComponent />);
51
+ const btn = screen.getByTitle('Add italic text');
52
+ btn.focus();
53
+ fireEvent(
54
+ btn,
55
+ new MouseEvent('click', {
56
+ bubbles: true,
57
+ cancelable: true,
58
+ }),
59
+ );
60
+ const inputNode = screen.getByTitle('test');
61
+ expect(inputNode).toHaveValue('*title*');
62
+ });
63
+
64
+ it('MDEditor commands code', async () => {
65
+ const handleChange = jest.fn((value) => value);
66
+ render(<MDEditor value={`He llo \nWold!`} textareaProps={{ title: 'test' }} onChange={handleChange} />);
67
+ const input = screen.getByTitle<HTMLInputElement>('test');
68
+ input.setSelectionRange(0, 5);
69
+ const btn = screen.getByLabelText('Insert code');
70
+ fireEvent(
71
+ btn,
72
+ new MouseEvent('click', {
73
+ bubbles: true,
74
+ cancelable: true,
75
+ }),
76
+ );
77
+ expect(handleChange).toHaveReturnedWith('`He ll`o \nWold!');
78
+ });
79
+
80
+ it('MDEditor commands selectOptions code', async () => {
81
+ const handleChange = jest.fn((value) => value);
82
+ render(<MDEditor value={`Hello\nWold!`} textareaProps={{ title: 'test' }} onChange={handleChange} />);
83
+ const input = screen.getByTitle<HTMLInputElement>('test');
84
+ input.setSelectionRange(0, 11);
85
+ const btn = screen.getByLabelText('Insert code');
86
+ fireEvent(
87
+ btn,
88
+ new MouseEvent('click', {
89
+ bubbles: true,
90
+ cancelable: true,
91
+ }),
92
+ );
93
+ expect(handleChange).toHaveReturnedWith('```\nHello\nWold!\n```');
94
+ });
95
+
96
+ it('MDEditor commands code `ctrlcmd+j`', async () => {
97
+ const handleChange = jest.fn((value) => value);
98
+ render(<MDEditor value={`Hello`} textareaProps={{ title: 'test' }} onChange={handleChange} />);
99
+ const input = screen.getByTitle('test');
100
+ fireEvent.keyDown(input, { key: 'J', code: 'KeyJ', ctrlKey: true, shiftKey: true });
101
+ expect(handleChange).toHaveReturnedWith('```\nHello\n```');
102
+ });
103
+
104
+ it('MDEditor commands quote', async () => {
105
+ const MyComponent = () => {
106
+ const [value, setValue] = React.useState('title');
107
+ return (
108
+ <MDEditor
109
+ value={value}
110
+ textareaProps={{ title: 'test' }}
111
+ onChange={(value) => {
112
+ setValue(value || '');
113
+ }}
114
+ />
115
+ );
116
+ };
117
+ render(<MyComponent />);
118
+ const btn = screen.getByLabelText('Insert a quote');
119
+ btn.focus();
120
+ fireEvent(
121
+ btn,
122
+ new MouseEvent('click', {
123
+ bubbles: true,
124
+ cancelable: true,
125
+ }),
126
+ );
127
+ const inputNode = screen.getByTitle('test');
128
+ expect(inputNode).toHaveValue('> title');
129
+ });
130
+
131
+ it('MDEditor commands HR', async () => {
132
+ const MyComponent = () => {
133
+ const [value, setValue] = React.useState('title');
134
+ return (
135
+ <MDEditor
136
+ value={value}
137
+ textareaProps={{ title: 'test' }}
138
+ onChange={(value) => {
139
+ setValue(value || '');
140
+ }}
141
+ />
142
+ );
143
+ };
144
+ render(<MyComponent />);
145
+ const btn = screen.getByLabelText('Insert HR');
146
+ btn.focus();
147
+ fireEvent(
148
+ btn,
149
+ new MouseEvent('click', {
150
+ bubbles: true,
151
+ cancelable: true,
152
+ }),
153
+ );
154
+ const inputNode = screen.getByTitle('test');
155
+ expect(inputNode).toHaveValue('\n\n----------\n\ntitle');
156
+ });
157
+
158
+ it('MDEditor commands strikethrough text', async () => {
159
+ const MyComponent = () => {
160
+ const [value, setValue] = React.useState('title');
161
+ return (
162
+ <MDEditor
163
+ value={value}
164
+ textareaProps={{ title: 'test' }}
165
+ onChange={(value) => {
166
+ setValue(value || '');
167
+ }}
168
+ />
169
+ );
170
+ };
171
+ render(<MyComponent />);
172
+ const btn = screen.getByLabelText('Add strikethrough text');
173
+ btn.focus();
174
+ fireEvent(
175
+ btn,
176
+ new MouseEvent('click', {
177
+ bubbles: true,
178
+ cancelable: true,
179
+ }),
180
+ );
181
+ const inputNode = screen.getByTitle('test');
182
+ expect(inputNode).toHaveValue('~~title~~');
183
+ });
184
+
185
+ it('MDEditor commands link', async () => {
186
+ const MyComponent = () => {
187
+ const [value, setValue] = React.useState('title');
188
+ return (
189
+ <MDEditor
190
+ value={value}
191
+ textareaProps={{ title: 'test' }}
192
+ onChange={(value) => {
193
+ setValue(value || '');
194
+ }}
195
+ />
196
+ );
197
+ };
198
+ render(<MyComponent />);
199
+ const btn = screen.getByLabelText('Add a link');
200
+ btn.focus();
201
+ fireEvent(
202
+ btn,
203
+ new MouseEvent('click', {
204
+ bubbles: true,
205
+ cancelable: true,
206
+ }),
207
+ );
208
+ const inputNode = screen.getByTitle('test');
209
+ expect(inputNode).toHaveValue('[title](url)');
210
+ });
211
+
212
+ it('MDEditor commands image', async () => {
213
+ const MyComponent = () => {
214
+ const [value, setValue] = React.useState('title');
215
+ return (
216
+ <MDEditor
217
+ value={value}
218
+ textareaProps={{ title: 'test' }}
219
+ onChange={(value) => {
220
+ setValue(value || '');
221
+ }}
222
+ />
223
+ );
224
+ };
225
+ render(<MyComponent />);
226
+ const btn = screen.getByLabelText('Add image');
227
+ btn.focus();
228
+ fireEvent(
229
+ btn,
230
+ new MouseEvent('click', {
231
+ bubbles: true,
232
+ cancelable: true,
233
+ }),
234
+ );
235
+ const inputNode = screen.getByTitle('test');
236
+ expect(inputNode).toHaveValue('![](title)');
237
+ });
238
+
239
+ it("MDEditor commands image === ''", async () => {
240
+ const MyComponent = () => {
241
+ const [value, setValue] = React.useState('');
242
+ return (
243
+ <MDEditor
244
+ value={value}
245
+ textareaProps={{ title: 'test' }}
246
+ onChange={(value) => {
247
+ setValue(value || '');
248
+ }}
249
+ />
250
+ );
251
+ };
252
+ render(<MyComponent />);
253
+ const btn = screen.getByLabelText('Add image');
254
+ btn.focus();
255
+ fireEvent(
256
+ btn,
257
+ new MouseEvent('click', {
258
+ bubbles: true,
259
+ cancelable: true,
260
+ }),
261
+ );
262
+ const inputNode = screen.getByTitle('test');
263
+ expect(inputNode).toHaveValue('![](https://example.com/your-image.png)');
264
+ });
265
+
266
+ it('MDEditor commands Add unordered list', async () => {
267
+ const MyComponent = () => {
268
+ const [value, setValue] = React.useState('title');
269
+ return (
270
+ <MDEditor
271
+ value={value}
272
+ textareaProps={{ title: 'test' }}
273
+ onChange={(value) => {
274
+ setValue(value || '');
275
+ }}
276
+ />
277
+ );
278
+ };
279
+ render(<MyComponent />);
280
+ const btn = screen.getByLabelText('Add unordered list');
281
+ btn.focus();
282
+ fireEvent(
283
+ btn,
284
+ new MouseEvent('click', {
285
+ bubbles: true,
286
+ cancelable: true,
287
+ }),
288
+ );
289
+ const inputNode = screen.getByTitle('test');
290
+ expect(inputNode).toHaveValue('- title');
291
+ });
292
+
293
+ it('MDEditor commands Add ordered list', async () => {
294
+ const handleChange = jest.fn((value) => value);
295
+ render(<MDEditor value="title" textareaProps={{ title: 'test' }} onChange={handleChange} />);
296
+ const btn = screen.getByLabelText('Add ordered list');
297
+ fireEvent(
298
+ btn,
299
+ new MouseEvent('click', {
300
+ bubbles: true,
301
+ cancelable: true,
302
+ }),
303
+ );
304
+ expect(handleChange).toHaveReturnedWith('1. title');
305
+ });
306
+
307
+ it('MDEditor commands Add checked list', async () => {
308
+ const MyComponent = () => {
309
+ const [value, setValue] = React.useState('title');
310
+ return (
311
+ <MDEditor
312
+ value={value}
313
+ textareaProps={{ title: 'test' }}
314
+ onChange={(value) => {
315
+ setValue(value || '');
316
+ }}
317
+ />
318
+ );
319
+ };
320
+ render(<MyComponent />);
321
+ const btn = screen.getByLabelText('Add checked list');
322
+
323
+ btn.focus();
324
+ fireEvent(
325
+ btn,
326
+ new MouseEvent('click', {
327
+ bubbles: true,
328
+ cancelable: true,
329
+ }),
330
+ );
331
+ const inputNode = screen.getByTitle('test');
332
+ expect(inputNode).toHaveValue('- [ ] title');
333
+ });
334
+
335
+ it('MDEditor commands fullscreen', async () => {
336
+ const handleChange = jest.fn((value) => value);
337
+ await render(<MDEditor value="title" textareaProps={{ title: 'test' }} onChange={handleChange} />);
338
+ const btn = screen.getByLabelText('fullscreen');
339
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
340
+ expect(document.body.style).toMatchObject({
341
+ overflow: 'hidden',
342
+ });
343
+ const input = screen.getByTitle('test');
344
+ input.focus();
345
+ expect(handleChange).not.toHaveReturned();
346
+ // await fireEvent.keyDown(input, { key: 'Escape' });
347
+ // await fireEvent.keyDown(input, { key: 'Escape' });
348
+ userEvent.type(input, `{esc}`);
349
+ userEvent.keyboard('{esc}');
350
+ expect(document.body.style).toMatchObject({
351
+ // overflow: 'visible',
352
+ // 🚨🚨🚨🚨🚨🚨🚨🚨🚨 ??????????
353
+ overflow: 'hidden',
354
+ });
355
+ });
356
+
357
+ it('MDEditor commands comment `ctrlcmd+/`', async () => {
358
+ const handleChange = jest.fn((value) => value);
359
+ render(<MDEditor value={`Hello`} textareaProps={{ title: 'test' }} onChange={handleChange} />);
360
+ const input = screen.getByTitle('test');
361
+ fireEvent.keyDown(input, { key: '/', code: 'Slash', ctrlKey: true });
362
+ expect(handleChange).toHaveReturnedWith('<!-- Hello -->');
363
+ });
364
+
365
+ it('MDEditor commands title1 value === undefined', async () => {
366
+ const handleChange = jest.fn((value) => value);
367
+ render(<MDEditor onChange={handleChange} commands={[commands.title1]} />);
368
+ const btn = screen.getByLabelText('Insert title 1');
369
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
370
+ expect(handleChange).toHaveReturnedWith('# ');
371
+ });
372
+
373
+ it('MDEditor commands title1 value === test', async () => {
374
+ const handleChange = jest.fn((value) => value);
375
+ render(
376
+ <MDEditor
377
+ value="test"
378
+ textareaProps={{ title: 'textarea' }}
379
+ onChange={handleChange}
380
+ commands={[commands.title1]}
381
+ />,
382
+ );
383
+ const btn = screen.getByLabelText('Insert title 1');
384
+ const input = screen.getByTitle<HTMLTextAreaElement>('textarea');
385
+ input.setSelectionRange(2, 2);
386
+
387
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
388
+ expect(handleChange).toHaveReturnedWith('# test');
389
+ });
390
+
391
+ it('MDEditor commands title2 value === undefined', async () => {
392
+ const handleChange = jest.fn((value) => value);
393
+ render(<MDEditor onChange={handleChange} textareaProps={{ title: 'test' }} commands={[commands.title2]} />);
394
+ const input = screen.getByTitle<HTMLInputElement>('test');
395
+ input.setSelectionRange(0, 0);
396
+ const btn = screen.getByLabelText('Insert title2');
397
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
398
+ input.setSelectionRange(0, 0);
399
+ expect(handleChange).toHaveReturnedWith('## ');
400
+ });
401
+
402
+ it('MDEditor commands title2 value === test', async () => {
403
+ const handleChange = jest.fn((value) => value);
404
+ render(
405
+ <MDEditor value="test" onChange={handleChange} textareaProps={{ title: 'test' }} commands={[commands.title2]} />,
406
+ );
407
+ const input = screen.getByTitle<HTMLInputElement>('test');
408
+ input.setSelectionRange(2, 2);
409
+ const btn = screen.getByLabelText('Insert title2');
410
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
411
+ expect(handleChange).toHaveReturnedWith('## test');
412
+ });
413
+
414
+ it('MDEditor commands title3 value === undefined', async () => {
415
+ const handleChange = jest.fn((value) => value);
416
+ render(<MDEditor onChange={handleChange} commands={[commands.title3]} />);
417
+ const btn = screen.getByLabelText('Insert title3');
418
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
419
+ expect(handleChange).toHaveReturnedWith('### ');
420
+ });
421
+
422
+ it('MDEditor commands title3 value === test', async () => {
423
+ const handleChange = jest.fn((value) => value);
424
+ render(
425
+ <MDEditor
426
+ value="test"
427
+ textareaProps={{ title: 'textarea' }}
428
+ onChange={handleChange}
429
+ commands={[commands.title3]}
430
+ />,
431
+ );
432
+ const btn = screen.getByLabelText('Insert title3');
433
+ const input = screen.getByTitle<HTMLInputElement>('textarea');
434
+ input.setSelectionRange(2, 2);
435
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
436
+ expect(handleChange).toHaveReturnedWith('### test');
437
+ });
438
+
439
+ it('MDEditor commands title4 value === undefined', async () => {
440
+ const handleChange = jest.fn((value) => value);
441
+ render(<MDEditor onChange={handleChange} commands={[commands.title4]} />);
442
+ const btn = screen.getByLabelText('Insert title4');
443
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
444
+ expect(handleChange).toHaveReturnedWith('#### ');
445
+ });
446
+
447
+ it('MDEditor commands title4 value === test', async () => {
448
+ const handleChange = jest.fn((value) => value);
449
+ render(
450
+ <MDEditor
451
+ value="test"
452
+ textareaProps={{ title: 'textarea' }}
453
+ onChange={handleChange}
454
+ commands={[commands.title4]}
455
+ />,
456
+ );
457
+ const btn = screen.getByLabelText('Insert title4');
458
+ const input = screen.getByTitle('textarea');
459
+ (input as any).setSelectionRange(2, 2);
460
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
461
+ expect(handleChange).toHaveReturnedWith('#### test');
462
+ });
463
+
464
+ it('MDEditor commands title5 value === undefined', async () => {
465
+ const handleChange = jest.fn((value) => value);
466
+ render(<MDEditor onChange={handleChange} commands={[commands.title5]} />);
467
+ const btn = screen.getByLabelText('Insert title5');
468
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
469
+ expect(handleChange).toHaveReturnedWith('##### ');
470
+ });
471
+
472
+ it('MDEditor commands title5 value === test', async () => {
473
+ const handleChange = jest.fn((value) => value);
474
+ render(
475
+ <MDEditor
476
+ value="test"
477
+ textareaProps={{ title: 'textarea' }}
478
+ onChange={handleChange}
479
+ commands={[commands.title5]}
480
+ />,
481
+ );
482
+ const btn = screen.getByLabelText('Insert title5');
483
+ const input = screen.getByTitle<HTMLInputElement>('textarea');
484
+ input.setSelectionRange(2, 2);
485
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
486
+ expect(handleChange).toHaveReturnedWith('##### test');
487
+ });
488
+
489
+ it('MDEditor commands title6 value === undefined', async () => {
490
+ const handleChange = jest.fn((value) => value);
491
+ render(<MDEditor onChange={handleChange} commands={[commands.title6]} />);
492
+ const btn = screen.getByLabelText('Insert title6');
493
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
494
+ expect(handleChange).toHaveReturnedWith('###### ');
495
+ });
496
+
497
+ it('MDEditor commands title6 value === test', async () => {
498
+ const handleChange = jest.fn((value) => value);
499
+ render(
500
+ <MDEditor
501
+ value="test"
502
+ textareaProps={{ title: 'textarea' }}
503
+ onChange={handleChange}
504
+ commands={[commands.title6]}
505
+ />,
506
+ );
507
+ const btn = screen.getByLabelText('Insert title6');
508
+ const input = screen.getByTitle('textarea');
509
+ (input as any).setSelectionRange(2, 2);
510
+ fireEvent(btn, new MouseEvent('click', { bubbles: true, cancelable: true }));
511
+ expect(handleChange).toHaveReturnedWith('###### test');
512
+ });
@@ -0,0 +1,63 @@
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('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) => 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(1);
61
+ expect(handleChange).lastReturnedWith('!');
62
+ expect(handleChange).nthCalledWith(7, '\n');
63
+ });