-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathsupportPolymiddleware.reactDOMRender.withCreateRoot.html
More file actions
73 lines (62 loc) · 2.53 KB
/
supportPolymiddleware.reactDOMRender.withCreateRoot.html
File metadata and controls
73 lines (62 loc) · 2.53 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
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
</head>
<body>
<main id="webchat"></main>
<script type="importmap">
{
"imports": {
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
"botframework-webchat/hook": "/__dist__/packages/bundle/static/botframework-webchat/hook.js",
"botframework-webchat/middleware": "/__dist__/packages/bundle/static/botframework-webchat/middleware.js",
"react": "https://cdn.jsdelivr.net/npm/react@18.3.1/+esm",
"react-dom": "https://cdn.jsdelivr.net/npm/react-dom@18.3.1/+esm",
"react-dom/client": "https://cdn.jsdelivr.net/npm/react-dom@18.3.1/client/+esm"
}
}
</script>
<script type="module">
import '/test-harness.mjs';
import '/test-page-object.mjs';
import { createDirectLine, createStoreWithOptions, hooks, ReactWebChat } from 'botframework-webchat';
import { useStyleOptions } from 'botframework-webchat/hook';
import { activityComponent, createActivityPolymiddleware } from 'botframework-webchat/middleware';
import { createElement } from 'react';
import { createRoot } from 'react-dom/client';
const {
testHelpers: { createDirectLineEmulator }
} = window;
// TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
window.WebChat = { createStoreWithOptions };
run(async function () {
const { directLine, store } = createDirectLineEmulator();
function MyMiddleware({ nextResult }) {
// THEN: Web Chat hooks can be called.
const [{ accent }] = useStyleOptions();
return createElement(
'div',
{ style: { borderColor: accent, borderStyle: 'solid', borderWidth: 2 } },
nextResult?.render({})
);
}
createRoot(document.getElementsByTagName('main')[0]).render(
createElement(ReactWebChat, {
directLine,
polymiddleware: [
createActivityPolymiddleware(
next => request => activityComponent(MyMiddleware, { nextResult: next(request) })
)
],
store
})
);
await pageConditions.uiConnected();
await directLine.emulateIncomingActivity('Hello, World!');
await pageConditions.numActivitiesShown(1);
await host.snapshot('local');
});
</script>
</body>
</html>