-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathconcludedLivestream.html
More file actions
209 lines (179 loc) · 7.24 KB
/
concludedLivestream.html
File metadata and controls
209 lines (179 loc) · 7.24 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
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<link href="./css/pauseAnimation.css" rel="stylesheet" type="text/css" />
<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>
</head>
<body>
<main id="webchat"></main>
<script type="module">
const streamingFormat = new URL(window.location.href).searchParams.get('streamingFormat') ?? 'channelData'; // can be entity or channelData
function addLivestreamingMetadata(activity, livestreamingMetadata) {
return streamingFormat === 'entity'
? {
...activity,
entities: [...(activity.entities ?? []), { ...livestreamingMetadata, type: 'streaminfo' }]
}
: {
...activity,
channelData: { ...activity.channelData, ...livestreamingMetadata }
};
}
run(async function () {
const {
React: { createElement },
ReactDOM: { render },
WebChat: {
Components: { BasicWebChat, Composer },
decorator: { WebChatDecorator },
hooks: { useActiveTyping, useActivityKeys, useGetActivitiesByKey }
}
} = window; // Imports in UMD fashion.
const { directLine, store } = testHelpers.createDirectLineEmulator();
let currentActivityKeysWithId = [];
let currentActiveTyping = {};
const Monitor = () => {
const [activityKeys] = useActivityKeys();
const [activeTyping] = useActiveTyping();
const getActivitiesByKey = useGetActivitiesByKey();
currentActivityKeysWithId = Object.freeze(
activityKeys.map(key => [key, getActivitiesByKey(key).map(({ id }) => id)])
);
currentActiveTyping = activeTyping;
return false;
};
render(
createElement(
WebChatDecorator,
{},
createElement(
Composer,
{
directLine,
store
},
createElement(BasicWebChat),
createElement(Monitor)
)
),
document.getElementById('webchat')
);
await pageConditions.uiConnected();
// WHEN: Bot is typing a message.
const firstTypingActivityId = 't-00001';
await directLine.emulateIncomingActivity(
addLivestreamingMetadata(
{
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
id: firstTypingActivityId,
text: 'A quick',
timestamp: 1,
type: 'typing'
},
{ streamSequence: 1, streamType: 'streaming' }
)
);
let firstTypingActivityKey = currentActivityKeysWithId[0][0];
// THEN: Should display 1 message.
await pageConditions.numActivitiesShown(1);
expect(pageElements.typingIndicator()).toBeFalsy();
expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'A quick');
await host.snapshot('local');
// THEN: Should have 1 activity key.
expect(currentActivityKeysWithId).toEqual([[firstTypingActivityKey, ['t-00001']]]);
// THEN: Should have active typing.
expect(currentActiveTyping).toEqual({
'u-00001': {
at: expect.any(Number),
expireAt: expect.any(Number),
name: 'Bot',
role: 'bot',
type: 'livestream'
}
});
// ---
// WHEN: Bot send final message.
await directLine.emulateIncomingActivity(
addLivestreamingMetadata(
{
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
id: 't-00002',
text: 'A quick brown fox jumped over the lazy dogs.',
type: 'message'
},
{ streamId: firstTypingActivityId, streamType: 'final' }
)
);
// THEN: Should display 1 message.
await pageConditions.numActivitiesShown(1);
expect(pageElements.typingIndicator()).toBeFalsy();
expect(pageElements.activityContents()[0]).toHaveProperty(
'textContent',
'A quick brown fox jumped over the lazy dogs.'
);
await host.snapshot('local');
// THEN: Should have 1 activity key only.
expect(currentActivityKeysWithId).toEqual([[firstTypingActivityKey, ['t-00002']]]);
// THEN: Should have no active typing.
expect(currentActiveTyping).toHaveProperty('u-00001', undefined);
// ---
// WHEN: Bot send an interim message and reuse the stream ID.
await directLine.emulateIncomingActivity(
addLivestreamingMetadata(
{
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
id: 't-00003',
text: 'Lorem',
type: 'typing'
},
{ streamId: firstTypingActivityId, streamSequence: 2, streamType: 'streaming' }
),
{ skipWait: true }
);
// THEN: Should not update the message.
await pageConditions.numActivitiesShown(1);
expect(pageElements.typingIndicator()).toBeFalsy();
expect(pageElements.activityContents()[0]).toHaveProperty(
'textContent',
'A quick brown fox jumped over the lazy dogs.'
);
await host.snapshot('local');
// THEN: Should have 1 activity key associated with a single activity ID only.
expect(currentActivityKeysWithId).toEqual([[firstTypingActivityKey, ['t-00002']]]);
// THEN: Should have no active typing.
expect(currentActiveTyping).toHaveProperty('u-00001', undefined);
// ---
// WHEN: Bot send a final message and reuse the stream ID.
await directLine.emulateIncomingActivity(
addLivestreamingMetadata(
{
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
id: 't-00004',
text: 'Lorem ipsum.',
type: 'message'
},
{ streamId: firstTypingActivityId, streamType: 'final' }
),
{ skipWait: true }
);
// THEN: Should not update the message.
await pageConditions.numActivitiesShown(1);
expect(pageElements.typingIndicator()).toBeFalsy();
expect(pageElements.activityContents()[0]).toHaveProperty(
'textContent',
'A quick brown fox jumped over the lazy dogs.'
);
await host.snapshot('local');
// THEN: Should have 1 activity key associated with 1 activity ID only (intermediate revisions pruned).
expect(currentActivityKeysWithId).toEqual([[firstTypingActivityKey, ['t-00002']]]);
// THEN: Should have no active typing.
expect(currentActiveTyping).toHaveProperty('u-00001', undefined);
});
</script>
</body>
</html>