Skip to content

Commit ae47f35

Browse files
authored
Outgoing activities restored from chat service should be marked as sent (#4532)
* Fix send status during chat history restoration * Add entry * Update tests
1 parent 42b07cc commit ae47f35

10 files changed

Lines changed: 220 additions & 174 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2222

2323
## [Unreleased]
2424

25+
### Fixed
26+
27+
- Fixes [#4501](https://github.com/microsoft/BotFramework-WebChat/issues/4501). Outgoing activities restored from chat service should be marked as sent, by [@compulim](https://github.com/compulim) in PR [#4532](https://github.com/microsoft/BotFramework-WebChat/pull/4532)
28+
2529
### Changed
2630

2731
- Fixes [#4523](https://github.com/microsoft/BotFramework-WebChat/issues/4523). Bumped Microsoft Cognitive Services Speech SDK to [`microsoft-cognitiveservices-speech-sdk@1.17.0`](https://npmjs.com/package/microsoft-cognitiveservices-speech-sdk), by [@compulim](https://github.com/compulim) in PR [#4533](https://github.com/microsoft/BotFramework-WebChat/pull/4533)
-1.92 KB
Loading

__tests__/html/activityGrouping.disableTimestamp.html

Lines changed: 31 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,13 @@
1111
<script>
1212
run(async function () {
1313
const clock = lolex.install();
14-
const directLine = await testHelpers.createDirectLineWithTranscript([
15-
{
16-
from: { role: 'bot' },
17-
id: '1.0',
18-
text: 'Culpa qui non id occaecat consectetur veniam laborum Lorem nulla commodo.',
19-
timestamp: -300001,
20-
type: 'message'
21-
},
22-
{
23-
channelData: { state: 'sent' },
24-
from: { role: 'user' },
25-
id: '2.0',
26-
text: 'Est labore mollit do cillum cillum est amet tempor quis reprehenderit veniam sunt.',
27-
timestamp: -300001,
28-
type: 'message'
29-
},
30-
{
31-
channelData: { clientActivityID: '2.1', state: 'sending', 'webchat:sequence-id': -300000.999 },
32-
from: { role: 'user' },
33-
localTimestamp: -300001,
34-
text: 'Elit adipisicing laborum sit anim.',
35-
type: 'message'
36-
},
37-
{
38-
channelData: { clientActivityID: '2.2', state: 'sending', 'webchat:sequence-id': -300000.998 },
39-
from: { role: 'user' },
40-
localTimestamp: -5001,
41-
text: 'Nostrud enim enim ipsum pariatur commodo.',
42-
type: 'message'
43-
},
44-
{
45-
channelData: { state: 'sent' },
46-
from: { role: 'user' },
47-
text: 'Culpa id proident sit officia aliquip.',
48-
timestamp: -5001,
49-
type: 'message'
50-
},
51-
{
52-
from: { role: 'bot' },
53-
id: '3.0',
54-
text: 'Quis sit aliquip sit velit in velit magna culpa velit qui.',
55-
timestamp: 0,
56-
type: 'message'
57-
}
58-
]);
14+
const store = testHelpers.createStore();
15+
const directLine = testHelpers.createDirectLineEmulator(store);
5916

6017
WebChat.renderWebChat(
6118
{
6219
directLine,
63-
store: testHelpers.createStore(),
20+
store,
6421
styleOptions: {
6522
botAvatarInitials: 'Bot',
6623
bubbleBackground: '#0063B1',
@@ -86,29 +43,40 @@
8643

8744
clock.tick(1000);
8845

46+
await directLine.emulateIncomingActivity(
47+
'Culpa qui non id occaecat consectetur veniam laborum Lorem nulla commodo.'
48+
);
49+
50+
await (
51+
await directLine.emulateOutgoingActivity(
52+
'Est labore mollit do cillum cillum est amet tempor quis reprehenderit veniam sunt.'
53+
)
54+
).resolveAll();
55+
56+
const { resolveAll: resolveAll1 } = await directLine.emulateOutgoingActivity(
57+
'Elit adipisicing laborum sit anim.'
58+
);
59+
60+
clock.tick(295000);
61+
62+
const { resolveAll: resolveAll2 } = await directLine.emulateOutgoingActivity(
63+
'Nostrud enim enim ipsum pariatur commodo.'
64+
);
65+
66+
await (await directLine.emulateOutgoingActivity('Culpa id proident sit officia aliquip.')).resolveAll();
67+
68+
clock.tick(5000);
69+
70+
await directLine.emulateIncomingActivity('Quis sit aliquip sit velit in velit magna culpa velit qui.');
71+
8972
await host.snapshot();
9073

9174
clock.tick(29000);
9275

9376
await host.snapshot();
9477

95-
directLine.activityDeferredObservable.next({
96-
channelData: { clientActivityID: '2.1', state: 'sent' },
97-
from: { role: 'user' },
98-
id: '2.1',
99-
text: 'Elit adipisicing laborum sit anim.',
100-
timestamp: -300001,
101-
type: 'message'
102-
});
103-
104-
directLine.activityDeferredObservable.next({
105-
channelData: { clientActivityID: '2.2', state: 'sent' },
106-
from: { role: 'user' },
107-
id: '2.2',
108-
text: 'Nostrud enim enim ipsum pariatur commodo.',
109-
timestamp: -5001,
110-
type: 'message'
111-
});
78+
await resolveAll1();
79+
await resolveAll2();
11280

11381
await host.snapshot();
11482
});

__tests__/html/activityGrouping.legacyActivityStatusMiddleware.html

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -68,41 +68,15 @@
6868
return next(...args);
6969
};
7070

71+
const store = testHelpers.createStore();
72+
73+
const directLine = testHelpers.createDirectLineEmulator(store);
74+
7175
WebChat.renderWebChat(
7276
{
7377
activityStatusMiddleware,
74-
directLine: await testHelpers.createDirectLineWithTranscript([
75-
{
76-
from: { role: 'bot' },
77-
id: '1.0',
78-
text: 'This message should have timestamp "Bot at Just now".',
79-
timestamp: -30001,
80-
type: 'message'
81-
},
82-
{
83-
channelData: { state: 'sent' },
84-
from: { role: 'user' },
85-
id: '2.0',
86-
text: 'This message should have timestamp "User at Just now".',
87-
timestamp: -30001,
88-
type: 'message'
89-
},
90-
{
91-
channelData: { clientActivityID: '2.1', state: 'sending', 'webchat:sequence-id': -30000.999 },
92-
from: { role: 'user' },
93-
localTimestamp: -20001,
94-
text: 'This message should have status "Send failed".',
95-
type: 'message'
96-
},
97-
{
98-
channelData: { clientActivityID: '2.2', state: 'sending', 'webchat:sequence-id': -30000.998 },
99-
from: { role: 'user' },
100-
localTimestamp: 0,
101-
text: 'This message should have status "Sending...", then turn to "Send failed".',
102-
type: 'message'
103-
}
104-
]),
105-
store: testHelpers.createStore()
78+
directLine,
79+
store
10680
},
10781
document.getElementById('webchat')
10882
);
@@ -111,9 +85,25 @@
11185

11286
clock.tick(1000);
11387

88+
await directLine.emulateIncomingActivity('This message should have timestamp "Bot at Just now".');
89+
90+
await (
91+
await directLine.emulateOutgoingActivity('This message should have timestamp "User at Just now".')
92+
).resolveAll();
93+
94+
clock.tick(10000);
95+
96+
await directLine.emulateOutgoingActivity('This message should have status "Send failed".');
97+
98+
clock.tick(20000);
99+
100+
await directLine.emulateOutgoingActivity(
101+
'This message should have status "Sending...", then turn to "Send failed".'
102+
);
103+
114104
await host.snapshot();
115105

116-
clock.tick(19000);
106+
clock.tick(20000);
117107

118108
await host.snapshot();
119109
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="/test-harness.js"></script>
6+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
7+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
8+
</head>
9+
<body>
10+
<div id="webchat"></div>
11+
<script>
12+
run(async function () {
13+
const clock = lolex.install({ now: new Date('2022-11-11T19:34:00.000Z') });
14+
15+
const store = testHelpers.createStore();
16+
17+
const directLine = testHelpers.createDirectLineEmulator(store);
18+
19+
WebChat.renderWebChat({ directLine, store, userID: 'u-00001' }, document.getElementById('webchat'));
20+
21+
await pageConditions.webChatRendered();
22+
23+
clock.tick(1000);
24+
25+
// Related to issue #4501.
26+
// WHEN: An outgoing activity arrived via chat history restoration.
27+
await directLine.emulateIncomingActivity({
28+
type: 'message',
29+
id: 'c00001-us|0000000',
30+
timestamp: '2022-11-11T19:34:00.000Z',
31+
// All messages sent from end-user must have `localTimestamp`.
32+
// If `localTimestamp` is not present, this will not repro.
33+
localTimestamp: '2022-11-11T11:34:00.000-08:00',
34+
from: {
35+
id: 'u00001',
36+
role: 'user'
37+
},
38+
text: 'Hello, World!',
39+
channelData: {
40+
clientActivityID: 'ca00001'
41+
}
42+
});
43+
44+
// THEN: Activity status on the outgoing activity should be "sent".
45+
// This is because all activities restored from service, are successfully sent.
46+
expect(
47+
pageElements.activityStatuses().map(element => element.querySelector('[aria-hidden="true"]').innerText)
48+
).toEqual(['Just now']);
49+
});
50+
</script>
51+
</body>
52+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */
2+
3+
describe('when restoring chat history', () => {
4+
test('outgoing activities should be marked as sent', () => runHTML('chatHistory.restore.sent.html'));
5+
});

__tests__/html/hooks.useCreateActivityStatusRenderer.html

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
} = window;
2222

2323
run(async function () {
24+
const clock = lolex.install();
25+
2426
const Test = () => {
2527
const [activities] = useActivities();
2628

@@ -39,52 +41,54 @@
3941
);
4042
};
4143

42-
const directLine = await testHelpers.createDirectLineWithTranscript([
43-
{
44-
// Setting sequence ID to simplify the order of these test cases.
45-
channelData: { 'webchat:sequence-id': 0 },
46-
from: { role: 'bot' },
47-
id: '1.0',
48-
text: 'Sint ex sunt ipsum exercitation id id reprehenderit cupidatat incididunt aliquip.',
49-
timestamp: -60001,
50-
type: 'message'
51-
},
52-
{
53-
channelData: { state: 'sending', 'webchat:sequence-id': 1 },
54-
from: { role: 'user' },
55-
id: '2.0',
56-
localTimestamp: -60001,
57-
text: 'Ipsum ex labore occaecat aute eu ea anim veniam tempor.',
58-
type: 'message'
59-
},
60-
{
61-
channelData: { state: 'sending', 'webchat:sequence-id': 2 },
62-
from: { role: 'user' },
63-
id: '3.0',
64-
localTimestamp: 0,
65-
text: 'Laboris Lorem sint magna sit ad eu ullamco irure.',
66-
type: 'message'
67-
},
68-
{
69-
channelData: { state: 'sent', 'webchat:sequence-id': 3 },
70-
from: { role: 'user' },
71-
id: '4.0',
72-
text: 'Sunt cupidatat mollit id adipisicing occaecat ipsum fugiat ullamco in aute deserunt ut.',
73-
timestamp: 0,
74-
type: 'message'
75-
}
76-
]);
77-
7844
const store = testHelpers.createStore();
7945

46+
const directLine = testHelpers.createDirectLineEmulator(store);
47+
8048
render(
8149
<Composer directLine={directLine} store={store}>
8250
<Test />
8351
</Composer>,
8452
document.getElementById('webchat')
8553
);
8654

87-
await pageConditions.uiConnected();
55+
await pageConditions.webChatRendered();
56+
57+
await directLine.emulateIncomingActivity({
58+
// Setting sequence ID to simplify the order of these test cases.
59+
channelData: { 'webchat:sequence-id': 0 },
60+
from: { role: 'bot' },
61+
text: 'Sint ex sunt ipsum exercitation id id reprehenderit cupidatat incididunt aliquip.',
62+
type: 'message'
63+
});
64+
65+
await directLine.emulateOutgoingActivity({
66+
channelData: { 'webchat:sequence-id': 1 },
67+
from: { role: 'user' },
68+
text: 'Ipsum ex labore occaecat aute eu ea anim veniam tempor.',
69+
type: 'message'
70+
});
71+
72+
clock.tick(60000);
73+
74+
await directLine.emulateOutgoingActivity({
75+
channelData: { 'webchat:sequence-id': 2 },
76+
from: { role: 'user' },
77+
localTimestamp: 0,
78+
text: 'Laboris Lorem sint magna sit ad eu ullamco irure.',
79+
type: 'message'
80+
});
81+
82+
await (
83+
await directLine.emulateOutgoingActivity({
84+
channelData: { 'webchat:sequence-id': 3 },
85+
from: { role: 'user' },
86+
text: 'Sunt cupidatat mollit id adipisicing occaecat ipsum fugiat ullamco in aute deserunt ut.',
87+
timestamp: 0,
88+
type: 'message'
89+
})
90+
).resolveAll();
91+
8892
await pageConditions.became('Done', () => document.querySelector('.done'), 1000);
8993

9094
await host.snapshot();

0 commit comments

Comments
 (0)