|
1 | | -import { getIsReactionEnabled } from '../getIsReactionEnabled'; |
| 1 | +import type { GroupChannel } from '@sendbird/chat/groupChannel'; |
2 | 2 |
|
3 | | -describe('Global-utils/getIsReactionEnabled', () => { |
4 | | - it('should enable as a default', () => { |
5 | | - expect(getIsReactionEnabled({})).toBeTrue(); |
| 3 | +import type { SendBirdStateConfig } from '../../lib/types'; |
| 4 | +import { getIsReactionEnabled } from '../getIsReactionEnabled'; |
6 | 5 |
|
7 | | - expect(getIsReactionEnabled({ |
8 | | - globalLevel: true, |
9 | | - })).toBeTrue(); |
10 | | - expect(getIsReactionEnabled({ |
11 | | - moduleLevel: true, |
12 | | - })).toBeTrue(); |
| 6 | +const normalGroupChannel = (props?) => ({ |
| 7 | + isBroadcast: false, |
| 8 | + isEphemeral: false, |
| 9 | + isSuper: false, |
| 10 | + ...props, |
| 11 | +} as GroupChannel); |
| 12 | +const normalConfigs = (props?, groupChannelProps?) => ({ |
| 13 | + groupChannel: { |
| 14 | + enableReactions: true, |
| 15 | + enableReactionsSupergroup: false, |
| 16 | + ...groupChannelProps, |
| 17 | + }, |
| 18 | + ...props, |
| 19 | +} as SendBirdStateConfig); |
13 | 20 |
|
14 | | - expect(getIsReactionEnabled({ |
15 | | - globalLevel: true, |
16 | | - moduleLevel: true, |
17 | | - })).toBeTrue(); |
| 21 | +describe('Global-utils/getIsReactionEnabled', () => { |
| 22 | + it('should prioritize the moduleLevel than global config', () => { |
| 23 | + const moduleLevel = true; |
| 24 | + expect(getIsReactionEnabled({ |
| 25 | + channel: normalGroupChannel(), |
| 26 | + config: normalConfigs(), |
| 27 | + moduleLevel, |
| 28 | + })).toBe(moduleLevel); |
| 29 | + const moduleLevel2 = false; |
| 30 | + expect(getIsReactionEnabled({ |
| 31 | + channel: normalGroupChannel(), |
| 32 | + config: normalConfigs(), |
| 33 | + moduleLevel: moduleLevel2, |
| 34 | + })).toBe(moduleLevel2); |
18 | 35 | }); |
19 | 36 |
|
20 | | - it('should disable if set values are false', () => { |
21 | | - expect(getIsReactionEnabled({ |
22 | | - globalLevel: false, |
23 | | - })).toBeFalse(); |
24 | | - expect(getIsReactionEnabled({ |
25 | | - moduleLevel: false, |
26 | | - })).toBeFalse(); |
27 | | - |
| 37 | + it('should prioritize the isSuper than moduleLevel', () => { |
| 38 | + const isSuper = true; |
28 | 39 | expect(getIsReactionEnabled({ |
29 | | - globalLevel: false, |
30 | | - moduleLevel: false, |
31 | | - })).toBeFalse(); |
32 | | - }); |
33 | | - |
34 | | - it('should have higher priority to the moduleLevel than globalLevel', () => { |
| 40 | + channel: normalGroupChannel({ isSuper }), |
| 41 | + config: normalConfigs(), |
| 42 | + moduleLevel: true, |
| 43 | + })).toBe(false); |
35 | 44 | expect(getIsReactionEnabled({ |
36 | | - globalLevel: true, |
| 45 | + channel: normalGroupChannel({ isSuper }), |
| 46 | + config: normalConfigs(), |
37 | 47 | moduleLevel: false, |
38 | | - })).toBeFalse(); |
39 | | - expect(getIsReactionEnabled({ |
40 | | - globalLevel: false, |
41 | | - moduleLevel: true, |
42 | | - })).toBeTrue(); |
| 48 | + })).toBe(false); |
43 | 49 | }); |
44 | 50 |
|
45 | | - it('should disable in the special type channels', () => { |
46 | | - expect(getIsReactionEnabled({ |
47 | | - globalLevel: true, |
48 | | - isBroadcast: true, |
49 | | - })).toBeFalse(); |
50 | | - expect(getIsReactionEnabled({ |
51 | | - globalLevel: true, |
52 | | - isSuper: true, |
53 | | - })).toBeFalse(); |
54 | | - expect(getIsReactionEnabled({ |
55 | | - globalLevel: true, |
56 | | - isBroadcast: true, |
57 | | - isSuper: true, |
58 | | - })).toBeFalse(); |
59 | | - |
60 | | - expect(getIsReactionEnabled({ |
61 | | - moduleLevel: true, |
62 | | - isBroadcast: true, |
63 | | - })).toBeFalse(); |
64 | | - expect(getIsReactionEnabled({ |
65 | | - moduleLevel: true, |
66 | | - isSuper: true, |
67 | | - })).toBeFalse(); |
68 | | - expect(getIsReactionEnabled({ |
69 | | - moduleLevel: true, |
70 | | - isBroadcast: true, |
71 | | - isSuper: true, |
72 | | - })).toBeFalse(); |
73 | | - |
| 51 | + it('should prioritize moduleLevel than enableReactionsSupergroup', () => { |
| 52 | + const isSuper = true; |
74 | 53 | expect(getIsReactionEnabled({ |
75 | | - globalLevel: true, |
| 54 | + channel: normalGroupChannel({ isSuper }), |
| 55 | + config: normalConfigs({}, { enableReactionsSupergroup: true }), |
76 | 56 | moduleLevel: true, |
77 | | - isBroadcast: true, |
78 | | - })).toBeFalse(); |
| 57 | + })).toBe(true); |
79 | 58 | expect(getIsReactionEnabled({ |
80 | | - globalLevel: true, |
81 | | - moduleLevel: true, |
82 | | - isSuper: true, |
83 | | - })).toBeFalse(); |
84 | | - expect(getIsReactionEnabled({ |
85 | | - globalLevel: true, |
86 | | - moduleLevel: true, |
87 | | - isBroadcast: true, |
88 | | - isSuper: true, |
89 | | - })).toBeFalse(); |
| 59 | + channel: normalGroupChannel({ isSuper }), |
| 60 | + config: normalConfigs({}, { enableReactionsSupergroup: true }), |
| 61 | + moduleLevel: false, |
| 62 | + })).toBe(false); |
90 | 63 | }); |
91 | 64 |
|
92 | | - it('should disable if only one special channel type is true', () => { |
93 | | - expect(getIsReactionEnabled({ |
94 | | - globalLevel: true, |
95 | | - moduleLevel: true, |
96 | | - isBroadcast: false, |
97 | | - isSuper: true, |
98 | | - })).toBeFalse(); |
| 65 | + it('should be false when it is broadcast or ephemeral channel', () => { |
| 66 | + const isBroadcast = true; |
99 | 67 | expect(getIsReactionEnabled({ |
100 | | - globalLevel: true, |
| 68 | + channel: normalGroupChannel({ isBroadcast }), |
| 69 | + config: normalConfigs(), |
101 | 70 | moduleLevel: true, |
102 | | - isBroadcast: true, |
103 | | - isSuper: false, |
104 | | - })).toBeFalse(); |
| 71 | + })).toBe(false); |
105 | 72 | expect(getIsReactionEnabled({ |
106 | | - globalLevel: true, |
107 | | - isBroadcast: false, |
108 | | - isSuper: true, |
109 | | - })).toBeFalse(); |
| 73 | + channel: normalGroupChannel({ isBroadcast }), |
| 74 | + config: normalConfigs(), |
| 75 | + moduleLevel: false, |
| 76 | + })).toBe(false); |
| 77 | + |
| 78 | + const isEphemeral = true; |
110 | 79 | expect(getIsReactionEnabled({ |
| 80 | + channel: normalGroupChannel({ isEphemeral }), |
| 81 | + config: normalConfigs(), |
111 | 82 | moduleLevel: true, |
112 | | - isBroadcast: true, |
113 | | - isSuper: false, |
114 | | - })).toBeFalse(); |
| 83 | + })).toBe(false); |
115 | 84 | expect(getIsReactionEnabled({ |
116 | | - isBroadcast: false, |
117 | | - isSuper: true, |
118 | | - })).toBeFalse(); |
119 | | - expect(getIsReactionEnabled({ |
120 | | - isBroadcast: true, |
121 | | - isSuper: false, |
122 | | - })).toBeFalse(); |
| 85 | + channel: normalGroupChannel({ isEphemeral }), |
| 86 | + config: normalConfigs(), |
| 87 | + moduleLevel: false, |
| 88 | + })).toBe(false); |
123 | 89 | }); |
124 | 90 | }); |
0 commit comments