1
1
import * as React from 'react' ;
2
- import { render } from 'react-testing-library' ;
2
+ import { render , fireEvent } from 'react-testing-library' ;
3
3
import MarkdownEditor , { MarkdownEditorProps } from '../MarkdownEditor' ;
4
4
5
5
describe ( 'MarkdownEditor' , ( ) => {
6
6
const setup = ( props : Partial < MarkdownEditorProps > = { } ) => {
7
- const initialProps : MarkdownEditorProps = { } ;
7
+ const initialProps : MarkdownEditorProps = {
8
+ onChangeMarkdown : ( ) => { } ,
9
+ onChangeTitle : ( ) => { } ,
10
+ title : '' ,
11
+ } ;
8
12
const utils = render ( < MarkdownEditor { ...initialProps } { ...props } /> ) ;
9
- const titleTextarea = utils . getByPlaceholderText ( '제목을 입력하세요' ) ;
13
+ const titleTextarea = utils . getByPlaceholderText (
14
+ '제목을 입력하세요' ,
15
+ ) as HTMLTextAreaElement ;
10
16
return {
11
17
titleTextarea,
12
18
...utils ,
@@ -19,4 +25,27 @@ describe('MarkdownEditor', () => {
19
25
const { container } = setup ( ) ;
20
26
expect ( container ) . toMatchSnapshot ( ) ;
21
27
} ) ;
28
+ it ( 'has codemirror editor' , ( ) => {
29
+ const utils = setup ( ) ;
30
+ utils . getByText ( '당신의 이야기를 적어보세요...' ) ;
31
+ } ) ;
32
+ it ( 'changes title properly' , ( ) => {
33
+ const onChangeTitle = jest . fn ( ) ;
34
+ const utils = setup ( {
35
+ onChangeTitle,
36
+ } ) ;
37
+ fireEvent . change ( utils . titleTextarea , {
38
+ target : {
39
+ value : 'changed' ,
40
+ } ,
41
+ } ) ;
42
+ expect ( onChangeTitle ) . toBeCalledWith ( 'changed' ) ;
43
+ // expect(utils.titleTextarea.value).toBe('changed!');
44
+ } ) ;
45
+ it ( 'uses title prop' , ( ) => {
46
+ const utils = setup ( {
47
+ title : 'hello world' ,
48
+ } ) ;
49
+ expect ( utils . titleTextarea . value ) . toBe ( 'hello world' ) ;
50
+ } ) ;
22
51
} ) ;
0 commit comments