Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 1e2a8b8

Browse files
update test cases
1 parent a28ece8 commit 1e2a8b8

File tree

4 files changed

+83
-21
lines changed

4 files changed

+83
-21
lines changed

lib/views/tab-header-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class TabHeaderView extends React.Component {
88

99
handleWorkDirSelect: PropTypes.func,
1010
onDidChangeWorkDirs: PropTypes.func,
11-
getCurrentWorkDirs: PropTypes.func,
11+
getCurrentWorkDirs: PropTypes.func.isRequired,
1212
}
1313

1414
constructor(props) {

test/views/git-tab-view.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ describe('GitTabView', function() {
286286
it('calls changeWorkingDirectory when a project is selected', async function() {
287287
const changeWorkingDirectory = sinon.spy();
288288
const wrapper = shallow(await buildApp({changeWorkingDirectory}));
289-
wrapper.find('TabHeaderView').prop('handleProjectSelect')({target: {value: 'some-path'}});
289+
wrapper.find('TabHeaderView').prop('handleWorkDirSelect')({target: {value: 'some-path'}});
290290
assert.isTrue(changeWorkingDirectory.calledWith('some-path'));
291291
});
292292
});

test/views/github-tab-view.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('GitHubTabView', function() {
6767
it('calls changeWorkingDirectory when a project is selected', async function() {
6868
const changeWorkingDirectory = sinon.spy();
6969
const wrapper = shallow(await buildApp({changeWorkingDirectory}));
70-
wrapper.find('TabHeaderView').prop('handleProjectSelect')({target: {value: 'some-path'}});
70+
wrapper.find('TabHeaderView').prop('handleWorkDirSelect')({target: {value: 'some-path'}});
7171
assert.isTrue(changeWorkingDirectory.calledWith('some-path'));
7272
});
7373
});

test/views/tab-header-view.test.js

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,91 @@ import path from 'path';
55
import TabHeaderView from '../../lib/views/tab-header-view';
66

77
describe('TabHeaderView', function() {
8-
let wrapper, select;
9-
const path1 = 'test/path/project1';
10-
const path2 = '2nd-test/path/project2';
11-
const paths = [path1, path2];
12-
13-
beforeEach(function() {
14-
select = sinon.spy();
15-
wrapper = shallow(<TabHeaderView handleProjectSelect={select} projectPaths={paths} currentProject={path2} />);
16-
});
8+
function build(options = {}) {
9+
const props = {
10+
currentWorkDir: undefined,
11+
onDidChangeWorkDirs: undefined,
12+
handleWorkDirSelect: undefined,
13+
getCurrentWorkDirs: () => [],
14+
...options,
15+
}
16+
return shallow(<TabHeaderView {...props}/>);
17+
}
18+
19+
describe('with a select listener and paths', function() {
20+
let wrapper, select;
21+
const path1 = path.normalize('test/path/project1');
22+
const path2 = path.normalize('2nd-test/path/project2');
23+
const paths = [path1, path2];
24+
25+
beforeEach(function() {
26+
select = sinon.spy();
27+
wrapper = build({handleWorkDirSelect: select, getCurrentWorkDirs: () => paths, currentWorkDir: path2});
28+
});
29+
30+
it('renders an option for all given working directories', function() {
31+
wrapper.find('option').forEach(function(node, index) {
32+
assert.strictEqual(node.props().value, paths[index]);
33+
assert.strictEqual(node.children().text(), path.basename(paths[index]));
34+
});
35+
});
1736

18-
it('renders an option for all given project paths', function() {
19-
wrapper.find('option').forEach(function(node, index) {
20-
assert.strictEqual(node.props().value, paths[index]);
21-
assert.strictEqual(node.children().text(), path.basename(paths[index]));
37+
it('selects the current working directory\'s path', function() {
38+
assert.strictEqual(wrapper.find('select').props().value, path2);
2239
});
40+
41+
it('calls handleWorkDirSelect on select', function() {
42+
wrapper.find('select').simulate('change', {target: {value: path1}});
43+
assert.isTrue(select.calledWith({target: {value: path1}}));
44+
});
45+
46+
it('updates paths', function() {
47+
const path3 = 'test3/path/project3';
48+
paths.push(path3);
49+
wrapper.instance().updateWorkDirs();
50+
assert.strictEqual(wrapper.find('option').length, 3);
51+
})
2352
});
2453

25-
it('selects the current project\'s path', function() {
26-
assert.strictEqual(wrapper.find('select').props().value, path2);
54+
describe('with onDidChangeWorkDirs', function() {
55+
let wrapper, changeSpy, disposeSpy;
56+
57+
beforeEach(function() {
58+
disposeSpy = sinon.spy();
59+
const stub = sinon.stub().callsFake(function(updateWorkDirs) {
60+
updateWorkDirs();
61+
return {dispose: disposeSpy};
62+
});
63+
changeSpy = sinon.spy(stub);
64+
wrapper = build({onDidChangeWorkDirs: changeSpy});
65+
});
66+
67+
it('calls onDidChangeWorkDirs with updateWorkDirs', function() {
68+
assert.isTrue(changeSpy.calledWith(wrapper.instance().updateWorkDirs));
69+
});
70+
71+
it('calls dispose on unmount', function() {
72+
wrapper.unmount();
73+
assert.isTrue(disposeSpy.called);
74+
});
75+
76+
it('does nothing on unmount without a disposable', function() {
77+
wrapper.instance().disposable = undefined;
78+
wrapper.unmount();
79+
assert.isFalse(disposeSpy.called);
80+
});
81+
2782
});
2883

29-
it('calls handleProjectSelect on select', function() {
30-
wrapper.find('select').simulate('change', {target: {value: path1}});
31-
assert.isTrue(select.calledWith({target: {value: path1}}));
84+
describe('with no paths', function() {
85+
let wrapper;
86+
87+
beforeEach(function() {
88+
wrapper = build();
89+
});
90+
91+
it('renders no options', function() {
92+
assert.isTrue(wrapper.find('select').children().isEmpty());
93+
});
3294
});
3395
});

0 commit comments

Comments
 (0)