forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen-commit-dialog.test.js
More file actions
97 lines (76 loc) · 3.16 KB
/
Copy pathopen-commit-dialog.test.js
File metadata and controls
97 lines (76 loc) · 3.16 KB
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
import React from 'react';
import {mount} from 'enzyme';
import OpenCommitDialog from '../../lib/views/open-commit-dialog';
describe('OpenCommitDialog', function() {
let atomEnv, commandRegistry;
let app, wrapper, didAccept, didCancel, isValidEntry;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
commandRegistry = atomEnv.commands;
didAccept = sinon.stub();
didCancel = sinon.stub();
isValidEntry = sinon.stub().returns(true);
app = (
<OpenCommitDialog
commandRegistry={commandRegistry}
didAccept={didAccept}
didCancel={didCancel}
isValidEntry={isValidEntry}
/>
);
wrapper = mount(app);
});
afterEach(function() {
atomEnv.destroy();
});
const setTextIn = function(selector, text) {
wrapper.find(selector).getDOMNode().getModel().setText(text);
};
describe('entering a commit sha', function() {
it("updates the commit ref automatically if it hasn't been modified", function() {
setTextIn('.github-CommitRef atom-text-editor', 'asdf1234');
assert.equal(wrapper.instance().getCommitRef(), 'asdf1234');
});
it('does update the ref if it was modified automatically', function() {
setTextIn('.github-CommitRef atom-text-editor', 'asdf1234');
assert.equal(wrapper.instance().getCommitRef(), 'asdf1234');
setTextIn('.github-CommitRef atom-text-editor', 'zxcv5678');
assert.equal(wrapper.instance().getCommitRef(), 'zxcv5678');
});
});
describe('open button enablement and error state', function() {
it('disables the open button with no commit ref', function() {
setTextIn('.github-CommitRef atom-text-editor', '');
wrapper.update();
assert.isTrue(wrapper.find('button.icon-commit').prop('disabled'));
assert.isFalse(wrapper.find('.error').exists());
});
it('disables the open button when the commit does not exist in repo', async function() {
isValidEntry.returns(false);
const ref = 'abcd1234';
setTextIn('.github-CommitRef atom-text-editor', ref);
wrapper.find('button.icon-commit').simulate('click');
await assert.async.strictEqual(wrapper.update().find('.error').text(), `There is no commit associated with "${ref}" in this repository`);
assert.isTrue(wrapper.find('button.icon-commit').prop('disabled'));
});
it('enables the open button when commit sha box is populated with a valid sha', function() {
setTextIn('.github-CommitRef atom-text-editor', 'abcd1234');
wrapper.update();
assert.isFalse(wrapper.find('button.icon-commit').prop('disabled'));
assert.isFalse(wrapper.find('.error').exists());
});
});
it('calls the acceptance callback after validation', async function() {
isValidEntry.returns(true);
const ref = 'abcd1234';
setTextIn('.github-CommitRef atom-text-editor', ref);
wrapper.find('button.icon-commit').simulate('click');
await assert.async.isTrue(didAccept.calledWith({ref}));
wrapper.unmount();
});
it('calls the cancellation callback', function() {
wrapper.find('button.github-CancelButton').simulate('click');
assert.isTrue(didCancel.called);
wrapper.unmount();
});
});