Skip to content

Commit 5ba6a3c

Browse files
committed
Add middleware test for tsx
1 parent 595f8e5 commit 5ba6a3c

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)