This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 402
/
Copy pathemoji-reactions-view.test.js
153 lines (120 loc) Β· 6.33 KB
/
emoji-reactions-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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import React from 'react';
import {shallow} from 'enzyme';
import {BareEmojiReactionsView} from '../../lib/views/emoji-reactions-view';
import ReactionPickerController from '../../lib/controllers/reaction-picker-controller';
import {issueBuilder} from '../builder/graphql/issue';
import reactableQuery from '../../lib/views/__generated__/emojiReactionsView_reactable.graphql';
describe('EmojiReactionsView', function() {
let atomEnv;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(override = {}) {
return (
<BareEmojiReactionsView
reactable={issueBuilder(reactableQuery).build()}
addReaction={() => {}}
removeReaction={() => {}}
tooltips={atomEnv.tooltips}
{...override}
/>
);
}
it('renders reaction groups', function() {
const reactable = issueBuilder(reactableQuery)
.addReactionGroup(group => group.content('THUMBS_UP').users(u => u.totalCount(10)))
.addReactionGroup(group => group.content('THUMBS_DOWN').users(u => u.totalCount(5)))
.addReactionGroup(group => group.content('ROCKET').users(u => u.totalCount(42)))
.addReactionGroup(group => group.content('EYES').users(u => u.totalCount(13)))
.addReactionGroup(group => group.content('LAUGH').users(u => u.totalCount(0)))
.build();
const wrapper = shallow(buildApp({reactable}));
const groups = wrapper.find('.github-EmojiReactions-group');
assert.lengthOf(groups.findWhere(n => /π/u.test(n.text()) && /\b10\b/.test(n.text())), 1);
assert.lengthOf(groups.findWhere(n => /π/u.test(n.text()) && /\b5\b/.test(n.text())), 1);
assert.lengthOf(groups.findWhere(n => /π/u.test(n.text()) && /\b42\b/.test(n.text())), 1);
assert.lengthOf(groups.findWhere(n => /π/u.test(n.text()) && /\b13\b/.test(n.text())), 1);
assert.isFalse(groups.someWhere(n => /π/u.test(n.text())));
});
it('gracefully skips unknown emoji', function() {
const reactable = issueBuilder(reactableQuery)
.addReactionGroup(group => group.content('AVOCADO').users(u => u.totalCount(11)))
.build();
const wrapper = shallow(buildApp({reactable}));
assert.notMatch(wrapper.text(), /\b11\b/);
});
it("shows which reactions you've personally given", function() {
const reactable = issueBuilder(reactableQuery)
.addReactionGroup(group => group.content('ROCKET').users(u => u.totalCount(5)).viewerHasReacted(true))
.addReactionGroup(group => group.content('EYES').users(u => u.totalCount(7)).viewerHasReacted(false))
.build();
const wrapper = shallow(buildApp({reactable}));
assert.isTrue(wrapper.find('.github-EmojiReactions-group.rocket').hasClass('selected'));
assert.isFalse(wrapper.find('.github-EmojiReactions-group.eyes').hasClass('selected'));
});
it('adds a reaction to an existing emoji on click', function() {
const addReaction = sinon.spy();
const reactable = issueBuilder(reactableQuery)
.addReactionGroup(group => group.content('THUMBS_UP').users(u => u.totalCount(2)).viewerHasReacted(false))
.build();
const wrapper = shallow(buildApp({addReaction, reactable}));
wrapper.find('.github-EmojiReactions-group.thumbs_up').simulate('click');
assert.isTrue(addReaction.calledWith('THUMBS_UP'));
});
it('removes a reaction from an existing emoji on click', function() {
const removeReaction = sinon.spy();
const reactable = issueBuilder(reactableQuery)
.addReactionGroup(group => group.content('THUMBS_DOWN').users(u => u.totalCount(3)).viewerHasReacted(true))
.build();
const wrapper = shallow(buildApp({removeReaction, reactable}));
wrapper.find('.github-EmojiReactions-group.thumbs_down').simulate('click');
assert.isTrue(removeReaction.calledWith('THUMBS_DOWN'));
});
it('disables the reaction toggle buttons if the viewer cannot react', function() {
const reactable = issueBuilder(reactableQuery)
.viewerCanReact(false)
.addReactionGroup(group => group.content('THUMBS_UP').users(u => u.totalCount(2)))
.build();
const wrapper = shallow(buildApp({reactable}));
assert.isTrue(wrapper.find('.github-EmojiReactions-group.thumbs_up').prop('disabled'));
});
it('displays an "add emoji" control if at least one reaction group is empty', function() {
const reactable = issueBuilder(reactableQuery)
.addReactionGroup(group => group.content('THUMBS_UP').users(u => u.totalCount(2)))
.addReactionGroup(group => group.content('THUMBS_DOWN').users(u => u.totalCount(0)))
.build();
const wrapper = shallow(buildApp({reactable}));
assert.isTrue(wrapper.exists('.github-EmojiReactions-add'));
assert.isTrue(wrapper.find(ReactionPickerController).exists());
});
it('displays an "add emoji" control when no reaction groups are present', function() {
// This happens when the Reactable is optimistically rendered.
const reactable = issueBuilder(reactableQuery).build();
const wrapper = shallow(buildApp({reactable}));
assert.isTrue(wrapper.exists('.github-EmojiReactions-add'));
assert.isTrue(wrapper.find(ReactionPickerController).exists());
});
it('does not display the "add emoji" control if all reaction groups are nonempty', function() {
const reactable = issueBuilder(reactableQuery)
.addReactionGroup(group => group.content('THUMBS_UP').users(u => u.totalCount(1)))
.addReactionGroup(group => group.content('THUMBS_DOWN').users(u => u.totalCount(1)))
.addReactionGroup(group => group.content('ROCKET').users(u => u.totalCount(1)))
.addReactionGroup(group => group.content('EYES').users(u => u.totalCount(1)))
.build();
const wrapper = shallow(buildApp({reactable}));
assert.isFalse(wrapper.exists('.github-EmojiReactions-add'));
assert.isFalse(wrapper.find(ReactionPickerController).exists());
});
it('disables the "add emoji" control if the viewer cannot react', function() {
const reactable = issueBuilder(reactableQuery)
.viewerCanReact(false)
.addReactionGroup(group => group.content('THUMBS_UP').users(u => u.totalCount(1)))
.addReactionGroup(group => group.content('THUMBS_DOWN').users(u => u.totalCount(0)))
.build();
const wrapper = shallow(buildApp({reactable}));
assert.isTrue(wrapper.find('.github-EmojiReactions-add').prop('disabled'));
});
});