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

Commit 7fe471e

Browse files
committed
GithubTabHeaderController tests
1 parent 5d6ea5a commit 7fe471e

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

lib/controllers/github-tab-header-controller.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ export default class GithubTabHeaderController extends React.Component {
5353
user={this.props.user}
5454

5555
// Workspace
56-
workdirs={this.state.currentWorkDirs}
5756
workdir={this.getWorkDir()}
57+
workdirs={this.state.currentWorkDirs}
5858
contextLocked={this.getContextLocked()}
59+
changingWorkDir={this.state.changingWorkDir !== null}
60+
changingLock={this.state.changingLock !== null}
5961

6062
handleWorkDirChange={this.handleWorkDirChange}
6163
handleLockToggle={this.handleLockToggle}
@@ -93,7 +95,7 @@ export default class GithubTabHeaderController extends React.Component {
9395
this.setState({changingWorkDir: nextWorkDir});
9496
await this.props.changeWorkingDirectory(nextWorkDir);
9597
} finally {
96-
await new Promise(resolve => this.setState({changingWork: null}, resolve));
98+
await new Promise(resolve => this.setState({changingWorkDir: null}, resolve));
9799
}
98100
}
99101

test/controllers/github-tab-header-controller.test.js

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ describe('GithubTabHeaderController', function() {
1515
function buildApp(overrides) {
1616
const props = {
1717
user: nullAuthor,
18+
currentWorkDir: null,
19+
contextLocked: false,
20+
changeWorkingDirectory: () => {},
21+
setContextLock: () => {},
1822
getCurrentWorkDirs: () => createWorkdirs([]),
19-
onDidUpdateRepo: () => new Disposable(),
2023
onDidChangeWorkDirs: () => new Disposable(),
21-
handleWorkDirSelect: () => null,
2224
...overrides,
2325
};
2426
return (
@@ -73,6 +75,62 @@ describe('GithubTabHeaderController', function() {
7375
assert.isTrue(getCurrentWorkDirs.calledTwice);
7476
});
7577

78+
it('handles a lock toggle', async function() {
79+
let resolveLockChange;
80+
const setContextLock = sinon.stub().returns(new Promise(resolve => {
81+
resolveLockChange = resolve;
82+
}))
83+
const wrapper = shallow(buildApp({currentWorkDir: 'the/workdir', contextLocked: false, setContextLock}));
84+
85+
assert.isFalse(wrapper.find('GithubTabHeaderView').prop('contextLocked'));
86+
assert.isFalse(wrapper.find('GithubTabHeaderView').prop('changingLock'));
87+
88+
const handlerPromise = wrapper.find('GithubTabHeaderView').prop('handleLockToggle')();
89+
wrapper.update();
90+
91+
assert.isTrue(wrapper.find('GithubTabHeaderView').prop('contextLocked'));
92+
assert.isTrue(wrapper.find('GithubTabHeaderView').prop('changingLock'));
93+
assert.isTrue(setContextLock.calledWith('the/workdir', true));
94+
95+
// Ignored while in-progress
96+
wrapper.find('GithubTabHeaderView').prop('handleLockToggle')();
97+
98+
resolveLockChange();
99+
await handlerPromise;
100+
101+
assert.isFalse(wrapper.find('GithubTabHeaderView').prop('changingLock'));
102+
});
103+
104+
it('handles a workdir selection', async function() {
105+
let resolveWorkdirChange;
106+
const changeWorkingDirectory = sinon.stub().returns(new Promise(resolve => {
107+
resolveWorkdirChange = resolve;
108+
}))
109+
const wrapper = shallow(buildApp({currentWorkDir: 'original', changeWorkingDirectory}));
110+
111+
assert.strictEqual(wrapper.find('GithubTabHeaderView').prop('workdir'), 'original');
112+
assert.isFalse(wrapper.find('GithubTabHeaderView').prop('changingWorkDir'));
113+
114+
const handlerPromise = wrapper.find('GithubTabHeaderView').prop('handleWorkDirChange')({
115+
target: {value: 'work/dir'},
116+
});
117+
wrapper.update();
118+
119+
assert.strictEqual(wrapper.find('GithubTabHeaderView').prop('workdir'), 'work/dir');
120+
assert.isTrue(wrapper.find('GithubTabHeaderView').prop('changingWorkDir'));
121+
assert.isTrue(changeWorkingDirectory.calledWith('work/dir'));
122+
123+
// Ignored while in-progress
124+
wrapper.find('GithubTabHeaderView').prop('handleWorkDirChange')({
125+
target: {value: 'ig/nored'},
126+
});
127+
128+
resolveWorkdirChange();
129+
await handlerPromise;
130+
131+
assert.isFalse(wrapper.find('GithubTabHeaderView').prop('changingWorkDir'));
132+
});
133+
76134
it('disposes on unmount', function() {
77135
const disposeSpy = sinon.spy();
78136
const onDidChangeWorkDirs = () => ({dispose: disposeSpy});

0 commit comments

Comments
 (0)