|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 5 | + <script type="importmap"> |
| 6 | + { |
| 7 | + "imports": { |
| 8 | + "react": "https://esm.sh/react@18.3.1" |
| 9 | + } |
| 10 | + } |
| 11 | + </script> |
| 12 | + <script crossorigin="anonymous" src="/test-harness.js"></script> |
| 13 | + <script crossorigin="anonymous" src="/test-page-object.js"></script> |
| 14 | + <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> |
| 15 | + <!-- <script crossorigin="anonymous" src="https://unpkg.com/botframework-webchat@main/dist/webchat-es5.js"></script> --> |
| 16 | + </head> |
| 17 | + |
| 18 | + <body> |
| 19 | + <main id="webchat"></main> |
| 20 | + <script type="module"> |
| 21 | + import { createElement } from 'react'; |
| 22 | + |
| 23 | + run(async function () { |
| 24 | + const { |
| 25 | + testHelpers: { createDirectLineEmulator } |
| 26 | + } = window; |
| 27 | + |
| 28 | + const { directLine, store } = createDirectLineEmulator(); |
| 29 | + |
| 30 | + const activityMiddleware = [ |
| 31 | + () => next => request => next(request), |
| 32 | + () => next => request => { |
| 33 | + const render = next(request); |
| 34 | + |
| 35 | + if (!request.activity.entities) { |
| 36 | + return render; |
| 37 | + } |
| 38 | + |
| 39 | + expect(request.activity).toEqual( |
| 40 | + expect.objectContaining({ |
| 41 | + text: 'Do you like my response?', |
| 42 | + type: 'message' |
| 43 | + }) |
| 44 | + ); |
| 45 | + |
| 46 | + return (renderAttachment, options) => { |
| 47 | + // TODO: Test every of the following deeply to make sure they are working as expected. |
| 48 | + expect(typeof renderAttachment).toBe('function'); |
| 49 | + expect(options.hideTimestamp).toEqual(false); |
| 50 | + expect(typeof options.renderActivityStatus).toBe('function'); |
| 51 | + expect(options.renderAvatar).toBe(false); |
| 52 | + expect(options.showCallout).toEqual(false); |
| 53 | + |
| 54 | + return createElement('div', { style: { border: 'solid 2px red' } }, render(renderAttachment, options)); |
| 55 | + }; |
| 56 | + } |
| 57 | + ]; |
| 58 | + |
| 59 | + WebChat.renderWebChat( |
| 60 | + { |
| 61 | + activityMiddleware, |
| 62 | + directLine, |
| 63 | + store |
| 64 | + }, |
| 65 | + document.getElementById('webchat') |
| 66 | + ); |
| 67 | + |
| 68 | + await pageConditions.uiConnected(); |
| 69 | + |
| 70 | + await directLine.emulateIncomingActivity({ |
| 71 | + text: 'This is the solution.\n\n\\[x - 1 = 0\\]\n\n\\[x = 1\\]', |
| 72 | + type: 'message' |
| 73 | + }); |
| 74 | + |
| 75 | + await directLine.emulateIncomingActivity({ |
| 76 | + entities: [ |
| 77 | + { |
| 78 | + '@id': '', |
| 79 | + '@type': 'Message', |
| 80 | + additionalType: 'Feedback' |
| 81 | + } |
| 82 | + ], |
| 83 | + text: 'Do you like my response?', |
| 84 | + type: 'message' |
| 85 | + }); |
| 86 | + }); |
| 87 | + </script> |
| 88 | + </body> |
| 89 | +</html> |
0 commit comments