1
1
import { refreshIcon } from '@jupyterlab/ui-components' ;
2
+ import * as commands from '@lumino/commands' ;
2
3
import { shallow } from 'enzyme' ;
3
4
import 'jest' ;
4
5
import * as React from 'react' ;
5
6
import { ActionButton } from '../../src/components/ActionButton' ;
6
7
import { Toolbar } from '../../src/components/Toolbar' ;
7
8
import * as git from '../../src/git' ;
9
+ import { CommandIDs } from '../../src/gitMenuCommands' ;
8
10
import { GitExtension } from '../../src/model' ;
9
11
import { pullIcon , pushIcon } from '../../src/style/icons' ;
10
12
import {
11
13
toolbarButtonClass ,
12
14
toolbarMenuButtonClass
13
15
} from '../../src/style/Toolbar' ;
14
16
17
+ jest . mock ( '@lumino/commands' ) ;
15
18
jest . mock ( '../../src/git' ) ;
16
19
17
- async function createModel ( ) {
18
- const model = new GitExtension ( ) ;
20
+ async function createModel ( commands ?: commands . CommandRegistry ) {
21
+ const app = {
22
+ commands,
23
+ shell : null as any
24
+ } ;
25
+ const model = new GitExtension ( app as any ) ;
19
26
20
27
jest . spyOn ( model , 'currentBranch' , 'get' ) . mockReturnValue ( {
21
28
is_current_branch : true ,
@@ -303,17 +310,25 @@ describe('Toolbar', () => {
303
310
304
311
describe ( 'pull changes' , ( ) => {
305
312
let model : GitExtension ;
313
+ let mockedExecute : any ;
306
314
307
315
beforeEach ( async ( ) => {
316
+ const mockedCommands = commands as jest . Mocked < typeof commands > ;
317
+ mockedExecute = jest . fn ( ) ;
318
+ mockedCommands . CommandRegistry . mockImplementation ( ( ) => {
319
+ return {
320
+ execute : mockedExecute
321
+ } as any ;
322
+ } ) ;
323
+ const registry = new commands . CommandRegistry ( ) ;
324
+
308
325
const mock = git as jest . Mocked < typeof git > ;
309
326
mock . httpGitRequest . mockImplementation ( request ) ;
310
327
311
- model = await createModel ( ) ;
328
+ model = await createModel ( registry ) ;
312
329
} ) ;
313
330
314
331
it ( 'should pull changes when the button to pull the latest changes is clicked' , ( ) => {
315
- const spy = jest . spyOn ( GitExtension . prototype , 'pull' ) ;
316
-
317
332
const props = {
318
333
model : model ,
319
334
branching : false ,
@@ -323,26 +338,32 @@ describe('Toolbar', () => {
323
338
const button = node . find ( `.${ toolbarButtonClass } ` ) . first ( ) ;
324
339
325
340
button . simulate ( 'click' ) ;
326
- expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
327
- expect ( spy ) . toHaveBeenCalledWith ( undefined ) ;
328
-
329
- spy . mockRestore ( ) ;
341
+ expect ( mockedExecute ) . toHaveBeenCalledTimes ( 1 ) ;
342
+ expect ( mockedExecute ) . toHaveBeenCalledWith ( CommandIDs . gitPull ) ;
330
343
} ) ;
331
344
} ) ;
332
345
333
346
describe ( 'push changes' , ( ) => {
334
347
let model : GitExtension ;
348
+ let mockedExecute : any ;
335
349
336
350
beforeEach ( async ( ) => {
351
+ const mockedCommands = commands as jest . Mocked < typeof commands > ;
352
+ mockedExecute = jest . fn ( ) ;
353
+ mockedCommands . CommandRegistry . mockImplementation ( ( ) => {
354
+ return {
355
+ execute : mockedExecute
356
+ } as any ;
357
+ } ) ;
358
+ const registry = new commands . CommandRegistry ( ) ;
359
+
337
360
const mock = git as jest . Mocked < typeof git > ;
338
361
mock . httpGitRequest . mockImplementation ( request ) ;
339
362
340
- model = await createModel ( ) ;
363
+ model = await createModel ( registry ) ;
341
364
} ) ;
342
365
343
366
it ( 'should push changes when the button to push the latest changes is clicked' , ( ) => {
344
- const spy = jest . spyOn ( GitExtension . prototype , 'push' ) ;
345
-
346
367
const props = {
347
368
model : model ,
348
369
branching : false ,
@@ -352,10 +373,8 @@ describe('Toolbar', () => {
352
373
const button = node . find ( `.${ toolbarButtonClass } ` ) . at ( 1 ) ;
353
374
354
375
button . simulate ( 'click' ) ;
355
- expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
356
- expect ( spy ) . toHaveBeenCalledWith ( undefined ) ;
357
-
358
- spy . mockRestore ( ) ;
376
+ expect ( mockedExecute ) . toHaveBeenCalledTimes ( 1 ) ;
377
+ expect ( mockedExecute ) . toHaveBeenCalledWith ( CommandIDs . gitPush ) ;
359
378
} ) ;
360
379
} ) ;
361
380
0 commit comments