Skip to content

Commit ab18c25

Browse files
committed
Fix jest tests
1 parent 6fb9866 commit ab18c25

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

tests/GitExtension.spec.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ describe('IGitExtension', () => {
7474
const app = {
7575
commands: {
7676
hasCommand: jest.fn().mockReturnValue(true)
77+
},
78+
docRegistry: {
79+
getFileTypesForPath: jest.fn().mockReturnValue([])
7780
}
7881
};
7982
model = new GitExtension(app as any);

tests/test-components/Toolbar.spec.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import * as React from 'react';
2-
import 'jest';
1+
import { refreshIcon } from '@jupyterlab/ui-components';
32
import { shallow } from 'enzyme';
4-
import { GitExtension } from '../../src/model';
5-
import * as git from '../../src/git';
3+
import 'jest';
4+
import * as React from 'react';
5+
import { ActionButton } from '../../src/components/ActionButton';
66
import { Toolbar } from '../../src/components/Toolbar';
7+
import * as git from '../../src/git';
8+
import { GitExtension } from '../../src/model';
9+
import { pullIcon, pushIcon } from '../../src/style/icons';
710
import {
8-
pullButtonClass,
9-
pushButtonClass,
10-
refreshButtonClass,
11+
toolbarButtonClass,
1112
toolbarMenuButtonClass
1213
} from '../../src/style/Toolbar';
1314

@@ -133,8 +134,9 @@ describe('Toolbar', () => {
133134
refresh: async () => {}
134135
};
135136
const node = shallow(<Toolbar {...props} />);
136-
const nodes = node.find(`.${pullButtonClass}`);
137-
137+
const nodes = node
138+
.find(ActionButton)
139+
.findWhere(n => n.prop('icon') === pullIcon);
138140
expect(nodes.length).toEqual(1);
139141
});
140142

@@ -145,7 +147,10 @@ describe('Toolbar', () => {
145147
refresh: async () => {}
146148
};
147149
const node = shallow(<Toolbar {...props} />);
148-
const button = node.find(`.${pullButtonClass}`).first();
150+
const button = node
151+
.find(ActionButton)
152+
.findWhere(n => n.prop('icon') === pullIcon)
153+
.first();
149154

150155
expect(button.prop('title')).toEqual('Pull latest changes');
151156
});
@@ -157,8 +162,9 @@ describe('Toolbar', () => {
157162
refresh: async () => {}
158163
};
159164
const node = shallow(<Toolbar {...props} />);
160-
const nodes = node.find(`.${pushButtonClass}`);
161-
165+
const nodes = node
166+
.find(ActionButton)
167+
.findWhere(n => n.prop('icon') === pushIcon);
162168
expect(nodes.length).toEqual(1);
163169
});
164170

@@ -169,7 +175,10 @@ describe('Toolbar', () => {
169175
refresh: async () => {}
170176
};
171177
const node = shallow(<Toolbar {...props} />);
172-
const button = node.find(`.${pushButtonClass}`).first();
178+
const button = node
179+
.find(ActionButton)
180+
.findWhere(n => n.prop('icon') === pushIcon)
181+
.first();
173182

174183
expect(button.prop('title')).toEqual('Push committed changes');
175184
});
@@ -181,7 +190,9 @@ describe('Toolbar', () => {
181190
refresh: async () => {}
182191
};
183192
const node = shallow(<Toolbar {...props} />);
184-
const nodes = node.find(`.${refreshButtonClass}`);
193+
const nodes = node
194+
.find(ActionButton)
195+
.findWhere(n => n.prop('icon') === refreshIcon);
185196

186197
expect(nodes.length).toEqual(1);
187198
});
@@ -193,7 +204,7 @@ describe('Toolbar', () => {
193204
refresh: async () => {}
194205
};
195206
const node = shallow(<Toolbar {...props} />);
196-
const button = node.find(`.${refreshButtonClass}`).first();
207+
const button = node.find(ActionButton).last();
197208

198209
expect(button.prop('title')).toEqual(
199210
'Refresh the repository to detect local and remote changes'
@@ -309,7 +320,7 @@ describe('Toolbar', () => {
309320
refresh: async () => {}
310321
};
311322
const node = shallow(<Toolbar {...props} />);
312-
const button = node.find(`.${pullButtonClass}`);
323+
const button = node.find(`.${toolbarButtonClass}`).first();
313324

314325
button.simulate('click');
315326
expect(spy).toHaveBeenCalledTimes(1);
@@ -338,7 +349,7 @@ describe('Toolbar', () => {
338349
refresh: async () => {}
339350
};
340351
const node = shallow(<Toolbar {...props} />);
341-
const button = node.find(`.${pushButtonClass}`);
352+
const button = node.find(`.${toolbarButtonClass}`).at(1);
342353

343354
button.simulate('click');
344355
expect(spy).toHaveBeenCalledTimes(1);
@@ -367,7 +378,7 @@ describe('Toolbar', () => {
367378
refresh: spy
368379
};
369380
const node = shallow(<Toolbar {...props} />);
370-
const button = node.find(`.${refreshButtonClass}`);
381+
const button = node.find(`.${toolbarButtonClass}`).last();
371382

372383
button.simulate('click');
373384
expect(spy).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)