forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-tab-controller.test.js
139 lines (115 loc) · 5.31 KB
/
github-tab-controller.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React from 'react';
import {shallow} from 'enzyme';
import GitHubTabController from '../../lib/controllers/github-tab-controller';
import Repository from '../../lib/models/repository';
import BranchSet from '../../lib/models/branch-set';
import Branch, {nullBranch} from '../../lib/models/branch';
import RemoteSet from '../../lib/models/remote-set';
import Remote, {nullRemote} from '../../lib/models/remote';
import {DOTCOM} from '../../lib/models/endpoint';
import {InMemoryStrategy, UNAUTHENTICATED} from '../../lib/shared/keytar-strategy';
import GithubLoginModel from '../../lib/models/github-login-model';
import RefHolder from '../../lib/models/ref-holder';
import Refresher from '../../lib/models/refresher';
import * as reporterProxy from '../../lib/reporter-proxy';
import {buildRepository, cloneRepository} from '../helpers';
describe('GitHubTabController', function() {
let atomEnv, repository;
beforeEach(async function() {
atomEnv = global.buildAtomEnvironment();
repository = await buildRepository(await cloneRepository());
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(props = {}) {
const repo = props.repository || repository;
return (
<GitHubTabController
workspace={atomEnv.workspace}
refresher={new Refresher()}
loginModel={new GithubLoginModel(InMemoryStrategy)}
token="1234"
rootHolder={new RefHolder()}
workingDirectory={repo.getWorkingDirectoryPath()}
repository={repo}
allRemotes={new RemoteSet()}
githubRemotes={new RemoteSet()}
currentRemote={nullRemote}
branches={new BranchSet()}
currentBranch={nullBranch}
aheadCount={0}
manyRemotesAvailable={false}
pushInProgress={false}
isLoading={false}
currentWorkDir={repo.getWorkingDirectoryPath()}
changeWorkingDirectory={() => {}}
setContextLock={() => {}}
contextLocked={false}
onDidChangeWorkDirs={() => {}}
getCurrentWorkDirs={() => []}
openCreateDialog={() => {}}
openPublishDialog={() => {}}
openCloneDialog={() => {}}
openGitTab={() => {}}
{...props}
/>
);
}
describe('derived view props', function() {
it('passes the endpoint from the current GitHub remote when one exists', function() {
const remote = new Remote('hub', '[email protected]:some/repo.git');
const wrapper = shallow(buildApp({currentRemote: remote}));
assert.strictEqual(wrapper.find('GitHubTabView').prop('endpoint'), remote.getEndpoint());
});
it('defaults the endpoint to dotcom', function() {
const wrapper = shallow(buildApp({currentRemote: nullRemote}));
assert.strictEqual(wrapper.find('GitHubTabView').prop('endpoint'), DOTCOM);
});
});
describe('actions', function() {
it('pushes a branch', async function() {
const absent = Repository.absent();
sinon.stub(absent, 'push').resolves(true);
const wrapper = shallow(buildApp({repository: absent}));
const branch = new Branch('abc');
const remote = new Remote('def', '[email protected]:def/ghi.git');
assert.isTrue(await wrapper.find('GitHubTabView').prop('handlePushBranch')(branch, remote));
assert.isTrue(absent.push.calledWith('abc', {remote, setUpstream: true}));
});
it('chooses a remote', async function() {
const absent = Repository.absent();
sinon.stub(absent, 'setConfig').resolves(true);
const wrapper = shallow(buildApp({repository: absent}));
const remote = new Remote('aaa', '[email protected]:aaa/aaa.git');
const event = {preventDefault: sinon.spy()};
assert.isTrue(await wrapper.find('GitHubTabView').prop('handleRemoteSelect')(event, remote));
assert.isTrue(event.preventDefault.called);
assert.isTrue(absent.setConfig.calledWith('atomGithub.currentRemote', 'aaa'));
});
it('opens the publish dialog on the active repository', async function() {
const someRepo = await buildRepository(await cloneRepository());
const openPublishDialog = sinon.spy();
const wrapper = shallow(buildApp({repository: someRepo, openPublishDialog}));
wrapper.find('GitHubTabView').prop('openBoundPublishDialog')();
assert.isTrue(openPublishDialog.calledWith(someRepo));
});
it('handles and instruments a login', async function() {
sinon.stub(reporterProxy, 'incrementCounter');
const loginModel = new GithubLoginModel(InMemoryStrategy);
const wrapper = shallow(buildApp({loginModel}));
await wrapper.find('GitHubTabView').prop('handleLogin')('good-token');
assert.strictEqual(await loginModel.getToken(DOTCOM.getLoginAccount()), 'good-token');
assert.isTrue(reporterProxy.incrementCounter.calledWith('github-login'));
});
it('handles and instruments a logout', async function() {
sinon.stub(reporterProxy, 'incrementCounter');
const loginModel = new GithubLoginModel(InMemoryStrategy);
await loginModel.setToken(DOTCOM.getLoginAccount(), 'good-token');
const wrapper = shallow(buildApp({loginModel}));
await wrapper.find('GitHubTabView').prop('handleLogout')();
assert.strictEqual(await loginModel.getToken(DOTCOM.getLoginAccount()), UNAUTHENTICATED);
assert.isTrue(reporterProxy.incrementCounter.calledWith('github-logout'));
});
});
});