-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathsequenceId.directLine.outgoing.html
More file actions
161 lines (135 loc) · 5.95 KB
/
sequenceId.directLine.outgoing.html
File metadata and controls
161 lines (135 loc) · 5.95 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
<!DOCTYPE html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<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>
const BASE_TIMESTAMP = +new Date(2020, 0, 1, 12, 34);
function createActivity(text, timestamp, sequenceId) {
return {
channelData: {
'webchat:sequence-id': sequenceId
},
from: { role: 'bot' },
id: Math.random().toString(36).substr(2, 5),
text,
timestamp: new Date(BASE_TIMESTAMP + timestamp),
type: 'message'
};
}
run(async function () {
const sending = [];
const directLine = await testHelpers.createDirectLineWithTranscript(
[
{
from: { role: 'bot' },
id: 'in-00001',
text: 'Bot activity has timestamp of 2.',
timestamp: new Date(BASE_TIMESTAMP + 2),
type: 'message'
}
],
{
overridePostActivity: activity => {
const deferred = createDeferred();
const observable = new Observable(observer => {
deferred.promise.then(
activity => {
directLine.activityDeferredObservable.next(activity);
observer.next(activity.id);
observer.complete();
},
err => observer.error(err)
);
});
sending.push({ activity, reject: deferred.reject, resolve: deferred.resolve });
return observable;
}
}
);
const store = testHelpers.createStore();
WebChat.renderWebChat(
{
directLine,
store
},
document.getElementById('webchat')
);
// SETUP: With 1 message from the bot.
await pageConditions.uiConnected();
await pageConditions.numActivitiesShown(1);
await pageConditions.scrollToBottomCompleted();
// WHEN: Sending 2 messages consecutively, before getting responses.
await pageObjects.sendMessageViaSendBox('User activity has timestamp of 1.', { waitForSend: false });
await pageObjects.sendMessageViaSendBox('User activity has timestamp of 0.', { waitForSend: false });
await pageConditions.numActivitiesShown(3);
const { activities } = store.getState();
// THEN: The first outgoing message should be the second, after the bot's message.
expect(activities[1].text).toBe('User activity has timestamp of 1.');
// THEN: The second outgoing message should be the third.
expect(activities[2].text).toBe('User activity has timestamp of 0.');
// THEN: The first outgoing message should have a smaller position than the bot's message.
expect(
activities[0].channelData['webchat:internal:position'] <
activities[1].channelData['webchat:internal:position']
).toBe(true);
// THEN: The first outgoing message should have a smaller position than the second outgoing message.
expect(
activities[1].channelData['webchat:internal:position'] <
activities[2].channelData['webchat:internal:position']
).toBe(true);
// THEN: Both outgoing messages should not send "webchat:sequence-id" and "state".
expect(sending[0].activity.channelData['webchat:sequence-id']).toBeUndefined();
expect(sending[0].activity.channelData.state).toBeUndefined();
expect(sending[1].activity.channelData['webchat:sequence-id']).toBeUndefined();
expect(sending[1].activity.channelData.state).toBeUndefined();
// THEN: It should show message in order of "2", "1", followed by "0".
await host.snapshot('local');
// WHEN: The first message has echoed back with a timestamp of 1.
sending[0].resolve({
...sending[0].activity,
id: 'out-00001',
timestamp: new Date(BASE_TIMESTAMP + 1).toISOString()
});
// THEN: At least one outgoing message should marked as sent.
await pageConditions.became(
'one message has been sent',
() => store.getState().activities.find(activity => activity.channelData.state === 'sent'),
2000
);
// THEN: It should show message in the order of "1", "2", followed by "0".
// "1" should be marked as sent.
// "0" should be sending.
await host.snapshot('local');
// THEN: The first outgoing message should appears first, before the bot's message.
// The first outgoing message has a smaller timestamp (t=1) than the bot's message (t=2).
expect(pageElements.activityContents().map(element => element.innerText)).toEqual([
'User activity has timestamp of 1.',
'Bot activity has timestamp of 2.',
'User activity has timestamp of 0.'
]);
// WHEN: The first message has echoed back with a timestamp of 0.
sending[1].resolve({
...sending[1].activity,
id: 'out-00002',
timestamp: new Date(BASE_TIMESTAMP).toISOString()
});
// THEN: All outgoing messages should be sent.
await pageConditions.allOutgoingActivitiesSent();
// THEN: All messages should sort based on timestamp.
expect(pageElements.activityContents().map(element => element.innerText)).toEqual([
'User activity has timestamp of 0.',
'User activity has timestamp of 1.',
'Bot activity has timestamp of 2.'
]);
// THEN: It should show message in the order of "0", "1", followed by "2".
await host.snapshot('local');
});
</script>
</body>
</html>