@@ -6,11 +6,13 @@ import Repository from '../../lib/models/repository';
66import BranchSet from '../../lib/models/branch-set' ;
77import Branch , { nullBranch } from '../../lib/models/branch' ;
88import 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' ;
1112import GithubLoginModel from '../../lib/models/github-login-model' ;
1213import RefHolder from '../../lib/models/ref-holder' ;
1314import Refresher from '../../lib/models/refresher' ;
15+ import * as reporterProxy from '../../lib/reporter-proxy' ;
1416
1517import { buildRepository , cloneRepository } from '../helpers' ;
1618
@@ -34,12 +36,18 @@ describe('GitHubTabController', function() {
3436 workspace = { atomEnv . workspace }
3537 refresher = { new Refresher ( ) }
3638 loginModel = { new GithubLoginModel ( InMemoryStrategy ) }
39+ token = "1234"
3740 rootHolder = { new RefHolder ( ) }
3841
3942 workingDirectory = { repo . getWorkingDirectoryPath ( ) }
4043 repository = { repo }
4144 allRemotes = { new RemoteSet ( ) }
45+ githubRemotes = { new RemoteSet ( ) }
46+ currentRemote = { nullRemote }
4247 branches = { new BranchSet ( ) }
48+ currentBranch = { nullBranch }
49+ aheadCount = { 0 }
50+ manyRemotesAvailable = { false }
4351 pushInProgress = { false }
4452 isLoading = { false }
4553 currentWorkDir = { repo . getWorkingDirectoryPath ( ) }
@@ -60,48 +68,15 @@ describe('GitHubTabController', function() {
6068 }
6169
6270 describe ( 'derived view props' , function ( ) {
63- const dotcom0 = new Remote ( 'yes0' , 'git@github.com:aaa/bbb.git' ) ;
64- const dotcom1 = new Remote ( 'yes1' , 'https://github.com/ccc/ddd.git' ) ;
65- const nonDotcom = new Remote ( 'no0' , 'git@sourceforge.net: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' , 'git@github.com:some/repo.git' ) ;
73+ const wrapper = shallow ( buildApp ( { currentRemote : remote } ) ) ;
74+ assert . strictEqual ( wrapper . find ( 'GitHubTabView' ) . prop ( 'endpoint' ) , remote . getEndpoint ( ) ) ;
9175 } ) ;
9276
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 ) ;
10580 } ) ;
10681 } ) ;
10782
@@ -139,5 +114,26 @@ describe('GitHubTabController', function() {
139114 wrapper . find ( 'GitHubTabView' ) . prop ( 'openBoundPublishDialog' ) ( ) ;
140115 assert . isTrue ( openPublishDialog . calledWith ( someRepo ) ) ;
141116 } ) ;
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+ } ) ;
142138 } ) ;
143139} ) ;
0 commit comments