@@ -13,7 +13,12 @@ import { createDefaultWrapperConfig } from './helper.js';
13
13
describe ( 'Test MonacoEditorReactComp' , ( ) => {
14
14
15
15
test ( 'onLoad' , async ( ) => {
16
- const wrapperConfig = createDefaultWrapperConfig ( ) ;
16
+ const wrapperConfig = createDefaultWrapperConfig ( {
17
+ modified : {
18
+ text : 'const text = "Hello World!";' ,
19
+ uri : `/workspace/${ expect . getState ( ) . testPath } .js` ,
20
+ }
21
+ } ) ;
17
22
18
23
let renderResult : RenderResult ;
19
24
// we have to await the full start of the editor with the onLoad callback, then it is save to contine
@@ -28,37 +33,47 @@ describe('Test MonacoEditorReactComp', () => {
28
33
} ) ;
29
34
30
35
test ( 'update onTextChanged' , async ( ) => {
31
- const wrapperConfig = createDefaultWrapperConfig ( ) ;
36
+ const wrapperConfig = createDefaultWrapperConfig ( {
37
+ modified : {
38
+ text : 'const text = "Hello World!";' ,
39
+ uri : `/workspace/${ expect . getState ( ) . testPath } .js` ,
40
+ }
41
+ } ) ;
32
42
33
43
const textReceiverHello = ( textChanges : TextContents ) => {
34
- expect ( textChanges . modified ) . toEqual ( 'hello world ' ) ;
44
+ expect ( textChanges . modified ) . toEqual ( 'const text = "Hello World!"; ' ) ;
35
45
} ;
36
46
37
47
const handleOnLoad = async ( wrapper : MonacoEditorLanguageClientWrapper ) => {
38
- expect ( wrapper . getTextModels ( ) ?. modified ?. getValue ( ) ) . toEqual ( 'hello world ' ) ;
48
+ expect ( wrapper . getTextModels ( ) ?. modified ?. getValue ( ) ) . toEqual ( 'const text = "Hello World!"; ' ) ;
39
49
} ;
40
50
render ( < MonacoEditorReactComp wrapperConfig = { wrapperConfig } onTextChanged = { ( textReceiverHello ) } onLoad = { handleOnLoad } /> ) ;
41
51
} ) ;
42
52
43
53
test ( 'update codeResources' , async ( ) => {
44
- const wrapperConfig = createDefaultWrapperConfig ( ) ;
54
+ const wrapperConfig = createDefaultWrapperConfig ( {
55
+ modified : {
56
+ text : 'const text = "Hello World!";' ,
57
+ uri : `/workspace/${ expect . getState ( ) . testPath } .js` ,
58
+ }
59
+ } ) ;
45
60
46
61
let count = 0 ;
47
62
const textReceiver = ( textChanges : TextContents ) => {
48
63
// initial call
49
64
if ( count === 0 ) {
50
- expect ( textChanges . modified ) . toBe ( 'hello world ' ) ;
65
+ expect ( textChanges . modified ) . toBe ( 'const text = "Hello World!"; ' ) ;
51
66
} else {
52
- expect ( textChanges . modified ) . toBe ( 'goodbye world ' ) ;
67
+ expect ( textChanges . modified ) . toBe ( 'const text = "Goodbye World!"; ' ) ;
53
68
}
54
69
} ;
55
70
56
71
const handleOnLoad = async ( wrapper : MonacoEditorLanguageClientWrapper ) => {
57
72
count ++ ;
58
73
await wrapper . updateCodeResources ( {
59
74
modified : {
60
- text : 'goodbye world ' ,
61
- uri : ' /workspace/test.js'
75
+ text : 'const text = "Goodbye World!"; ' ,
76
+ uri : ` /workspace/${ expect . getState ( ) . testPath } _goodbye.js` ,
62
77
}
63
78
} ) ;
64
79
@@ -69,9 +84,18 @@ describe('Test MonacoEditorReactComp', () => {
69
84
test ( 'rerender without error' , async ( ) => {
70
85
let error = false ;
71
86
try {
72
- const wrapperConfig = createDefaultWrapperConfig ( ) ;
73
- const newWrapperConfig = createDefaultWrapperConfig ( ) ;
74
- newWrapperConfig . editorAppConfig ! . codeResources ! . modified ! . text = 'hello world 2' ;
87
+ const wrapperConfig = createDefaultWrapperConfig ( {
88
+ modified : {
89
+ text : 'const text = "Hello World!";' ,
90
+ uri : `/workspace/${ expect . getState ( ) . testPath } .js` ,
91
+ }
92
+ } ) ;
93
+ const newWrapperConfig = createDefaultWrapperConfig ( {
94
+ modified : {
95
+ text : 'const text = "Goodbye World 2!";' ,
96
+ uri : `/workspace/${ expect . getState ( ) . testPath } _2.js` ,
97
+ }
98
+ } ) ;
75
99
let renderResult : RenderResult ;
76
100
77
101
const result1 = await new Promise < void > ( resolve => {
0 commit comments