@@ -11,6 +11,12 @@ import MDEditor from '../core/src';
1111import MDEditorCommon from '../core/src/index.common' ;
1212import MDEditorNoHighlight from '../core/src/index.nohighlight' ;
1313
14+ const modeEditors = [
15+ [ 'default' , MDEditor ] ,
16+ [ 'common' , MDEditorCommon ] ,
17+ [ 'nohighlight' , MDEditorNoHighlight ] ,
18+ ] as const ;
19+
1420// In your test setup file
1521// @ts -ignore
1622// globalThis.IS_REACT_ACT_ENVIRONMENT = true;
@@ -93,20 +99,32 @@ it('MDEditor KeyboardEvent onHeightChange', async () => {
9399 expect ( handleChange ) . toHaveLength ( 3 ) ;
94100} ) ;
95101
96- it ( 'MDEditor common exposes Markdown preview component' , ( ) => {
97- expect ( MDEditorCommon . Markdown ) . toBeDefined ( ) ;
98- } ) ;
102+ describe . each ( modeEditors ) ( 'MDEditor %s mode' , ( modeName , EditorComponent ) => {
103+ it ( 'exposes Markdown preview component' , ( ) => {
104+ expect ( EditorComponent . Markdown ) . toBeDefined ( ) ;
105+ } ) ;
99106
100- it ( 'MDEditor common Markdown renders source content ' , ( ) => {
101- const { container } = render ( < MDEditorCommon . Markdown source = { '```js\nconsole.log("hello")\n```' } /> ) ;
102- expect ( container ) . toHaveTextContent ( 'console.log("hello")' ) ;
103- } ) ;
107+ it ( 'renders editor textarea ' , ( ) => {
108+ render ( < EditorComponent value = "**Hello world!!!**" textareaProps = { { title : ` ${ modeName } -textarea` } } /> ) ;
109+ expect ( screen . getByTitle ( ` ${ modeName } -textarea` ) ) . toBeInTheDocument ( ) ;
110+ } ) ;
104111
105- it ( 'MDEditor nohighlight exposes Markdown preview component' , ( ) => {
106- expect ( MDEditorNoHighlight . Markdown ) . toBeDefined ( ) ;
107- } ) ;
112+ it ( 'calls onChange when textarea value changes' , ( ) => {
113+ const handleChange = jest . fn ( ) ;
114+ render (
115+ < EditorComponent
116+ value = "**Hello world!!!**"
117+ textareaProps = { { title : `${ modeName } -change-textarea` } }
118+ onChange = { handleChange }
119+ /> ,
120+ ) ;
121+ fireEvent . change ( screen . getByTitle ( `${ modeName } -change-textarea` ) , { target : { value : '# title' } } ) ;
122+ expect ( handleChange ) . toHaveBeenCalled ( ) ;
123+ expect ( handleChange . mock . calls . at ( - 1 ) ?. [ 0 ] ) . toBe ( '# title' ) ;
124+ } ) ;
108125
109- it ( 'MDEditor nohighlight Markdown renders source content' , ( ) => {
110- const { container } = render ( < MDEditorNoHighlight . Markdown source = { '```js\nconsole.log("hello")\n```' } /> ) ;
111- expect ( container ) . toHaveTextContent ( 'console.log("hello")' ) ;
126+ it ( 'Markdown renders source content' , ( ) => {
127+ const { container } = render ( < EditorComponent . Markdown source = { '```js\nconsole.log("hello")\n```' } /> ) ;
128+ expect ( container ) . toHaveTextContent ( 'console.log("hello")' ) ;
129+ } ) ;
112130} ) ;
0 commit comments