|
| 1 | +import React from 'react'; |
| 2 | +import { render, act } from '@testing-library/react'; |
| 3 | +import CodeEditor from '../src/CodeEditor'; |
| 4 | + |
| 5 | +it('renders without crashing', async () => { |
| 6 | + await act(async () => { |
| 7 | + render(<CodeEditor />); |
| 8 | + }); |
| 9 | +}); |
| 10 | + |
| 11 | +it('editor should be initialized', async () => { |
| 12 | + await act(async () => { |
| 13 | + const { container } = render( |
| 14 | + <CodeEditor |
| 15 | + onInitialized={() => { |
| 16 | + expect(container.querySelector('.rcv-editor-loader')).toBeFalsy(); |
| 17 | + }} |
| 18 | + /> |
| 19 | + ); |
| 20 | + expect(container.querySelector('.rcv-editor-loader')).toBeTruthy(); |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +it('should be initialized code', async () => { |
| 25 | + await act(async () => { |
| 26 | + const { container } = render( |
| 27 | + <CodeEditor |
| 28 | + code={'const a = 1;'} |
| 29 | + onInitialized={() => { |
| 30 | + expect(container.querySelector('textarea').value).toBe('const a = 1;'); |
| 31 | + expect(container.querySelector('.CodeMirror').textContent).toBe('const a = 1;'); |
| 32 | + }} |
| 33 | + /> |
| 34 | + ); |
| 35 | + expect(container.querySelector('.rcv-editor-loader')).toBeTruthy(); |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
| 39 | +it('should call onChange callback', async () => { |
| 40 | + await act(async () => { |
| 41 | + const { container } = render( |
| 42 | + <CodeEditor |
| 43 | + code={'const a = 1;'} |
| 44 | + onChange={value => { |
| 45 | + expect(container.querySelector('textarea').value).toBe('const a = 1;'); |
| 46 | + expect(value).toBe('const a = 2;'); |
| 47 | + }} |
| 48 | + onInitialized={editor => { |
| 49 | + editor.setValue('const a = 2;'); |
| 50 | + }} |
| 51 | + /> |
| 52 | + ); |
| 53 | + }); |
| 54 | +}); |
0 commit comments