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

Commit 5d6ea5a

Browse files
committed
GithubTabHeaderView tests
1 parent 72e9eff commit 5d6ea5a

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

lib/views/github-tab-header-view.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export default class GithubTabHeaderView extends React.Component {
1313
workdir: PropTypes.string,
1414
workdirs: PropTypes.shape({[Symbol.iterator]: PropTypes.func.isRequired}).isRequired,
1515
contextLocked: PropTypes.bool.isRequired,
16+
changingWorkDir: PropTypes.bool.isRequired,
17+
changingLock: PropTypes.bool.isRequired,
1618
handleWorkDirChange: PropTypes.func.isRequired,
1719
handleLockToggle: PropTypes.func.isRequired,
1820
}
@@ -22,11 +24,15 @@ export default class GithubTabHeaderView extends React.Component {
2224
<header className="github-Project">
2325
{this.renderUser()}
2426
<select className="github-Project-path input-select"
25-
value={this.props.workdir ? path.normalize(this.props.workdir) : undefined}
27+
value={this.props.workdir}
28+
disabled={this.props.changingWorkDir}
2629
onChange={this.props.handleWorkDirChange}>
2730
{this.renderWorkDirs()}
2831
</select>
29-
<button className="github-Project-lock btn btn-small" onClick={this.props.handleLockToggle}>
32+
<button
33+
className="github-Project-lock btn btn-small"
34+
disabled={this.props.changingLock}
35+
onClick={this.props.handleLockToggle}>
3036
<Octicon icon={this.props.contextLocked ? 'lock' : 'globe'} />
3137
</button>
3238
</header>

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ describe('GithubTabHeaderView', function() {
1515
function build(options = {}) {
1616
const props = {
1717
user: nullAuthor,
18+
workdir: null,
1819
workdirs: createWorkdirs([]),
20+
contextLocked: false,
21+
changingWorkDir: false,
22+
changingLock: false,
23+
handleWorkDirChange: () => {},
24+
handleLockToggle: () => {},
1925
...options,
2026
};
2127
return shallow(<GithubTabHeaderView {...props} />);
@@ -29,7 +35,7 @@ describe('GithubTabHeaderView', function() {
2935

3036
beforeEach(function() {
3137
select = sinon.spy();
32-
wrapper = build({handleWorkDirSelect: select, workdirs: createWorkdirs(paths), workdir: path2});
38+
wrapper = build({handleWorkDirChange: select, workdirs: createWorkdirs(paths), workdir: path2});
3339
});
3440

3541
it('renders an option for all given working directories', function() {
@@ -49,6 +55,42 @@ describe('GithubTabHeaderView', function() {
4955
});
5056
});
5157

58+
describe('context lock control', function() {
59+
it('renders locked when the lock is engaged', function() {
60+
const wrapper = build({contextLocked: true});
61+
62+
assert.isTrue(wrapper.exists('Octicon[icon="lock"]'));
63+
});
64+
65+
it('renders unlocked when the lock is disengaged', function() {
66+
const wrapper = build({contextLocked: false});
67+
68+
assert.isTrue(wrapper.exists('Octicon[icon="globe"]'));
69+
});
70+
71+
it('calls handleLockToggle when the lock is clicked', function() {
72+
const handleLockToggle = sinon.spy();
73+
const wrapper = build({handleLockToggle});
74+
75+
wrapper.find('button').simulate('click');
76+
assert.isTrue(handleLockToggle.called);
77+
});
78+
});
79+
80+
describe('when changes are in progress', function() {
81+
it('disables the workdir select while the workdir is changing', function() {
82+
const wrapper = build({changingWorkDir: true});
83+
84+
assert.isTrue(wrapper.find('select').prop('disabled'));
85+
});
86+
87+
it('disables the context lock toggle while the context lock is changing', function() {
88+
const wrapper = build({changingLock: true});
89+
90+
assert.isTrue(wrapper.find('button').prop('disabled'));
91+
})
92+
});
93+
5294
describe('with falsish props', function() {
5395
let wrapper;
5496

0 commit comments

Comments
 (0)