Skip to content

Commit 00da7ea

Browse files
committed
Add new test to validate streaming entities in the entities field rather than channelData
1 parent 8867617 commit 00da7ea

5 files changed

Lines changed: 184 additions & 0 deletions

File tree

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
npm <!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<link href="./css/pauseAnimation.css" rel="stylesheet" type="text/css" />
6+
<script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script>
7+
<script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script>
8+
<script crossorigin="anonymous" src="/test-harness.js"></script>
9+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
10+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
11+
</head>
12+
<body>
13+
<main id="webchat"></main>
14+
<script type="module">
15+
run(async function () {
16+
const {
17+
React: { createElement },
18+
ReactDOM: { render },
19+
WebChat: {
20+
Components: { BasicWebChat, Composer },
21+
decorator: { WebChatDecorator },
22+
hooks: { useActivityKeys, useGetActivitiesByKey }
23+
}
24+
} = window; // Imports in UMD fashion.
25+
26+
const { directLine, store } = testHelpers.createDirectLineEmulator();
27+
let currentActivityKeysWithId = [];
28+
29+
const Monitor = () => {
30+
const [activityKeys] = useActivityKeys();
31+
const getActivitiesByKey = useGetActivitiesByKey();
32+
33+
currentActivityKeysWithId = Object.freeze(
34+
activityKeys.map(key => [key, getActivitiesByKey(key).map(({ id }) => id)])
35+
);
36+
37+
return false;
38+
};
39+
40+
render(
41+
createElement(
42+
WebChatDecorator,
43+
{},
44+
createElement(
45+
Composer,
46+
{
47+
directLine,
48+
store
49+
},
50+
createElement(BasicWebChat),
51+
createElement(Monitor)
52+
)
53+
),
54+
document.getElementById('webchat')
55+
);
56+
57+
await pageConditions.uiConnected();
58+
59+
// SETUP: Bot sent a message.
60+
await directLine.emulateIncomingActivity({
61+
id: 'a-00001',
62+
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
63+
text: 'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.',
64+
type: 'message'
65+
});
66+
67+
let firstActivityKey = currentActivityKeysWithId[0][0];
68+
69+
// WHEN: Bot is typing a message.
70+
const firstTypingActivityId = 't-00001';
71+
72+
await directLine.emulateIncomingActivity({
73+
entities: [{ streamSequence: 1, streamType: 'streaming', type: 'streaminfo', streamId: 'a-entities' }],
74+
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
75+
id: firstTypingActivityId,
76+
text: 'A quick',
77+
type: 'typing'
78+
});
79+
80+
let secondActivityKey = currentActivityKeysWithId[1][0];
81+
82+
// THEN: Should display 2 messages.
83+
await pageConditions.numActivitiesShown(2);
84+
85+
expect(pageElements.typingIndicator()).toBeFalsy();
86+
expect(pageElements.activityContents()[0]).toHaveProperty(
87+
'textContent',
88+
'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.'
89+
);
90+
expect(pageElements.activityContents()[1]).toHaveProperty('textContent', 'A quick');
91+
await host.snapshot('local');
92+
93+
// THEN: Should have 2 activity keys.
94+
expect(currentActivityKeysWithId).toEqual([
95+
[firstActivityKey, ['a-00001']],
96+
[secondActivityKey, ['t-00001']]
97+
]);
98+
99+
// ---
100+
101+
// WHEN: Bot continue typing the message.
102+
await directLine.emulateIncomingActivity({
103+
entities: [{ streamId: 'a-entities', streamSequence: 2, type: 'streaminfo', streamType: 'streaming' }],
104+
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
105+
id: 't-00002',
106+
text: 'A quick brown fox',
107+
type: 'typing'
108+
});
109+
110+
// THEN: Should display 2 messages.
111+
await pageConditions.numActivitiesShown(2);
112+
113+
expect(pageElements.typingIndicator()).toBeFalsy();
114+
expect(pageElements.activityContents()[0]).toHaveProperty(
115+
'textContent',
116+
'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.'
117+
);
118+
expect(pageElements.activityContents()[1]).toHaveProperty('textContent', 'A quick brown fox');
119+
await host.snapshot('local');
120+
121+
// THEN: Should have 2 activity keys only.
122+
expect(currentActivityKeysWithId).toEqual([
123+
[firstActivityKey, ['a-00001']],
124+
[secondActivityKey, ['t-00001', 't-00002']]
125+
]);
126+
127+
// ---
128+
129+
// WHEN: Bot continue typing the message.
130+
await directLine.emulateIncomingActivity({
131+
entities: [{ streamId: 'a-entities', streamSequence: 3, type: 'streaminfo', streamType: 'streaming' }],
132+
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
133+
id: 't-00003',
134+
text: 'A quick brown fox jumped over',
135+
type: 'typing'
136+
});
137+
138+
// THEN: Should display 2 messages.
139+
await pageConditions.numActivitiesShown(2);
140+
expect(pageElements.typingIndicator()).toBeFalsy();
141+
expect(pageElements.activityContents()[0]).toHaveProperty(
142+
'textContent',
143+
'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.'
144+
);
145+
expect(pageElements.activityContents()[1]).toHaveProperty('textContent', 'A quick brown fox jumped over');
146+
await host.snapshot('local');
147+
148+
// THEN: Should have 2 activity keys.
149+
expect(currentActivityKeysWithId).toEqual([
150+
[firstActivityKey, ['a-00001']],
151+
[secondActivityKey, ['t-00001', 't-00002', 't-00003']]
152+
]);
153+
154+
// WHEN: Bot finished typing the message.
155+
await directLine.emulateIncomingActivity({
156+
entities: [{ streamId: 'a-entities', type: 'streaminfo', streamType: 'final' }],
157+
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
158+
id: 'a-00002',
159+
text: 'A quick brown fox jumped over the lazy dogs.',
160+
type: 'message'
161+
});
162+
163+
// THEN: Should display 2 messages.
164+
await pageConditions.numActivitiesShown(2);
165+
expect(pageElements.typingIndicator()).toBeFalsy();
166+
expect(pageElements.activityContents()[0]).toHaveProperty(
167+
'textContent',
168+
'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.'
169+
);
170+
expect(pageElements.activityContents()[1]).toHaveProperty(
171+
'textContent',
172+
'A quick brown fox jumped over the lazy dogs.'
173+
);
174+
await host.snapshot('local');
175+
176+
// THEN: Should have 2 activity keys.
177+
expect(currentActivityKeysWithId).toEqual([
178+
[firstActivityKey, ['a-00001']],
179+
[secondActivityKey, ['t-00001', 't-00002', 't-00003', 'a-00002']]
180+
]);
181+
});
182+
</script>
183+
</body>
184+
</html>
32 KB
Loading
33.5 KB
Loading
34.9 KB
Loading
37.4 KB
Loading

0 commit comments

Comments
 (0)