-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix streaming behavior by capturing typingActivityId in nextActivityIdToKeyMap #5609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
88c4d49
8867617
00da7ea
7c4d142
8e15b00
5f955d0
bbe6a55
9a34ff2
02bb569
a669a32
eeec789
442dc40
46c95d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<!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 } | ||
} | ||
} = window; // Imports in UMD fashion. | ||
|
||
const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
||
const styleOptions = { | ||
typingAnimationBackgroundImage: `url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAUACgDASIAAhEBAxEB/8QAGgABAQACAwAAAAAAAAAAAAAAAAYCBwMFCP/EACsQAAECBQIEBQUAAAAAAAAAAAECAwAEBQYRBxITIjFBMlFhccFScoGh8f/EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwD0lctx023JVD9UeKOIcNoSNylkdcCMbauSmXHLOPUx8r4ZAcQtO1SM9Mj5iO1gtWo1syc7S2zMKYSptbIPNgnII8/5HBpRZ9RpaKjNVVCpUzLPAQ1nmA7qPl6fmAondRrcaqhkVTiiQrYXgglsH7vnpHc3DcNNoEimaqT4Q2s4bCRuUs+gEaLd05uNFVMmiS3o3YEwFDhlP1Z7e3WLzUuzahUKHRk0zM07TmeApvOFLGEjcM9+Xp6wFnbN0Uu5GnF0x4qW1je2tO1Sc9Djy9oRD6QWlU6PPzVSqjRlgtksttKPMcqBKiO3h/cIDacIQgEIQgEIQgP/2Q==')` | ||
}; | ||
|
||
render( | ||
createElement( | ||
WebChatDecorator, | ||
{}, | ||
createElement( | ||
Composer, | ||
{ | ||
directLine, | ||
store, | ||
styleOptions | ||
}, | ||
createElement(BasicWebChat) | ||
) | ||
), | ||
document.getElementById('webchat') | ||
); | ||
|
||
await pageConditions.uiConnected(); | ||
|
||
await directLine.emulateIncomingActivity({ | ||
from: { | ||
id: 'u-00001', | ||
name: 'Bot', | ||
role: 'bot' | ||
}, | ||
text: 'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.' | ||
}); | ||
|
||
const firstTypingActivityId = 't-00001'; | ||
|
||
// WHEN: An informative message is received. | ||
await directLine.emulateIncomingActivity({ | ||
entities: [{ | ||
streamSequence: 1, | ||
streamType: 'informative', | ||
type: 'streaminfo', | ||
}], | ||
from: { | ||
id: 'u-00001', | ||
name: 'Bot', | ||
role: 'bot' | ||
}, | ||
id: 't-00001', | ||
text: 'Nisi elit quis nisi consectetur.', | ||
type: 'typing' | ||
}); | ||
|
||
// THEN: Should render the informative message. | ||
expect(pageElements.activityContents()[0]).toHaveProperty( | ||
'textContent', | ||
'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.' | ||
); | ||
expect(pageElements.activityContents()[1]).toHaveProperty('textContent', 'Nisi elit quis nisi consectetur.'); | ||
|
||
await pageConditions.numActivitiesShown(2); | ||
await host.snapshot('local'); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,184 @@ | ||||||||||||||||||||||
npm <!doctype html> | ||||||||||||||||||||||
benbrown marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
<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({ | ||||||||||||||||||||||
entities: [{ streamSequence: 1, streamType: 'streaming', type: 'streaminfo', streamId: 'a-entities' }], | ||||||||||||||||||||||
benbrown marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
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 continue typing the message. | ||||||||||||||||||||||
await directLine.emulateIncomingActivity({ | ||||||||||||||||||||||
entities: [{ streamId: 'a-entities', streamSequence: 2, type: 'streaminfo', streamType: 'streaming' }], | ||||||||||||||||||||||
compulim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
from: { id: 'u-00001', name: 'Bot', role: 'bot' }, | ||||||||||||||||||||||
id: 't-00002', | ||||||||||||||||||||||
text: 'A quick brown fox', | ||||||||||||||||||||||
type: 'typing' | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// 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 brown fox'); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Probably need |
||||||||||||||||||||||
await host.snapshot('local'); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// THEN: Should have 2 activity keys only. | ||||||||||||||||||||||
expect(currentActivityKeysWithId).toEqual([ | ||||||||||||||||||||||
[firstActivityKey, ['a-00001']], | ||||||||||||||||||||||
[secondActivityKey, ['t-00001', 't-00002']] | ||||||||||||||||||||||
]); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// --- | ||||||||||||||||||||||
|
||||||||||||||||||||||
// WHEN: Bot continue typing the message. | ||||||||||||||||||||||
await directLine.emulateIncomingActivity({ | ||||||||||||||||||||||
entities: [{ streamId: 'a-entities', streamSequence: 3, type: 'streaminfo', streamType: 'streaming' }], | ||||||||||||||||||||||
benbrown marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
from: { id: 'u-00001', name: 'Bot', role: 'bot' }, | ||||||||||||||||||||||
id: 't-00003', | ||||||||||||||||||||||
text: 'A quick brown fox jumped over', | ||||||||||||||||||||||
type: 'typing' | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// 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 brown fox jumped over'); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This probably need |
||||||||||||||||||||||
await host.snapshot('local'); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// THEN: Should have 2 activity keys. | ||||||||||||||||||||||
expect(currentActivityKeysWithId).toEqual([ | ||||||||||||||||||||||
[firstActivityKey, ['a-00001']], | ||||||||||||||||||||||
[secondActivityKey, ['t-00001', 't-00002', 't-00003']] | ||||||||||||||||||||||
]); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// WHEN: Bot finished typing the message. | ||||||||||||||||||||||
await directLine.emulateIncomingActivity({ | ||||||||||||||||||||||
entities: [{ streamId: 'a-entities', type: 'streaminfo', streamType: 'final' }], | ||||||||||||||||||||||
benbrown marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
from: { id: 'u-00001', name: 'Bot', role: 'bot' }, | ||||||||||||||||||||||
id: 'a-00002', | ||||||||||||||||||||||
text: 'A quick brown fox jumped over the lazy dogs.', | ||||||||||||||||||||||
type: 'message' | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// 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 brown fox jumped over the lazy dogs.' | ||||||||||||||||||||||
); | ||||||||||||||||||||||
Comment on lines
+170
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
await host.snapshot('local'); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// THEN: Should have 2 activity keys. | ||||||||||||||||||||||
expect(currentActivityKeysWithId).toEqual([ | ||||||||||||||||||||||
[firstActivityKey, ['a-00001']], | ||||||||||||||||||||||
[secondActivityKey, ['t-00001', 't-00002', 't-00003', 'a-00002']] | ||||||||||||||||||||||
]); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
</script> | ||||||||||||||||||||||
</body> | ||||||||||||||||||||||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to pause the animation, or maybe it is already paused when running in WebDriver.
In case pause is needed, set accessibility "reduced motion" in Dev Tools.