Repository navigation
Expand file tree
/
Copy pathgithub-tab-view.test.js
More file actions
136 lines (113 loc) · 4.78 KB
/
Copy pathgithub-tab-view.test.js
File metadata and controls
136 lines (113 loc) · 4.78 KB
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
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 {InMemoryStrategy} 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 {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()}
loginModel={new GithubLoginModel(InMemoryStrategy)}
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}
handleWorkDirSelect={() => {}}
handlePushBranch={() => {}}
handleRemoteSelect={() => {}}
onDidChangeWorkDirs={() => {}}
openCreateDialog={() => {}}
openBoundPublishDialog={() => {}}
openCloneDialog={() => {}}
openGitTab={() => {}}
{...props}
/>
);
}
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'));
});
});