-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathbasic.sendbox.with.mic.html
More file actions
123 lines (105 loc) · 5.16 KB
/
Copy pathbasic.sendbox.with.mic.html
File metadata and controls
123 lines (105 loc) · 5.16 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
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script>
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
<script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script>
</head>
<body>
<main id="webchat"></main>
<script type="module">
import { setupMockMediaDevices } from '/assets/esm/speechToSpeech/mockMediaDevices.js';
import { setupMockAudioPlayback } from '/assets/esm/speechToSpeech/mockAudioPlayback.js';
setupMockMediaDevices();
setupMockAudioPlayback();
</script>
<script type="text/babel">
run(async function () {
const {
React,
ReactDOM: { render },
WebChat: { FluentThemeProvider, ReactWebChat, testIds }
} = window;
// GIVEN: Web Chat with Fluent Theme and microphone button enabled
const { directLine, store } = testHelpers.createDirectLineEmulator();
// Multi-modal experience: server announces audio, consumer opted into voice mode.
directLine.setCapability('getVoiceConfiguration', { sampleRate: 24000, chunkIntervalMs: 100 }, { emitEvent: false });
directLine.setCapability('getIsVoiceModeEnabled', true, { emitEvent: false });
render(
<FluentThemeProvider variant="fluent">
<ReactWebChat
directLine={directLine}
store={store}
styleOptions={{
disableFileUpload: true,
hideTelephoneKeypadButton: false,
}}
/>
</FluentThemeProvider>,
document.getElementById('webchat')
);
await pageConditions.uiConnected();
// THEN: Microphone button should be present
const micButton = document.querySelector(`[data-testid="${testIds.sendBoxMicrophoneButton}"]`);
expect(micButton).toBeTruthy();
// THEN: Telephone keypad button should be present
const keypadButton = document.querySelector(`[data-testid="${testIds.sendBoxTelephoneKeypadToolbarButton}"]`);
expect(keypadButton).toBeTruthy();
// THEN: Multi-modal design: send button coexists with mic. While idle it is enabled
// so the user can also send text without leaving voice mode.
const sendButton = document.querySelector(`[data-testid="${testIds.sendBoxSendButton}"]`);
const textArea = document.querySelector(`[data-testid="${testIds.sendBoxTextBox}"]`);
const isSendDisabled = () => sendButton.getAttribute('aria-disabled') === 'true';
expect(sendButton).toBeTruthy();
expect(isSendDisabled()).toBe(false);
expect(textArea.hasAttribute('readonly')).toBe(false);
// THEN: Should show sendbox with microphone, keypad and send buttons
await host.snapshot('local');
// WHEN: User starts recording
await host.click(micButton);
// First wait for the voice toggle to actually flip on so we know recording started.
await pageConditions.became(
'Recording started',
() => micButton.getAttribute('aria-label')?.includes('Microphone on'),
2000
);
// THEN: Send button is disabled and text input becomes read-only — voice and text
// are mutually exclusive while the mic is open.
await pageConditions.became(
'Send button disabled while recording',
() => isSendDisabled() && textArea.hasAttribute('readonly'),
2000
);
// WHEN: User stops recording
await host.click(micButton);
await pageConditions.became(
'Recording stopped',
() => micButton.getAttribute('aria-label')?.includes('Microphone off'),
2000
);
// THEN: Send button and text input are re-enabled — back to free text entry.
await pageConditions.became(
'Send button re-enabled after stopping recording',
() => !isSendDisabled() && !textArea.hasAttribute('readonly'),
2000
);
// WHEN: Voice configuration is removed from directLine
directLine.setCapability('getVoiceConfiguration', undefined);
// Wait for UI to update
await pageConditions.became(
'Microphone button should be hidden after removing voice configuration',
() => !document.querySelector(`[data-testid="${testIds.sendBoxMicrophoneButton}"]`),
1000
);
// THEN: Microphone button should NOT be present anymore
const micButtonAfterRemoval = document.querySelector(`[data-testid="${testIds.sendBoxMicrophoneButton}"]`);
expect(micButtonAfterRemoval).toBeFalsy();
});
</script>
</body>
</html>