Skip to content

Commit 95b0c26

Browse files
committed
Add test for createRoot
1 parent ab927c7 commit 95b0c26

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
</head>
8+
<body>
9+
<main id="webchat"></main>
10+
<script type="importmap">
11+
{
12+
"imports": {
13+
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
14+
"botframework-webchat/middleware": "/__dist__/packages/bundle/static/botframework-webchat.middleware.js",
15+
"react": "https://esm.sh/react@18",
16+
"react-dom": "https://esm.sh/react-dom@18",
17+
"react-dom/": "https://esm.sh/react-dom@18/"
18+
}
19+
}
20+
</script>
21+
<script type="module">
22+
import { createDirectLine, createStoreWithOptions, hooks, ReactWebChat } from 'botframework-webchat';
23+
import { activityComponent, createActivityPolymiddleware } from 'botframework-webchat/middleware';
24+
import { createElement } from 'react';
25+
import { createRoot } from 'react-dom';
26+
27+
const { useStyleOptions } = hooks;
28+
const {
29+
testHelpers: { createDirectLineEmulator }
30+
} = window;
31+
32+
// TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
33+
window.WebChat = { createStoreWithOptions };
34+
35+
run(async function () {
36+
const { directLine, store } = createDirectLineEmulator();
37+
38+
function MyMiddleware({ nextResult }) {
39+
// THEN: Web Chat hooks can be called.
40+
const [{ accent }] = useStyleOptions();
41+
42+
return createElement(
43+
'div',
44+
{ style: { borderColor: accent, borderStyle: 'solid', borderWidth: 2 } },
45+
nextResult?.render({})
46+
);
47+
}
48+
49+
createRoot(document.getElementsByTagName('main')[0]).render(
50+
createElement(ReactWebChat, {
51+
directLine,
52+
polymiddleware: [
53+
createActivityPolymiddleware(
54+
next => request => activityComponent(MyMiddleware, { nextResult: next(request) })
55+
)
56+
],
57+
store
58+
})
59+
);
60+
61+
await pageConditions.uiConnected();
62+
63+
await directLine.emulateIncomingActivity('Hello, World!');
64+
65+
await pageConditions.numActivitiesShown(1);
66+
67+
await host.snapshot('local');
68+
});
69+
</script>
70+
</body>
71+
</html>
8.73 KB
Loading

0 commit comments

Comments
 (0)