-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathcall-control-cad.tsx
More file actions
641 lines (581 loc) · 21.9 KB
/
Copy pathcall-control-cad.tsx
File metadata and controls
641 lines (581 loc) · 21.9 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
import React from 'react';
import {render} from '@testing-library/react';
import CallControlCADComponent from '../../../../src/components/task/CallControlCAD/call-control-cad';
import {CallControlComponentProps, TARGET_TYPE, OUTBOUND_TYPE} from '../../../../src/components/task/task.types';
import {
mockTask,
createEnabledMainTaskUIControls,
createMockTaskUIControls,
enabledControl,
} from '@webex/test-fixtures';
import {BuddyDetails} from '@webex/cc-store';
import '@testing-library/jest-dom';
// Mock MediaStream for testing
Object.defineProperty(window, 'MediaStream', {
writable: true,
value: jest.fn().mockImplementation(() => ({
getTracks: jest.fn(() => []),
addTrack: jest.fn(),
removeTrack: jest.fn(),
})),
});
// Mock TaskTimer component to avoid Worker issues in Jest
jest.mock('../../../../src/components/task/TaskTimer/index', () =>
// eslint-disable-next-line react/display-name
() => <span data-testid="TaskTimer">00:00</span>
);
// Mock utilities that require external dependencies
jest.mock('../../../../src/utils', () => ({
getMediaTypeInfo: jest.fn((mediaType) => ({
labelName: mediaType === 'telephony' ? 'Voice' : 'Chat',
iconName: mediaType === 'telephony' ? 'headset' : 'chat',
className: mediaType === 'telephony' ? 'voice-media' : 'chat-media',
isBrandVisual: false,
})),
}));
describe('CallControlCADComponent', () => {
const mockLogger = {
log: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
debug: jest.fn(),
trace: jest.fn(),
};
const mockCurrentTask = {
...mockTask,
id: 'task-123',
data: {
...mockTask.data,
interaction: {
...mockTask.data.interaction,
mediaType: 'telephony',
mediaChannel: 'telephony',
interactionId: 'interaction-123',
callAssociatedDetails: {
customerName: 'John Doe',
ani: '555-123-4567',
dn: '555-999-0000',
virtualTeamName: 'Support Team',
ronaTimeout: '30',
},
},
},
status: 'connected',
isHeld: false,
recording: {isRecording: false},
wrapUpReason: null,
};
const mockWrapupCodes = [
{id: 'wrap1', name: 'Customer Issue', isSystem: false},
{id: 'wrap2', name: 'Technical Support', isSystem: false},
];
const mockBuddyAgents: BuddyDetails[] = [
{
agentId: 'agent1',
agentName: 'John Doe',
dn: '1001',
teamId: 'team1',
siteId: 'site1',
state: 'Available',
} as BuddyDetails,
];
const mockControls = createEnabledMainTaskUIControls();
const defaultProps: CallControlComponentProps = {
currentTask: mockCurrentTask,
wrapupCodes: mockWrapupCodes,
toggleHold: jest.fn(),
toggleRecording: jest.fn(),
toggleMute: jest.fn(),
isMuted: false,
endCall: jest.fn(),
wrapupCall: jest.fn(),
isRecording: false,
setIsRecording: jest.fn(),
buddyAgents: mockBuddyAgents,
loadBuddyAgents: jest.fn(),
loadingBuddyAgents: false,
transferCall: jest.fn(),
consultCall: jest.fn(),
endConsultCall: jest.fn(),
consultTransfer: jest.fn(),
callControlAudio: null as unknown as MediaStream,
consultAgentName: '',
setConsultAgentName: jest.fn(),
holdTime: 0,
callControlClassName: '',
callControlConsultClassName: '',
startTimestamp: Date.now(),
stateTimerLabel: null,
stateTimerTimestamp: 0,
consultTimerLabel: 'Consulting',
consultTimerTimestamp: 0,
allowConsultToQueue: true,
lastTargetType: TARGET_TYPE.AGENT,
setLastTargetType: jest.fn(),
isHeld: false,
conferenceEnabled: true,
controls: mockControls,
logger: mockLogger,
secondsUntilAutoWrapup: undefined,
cancelAutoWrapup: jest.fn(),
exitConference: jest.fn(),
consultConference: jest.fn(),
switchToMainCall: jest.fn(),
switchToConsult: jest.fn(),
conferenceParticipants: [],
};
beforeEach(() => {
jest.clearAllMocks();
});
it('should render telephony call control with all basic information', () => {
const screen = render(<CallControlCADComponent {...defaultProps} />);
// Verify main structure
const container = screen.container.querySelector('.call-control-container');
expect(container).toBeInTheDocument();
// Verify call information display
expect(screen.getByText('Queue:')).toBeInTheDocument();
expect(screen.getByText('Support Team')).toBeInTheDocument();
expect(screen.getByText('Phone Number:')).toBeInTheDocument();
// Verify media icon and timer
const mediaIcon = screen.container.querySelector('.media-icon.voice-media');
expect(mediaIcon).toBeInTheDocument();
const timerElement = screen.container.querySelector('.call-timer');
expect(timerElement).toBeInTheDocument();
// Verify recording indicator
const recordingIndicator = screen.container.querySelector('.recording-indicator');
expect(recordingIndicator).toBeInTheDocument();
// Verify phone numbers displayed
const phoneNumbers = screen.getAllByText('555-123-4567');
expect(phoneNumbers.length).toBeGreaterThan(0);
});
it('should handle different states and media types', () => {
// Test held state with hold time
const heldProps = {
...defaultProps,
isHeld: true,
holdTime: 65,
};
const heldScreen = render(<CallControlCADComponent {...heldProps} />);
expect(heldScreen.getByText(/On hold/)).toBeInTheDocument();
expect(heldScreen.getByText(/01:05/)).toBeInTheDocument();
const holdIcon = heldScreen.container.querySelector('.call-hold-filled-icon');
expect(holdIcon).toBeInTheDocument();
heldScreen.unmount();
// Test social media interaction
const socialProps = {
...defaultProps,
currentTask: {
...defaultProps.currentTask,
data: {
...defaultProps.currentTask.data,
interaction: {
...defaultProps.currentTask.data.interaction,
mediaType: 'social',
mediaChannel: 'social',
callAssociatedDetails: {
customerName: 'Social Customer',
ani: '555-123-4567',
virtualTeamName: 'Support Team',
ronaTimeout: '30',
},
},
},
},
};
const socialScreen = render(<CallControlCADComponent {...socialProps} />);
expect(socialScreen.getByText('Customer Name')).toBeInTheDocument();
const socialCustomerNames = socialScreen.getAllByText('Social Customer');
expect(socialCustomerNames.length).toBeGreaterThan(0);
socialScreen.unmount();
// Test consultation functionality for telephony
const consultProps = {
...defaultProps,
consultAgentName: 'Consult Agent',
controls: createMockTaskUIControls({
main: {endConsult: enabledControl},
consult: {
mute: enabledControl,
switch: enabledControl,
transfer: enabledControl,
mergeToConference: enabledControl,
endConsult: enabledControl,
},
activeLeg: 'consult',
}),
};
const consultScreen = render(<CallControlCADComponent {...consultProps} />);
const consultContainer = consultScreen.container.querySelector('.call-control-consult-container');
expect(consultContainer).toBeInTheDocument();
consultScreen.unmount();
// Test that consultation is hidden for non-telephony
const chatConsultProps = {
...defaultProps,
currentTask: {
...defaultProps.currentTask,
data: {
...defaultProps.currentTask.data,
interaction: {
...defaultProps.currentTask.data.interaction,
mediaType: 'chat',
mediaChannel: 'chat',
},
},
},
};
const chatConsultScreen = render(<CallControlCADComponent {...chatConsultProps} />);
const chatConsultContainer = chatConsultScreen.container.querySelector('.call-control-consult-container');
expect(chatConsultContainer).not.toBeInTheDocument();
chatConsultScreen.unmount();
});
it.skip('should display correct phone number for inbound vs outdial calls', () => {
// Inbound call: caller ID = ani, phone number = ani
const inboundScreen = render(<CallControlCADComponent {...defaultProps} />);
// ani (555-123-4567) should appear as both caller ID and phone number
const aniElements = inboundScreen.getAllByText('555-123-4567');
expect(aniElements.length).toBe(2); // caller ID + phone number
// dn (555-999-0000) should NOT appear anywhere
expect(inboundScreen.queryByText('555-999-0000')).not.toBeInTheDocument();
inboundScreen.unmount();
// Outdial call: caller ID = dn, phone number = ani
const outdialProps = {
...defaultProps,
currentTask: {
...defaultProps.currentTask,
data: {
...defaultProps.currentTask.data,
interaction: {
...defaultProps.currentTask.data.interaction,
outboundType: OUTBOUND_TYPE.OUTDIAL,
},
},
},
};
const outdialScreen = render(<CallControlCADComponent {...outdialProps} />);
// Caller ID should show dn (555-999-0000)
expect(outdialScreen.getByText('555-999-0000')).toBeInTheDocument();
// Phone number should show ani (555-123-4567)
const phoneLabel = outdialScreen.getByText('Phone Number:');
const phoneValue = phoneLabel.nextElementSibling;
expect(phoneValue?.textContent).toBe('555-123-4567');
outdialScreen.unmount();
});
it('should handle wrapup mode and edge cases', () => {
// Test wrapup mode hides elements
const wrapupProps = {
...defaultProps,
controls: createEnabledMainTaskUIControls({wrapup: enabledControl}),
isHeld: true,
isRecording: true,
};
const screen = render(<CallControlCADComponent {...wrapupProps} />);
// Verify elements are hidden in wrapup mode
expect(screen.queryByText('On Hold')).not.toBeInTheDocument();
const recordingIndicator = screen.container.querySelector('.recording-indicator');
expect(recordingIndicator).not.toBeInTheDocument();
const consultContainer = screen.container.querySelector('.call-control-consult-container');
expect(consultContainer).not.toBeInTheDocument();
screen.unmount();
// Test fallback values when data is missing
const noDataProps = {
...defaultProps,
currentTask: {
...defaultProps.currentTask,
data: {
...defaultProps.currentTask.data,
interaction: {
...defaultProps.currentTask.data.interaction,
callAssociatedDetails: {},
},
},
},
};
const noDataScreen = render(<CallControlCADComponent {...noDataProps} />);
expect(noDataScreen.getByText('No Caller ID')).toBeInTheDocument();
expect(noDataScreen.getByText('No Team Name')).toBeInTheDocument();
expect(noDataScreen.getByText('No Phone Number')).toBeInTheDocument();
noDataScreen.unmount();
// Test wrapup mode hiding recording indicator
const noRecordingProps = {
...defaultProps,
controls: createEnabledMainTaskUIControls({wrapup: enabledControl}),
};
const noRecordingScreen = render(<CallControlCADComponent {...noRecordingProps} />);
const hiddenRecordingIndicator = noRecordingScreen.container.querySelector('.recording-indicator');
expect(hiddenRecordingIndicator).not.toBeInTheDocument();
noRecordingScreen.unmount();
// Test custom CSS classes
const customProps = {
...defaultProps,
callControlClassName: 'custom-call-control',
callControlConsultClassName: 'custom-consult-control',
controls: createMockTaskUIControls({
main: {endConsult: enabledControl},
consult: {
mute: enabledControl,
switch: enabledControl,
transfer: enabledControl,
mergeToConference: enabledControl,
endConsult: enabledControl,
},
activeLeg: 'consult',
}),
};
const customScreen = render(<CallControlCADComponent {...customProps} />);
const container = customScreen.container.querySelector('.call-control-container');
expect(container).toHaveClass('custom-call-control');
const customConsultContainer = customScreen.container.querySelector('.call-control-consult-container');
expect(customConsultContainer).toHaveClass('custom-consult-control');
});
describe('on hold banner visibility', () => {
const baseControls = {
main: {
wrapup: {isVisible: false, isEnabled: false},
endConsult: {isVisible: false, isEnabled: false},
exitConference: {isVisible: false, isEnabled: false},
},
consult: {
endConsult: {isVisible: false, isEnabled: false},
},
activeLeg: 'main',
};
it('shows On hold banner when isHeld is true', () => {
const screen = render(
<CallControlCADComponent
{...defaultProps}
isHeld={true}
holdTime={65}
controls={baseControls as unknown as CallControlComponentProps['controls']}
/>
);
expect(screen.getByText(/On hold/)).toBeInTheDocument();
expect(screen.getByText(/01:05/)).toBeInTheDocument();
});
it('hides On hold banner when isHeld is false', () => {
const screen = render(
<CallControlCADComponent
{...defaultProps}
isHeld={false}
controls={baseControls as unknown as CallControlComponentProps['controls']}
/>
);
expect(screen.queryByText(/On hold/)).not.toBeInTheDocument();
});
it('hides On hold banner during wrapup even if isHeld is true', () => {
const wrapupControls = {
...baseControls,
main: {
...baseControls.main,
wrapup: {isVisible: true, isEnabled: true},
},
};
const screen = render(
<CallControlCADComponent
{...defaultProps}
isHeld={true}
controls={wrapupControls as unknown as CallControlComponentProps['controls']}
/>
);
expect(screen.queryByText(/On hold/)).not.toBeInTheDocument();
});
});
describe('conference participants list visibility', () => {
it('shows participants list when conference is active and other agents are present', () => {
const screen = render(
<CallControlCADComponent
{...defaultProps}
controls={createEnabledMainTaskUIControls({exitConference: {isVisible: true, isEnabled: true}})}
conferenceParticipants={[{id: 'agent-2', name: 'Agent Two', pType: 'Agent'}]}
/>
);
expect(screen.getByTestId('call-control:participants-trigger')).toBeInTheDocument();
});
it('hides participants list when exitConference is not visible and conference is not in progress', () => {
const screen = render(
<CallControlCADComponent
{...defaultProps}
controls={createEnabledMainTaskUIControls({exitConference: {isVisible: false, isEnabled: false}})}
conferenceParticipants={[
{id: 'agent-2', name: 'Agent Two', pType: 'Agent'},
{id: 'agent-3', name: 'Agent Three', pType: 'Agent'},
]}
/>
);
expect(screen.queryByTestId('call-control:participants-trigger')).not.toBeInTheDocument();
});
it('shows participants list during nested consult when interaction state is conference', () => {
const conferenceTask = {
...defaultProps.currentTask,
data: {
...defaultProps.currentTask.data,
isConferenceInProgress: false,
interaction: {
...defaultProps.currentTask.data.interaction,
state: 'conference',
},
},
};
const screen = render(
<CallControlCADComponent
{...defaultProps}
currentTask={conferenceTask}
controls={createEnabledMainTaskUIControls({exitConference: {isVisible: false, isEnabled: false}})}
conferenceParticipants={[{id: 'agent-2', name: 'Agent Two', pType: 'Agent'}]}
/>
);
expect(screen.getByTestId('call-control:participants-trigger')).toBeInTheDocument();
});
it('hides participants list for consult-only secondary agents even when participants exist', () => {
const consultTask = {
...defaultProps.currentTask,
data: {
...defaultProps.currentTask.data,
isConferenceInProgress: false,
interaction: {
...defaultProps.currentTask.data.interaction,
state: 'consult',
interactionId: 'child-interaction-id',
callProcessingDetails: {
relationshipType: 'consult',
parentInteractionId: 'parent-interaction-id',
},
},
},
};
const screen = render(
<CallControlCADComponent
{...defaultProps}
currentTask={consultTask}
controls={createEnabledMainTaskUIControls({exitConference: {isVisible: true, isEnabled: true}})}
conferenceParticipants={[
{id: 'agent-2', name: 'Agent Two', pType: 'Agent'},
{id: 'agent-3', name: 'Agent Three', pType: 'Agent'},
]}
/>
);
expect(screen.queryByTestId('call-control:participants-trigger')).not.toBeInTheDocument();
});
it('hides participants list when conference is active but no other agents are present', () => {
const screen = render(
<CallControlCADComponent
{...defaultProps}
controls={createEnabledMainTaskUIControls({exitConference: {isVisible: true, isEnabled: true}})}
conferenceParticipants={[]}
/>
);
expect(screen.queryByTestId('call-control:participants-trigger')).not.toBeInTheDocument();
});
it('should accumulate global variables across re-renders (CAI-8143)', () => {
const firstPayload: CallAssociatedDataMap = {
Global_Language: {
name: 'Global_Language',
displayName: 'Customer Language',
value: 'English',
type: 'STRING',
agentEditable: false,
agentViewable: true,
global: true,
isSecure: false,
secureKeyId: '',
secureKeyVersion: 0,
},
};
const secondPayload: CallAssociatedDataMap = {
Global_FeedbackSurveyOptIn: {
name: 'Global_FeedbackSurveyOptIn',
displayName: 'Post Call Survey Opt-in',
value: 'true',
type: 'STRING',
agentEditable: false,
agentViewable: true,
global: true,
isSecure: false,
secureKeyId: '',
secureKeyVersion: 0,
},
};
// First render with only Global_Language
const screen = render(<CallControlCADComponent {...makePropsWithCallAssociatedData(firstPayload)} />);
expect(screen.getByText('Customer Language:')).toBeInTheDocument();
expect(screen.getByText('English')).toBeInTheDocument();
// Re-render with only Global_FeedbackSurveyOptIn (simulating a new websocket payload)
screen.rerender(<CallControlCADComponent {...makePropsWithCallAssociatedData(secondPayload)} />);
// Both variables should now be visible (merged, not replaced)
expect(screen.getByText('Customer Language:')).toBeInTheDocument();
expect(screen.getByText('English')).toBeInTheDocument();
expect(screen.getByText('Post Call Survey Opt-in:')).toBeInTheDocument();
expect(screen.getByText('true')).toBeInTheDocument();
});
it('should update existing variable values when re-rendered with new data (CAI-8143)', () => {
const initialPayload: CallAssociatedDataMap = {
Global_Language: {
name: 'Global_Language',
displayName: 'Customer Language',
value: 'English',
type: 'STRING',
agentEditable: false,
agentViewable: true,
global: true,
isSecure: false,
secureKeyId: '',
secureKeyVersion: 0,
},
};
const updatedPayload: CallAssociatedDataMap = {
Global_Language: {
name: 'Global_Language',
displayName: 'Customer Language',
value: 'Spanish',
type: 'STRING',
agentEditable: false,
agentViewable: true,
global: true,
isSecure: false,
secureKeyId: '',
secureKeyVersion: 0,
},
};
const screen = render(<CallControlCADComponent {...makePropsWithCallAssociatedData(initialPayload)} />);
expect(screen.getByText('English')).toBeInTheDocument();
// Re-render with updated value for the same variable
screen.rerender(<CallControlCADComponent {...makePropsWithCallAssociatedData(updatedPayload)} />);
expect(screen.getByText('Spanish')).toBeInTheDocument();
expect(screen.queryByText('English')).not.toBeInTheDocument();
});
it('should reset global variables when interaction changes (CAI-8143)', () => {
const payload: CallAssociatedDataMap = {
Global_Language: {
name: 'Global_Language',
displayName: 'Customer Language',
value: 'English',
type: 'STRING',
agentEditable: false,
agentViewable: true,
global: true,
isSecure: false,
secureKeyId: '',
secureKeyVersion: 0,
},
};
const screen = render(<CallControlCADComponent {...makePropsWithCallAssociatedData(payload)} />);
expect(screen.getByText('Customer Language:')).toBeInTheDocument();
// Re-render with a different interaction ID and no global variables
const newInteractionProps = {
...defaultProps,
currentTask: {
...defaultProps.currentTask,
data: {
...defaultProps.currentTask.data,
interaction: {
...defaultProps.currentTask.data.interaction,
interactionId: 'new-interaction-456',
},
},
},
};
screen.rerender(<CallControlCADComponent {...newInteractionProps} />);
// Old variables should be cleared for the new interaction
expect(screen.queryByText('Customer Language:')).not.toBeInTheDocument();
});
});
});