forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreaction-picker-view.test.js
77 lines (60 loc) · 2.4 KB
/
reaction-picker-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
import React from 'react';
import {shallow} from 'enzyme';
import ReactionPickerView from '../../lib/views/reaction-picker-view';
import {reactionTypeToEmoji} from '../../lib/helpers';
describe('ReactionPickerView', function() {
let atomEnv;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(override = {}) {
const props = {
viewerReacted: [],
addReactionAndClose: () => {},
removeReactionAndClose: () => {},
...override,
};
return <ReactionPickerView {...props} />;
}
it('renders a button for each known content type', function() {
const knownTypes = Object.keys(reactionTypeToEmoji);
assert.include(knownTypes, 'THUMBS_UP');
const wrapper = shallow(buildApp());
for (const contentType of knownTypes) {
assert.isTrue(
wrapper
.find('.github-ReactionPicker-reaction')
.someWhere(w => w.text().includes(reactionTypeToEmoji[contentType])),
`does not include a button for ${contentType}`,
);
}
});
it('adds the "selected" class to buttons included in viewerReacted', function() {
const viewerReacted = ['THUMBS_UP', 'ROCKET'];
const wrapper = shallow(buildApp({viewerReacted}));
const reactions = wrapper.find('.github-ReactionPicker-reaction');
const selectedReactions = reactions.find('.selected').map(w => w.text());
assert.sameMembers(selectedReactions, [reactionTypeToEmoji.ROCKET, reactionTypeToEmoji.THUMBS_UP]);
});
it('calls addReactionAndClose when clicking a reaction button', function() {
const addReactionAndClose = sinon.spy();
const wrapper = shallow(buildApp({addReactionAndClose}));
wrapper
.find('.github-ReactionPicker-reaction')
.filterWhere(w => w.text().includes(reactionTypeToEmoji.LAUGH))
.simulate('click');
assert.isTrue(addReactionAndClose.calledWith('LAUGH'));
});
it('calls removeReactionAndClose when clicking a reaction in viewerReacted', function() {
const removeReactionAndClose = sinon.spy();
const wrapper = shallow(buildApp({viewerReacted: ['CONFUSED', 'HEART'], removeReactionAndClose}));
wrapper
.find('.github-ReactionPicker-reaction')
.filterWhere(w => w.text().includes(reactionTypeToEmoji.CONFUSED))
.simulate('click');
assert.isTrue(removeReactionAndClose.calledWith('CONFUSED'));
});
});