@@ -6,11 +6,13 @@ import Repository from '../../lib/models/repository';
6
6
import BranchSet from '../../lib/models/branch-set' ;
7
7
import Branch , { nullBranch } from '../../lib/models/branch' ;
8
8
import RemoteSet from '../../lib/models/remote-set' ;
9
- import Remote from '../../lib/models/remote' ;
10
- import { InMemoryStrategy } from '../../lib/shared/keytar-strategy' ;
9
+ import Remote , { nullRemote } from '../../lib/models/remote' ;
10
+ import { DOTCOM } from '../../lib/models/endpoint' ;
11
+ import { InMemoryStrategy , UNAUTHENTICATED } from '../../lib/shared/keytar-strategy' ;
11
12
import GithubLoginModel from '../../lib/models/github-login-model' ;
12
13
import RefHolder from '../../lib/models/ref-holder' ;
13
14
import Refresher from '../../lib/models/refresher' ;
15
+ import * as reporterProxy from '../../lib/reporter-proxy' ;
14
16
15
17
import { buildRepository , cloneRepository } from '../helpers' ;
16
18
@@ -34,12 +36,18 @@ describe('GitHubTabController', function() {
34
36
workspace = { atomEnv . workspace }
35
37
refresher = { new Refresher ( ) }
36
38
loginModel = { new GithubLoginModel ( InMemoryStrategy ) }
39
+ token = "1234"
37
40
rootHolder = { new RefHolder ( ) }
38
41
39
42
workingDirectory = { repo . getWorkingDirectoryPath ( ) }
40
43
repository = { repo }
41
44
allRemotes = { new RemoteSet ( ) }
45
+ githubRemotes = { new RemoteSet ( ) }
46
+ currentRemote = { nullRemote }
42
47
branches = { new BranchSet ( ) }
48
+ currentBranch = { nullBranch }
49
+ aheadCount = { 0 }
50
+ manyRemotesAvailable = { false }
43
51
pushInProgress = { false }
44
52
isLoading = { false }
45
53
currentWorkDir = { repo . getWorkingDirectoryPath ( ) }
@@ -60,48 +68,15 @@ describe('GitHubTabController', function() {
60
68
}
61
69
62
70
describe ( 'derived view props' , function ( ) {
63
- const dotcom0 = new Remote ( 'yes0' , '[email protected] :aaa/bbb.git' ) ;
64
- const dotcom1 = new Remote ( 'yes1' , 'https://github.com/ccc/ddd.git' ) ;
65
- const nonDotcom = new Remote ( 'no0' , '[email protected] :eee/fff.git' ) ;
66
-
67
- it ( 'passes the current branch' , function ( ) {
68
- const currentBranch = new Branch ( 'aaa' , nullBranch , nullBranch , true ) ;
69
- const otherBranch = new Branch ( 'bbb' ) ;
70
- const branches = new BranchSet ( [ currentBranch , otherBranch ] ) ;
71
- const wrapper = shallow ( buildApp ( { branches} ) ) ;
72
-
73
- assert . strictEqual ( wrapper . find ( 'GitHubTabView' ) . prop ( 'currentBranch' ) , currentBranch ) ;
74
- } ) ;
75
-
76
- it ( 'passes remotes hosted on GitHub' , function ( ) {
77
- const allRemotes = new RemoteSet ( [ dotcom0 , dotcom1 , nonDotcom ] ) ;
78
- const wrapper = shallow ( buildApp ( { allRemotes} ) ) ;
79
-
80
- const passed = wrapper . find ( 'GitHubTabView' ) . prop ( 'remotes' ) ;
81
- assert . isTrue ( passed . withName ( 'yes0' ) . isPresent ( ) ) ;
82
- assert . isTrue ( passed . withName ( 'yes1' ) . isPresent ( ) ) ;
83
- assert . isFalse ( passed . withName ( 'no0' ) . isPresent ( ) ) ;
84
- } ) ;
85
-
86
- it ( 'detects an explicitly specified current remote' , function ( ) {
87
- const allRemotes = new RemoteSet ( [ dotcom0 , dotcom1 , nonDotcom ] ) ;
88
- const wrapper = shallow ( buildApp ( { allRemotes, selectedRemoteName : 'yes1' } ) ) ;
89
- assert . strictEqual ( wrapper . find ( 'GitHubTabView' ) . prop ( 'currentRemote' ) , dotcom1 ) ;
90
- assert . isFalse ( wrapper . find ( 'GitHubTabView' ) . prop ( 'manyRemotesAvailable' ) ) ;
71
+ it ( 'passes the endpoint from the current GitHub remote when one exists' , function ( ) {
72
+ const remote = new Remote ( 'hub' , '[email protected] :some/repo.git' ) ;
73
+ const wrapper = shallow ( buildApp ( { currentRemote : remote } ) ) ;
74
+ assert . strictEqual ( wrapper . find ( 'GitHubTabView' ) . prop ( 'endpoint' ) , remote . getEndpoint ( ) ) ;
91
75
} ) ;
92
76
93
- it ( 'uses a single GitHub-hosted remote' , function ( ) {
94
- const allRemotes = new RemoteSet ( [ dotcom0 , nonDotcom ] ) ;
95
- const wrapper = shallow ( buildApp ( { allRemotes} ) ) ;
96
- assert . strictEqual ( wrapper . find ( 'GitHubTabView' ) . prop ( 'currentRemote' ) , dotcom0 ) ;
97
- assert . isFalse ( wrapper . find ( 'GitHubTabView' ) . prop ( 'manyRemotesAvailable' ) ) ;
98
- } ) ;
99
-
100
- it ( 'indicates when multiple remotes are available' , function ( ) {
101
- const allRemotes = new RemoteSet ( [ dotcom0 , dotcom1 ] ) ;
102
- const wrapper = shallow ( buildApp ( { allRemotes} ) ) ;
103
- assert . isFalse ( wrapper . find ( 'GitHubTabView' ) . prop ( 'currentRemote' ) . isPresent ( ) ) ;
104
- assert . isTrue ( wrapper . find ( 'GitHubTabView' ) . prop ( 'manyRemotesAvailable' ) ) ;
77
+ it ( 'defaults the endpoint to dotcom' , function ( ) {
78
+ const wrapper = shallow ( buildApp ( { currentRemote : nullRemote } ) ) ;
79
+ assert . strictEqual ( wrapper . find ( 'GitHubTabView' ) . prop ( 'endpoint' ) , DOTCOM ) ;
105
80
} ) ;
106
81
} ) ;
107
82
@@ -139,5 +114,26 @@ describe('GitHubTabController', function() {
139
114
wrapper . find ( 'GitHubTabView' ) . prop ( 'openBoundPublishDialog' ) ( ) ;
140
115
assert . isTrue ( openPublishDialog . calledWith ( someRepo ) ) ;
141
116
} ) ;
117
+
118
+ it ( 'handles and instruments a login' , async function ( ) {
119
+ sinon . stub ( reporterProxy , 'incrementCounter' ) ;
120
+ const loginModel = new GithubLoginModel ( InMemoryStrategy ) ;
121
+
122
+ const wrapper = shallow ( buildApp ( { loginModel} ) ) ;
123
+ await wrapper . find ( 'GitHubTabView' ) . prop ( 'handleLogin' ) ( 'good-token' ) ;
124
+ assert . strictEqual ( await loginModel . getToken ( DOTCOM . getLoginAccount ( ) ) , 'good-token' ) ;
125
+ assert . isTrue ( reporterProxy . incrementCounter . calledWith ( 'github-login' ) ) ;
126
+ } ) ;
127
+
128
+ it ( 'handles and instruments a logout' , async function ( ) {
129
+ sinon . stub ( reporterProxy , 'incrementCounter' ) ;
130
+ const loginModel = new GithubLoginModel ( InMemoryStrategy ) ;
131
+ await loginModel . setToken ( DOTCOM . getLoginAccount ( ) , 'good-token' ) ;
132
+
133
+ const wrapper = shallow ( buildApp ( { loginModel} ) ) ;
134
+ await wrapper . find ( 'GitHubTabView' ) . prop ( 'handleLogout' ) ( ) ;
135
+ assert . strictEqual ( await loginModel . getToken ( DOTCOM . getLoginAccount ( ) ) , UNAUTHENTICATED ) ;
136
+ assert . isTrue ( reporterProxy . incrementCounter . calledWith ( 'github-logout' ) ) ;
137
+ } ) ;
142
138
} ) ;
143
139
} ) ;
0 commit comments