Skip to content

Commit a8a3376

Browse files
benbrowncompulim
andauthored
Fix streaming behavior by capturing typingActivityId in nextActivityIdToKeyMap (#5609)
* Fix streaming behavior by capturing typingActivityId in nextActivityIdToKeyMap * Add new test to validate streaming entities in the entities field rather than channelData * additional tests for entities * Update streaming test data to better match reality This results in a single combined message rather than 3 separate messages * remove old snapshot * minor typo * add one additional message to the test data * updated snapshots * remove streamId from first entity * refactor livestream tests to test both channelData and entity style data formats * rebuild snaps of entity tests * Clean up --------- Co-authored-by: William Wong <compulim@users.noreply.github.com>
1 parent 4a21b9c commit a8a3376

File tree

108 files changed

+1149
-487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1149
-487
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>activityOrder (entity): redirects to ?streamingFormat=entity</title>
5+
<script>
6+
location = './activityOrder?streamingFormat=entity';
7+
</script>
8+
</head>
9+
<body></body>
10+
</html>
11.5 KB
Loading
16.3 KB
Loading
17.2 KB
Loading
18.2 KB
Loading
19.9 KB
Loading

__tests__/html2/livestream/activityOrder.html

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@
1212
<body>
1313
<main id="webchat"></main>
1414
<script type="module">
15+
const streamingFormat = new URL(window.location.href).searchParams.get('streamingFormat') ?? 'channelData'; // can be entity or channelData
16+
17+
function addLivestreamingMetadata(activity, livestreamingMetadata) {
18+
return streamingFormat === 'entity'
19+
? {
20+
...activity,
21+
entities: [...(activity.entities ?? []), { ...livestreamingMetadata, type: 'streaminfo' }]
22+
}
23+
: {
24+
...activity,
25+
channelData: { ...activity.channelData, ...livestreamingMetadata }
26+
};
27+
}
28+
1529
run(async function () {
1630
const {
1731
React: { createElement },
@@ -61,13 +75,17 @@
6175
// WHEN: Bot is typing a message.
6276
const firstTypingActivityId = 't-00001';
6377

64-
await directLine.emulateIncomingActivity({
65-
channelData: { streamSequence: 1, streamType: 'streaming' },
66-
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
67-
id: firstTypingActivityId,
68-
text: 'A quick',
69-
type: 'typing'
70-
});
78+
await directLine.emulateIncomingActivity(
79+
addLivestreamingMetadata(
80+
{
81+
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
82+
id: firstTypingActivityId,
83+
text: 'A quick',
84+
type: 'typing'
85+
},
86+
{ streamSequence: 1, streamType: 'streaming' }
87+
)
88+
);
7189

7290
let secondActivityKey = currentActivityKeysWithId[1][0];
7391

@@ -123,13 +141,17 @@
123141
// ---
124142

125143
// WHEN: Bot continue typing the message.
126-
await directLine.emulateIncomingActivity({
127-
channelData: { streamId: firstTypingActivityId, streamSequence: 2, streamType: 'streaming' },
128-
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
129-
id: 't-00002',
130-
text: 'A quick brown fox',
131-
type: 'typing'
132-
});
144+
await directLine.emulateIncomingActivity(
145+
addLivestreamingMetadata(
146+
{
147+
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
148+
id: 't-00002',
149+
text: 'A quick brown fox',
150+
type: 'typing'
151+
},
152+
{ streamId: firstTypingActivityId, streamSequence: 2, streamType: 'streaming' }
153+
)
154+
);
133155

134156
// THEN: Should display 3 messages, the order should kept the same.
135157
await pageConditions.numActivitiesShown(3);
@@ -155,13 +177,17 @@
155177
// ---
156178

157179
// WHEN: Bot continue typing the message.
158-
await directLine.emulateIncomingActivity({
159-
channelData: { streamId: firstTypingActivityId, streamSequence: 3, streamType: 'streaming' },
160-
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
161-
id: 't-00003',
162-
text: 'A quick brown fox jumped over',
163-
type: 'typing'
164-
});
180+
await directLine.emulateIncomingActivity(
181+
addLivestreamingMetadata(
182+
{
183+
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
184+
id: 't-00003',
185+
text: 'A quick brown fox jumped over',
186+
type: 'typing'
187+
},
188+
{ streamId: firstTypingActivityId, streamSequence: 3, streamType: 'streaming' }
189+
)
190+
);
165191

166192
// THEN: Should display 3 messages, the order should kept the same.
167193
await pageConditions.numActivitiesShown(3);
@@ -187,13 +213,17 @@
187213
// ---
188214

189215
// WHEN: Bot finished typing the message.
190-
await directLine.emulateIncomingActivity({
191-
channelData: { streamId: firstTypingActivityId, streamType: 'final' },
192-
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
193-
id: 'a-00002',
194-
text: 'A quick brown fox jumped over the lazy dogs.',
195-
type: 'message'
196-
});
216+
await directLine.emulateIncomingActivity(
217+
addLivestreamingMetadata(
218+
{
219+
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
220+
id: 'a-00002',
221+
text: 'A quick brown fox jumped over the lazy dogs.',
222+
type: 'message'
223+
},
224+
{ streamId: firstTypingActivityId, streamType: 'final' }
225+
)
226+
);
197227

198228
// THEN: Should display 3 messages.
199229
await pageConditions.numActivitiesShown(3);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script>
5+
location = './attachmentWithoutText?layout=carousel&streamingFormat=entity';
6+
</script>
7+
</head>
8+
<body></body>
9+
</html>
6.58 KB
Loading
6.84 KB
Loading

0 commit comments

Comments
 (0)