This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 402
/
Copy pathgit-tab-header-view.test.js
122 lines (98 loc) · 3.7 KB
/
git-tab-header-view.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React from 'react';
import {shallow} from 'enzyme';
import path from 'path';
import {nullAuthor} from '../../lib/models/author';
import GitTabHeaderView from '../../lib/views/git-tab-header-view';
describe('GitTabHeaderView', function() {
function *createWorkdirs(workdirs) {
for (const workdir of workdirs) {
yield workdir;
}
}
function build(options = {}) {
const props = {
committer: nullAuthor,
workdir: null,
workdirs: createWorkdirs([]),
contextLocked: false,
changingWorkDir: false,
changingLock: false,
handleAvatarClick: () => {},
handleWorkDirSelect: () => {},
handleLockToggle: () => {},
...options,
};
return shallow(<GitTabHeaderView {...props} />);
}
describe('with a select listener and paths', function() {
let wrapper, select;
const path1 = path.normalize('test/path/project1');
const path2 = path.normalize('2nd-test/path/project2');
const paths = [path1, path2];
beforeEach(function() {
select = sinon.spy();
wrapper = build({
handleWorkDirSelect: select,
workdirs: createWorkdirs(paths),
workdir: path2,
});
});
it('renders an option for all given working directories', function() {
wrapper.find('option').forEach(function(node, index) {
assert.strictEqual(node.props().value, paths[index]);
assert.strictEqual(node.children().text(), path.basename(paths[index]));
});
});
it('selects the current working directory\'s path', function() {
assert.strictEqual(wrapper.find('select').props().value, path2);
});
it('calls handleWorkDirSelect on select', function() {
wrapper.find('select').simulate('change', {target: {value: path1}});
assert.isTrue(select.calledWith({target: {value: path1}}));
});
});
it('triggers the handler callback on avatar button click', function() {
const handleAvatarClick = sinon.spy();
const wrapper = build({handleAvatarClick});
wrapper.find('.github-Project-avatarBtn').simulate('click');
assert.isTrue(handleAvatarClick.called);
});
describe('context lock control', function() {
it('renders locked when the lock is engaged', function() {
const wrapper = build({contextLocked: true});
assert.isTrue(wrapper.exists('Octicon[icon="lock"]'));
});
it('renders unlocked when the lock is disengaged', function() {
const wrapper = build({contextLocked: false});
assert.isTrue(wrapper.exists('Octicon[icon="unlock"]'));
});
it('calls handleLockToggle when the lock is clicked', function() {
const handleLockToggle = sinon.spy();
const wrapper = build({handleLockToggle});
wrapper.find('.github-Project-lock').simulate('click');
assert.isTrue(handleLockToggle.called);
});
});
describe('when changes are in progress', function() {
it('disables the workdir select while the workdir is changing', function() {
const wrapper = build({changingWorkDir: true});
assert.isTrue(wrapper.find('select').prop('disabled'));
});
it('disables the context lock toggle while the context lock is changing', function() {
const wrapper = build({changingLock: true});
assert.isTrue(wrapper.find('.github-Project-lock').prop('disabled'));
});
});
describe('with falsish props', function() {
let wrapper;
beforeEach(function() {
wrapper = build();
});
it('renders no options', function() {
assert.isFalse(wrapper.find('select').children().exists());
});
it('renders an avatar placeholder', function() {
assert.strictEqual(wrapper.find('img.github-Project-avatar').prop('src'), 'atom://github/img/avatar.svg');
});
});
});