This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 402
/
Copy pathgithub-tab-view.test.js
164 lines (137 loc) · 5.84 KB
/
github-tab-view.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import React from 'react';
import {shallow} from 'enzyme';
import temp from 'temp';
import Repository from '../../lib/models/repository';
import Remote, {nullRemote} from '../../lib/models/remote';
import RemoteSet from '../../lib/models/remote-set';
import Branch, {nullBranch} from '../../lib/models/branch';
import BranchSet from '../../lib/models/branch-set';
import GitHubTabView from '../../lib/views/github-tab-view';
import {DOTCOM} from '../../lib/models/endpoint';
import RefHolder from '../../lib/models/ref-holder';
import Refresher from '../../lib/models/refresher';
import {UNAUTHENTICATED, INSUFFICIENT} from '../../lib/shared/keytar-strategy';
import {buildRepository, cloneRepository} from '../helpers';
describe('GitHubTabView', function() {
let atomEnv;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(props) {
const repo = props.repository || Repository.absent();
return (
<GitHubTabView
refresher={new Refresher()}
rootHolder={new RefHolder()}
endpoint={DOTCOM}
token="1234"
workspace={atomEnv.workspace}
workingDirectory={repo.getWorkingDirectoryPath()}
getCurrentWorkDirs={() => []}
changeWorkingDirectory={() => {}}
contextLocked={false}
setContextLock={() => {}}
repository={repo}
remotes={new RemoteSet()}
currentRemote={nullRemote}
manyRemotesAvailable={false}
isLoading={false}
branches={new BranchSet()}
currentBranch={nullBranch}
pushInProgress={false}
handleLogin={() => {}}
handleLogout={() => {}}
handleTokenRetry={() => {}}
handleWorkDirSelect={() => {}}
handlePushBranch={() => {}}
handleRemoteSelect={() => {}}
onDidChangeWorkDirs={() => {}}
openCreateDialog={() => {}}
openBoundPublishDialog={() => {}}
openCloneDialog={() => {}}
openGitTab={() => {}}
{...props}
/>
);
}
it('renders a LoadingView if the token is still loading', function() {
const wrapper = shallow(buildApp({token: null}));
assert.isTrue(wrapper.exists('LoadingView'));
});
it('renders a login view if the token is missing or incorrect', function() {
const wrapper = shallow(buildApp({token: UNAUTHENTICATED}));
assert.isTrue(wrapper.exists('GithubLoginView'));
});
it('renders a login view with a custom message if the token has insufficient scopes', function() {
const wrapper = shallow(buildApp({token: INSUFFICIENT}));
assert.isTrue(wrapper.exists('GithubLoginView'));
assert.isTrue(wrapper.find('GithubLoginView').exists('p'));
});
it('renders an error view if there was an error acquiring the token', function() {
const e = new Error('oh no');
e.rawStack = e.stack;
const wrapper = shallow(buildApp({token: e}));
assert.isTrue(wrapper.exists('QueryErrorView'));
assert.strictEqual(wrapper.find('QueryErrorView').prop('error'), e);
});
it('renders a LoadingView if data is still loading', function() {
const wrapper = shallow(buildApp({isLoading: true}));
assert.isTrue(wrapper.find('LoadingView').exists());
});
it('renders a no-local view when no local repository is found', function() {
const wrapper = shallow(buildApp({
repository: Repository.absent(),
}));
assert.isTrue(wrapper.exists('GitHubBlankNoLocal'));
});
it('renders a uninitialized view when a local repository is not initialized', async function() {
const workdir = temp.mkdirSync();
const repository = await buildRepository(workdir);
const wrapper = shallow(buildApp({repository}));
assert.isTrue(wrapper.exists('GitHubBlankUninitialized'));
});
it('renders a no-remote view when the local repository has no remotes', async function() {
const repository = await buildRepository(await cloneRepository());
const wrapper = shallow(buildApp({repository, currentRemote: nullRemote, manyRemotesAvailable: false}));
assert.isTrue(wrapper.exists('GitHubBlankNoRemote'));
});
it('renders a RemoteContainer if a remote has been chosen', async function() {
const repository = await buildRepository(await cloneRepository());
const currentRemote = new Remote('aaa', 'git@github.com:aaa/bbb.git');
const currentBranch = new Branch('bbb');
const handlePushBranch = sinon.spy();
const wrapper = shallow(buildApp({repository, currentRemote, currentBranch, handlePushBranch}));
const container = wrapper.find('RemoteContainer');
assert.isTrue(container.exists());
assert.strictEqual(container.prop('remote'), currentRemote);
container.prop('onPushBranch')();
assert.isTrue(handlePushBranch.calledWith(currentBranch, currentRemote));
});
it('renders a RemoteSelectorView when many remote choices are available', async function() {
const repository = await buildRepository(await cloneRepository());
const remotes = new RemoteSet();
const handleRemoteSelect = sinon.spy();
const wrapper = shallow(buildApp({
repository,
remotes,
currentRemote: nullRemote,
manyRemotesAvailable: true,
handleRemoteSelect,
}));
const selector = wrapper.find('RemoteSelectorView');
assert.isTrue(selector.exists());
assert.strictEqual(selector.prop('remotes'), remotes);
selector.prop('selectRemote')();
assert.isTrue(handleRemoteSelect.called);
});
it('calls changeWorkingDirectory when a project is selected', function() {
const currentRemote = new Remote('aaa', 'git@github.com:aaa/bbb.git');
const changeWorkingDirectory = sinon.spy();
const wrapper = shallow(buildApp({currentRemote, changeWorkingDirectory}));
wrapper.find('GithubTabHeaderContainer').prop('changeWorkingDirectory')('some-path');
assert.isTrue(changeWorkingDirectory.calledWith('some-path'));
});
});