-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathgetHistoryMessagePayload.spec.ts
More file actions
278 lines (248 loc) · 8.54 KB
/
getHistoryMessagePayload.spec.ts
File metadata and controls
278 lines (248 loc) · 8.54 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import { callStateToTranslationKey, callStateToIcon, getFormattedCallDuration, getHistoryMessagePayload } from './getHistoryMessagePayload';
const appId = 'media-call-core';
describe('callStateToTranslationKey', () => {
it('should return correct translation key for "ended" state', () => {
const result = callStateToTranslationKey('ended');
expect(result).toEqual({ type: 'mrkdwn', i18n: { key: 'Call_ended_bold' }, text: 'Call ended' });
});
it('should return correct translation key for "not-answered" state', () => {
const result = callStateToTranslationKey('not-answered');
expect(result).toEqual({ type: 'mrkdwn', i18n: { key: 'Call_not_answered_bold' }, text: 'Call not answered' });
});
it('should return correct translation key for "failed" state', () => {
const result = callStateToTranslationKey('failed');
expect(result).toEqual({ type: 'mrkdwn', i18n: { key: 'Call_failed_bold' }, text: 'Call failed' });
});
it('should return correct translation key for "error" state', () => {
const result = callStateToTranslationKey('error');
expect(result).toEqual({ type: 'mrkdwn', i18n: { key: 'Call_failed_bold' }, text: 'Call failed' });
});
it('should return correct translation key for "transferred" state', () => {
const result = callStateToTranslationKey('transferred');
expect(result).toEqual({ type: 'mrkdwn', i18n: { key: 'Call_transferred_bold' }, text: 'Call transferred' });
});
});
describe('callStateToIcon', () => {
it('should return correct icon for "ended" state', () => {
const result = callStateToIcon('ended');
expect(result).toEqual({ type: 'icon', icon: 'phone-off', variant: 'secondary' });
});
it('should return correct icon for "not-answered" state', () => {
const result = callStateToIcon('not-answered');
expect(result).toEqual({ type: 'icon', icon: 'clock', variant: 'danger' });
});
it('should return correct icon for "failed" state', () => {
const result = callStateToIcon('failed');
expect(result).toEqual({ type: 'icon', icon: 'phone-issue', variant: 'danger' });
});
it('should return correct icon for "error" state', () => {
const result = callStateToIcon('error');
expect(result).toEqual({ type: 'icon', icon: 'phone-issue', variant: 'danger' });
});
it('should return correct icon for "transferred" state', () => {
const result = callStateToIcon('transferred');
expect(result).toEqual({ type: 'icon', icon: 'arrow-forward', variant: 'secondary' });
});
});
describe('getFormattedCallDuration', () => {
it('should return undefined when callDuration is undefined', () => {
const result = getFormattedCallDuration(undefined);
expect(result).toBeUndefined();
});
it('should return undefined when callDuration is 0', () => {
const result = getFormattedCallDuration(0);
expect(result).toBeUndefined();
});
it('should format duration correctly for seconds only (less than 60 seconds)', () => {
const result = getFormattedCallDuration(30);
expect(result).toEqual({ type: 'mrkdwn', text: '*00:30*' });
});
it('should format duration correctly for minutes and seconds (less than 1 hour)', () => {
const result = getFormattedCallDuration(125); // 2 minutes 5 seconds
expect(result).toEqual({ type: 'mrkdwn', text: '*02:05*' });
});
it('should format duration correctly for exactly 1 minute', () => {
const result = getFormattedCallDuration(60);
expect(result).toEqual({ type: 'mrkdwn', text: '*01:00*' });
});
it('should format duration correctly for hours, minutes, and seconds', () => {
const result = getFormattedCallDuration(3665); // 1 hour 1 minute 5 seconds
expect(result).toEqual({ type: 'mrkdwn', text: '*01:01:05*' });
});
it('should format duration correctly for multiple hours', () => {
const result = getFormattedCallDuration(7325); // 2 hours 2 minutes 5 seconds
expect(result).toEqual({ type: 'mrkdwn', text: '*02:02:05*' });
});
it('should pad single digit values with zeros', () => {
const result = getFormattedCallDuration(61); // 1 minute 1 second
expect(result).toEqual({ type: 'mrkdwn', text: '*01:01*' });
});
it('should handle large durations correctly', () => {
const result = getFormattedCallDuration(36661); // 10 hours 11 minutes 1 second
expect(result).toEqual({ type: 'mrkdwn', text: '*10:11:01*' });
});
});
describe('getHistoryMessagePayload', () => {
it('should return correct payload for "ended" state without duration', () => {
const result = getHistoryMessagePayload('ended', undefined);
expect(result).toEqual({
msg: '',
groupable: false,
blocks: [
{
appId,
type: 'info_card',
rows: [
{
background: 'default',
elements: [
{ type: 'icon', icon: 'phone-off', variant: 'secondary' },
{ type: 'mrkdwn', i18n: { key: 'Call_ended_bold' }, text: 'Call ended' },
],
},
],
},
],
});
});
it('should return correct payload for "ended" state with duration', () => {
const result = getHistoryMessagePayload('ended', 125);
expect(result).toEqual({
msg: '',
groupable: false,
blocks: [
{
appId,
type: 'info_card',
rows: [
{
background: 'default',
elements: [
{ type: 'icon', icon: 'phone-off', variant: 'secondary' },
{ type: 'mrkdwn', i18n: { key: 'Call_ended_bold' }, text: 'Call ended' },
],
},
{
background: 'secondary',
elements: [{ type: 'mrkdwn', text: '*02:05*' }],
},
],
},
],
});
});
it('should return correct payload for "not-answered" state', () => {
const result = getHistoryMessagePayload('not-answered', undefined);
expect(result).toEqual({
msg: '',
groupable: false,
blocks: [
{
appId,
type: 'info_card',
rows: [
{
background: 'default',
elements: [
{ type: 'icon', icon: 'clock', variant: 'danger' },
{ type: 'mrkdwn', i18n: { key: 'Call_not_answered_bold' }, text: 'Call not answered' },
],
},
],
},
],
});
});
it('should return correct payload for "failed" state', () => {
const result = getHistoryMessagePayload('failed', undefined);
expect(result).toEqual({
msg: '',
groupable: false,
blocks: [
{
appId,
type: 'info_card',
rows: [
{
background: 'default',
elements: [
{ type: 'icon', icon: 'phone-issue', variant: 'danger' },
{ type: 'mrkdwn', i18n: { key: 'Call_failed_bold' }, text: 'Call failed' },
],
},
],
},
],
});
});
it('should return correct payload for "error" state', () => {
const result = getHistoryMessagePayload('error', undefined);
expect(result).toEqual({
msg: '',
groupable: false,
blocks: [
{
appId,
type: 'info_card',
rows: [
{
background: 'default',
elements: [
{ type: 'icon', icon: 'phone-issue', variant: 'danger' },
{ type: 'mrkdwn', i18n: { key: 'Call_failed_bold' }, text: 'Call failed' },
],
},
],
},
],
});
});
it('should return correct payload for "transferred" state', () => {
const result = getHistoryMessagePayload('transferred', undefined);
expect(result).toEqual({
msg: '',
groupable: false,
blocks: [
{
appId,
type: 'info_card',
rows: [
{
background: 'default',
elements: [
{ type: 'icon', icon: 'arrow-forward', variant: 'secondary' },
{ type: 'mrkdwn', i18n: { key: 'Call_transferred_bold' }, text: 'Call transferred' },
],
},
],
},
],
});
});
it('should include duration row when duration is provided', () => {
const result = getHistoryMessagePayload('ended', 3665);
expect(result.blocks[0].rows).toHaveLength(2);
expect(result.blocks[0].rows[1]).toEqual({
background: 'secondary',
elements: [{ type: 'mrkdwn', text: '*01:01:05*' }],
});
});
it('should not include duration row when duration is undefined', () => {
const result = getHistoryMessagePayload('ended', undefined);
expect(result.blocks[0].rows).toHaveLength(1);
});
it('should handle all call states with duration correctly', () => {
const states = ['ended', 'transferred', 'not-answered', 'failed', 'error'] as const;
const duration = 125;
states.forEach((state) => {
const result = getHistoryMessagePayload(state, duration);
expect(result.msg).toBe('');
expect(result.groupable).toBe(false);
expect(result.blocks).toHaveLength(1);
expect(result.blocks[0].type).toBe('info_card');
expect(result.blocks[0].rows).toHaveLength(2);
expect(result.blocks[0].rows[1].background).toBe('secondary');
expect(result.blocks[0].rows[1].elements[0].type).toBe('mrkdwn');
});
});
});