@@ -7,6 +7,7 @@ import { expectFnCalled } from '@test/utils';
7
7
import { modules } from 'mo/services/builtinService/const' ;
8
8
import { editor as MonacoEditor } from 'mo/monaco' ;
9
9
import { cloneDeep } from 'lodash' ;
10
+ import { act } from 'react-dom/test-utils' ;
10
11
11
12
describe ( 'Test EditorService' , ( ) => {
12
13
let mockTab : IEditorTab ;
@@ -189,6 +190,67 @@ describe('Test EditorService', () => {
189
190
}
190
191
} ) ;
191
192
193
+ test ( 'Should update editor text via updateTab' , ( ) => {
194
+ const editor = new EditorService ( ) ;
195
+ editor . open ( { ...mockTab , data : { value : 'tabData' } } ) ;
196
+
197
+ const { groups } = editor . getState ( ) ;
198
+ expect ( groups ?. length ) . toBe ( 1 ) ;
199
+
200
+ const setValFn = jest . fn ( ) ;
201
+ const getValFn = jest . fn ( ( ) => '' ) ;
202
+ groups ! [ 0 ] . editorInstance = {
203
+ getModel : ( ) => ( {
204
+ getValue : getValFn ,
205
+ setValue : setValFn ,
206
+ } ) ,
207
+ } ;
208
+
209
+ act ( ( ) => {
210
+ editor . updateTab ( {
211
+ id : mockTab . id ,
212
+ data : {
213
+ value : 'test' ,
214
+ } ,
215
+ } ) ;
216
+ } ) ;
217
+
218
+ expect ( setValFn ) . toBeCalled ( ) ;
219
+ expect ( setValFn . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'test' ) ;
220
+ } ) ;
221
+
222
+ test ( 'Should prevent update editor text if current tab with renderPane' , ( ) => {
223
+ const editor = new EditorService ( ) ;
224
+ editor . open ( {
225
+ ...mockTab ,
226
+ data : { value : 'tabData' } ,
227
+ renderPane : ( ) => < div > test</ div > ,
228
+ } ) ;
229
+
230
+ const { groups } = editor . getState ( ) ;
231
+ expect ( groups ?. length ) . toBe ( 1 ) ;
232
+
233
+ const setValFn = jest . fn ( ) ;
234
+ const getValFn = jest . fn ( ( ) => '' ) ;
235
+ groups ! [ 0 ] . editorInstance = {
236
+ getModel : ( ) => ( {
237
+ getValue : getValFn ,
238
+ setValue : setValFn ,
239
+ } ) ,
240
+ } ;
241
+
242
+ act ( ( ) => {
243
+ editor . updateTab ( {
244
+ id : mockTab . id ,
245
+ data : {
246
+ value : 'test' ,
247
+ } ,
248
+ } ) ;
249
+ } ) ;
250
+
251
+ expect ( setValFn ) . not . toBeCalled ( ) ;
252
+ } ) ;
253
+
192
254
test ( 'Close a tab' , ( ) => {
193
255
const editor : any = new EditorService ( ) ;
194
256
editor . disposeModel = jest . fn ( ) ;
0 commit comments