forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-pull-request-tile.test.js
221 lines (193 loc) · 6.67 KB
/
create-pull-request-tile.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import React from 'react';
import {shallow} from 'enzyme';
import CreatePullRequestTile from '../../lib/views/create-pull-request-tile';
import Remote from '../../lib/models/remote';
import Branch, {nullBranch} from '../../lib/models/branch';
import BranchSet from '../../lib/models/branch-set';
describe('CreatePullRequestTile', function() {
function buildApp(overrides = {}) {
const repository = {
defaultBranchRef: {
prefix: 'refs/heads',
name: 'master',
},
};
const branches = new BranchSet([
new Branch('feature', nullBranch, nullBranch, true),
]);
return (
<CreatePullRequestTile
repository={repository}
remote={new Remote('origin', '[email protected]:atom/github.git')}
branches={branches}
aheadCount={0}
pushInProgress={false}
onCreatePr={() => {}}
{...overrides}
/>
);
}
describe('static messages', function() {
it('reports a repository that is no longer found', function() {
const wrapper = shallow(buildApp({
repository: null,
}));
assert.strictEqual(
wrapper.find('.github-CreatePullRequestTile-message strong').at(0).text(),
'Repository not found',
);
});
it('reports a detached HEAD', function() {
const branches = new BranchSet([new Branch('other')]);
const wrapper = shallow(buildApp({branches}));
assert.strictEqual(
wrapper.find('.github-CreatePullRequestTile-message strong').at(0).text(),
'any branch',
);
});
it('reports when the remote repository has no default branch', function() {
const wrapper = shallow(buildApp({
repository: {
defaultBranchRef: null,
},
}));
assert.strictEqual(
wrapper.find('.github-CreatePullRequestTile-message strong').at(0).text(),
'empty',
);
});
it('reports when you are still on the default ref', function() {
// The destination ref of HEAD's *push* target is used to determine whether or not you're on the default ref
const branches = new BranchSet([
new Branch(
'current',
nullBranch,
Branch.createRemoteTracking('refs/remotes/origin/current', 'origin', 'refs/heads/whatever'),
true,
),
]);
const repository = {
defaultBranchRef: {
prefix: 'refs/heads/',
name: 'whatever',
},
};
const wrapper = shallow(buildApp({branches, repository}));
assert.strictEqual(
wrapper.find('.github-CreatePullRequestTile-message strong').at(0).text(),
'default branch',
);
});
it('reports when HEAD has not moved from the default ref', function() {
const branches = new BranchSet([
new Branch(
'current',
nullBranch,
Branch.createRemoteTracking('refs/remotes/origin/current', 'origin', 'refs/heads/whatever'),
true,
{sha: '1234'},
),
new Branch(
'pushes-to-main',
nullBranch,
Branch.createRemoteTracking('refs/remotes/origin/main', 'origin', 'refs/heads/main'),
false,
{sha: '1234'},
),
new Branch(
'pushes-to-main-2',
nullBranch,
Branch.createRemoteTracking('refs/remotes/origin/main', 'origin', 'refs/heads/main'),
false,
{sha: '5678'},
),
]);
const repository = {
defaultBranchRef: {
prefix: 'refs/heads/',
name: 'main',
},
};
const wrapper = shallow(buildApp({branches, repository}));
assert.strictEqual(
wrapper.find('.github-CreatePullRequestTile-message strong').at(0).text(),
'has not moved',
);
});
});
describe('pushing or publishing a branch', function() {
let repository, branches;
beforeEach(function() {
repository = {
defaultBranchRef: {
prefix: 'refs/heads/',
name: 'master',
},
};
const masterTracking = Branch.createRemoteTracking('refs/remotes/origin/current', 'origin', 'refs/heads/current');
branches = new BranchSet([
new Branch('current', masterTracking, masterTracking, true),
]);
});
it('disables the button while a push is in progress', function() {
const wrapper = shallow(buildApp({
repository,
branches,
pushInProgress: true,
}));
assert.strictEqual(wrapper.find('.github-CreatePullRequestTile-createPr').text(), 'Pushing...');
assert.isTrue(wrapper.find('.github-CreatePullRequestTile-createPr').prop('disabled'));
});
it('prompts to publish with no upstream', function() {
branches = new BranchSet([
new Branch('current', nullBranch, nullBranch, true),
]);
const wrapper = shallow(buildApp({
repository,
branches,
}));
assert.strictEqual(
wrapper.find('.github-CreatePullRequestTile-createPr').text(),
'Publish + open new pull request',
);
assert.isFalse(wrapper.find('.github-CreatePullRequestTile-createPr').prop('disabled'));
});
it('prompts to publish with an upstream on a different remote', function() {
const onDifferentRemote = Branch.createRemoteTracking(
'refs/remotes/upstream/current', 'upstream', 'refs/heads/current');
branches = new BranchSet([
new Branch('current', nullBranch, onDifferentRemote, true),
]);
const wrapper = shallow(buildApp({
repository,
branches,
}));
assert.strictEqual(
wrapper.find('.github-CreatePullRequestTile-message strong').at(0).text(),
'configured',
);
assert.strictEqual(
wrapper.find('.github-CreatePullRequestTile-createPr').text(),
'Publish + open new pull request',
);
assert.isFalse(wrapper.find('.github-CreatePullRequestTile-createPr').prop('disabled'));
});
it('prompts to push when the local ref is ahead', function() {
const wrapper = shallow(buildApp({
repository,
branches,
aheadCount: 10,
}));
assert.strictEqual(
wrapper.find('.github-CreatePullRequestTile-createPr').text(),
'Push + open new pull request',
);
assert.isFalse(wrapper.find('.github-CreatePullRequestTile-createPr').prop('disabled'));
});
it('falls back to prompting to open the PR', function() {
const wrapper = shallow(buildApp({repository, branches}));
assert.strictEqual(wrapper.find('.github-CreatePullRequestTile-createPr').text(), 'Open new pull request');
assert.isFalse(wrapper.find('.github-CreatePullRequestTile-createPr').prop('disabled'));
});
});
});