-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathwrongId.html
More file actions
131 lines (113 loc) · 4.63 KB
/
wrongId.html
File metadata and controls
131 lines (113 loc) · 4.63 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
<!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">
run(async function () {
const {
React: { createElement },
ReactDOM: { render },
WebChat: {
Components: { BasicWebChat, Composer },
decorator: { WebChatDecorator },
hooks: { useActivityKeys, useGetActivitiesByKey }
}
} = window; // Imports in UMD fashion.
const { directLine, store } = testHelpers.createDirectLineEmulator();
let currentActivityKeysWithId = [];
const Monitor = () => {
const [activityKeys] = useActivityKeys();
const getActivitiesByKey = useGetActivitiesByKey();
currentActivityKeysWithId = Object.freeze(
activityKeys.map(key => [key, getActivitiesByKey(key).map(({ id }) => id)])
);
return false;
};
render(
createElement(
WebChatDecorator,
{},
createElement(
Composer,
{
directLine,
store
},
createElement(BasicWebChat),
createElement(Monitor)
)
),
document.getElementById('webchat')
);
await pageConditions.uiConnected();
// SETUP: Bot sent a message.
await directLine.emulateIncomingActivity({
id: 'a-00001',
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
text: 'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.',
type: 'message'
});
let firstActivityKey = currentActivityKeysWithId[0][0];
// WHEN: Bot is typing a message.
const firstTypingActivityId = 't-00001';
await directLine.emulateIncomingActivity({
channelData: { streamSequence: 1, streamType: 'streaming' },
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
id: firstTypingActivityId,
text: 'A quick',
type: 'typing'
});
let secondActivityKey = currentActivityKeysWithId[1][0];
// THEN: Should display 2 messages.
await pageConditions.numActivitiesShown(2);
expect(pageElements.typingIndicator()).toBeFalsy();
expect(pageElements.activityContents()[0]).toHaveProperty(
'textContent',
'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.'
);
expect(pageElements.activityContents()[1]).toHaveProperty('textContent', 'A quick');
await host.snapshot('local');
// THEN: Should have 2 activity keys.
expect(currentActivityKeysWithId).toEqual([
[firstActivityKey, ['a-00001']],
[secondActivityKey, ['t-00001']]
]);
// ---
// WHEN: Bot send another unrelated message.
await directLine.emulateIncomingActivity({
channelData: { streamId: 'x-99999', streamSequence: 2, streamType: 'streaming' },
from: { id: 'u-00001', name: 'Bot', role: 'bot' },
id: 't-00002',
text: 'A quick brown fox',
type: 'typing'
});
let thirdActivityKey = currentActivityKeysWithId[2][0];
// THEN: Should display 3 messages.
await pageConditions.numActivitiesShown(3);
expect(pageElements.typingIndicator()).toBeFalsy();
expect(pageElements.activityContents()[0]).toHaveProperty(
'textContent',
'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.'
);
expect(pageElements.activityContents()[1]).toHaveProperty('textContent', 'A quick');
expect(pageElements.activityContents()[2]).toHaveProperty('textContent', 'A quick brown fox');
await host.snapshot('local');
// THEN: Should have 2 activity keys only.
expect(currentActivityKeysWithId).toEqual([
[firstActivityKey, ['a-00001']],
[secondActivityKey, ['t-00001']],
[thirdActivityKey, ['t-00002']]
]);
});
</script>
</body>
</html>