forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout-button.test.js
66 lines (55 loc) · 2.41 KB
/
checkout-button.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
import React from 'react';
import {shallow} from 'enzyme';
import EnableableOperation from '../../lib/models/enableable-operation';
import {checkoutStates} from '../../lib/controllers/pr-checkout-controller';
import CheckoutButton from '../../lib/views/checkout-button';
describe('Checkout button', function() {
function buildApp(overrideProps = {}) {
return (
<CheckoutButton
checkoutOp={new EnableableOperation(() => {}).disable(checkoutStates.CURRENT)}
classNamePrefix=""
{...overrideProps}
/>
);
}
it('renders checkout button with proper class names', function() {
const button = shallow(buildApp({
classNames: ['not', 'necessary'],
classNamePrefix: 'prefix--',
})).find('.checkoutButton');
assert.isTrue(button.hasClass('prefix--current'));
assert.isTrue(button.hasClass('not'));
assert.isTrue(button.hasClass('necessary'));
});
it('triggers its operation callback on click', function() {
const cb = sinon.spy();
const checkoutOp = new EnableableOperation(cb);
const wrapper = shallow(buildApp({checkoutOp}));
const button = wrapper.find('.checkoutButton');
assert.strictEqual(button.text(), 'Checkout');
button.simulate('click');
assert.isTrue(cb.called);
});
it('renders as disabled with hover text set to the disablement message', function() {
const checkoutOp = new EnableableOperation(() => {}).disable(checkoutStates.DISABLED, 'message');
const wrapper = shallow(buildApp({checkoutOp}));
const button = wrapper.find('.checkoutButton');
assert.isTrue(button.prop('disabled'));
assert.strictEqual(button.text(), 'Checkout');
assert.strictEqual(button.prop('title'), 'message');
});
it('changes the button text when disabled because the PR is the current branch', function() {
const checkoutOp = new EnableableOperation(() => {}).disable(checkoutStates.CURRENT, 'message');
const wrapper = shallow(buildApp({checkoutOp}));
const button = wrapper.find('.checkoutButton');
assert.isTrue(button.prop('disabled'));
assert.strictEqual(button.text(), 'Checked out');
assert.strictEqual(button.prop('title'), 'message');
});
it('renders hidden', function() {
const checkoutOp = new EnableableOperation(() => {}).disable(checkoutStates.HIDDEN, 'message');
const wrapper = shallow(buildApp({checkoutOp}));
assert.isFalse(wrapper.find('.checkoutButton').exists());
});
});