forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectory-select.test.js
71 lines (53 loc) · 2.19 KB
/
directory-select.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
import React from 'react';
import {shallow} from 'enzyme';
import {TextBuffer} from 'atom';
import DirectorySelect from '../../lib/views/directory-select';
import TabGroup from '../../lib/tab-group';
import {TabbableTextEditor} from '../../lib/views/tabbable';
describe('DirectorySelect', function() {
let atomEnv;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(override = {}) {
const buffer = new TextBuffer();
return (
<DirectorySelect
currentWindow={atomEnv.getCurrentWindow()}
buffer={buffer}
showOpenDialog={() => Promise.resolve()}
tabGroup={new TabGroup()}
{...override}
/>
);
}
it('renders an editor for the destination path', function() {
const buffer = new TextBuffer();
const wrapper = shallow(buildApp({buffer}));
assert.strictEqual(wrapper.find('.github-DirectorySelect-destinationPath').prop('buffer'), buffer);
});
it('disables both controls', function() {
const wrapper = shallow(buildApp({disabled: true}));
assert.isTrue(wrapper.find(TabbableTextEditor).prop('readOnly'));
assert.isTrue(wrapper.find('.btn.icon-file-directory').prop('disabled'));
});
describe('clicking the directory button', function() {
it('populates the destination path buffer on accept', async function() {
const showOpenDialog = sinon.stub().returns(Promise.resolve({filePaths: ['/some/directory/path']}));
const buffer = new TextBuffer({text: '/original'});
const wrapper = shallow(buildApp({showOpenDialog, buffer}));
await wrapper.find('.btn.icon-file-directory').prop('onClick')();
assert.strictEqual(buffer.getText(), '/some/directory/path');
});
it('leaves the destination path buffer unmodified on cancel', async function() {
const showOpenDialog = sinon.stub().returns(Promise.resolve({filePaths: []}));
const buffer = new TextBuffer({text: '/original'});
const wrapper = shallow(buildApp({showOpenDialog, buffer}));
await wrapper.find('.btn.icon-file-directory').prop('onClick')();
assert.strictEqual(buffer.getText(), '/original');
});
});
});