@@ -15,10 +15,12 @@ describe('GithubTabHeaderController', function() {
15
15
function buildApp ( overrides ) {
16
16
const props = {
17
17
user : nullAuthor ,
18
+ currentWorkDir : null ,
19
+ contextLocked : false ,
20
+ changeWorkingDirectory : ( ) => { } ,
21
+ setContextLock : ( ) => { } ,
18
22
getCurrentWorkDirs : ( ) => createWorkdirs ( [ ] ) ,
19
- onDidUpdateRepo : ( ) => new Disposable ( ) ,
20
23
onDidChangeWorkDirs : ( ) => new Disposable ( ) ,
21
- handleWorkDirSelect : ( ) => null ,
22
24
...overrides ,
23
25
} ;
24
26
return (
@@ -73,6 +75,62 @@ describe('GithubTabHeaderController', function() {
73
75
assert . isTrue ( getCurrentWorkDirs . calledTwice ) ;
74
76
} ) ;
75
77
78
+ it ( 'handles a lock toggle' , async function ( ) {
79
+ let resolveLockChange ;
80
+ const setContextLock = sinon . stub ( ) . returns ( new Promise ( resolve => {
81
+ resolveLockChange = resolve ;
82
+ } ) )
83
+ const wrapper = shallow ( buildApp ( { currentWorkDir : 'the/workdir' , contextLocked : false , setContextLock} ) ) ;
84
+
85
+ assert . isFalse ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'contextLocked' ) ) ;
86
+ assert . isFalse ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'changingLock' ) ) ;
87
+
88
+ const handlerPromise = wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'handleLockToggle' ) ( ) ;
89
+ wrapper . update ( ) ;
90
+
91
+ assert . isTrue ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'contextLocked' ) ) ;
92
+ assert . isTrue ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'changingLock' ) ) ;
93
+ assert . isTrue ( setContextLock . calledWith ( 'the/workdir' , true ) ) ;
94
+
95
+ // Ignored while in-progress
96
+ wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'handleLockToggle' ) ( ) ;
97
+
98
+ resolveLockChange ( ) ;
99
+ await handlerPromise ;
100
+
101
+ assert . isFalse ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'changingLock' ) ) ;
102
+ } ) ;
103
+
104
+ it ( 'handles a workdir selection' , async function ( ) {
105
+ let resolveWorkdirChange ;
106
+ const changeWorkingDirectory = sinon . stub ( ) . returns ( new Promise ( resolve => {
107
+ resolveWorkdirChange = resolve ;
108
+ } ) )
109
+ const wrapper = shallow ( buildApp ( { currentWorkDir : 'original' , changeWorkingDirectory} ) ) ;
110
+
111
+ assert . strictEqual ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'workdir' ) , 'original' ) ;
112
+ assert . isFalse ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'changingWorkDir' ) ) ;
113
+
114
+ const handlerPromise = wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'handleWorkDirChange' ) ( {
115
+ target : { value : 'work/dir' } ,
116
+ } ) ;
117
+ wrapper . update ( ) ;
118
+
119
+ assert . strictEqual ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'workdir' ) , 'work/dir' ) ;
120
+ assert . isTrue ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'changingWorkDir' ) ) ;
121
+ assert . isTrue ( changeWorkingDirectory . calledWith ( 'work/dir' ) ) ;
122
+
123
+ // Ignored while in-progress
124
+ wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'handleWorkDirChange' ) ( {
125
+ target : { value : 'ig/nored' } ,
126
+ } ) ;
127
+
128
+ resolveWorkdirChange ( ) ;
129
+ await handlerPromise ;
130
+
131
+ assert . isFalse ( wrapper . find ( 'GithubTabHeaderView' ) . prop ( 'changingWorkDir' ) ) ;
132
+ } ) ;
133
+
76
134
it ( 'disposes on unmount' , function ( ) {
77
135
const disposeSpy = sinon . spy ( ) ;
78
136
const onDidChangeWorkDirs = ( ) => ( { dispose : disposeSpy } ) ;
0 commit comments