Skip to content

Commit 4e3595c

Browse files
committed
Correct unit tests
1 parent 6a8b86b commit 4e3595c

File tree

3 files changed

+91
-32
lines changed

3 files changed

+91
-32
lines changed

src/components/NewBranchDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class NewBranchDialog extends React.Component<
218218
* @returns array of React elements
219219
*/
220220
private _renderItems(): JSX.Element {
221-
const current = this.props.model.currentBranch.name;
221+
const current = this.props.currentBranch;
222222
// Perform a "simple" filter... (TODO: consider implementing fuzzy filtering)
223223
const filter = this.state.filter;
224224
const branches = this.props.branches

tests/test-components/BranchMenu.spec.tsx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ const BRANCHES = [
4747

4848
async function createModel() {
4949
const model = new GitExtension('/server/root');
50-
51-
jest.spyOn(model, 'branches', 'get').mockReturnValue(BRANCHES);
52-
jest.spyOn(model, 'currentBranch', 'get').mockReturnValue(BRANCHES[0]);
5350
model.pathRepository = '/path/to/repo';
5451

5552
await model.ready;
@@ -82,6 +79,8 @@ describe('BranchMenu', () => {
8279
describe('constructor', () => {
8380
it('should return a new instance', () => {
8481
const props = {
82+
currentBranch: BRANCHES[0].name,
83+
branches: BRANCHES,
8584
model: model,
8685
branching: false,
8786
logger: new Logger(),
@@ -92,6 +91,8 @@ describe('BranchMenu', () => {
9291

9392
it('should set the default menu filter to an empty string', () => {
9493
const props = {
94+
currentBranch: BRANCHES[0].name,
95+
branches: BRANCHES,
9596
model: model,
9697
branching: false,
9798
logger: new Logger(),
@@ -102,6 +103,8 @@ describe('BranchMenu', () => {
102103

103104
it('should set the default flag indicating whether to show a dialog to create a new branch to `false`', () => {
104105
const props = {
106+
currentBranch: BRANCHES[0].name,
107+
branches: BRANCHES,
105108
model: model,
106109
branching: false,
107110
logger: new Logger(),
@@ -114,6 +117,8 @@ describe('BranchMenu', () => {
114117
describe('render', () => {
115118
it('should display placeholder text for the menu filter', () => {
116119
const props = {
120+
currentBranch: BRANCHES[0].name,
121+
branches: BRANCHES,
117122
model: model,
118123
branching: false,
119124
logger: new Logger(),
@@ -125,6 +130,8 @@ describe('BranchMenu', () => {
125130

126131
it('should set a `title` attribute on the input element to filter a branch menu', () => {
127132
const props = {
133+
currentBranch: BRANCHES[0].name,
134+
branches: BRANCHES,
128135
model: model,
129136
branching: false,
130137
logger: new Logger(),
@@ -136,6 +143,8 @@ describe('BranchMenu', () => {
136143

137144
it('should display a button to clear the menu filter once a filter is provided', () => {
138145
const props = {
146+
currentBranch: BRANCHES[0].name,
147+
branches: BRANCHES,
139148
model: model,
140149
branching: false,
141150
logger: new Logger(),
@@ -150,6 +159,8 @@ describe('BranchMenu', () => {
150159

151160
it('should set a `title` on the button to clear the menu filter', () => {
152161
const props = {
162+
currentBranch: BRANCHES[0].name,
163+
branches: BRANCHES,
153164
model: model,
154165
branching: false,
155166
logger: new Logger(),
@@ -167,6 +178,8 @@ describe('BranchMenu', () => {
167178

168179
it('should display a button to create a new branch', () => {
169180
const props = {
181+
currentBranch: BRANCHES[0].name,
182+
branches: BRANCHES,
170183
model: model,
171184
branching: false,
172185
logger: new Logger(),
@@ -178,6 +191,8 @@ describe('BranchMenu', () => {
178191

179192
it('should set a `title` attribute on the button to create a new branch', () => {
180193
const props = {
194+
currentBranch: BRANCHES[0].name,
195+
branches: BRANCHES,
181196
model: model,
182197
branching: false,
183198
logger: new Logger(),
@@ -189,14 +204,16 @@ describe('BranchMenu', () => {
189204

190205
it('should display a list of branches', () => {
191206
const props = {
207+
currentBranch: BRANCHES[0].name,
208+
branches: BRANCHES,
192209
model: model,
193210
branching: false,
194211
logger: new Logger(),
195212
};
196213
const component = render(<BranchMenu {...props} />);
197214
const nodes = component.find(`.${listItemClass}`);
198215

199-
const branches = model.branches;
216+
const branches = BRANCHES;
200217
expect(nodes.length).toEqual(branches.length);
201218

202219
// Should contain the branch names...
@@ -209,14 +226,16 @@ describe('BranchMenu', () => {
209226

210227
it('should set a `title` attribute for each displayed branch', () => {
211228
const props = {
229+
currentBranch: BRANCHES[0].name,
230+
branches: BRANCHES,
212231
model: model,
213232
branching: false,
214233
logger: new Logger(),
215234
};
216235
const component = render(<BranchMenu {...props} />);
217236
const nodes = component.find(`.${listItemClass}`);
218237

219-
const branches = model.branches;
238+
const branches = BRANCHES;
220239
expect(nodes.length).toEqual(branches.length);
221240

222241
for (let i = 0; i < branches.length; i++) {
@@ -226,6 +245,8 @@ describe('BranchMenu', () => {
226245

227246
it('should not, by default, show a dialog to create a new branch', () => {
228247
const props = {
248+
currentBranch: BRANCHES[0].name,
249+
branches: BRANCHES,
229250
model: model,
230251
branching: false,
231252
logger: new Logger(),
@@ -237,6 +258,8 @@ describe('BranchMenu', () => {
237258

238259
it('should show a dialog to create a new branch when the flag indicating whether to show the dialog is `true`', () => {
239260
const props = {
261+
currentBranch: BRANCHES[0].name,
262+
branches: BRANCHES,
240263
model: model,
241264
branching: false,
242265
logger: new Logger(),
@@ -255,6 +278,8 @@ describe('BranchMenu', () => {
255278
const spy = jest.spyOn(GitExtension.prototype, 'checkout');
256279

257280
const props = {
281+
currentBranch: BRANCHES[0].name,
282+
branches: BRANCHES,
258283
model: model,
259284
branching: false,
260285
logger: new Logger(),
@@ -271,6 +296,8 @@ describe('BranchMenu', () => {
271296
const spy = jest.spyOn(GitExtension.prototype, 'checkout');
272297

273298
const props = {
299+
currentBranch: BRANCHES[0].name,
300+
branches: BRANCHES,
274301
model: model,
275302
branching: true,
276303
logger: new Logger(),
@@ -293,6 +320,8 @@ describe('BranchMenu', () => {
293320
const spy = jest.spyOn(GitExtension.prototype, 'checkout');
294321

295322
const props = {
323+
currentBranch: BRANCHES[0].name,
324+
branches: BRANCHES,
296325
model: model,
297326
branching: false,
298327
logger: new Logger(),
@@ -311,6 +340,8 @@ describe('BranchMenu', () => {
311340
const spy = jest.spyOn(GitExtension.prototype, 'checkout');
312341

313342
const props = {
343+
currentBranch: BRANCHES[0].name,
344+
branches: BRANCHES,
314345
model: model,
315346
branching: true,
316347
logger: new Logger(),

0 commit comments

Comments
 (0)