|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 5 | + </head> |
| 6 | + <body> |
| 7 | + <main id="webchat"></main> |
| 8 | + <script type="importmap"> |
| 9 | + { |
| 10 | + "imports": { |
| 11 | + "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", |
| 12 | + "botframework-webchat/middleware": "/__dist__/packages/bundle/static/botframework-webchat/middleware.js", |
| 13 | + "react": "/__dist__/packages/bundle/static/react.js", |
| 14 | + "react-dom": "/__dist__/packages/bundle/static/react-dom.js" |
| 15 | + } |
| 16 | + } |
| 17 | + </script> |
| 18 | + <script type="module"> |
| 19 | + import '/test-harness.mjs'; |
| 20 | + import '/test-page-object.mjs'; |
| 21 | + |
| 22 | + import { createStoreWithOptions, renderWebChat, testIds } from 'botframework-webchat'; |
| 23 | + import { avatarComponent, createAvatarPolymiddleware } from 'botframework-webchat/middleware'; |
| 24 | + import { createElement } from 'react'; |
| 25 | + |
| 26 | + const { |
| 27 | + testHelpers: { createDirectLineEmulator } |
| 28 | + } = window; |
| 29 | + |
| 30 | + testHelpers.hideKnownError(); |
| 31 | + |
| 32 | + // TODO: Should find ways to eliminate this line. |
| 33 | + window.WebChat = { createStoreWithOptions, testIds }; |
| 34 | + |
| 35 | + run(async function () { |
| 36 | + const { directLine, store } = createDirectLineEmulator(); |
| 37 | + |
| 38 | + const MiddlewareAvatar = ({ activity, children, fromUser }) => |
| 39 | + createElement( |
| 40 | + 'div', |
| 41 | + { |
| 42 | + style: { |
| 43 | + borderRadius: 40, |
| 44 | + height: 40, |
| 45 | + outlineColor: 'green', |
| 46 | + outlineOffset: 2, |
| 47 | + outlineStyle: fromUser ? 'dotted' : 'dashed', |
| 48 | + outlineWidth: 2, |
| 49 | + overflow: 'hidden', |
| 50 | + width: 40 |
| 51 | + } |
| 52 | + }, |
| 53 | + children |
| 54 | + ); |
| 55 | + |
| 56 | + function render(withMiddleware) { |
| 57 | + renderWebChat( |
| 58 | + { |
| 59 | + avatarMiddleware: withMiddleware |
| 60 | + ? [ |
| 61 | + () => next => request => { |
| 62 | + const children = next(request); |
| 63 | + |
| 64 | + expect(Object.getOwnPropertyNames(request)).toEqual(['activity', 'fromUser', 'styleOptions']); |
| 65 | + expect(request.styleOptions).toHaveProperty('botAvatarInitials', 'WC'); |
| 66 | + |
| 67 | + return (...args) => |
| 68 | + createElement( |
| 69 | + MiddlewareAvatar, |
| 70 | + { activity: request.activity, fromUser: request.fromUser }, |
| 71 | + children(...args) |
| 72 | + ); |
| 73 | + } |
| 74 | + ] |
| 75 | + : undefined, |
| 76 | + directLine, |
| 77 | + store, |
| 78 | + styleOptions: { |
| 79 | + botAvatarImage: '/assets/bot-avatar.jpg', |
| 80 | + botAvatarInitials: 'WC', |
| 81 | + userAvatarImage: '/assets/user-avatar.jpg', |
| 82 | + userAvatarInitials: 'WW' |
| 83 | + } |
| 84 | + }, |
| 85 | + document.getElementById('webchat') |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + render(false); |
| 90 | + |
| 91 | + await pageConditions.uiConnected(); |
| 92 | + |
| 93 | + await directLine.emulateIncomingActivity({ |
| 94 | + from: { role: 'bot' }, |
| 95 | + id: 'a-00001', |
| 96 | + text: 'Hello, World!', |
| 97 | + type: 'message' |
| 98 | + }); |
| 99 | + |
| 100 | + await directLine.emulateIncomingActivity({ |
| 101 | + from: { role: 'user' }, |
| 102 | + id: 'a-00002', |
| 103 | + text: 'Aloha!', |
| 104 | + type: 'message' |
| 105 | + }); |
| 106 | + |
| 107 | + // THEN: Should show an image with a green outside border with a red inside border. |
| 108 | + // Legacy middleware has higher priority than polymiddleware. |
| 109 | + await host.snapshot('local'); |
| 110 | + |
| 111 | + render(true); |
| 112 | + |
| 113 | + await host.snapshot('local'); |
| 114 | + }); |
| 115 | + </script> |
| 116 | + </body> |
| 117 | +</html> |
0 commit comments