forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathco-author-form.test.js
94 lines (75 loc) · 2.73 KB
/
co-author-form.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
import React from 'react';
import {mount} from 'enzyme';
import CoAuthorForm from '../../lib/views/co-author-form';
import Author from '../../lib/models/author';
describe('CoAuthorForm', function() {
let atomEnv;
let app, wrapper, didSubmit, didCancel;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
didSubmit = sinon.stub();
didCancel = sinon.stub();
app = (
<CoAuthorForm
commands={atomEnv.commands}
onSubmit={didSubmit}
onCancel={didCancel}
/>
);
});
afterEach(function() {
atomEnv.destroy();
});
const setTextIn = function(selector, text) {
wrapper.find(selector).simulate('change', {target: {value: text}});
};
describe('initial component state', function() {
it('name prop is in name input field if supplied', function() {
const name = 'Original Name';
app = React.cloneElement(app, {name});
wrapper = mount(app);
assert.strictEqual(wrapper.find('.github-CoAuthorForm-name').prop('value'), name);
});
});
describe('submit', function() {
it('submits current co author name and email when form contains valid input', function() {
wrapper = mount(app);
const name = 'Coauthor Name';
const email = '[email protected]';
setTextIn('.github-CoAuthorForm-name', name);
setTextIn('.github-CoAuthorForm-email', email);
wrapper.find('.btn-primary').simulate('click');
assert.deepEqual(didSubmit.firstCall.args[0], new Author(email, name));
});
it('submit button is initially disabled', function() {
wrapper = mount(app);
const submitButton = wrapper.find('.btn-primary');
assert.isTrue(submitButton.prop('disabled'));
submitButton.simulate('click');
assert.isFalse(didSubmit.called);
});
it('submit button is disabled when form contains invalid input', function() {
wrapper = mount(app);
const name = 'Coauthor Name';
const email = 'foobar.com';
setTextIn('.github-CoAuthorForm-name', name);
setTextIn('.github-CoAuthorForm-email', email);
const submitButton = wrapper.find('.btn-primary');
assert.isTrue(submitButton.prop('disabled'));
submitButton.simulate('click');
assert.isFalse(didSubmit.called);
});
});
describe('cancel', function() {
it('calls cancel prop when cancel is clicked', function() {
wrapper = mount(app);
wrapper.find('.github-CancelButton').simulate('click');
assert.isTrue(didCancel.called);
});
it('calls cancel prop when `core:cancel` is triggered', function() {
wrapper = mount(app);
atomEnv.commands.dispatch(wrapper.find('.github-CoAuthorForm').getDOMNode(), 'core:cancel');
assert.isTrue(didCancel.called);
});
});
});