@@ -7,6 +7,10 @@ import GitHubTabController from '../../lib/controllers/github-tab-controller';
7
7
import Repository from '../../lib/models/repository' ;
8
8
import { InMemoryStrategy } from '../../lib/shared/keytar-strategy' ;
9
9
import GithubLoginModel from '../../lib/models/github-login-model' ;
10
+ import Remote from '../../lib/models/remote' ;
11
+ import RemoteSet from '../../lib/models/remote-set' ;
12
+ import Branch , { nullBranch } from '../../lib/models/branch' ;
13
+ import BranchSet from '../../lib/models/branch-set' ;
10
14
import RefHolder from '../../lib/models/ref-holder' ;
11
15
12
16
describe ( 'GitHubTabContainer' , function ( ) {
@@ -37,6 +41,7 @@ describe('GitHubTabContainer', function() {
37
41
repository = { repository }
38
42
loginModel = { new GithubLoginModel ( InMemoryStrategy ) }
39
43
rootHolder = { new RefHolder ( ) }
44
+ contextLocked = { false }
40
45
41
46
changeWorkingDirectory = { ( ) => { } }
42
47
onDidChangeWorkDirs = { ( ) => { } }
@@ -45,6 +50,7 @@ describe('GitHubTabContainer', function() {
45
50
openPublishDialog = { ( ) => { } }
46
51
openCloneDialog = { ( ) => { } }
47
52
openGitTab = { ( ) => { } }
53
+ setContextLock = { ( ) => { } }
48
54
49
55
{ ...props }
50
56
/>
@@ -72,10 +78,11 @@ describe('GitHubTabContainer', function() {
72
78
73
79
beforeEach ( function ( ) {
74
80
wrapper = shallow ( buildApp ( ) ) ;
75
- const childWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( defaultRepositoryData ) ;
81
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( defaultRepositoryData ) ;
82
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
76
83
77
84
retry = sinon . spy ( ) ;
78
- const refresher = childWrapper . find ( GitHubTabController ) . prop ( 'refresher' ) ;
85
+ const refresher = tokenWrapper . find ( GitHubTabController ) . prop ( 'refresher' ) ;
79
86
refresher . setRetryCallback ( Symbol ( 'key' ) , retry ) ;
80
87
81
88
stubRepository ( repository ) ;
@@ -106,6 +113,13 @@ describe('GitHubTabContainer', function() {
106
113
assert . isTrue ( retry . called ) ;
107
114
} ) ;
108
115
116
+ it ( 'preserves the observer when the repository is unchanged' , function ( ) {
117
+ wrapper . setProps ( { } ) ;
118
+
119
+ simulateOperation ( repository , 'fetch' ) ;
120
+ assert . isTrue ( retry . called ) ;
121
+ } ) ;
122
+
109
123
it ( 'un-observes the repository when unmounting' , function ( ) {
110
124
wrapper . unmount ( ) ;
111
125
@@ -114,25 +128,152 @@ describe('GitHubTabContainer', function() {
114
128
} ) ;
115
129
} ) ;
116
130
131
+ describe ( 'before loading' , function ( ) {
132
+ it ( 'passes isLoading to the controller' , async function ( ) {
133
+ const loadingRepo = new Repository ( await cloneRepository ( ) ) ;
134
+ const wrapper = shallow ( buildApp ( { repository : loadingRepo } ) ) ;
135
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( null ) ;
136
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
137
+
138
+ assert . isTrue ( tokenWrapper . find ( 'GitHubTabController' ) . prop ( 'isLoading' ) ) ;
139
+ } ) ;
140
+ } ) ;
141
+
117
142
describe ( 'while loading' , function ( ) {
118
- it ( 'passes isLoading to its view ' , async function ( ) {
143
+ it ( 'passes isLoading to the controller ' , async function ( ) {
119
144
const loadingRepo = new Repository ( await cloneRepository ( ) ) ;
120
145
assert . isTrue ( loadingRepo . isLoading ( ) ) ;
121
- const wrapper = mount ( buildApp ( { repository : loadingRepo } ) ) ;
146
+ const wrapper = shallow ( buildApp ( { repository : loadingRepo } ) ) ;
147
+ const repoData = await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( loadingRepo ) ;
148
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( repoData ) ;
149
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
122
150
123
- assert . isTrue ( wrapper . find ( 'GitHubTabController' ) . prop ( 'isLoading' ) ) ;
151
+ assert . isTrue ( tokenWrapper . find ( 'GitHubTabController' ) . prop ( 'isLoading' ) ) ;
152
+ } ) ;
153
+ } ) ;
154
+
155
+ describe ( 'when absent' , function ( ) {
156
+ it ( 'passes placeholder data to the controller' , async function ( ) {
157
+ const absent = Repository . absent ( ) ;
158
+ const wrapper = shallow ( buildApp ( { repository : absent } ) ) ;
159
+ const repoData = await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( absent ) ;
160
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( repoData ) ;
161
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
162
+ const controller = tokenWrapper . find ( 'GitHubTabController' ) ;
163
+
164
+ assert . strictEqual ( controller . prop ( 'allRemotes' ) . size ( ) , 0 ) ;
165
+ assert . strictEqual ( controller . prop ( 'githubRemotes' ) . size ( ) , 0 ) ;
166
+ assert . isFalse ( controller . prop ( 'currentRemote' ) . isPresent ( ) ) ;
167
+ assert . strictEqual ( controller . prop ( 'branches' ) . getNames ( ) . length , 0 ) ;
168
+ assert . isFalse ( controller . prop ( 'currentBranch' ) . isPresent ( ) ) ;
169
+ assert . strictEqual ( controller . prop ( 'aheadCount' ) , 0 ) ;
170
+ assert . isFalse ( controller . prop ( 'manyRemotesAvailable' ) ) ;
171
+ assert . isFalse ( controller . prop ( 'pushInProgress' ) ) ;
172
+ assert . isFalse ( controller . prop ( 'isLoading' ) ) ;
124
173
} ) ;
125
174
} ) ;
126
175
127
176
describe ( 'once loaded' , function ( ) {
177
+ let nonGitHub , github0 , github1 ;
178
+ let loadedRepo , singleGitHubRemoteSet , multiGitHubRemoteSet ;
179
+ let otherBranch , mainBranch ;
180
+ let branches ;
181
+
182
+ beforeEach ( async function ( ) {
183
+ loadedRepo = new Repository ( await cloneRepository ( ) ) ;
184
+ await loadedRepo . getLoadPromise ( ) ;
185
+
186
+ nonGitHub = new Remote ( 'no' , '[email protected] :abc/def.git' ) ;
187
+ github0 = new Remote ( 'yes0' , '[email protected] :user/repo0.git' ) ;
188
+ github1 = new Remote ( 'yes1' , '[email protected] :user/repo1.git' ) ;
189
+
190
+ singleGitHubRemoteSet = new RemoteSet ( [ nonGitHub , github0 ] ) ;
191
+ multiGitHubRemoteSet = new RemoteSet ( [ nonGitHub , github0 , github1 ] ) ;
192
+
193
+ otherBranch = new Branch ( 'other' ) ;
194
+ mainBranch = new Branch ( 'main' , nullBranch , nullBranch , true ) ;
195
+ branches = new BranchSet ( [ otherBranch , mainBranch ] ) ;
196
+ } ) ;
197
+
198
+ function installRemoteSet ( remoteSet ) {
199
+ return Promise . all (
200
+ Array . from ( remoteSet , remote => loadedRepo . addRemote ( remote . getName ( ) , remote . getUrl ( ) ) ) ,
201
+ ) ;
202
+ }
203
+
204
+ it ( 'derives the subset of GitHub remotes' , async function ( ) {
205
+ await installRemoteSet ( multiGitHubRemoteSet ) ;
206
+
207
+ const wrapper = shallow ( buildApp ( { repository : loadedRepo } ) ) ;
208
+ const repoData = await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( loadedRepo ) ;
209
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( repoData ) ;
210
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
211
+ const githubRemotes = tokenWrapper . find ( 'GitHubTabController' ) . prop ( 'githubRemotes' ) ;
212
+
213
+ assert . sameMembers ( Array . from ( githubRemotes , remote => remote . getName ( ) ) , [ 'yes0' , 'yes1' ] ) ;
214
+ } ) ;
215
+
216
+ it ( 'derives the current branch' , async function ( ) {
217
+ const wrapper = shallow ( buildApp ( { repository : loadedRepo } ) ) ;
218
+ const repoData = await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( loadedRepo ) ;
219
+ repoData . branches = branches ;
220
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( repoData ) ;
221
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
222
+ const currentBranch = tokenWrapper . find ( 'GitHubTabController' ) . prop ( 'currentBranch' ) ;
223
+
224
+ assert . strictEqual ( mainBranch , currentBranch ) ;
225
+ } ) ;
226
+
227
+ it ( 'identifies the current remote from the config key' , async function ( ) {
228
+ await loadedRepo . setConfig ( 'atomGithub.currentRemote' , 'yes1' ) ;
229
+ await installRemoteSet ( multiGitHubRemoteSet ) ;
230
+
231
+ const wrapper = shallow ( buildApp ( { repository : loadedRepo } ) ) ;
232
+ const repoData = await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( loadedRepo ) ;
233
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( repoData ) ;
234
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
235
+ const currentRemote = tokenWrapper . find ( 'GitHubTabController' ) . prop ( 'currentRemote' ) ;
236
+
237
+ assert . strictEqual ( currentRemote . getUrl ( ) , github1 . getUrl ( ) ) ;
238
+ } ) ;
239
+
240
+ it ( 'identifies the current remote as the only GitHub remote' , async function ( ) {
241
+ await installRemoteSet ( singleGitHubRemoteSet ) ;
242
+
243
+ const wrapper = shallow ( buildApp ( { repository : loadedRepo } ) ) ;
244
+ const repoData = await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( loadedRepo ) ;
245
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( repoData ) ;
246
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
247
+ const currentRemote = tokenWrapper . find ( 'GitHubTabController' ) . prop ( 'currentRemote' ) ;
248
+
249
+ assert . strictEqual ( currentRemote . getUrl ( ) , github0 . getUrl ( ) ) ;
250
+ } ) ;
251
+
252
+ it ( 'identifies when there are multiple GitHub remotes available' , async function ( ) {
253
+ await installRemoteSet ( multiGitHubRemoteSet ) ;
254
+
255
+ const wrapper = shallow ( buildApp ( { repository : loadedRepo } ) ) ;
256
+ const repoData = await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( loadedRepo ) ;
257
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( repoData ) ;
258
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
259
+ const controller = tokenWrapper . find ( 'GitHubTabController' ) ;
260
+
261
+ assert . isFalse ( controller . prop ( 'currentRemote' ) . isPresent ( ) ) ;
262
+ assert . isTrue ( controller . prop ( 'manyRemotesAvailable' ) ) ;
263
+ } ) ;
264
+
128
265
it ( 'renders the controller' , async function ( ) {
129
- const workdir = await cloneRepository ( ) ;
130
- const presentRepo = new Repository ( workdir ) ;
131
- await presentRepo . getLoadPromise ( ) ;
132
- const wrapper = mount ( buildApp ( { repository : presentRepo } ) ) ;
266
+ await installRemoteSet ( singleGitHubRemoteSet ) ;
267
+
268
+ const wrapper = shallow ( buildApp ( { repository : loadedRepo } ) ) ;
269
+ const repoData = await wrapper . find ( 'ObserveModel' ) . prop ( 'fetchData' ) ( loadedRepo ) ;
270
+ const repoWrapper = wrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( repoData ) ;
271
+ const tokenWrapper = repoWrapper . find ( 'ObserveModel' ) . renderProp ( 'children' ) ( '1234' ) ;
272
+ const controller = tokenWrapper . find ( 'GitHubTabController' ) ;
133
273
134
- await assert . async . isFalse ( wrapper . update ( ) . find ( 'GitHubTabController' ) . prop ( 'isLoading' ) ) ;
135
- assert . strictEqual ( wrapper . find ( 'GitHubTabController' ) . prop ( 'workingDirectory' ) , workdir ) ;
274
+ assert . isFalse ( controller . prop ( 'isLoading' ) ) ;
275
+ assert . isFalse ( controller . prop ( 'manyRemotesAvailable' ) ) ;
276
+ assert . strictEqual ( controller . prop ( 'token' ) , '1234' ) ;
136
277
} ) ;
137
278
} ) ;
138
279
} ) ;
0 commit comments