|
| 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 | + "react": "/__dist__/packages/bundle/static/react.js", |
| 13 | + "react-dom": "/__dist__/packages/bundle/static/react-dom.js" |
| 14 | + } |
| 15 | + } |
| 16 | + </script> |
| 17 | + <script type="module"> |
| 18 | + import '/test-harness.mjs'; |
| 19 | + import '/test-page-object.mjs'; |
| 20 | + |
| 21 | + import { createStoreWithOptions, renderWebChat, testIds } from 'botframework-webchat'; |
| 22 | + import { fn, spyOn } from 'https://esm.sh/jest-mock'; |
| 23 | + import { waitFor } from 'https://esm.sh/@testduet/wait-for'; |
| 24 | + |
| 25 | + const { |
| 26 | + testHelpers: { createDirectLineEmulator } |
| 27 | + } = window; |
| 28 | + |
| 29 | + testHelpers.hideKnownError(); |
| 30 | + |
| 31 | + // TODO: Should find ways to eliminate this line. |
| 32 | + window.WebChat = { createStoreWithOptions, testIds }; |
| 33 | + |
| 34 | + run(async function () { |
| 35 | + const { directLine, store } = createDirectLineEmulator(); |
| 36 | + |
| 37 | + renderWebChat({ directLine, role: 'complementary', store }, document.getElementById('webchat')); |
| 38 | + |
| 39 | + await pageConditions.uiConnected(); |
| 40 | + |
| 41 | + const rootElement = document.querySelector('#webchat > *'); |
| 42 | + |
| 43 | + // THEN: Make sure we are exposing the public version. |
| 44 | + expect('breakpoint' in rootElement.webChat).toBe(true); |
| 45 | + expect('debugger' in rootElement.webChat).toBe(true); |
| 46 | + |
| 47 | + // THEN: Make sure we are not exposing the private version. |
| 48 | + expect('~types' in rootElement.webChat).toBe(false); |
| 49 | + expect('toPublic' in rootElement.webChat).toBe(false); |
| 50 | + expect('UNSAFE_callBreakpoint' in rootElement.webChat).toBe(false); |
| 51 | + expect('UNSAFE_extendsDebugContextOnce' in rootElement.webChat).toBe(false); |
| 52 | + |
| 53 | + spyOn(rootElement.webChat.breakpoint, 'incomingActivity'); |
| 54 | + |
| 55 | + await directLine.emulateIncomingActivity('Hello, World!'); |
| 56 | + |
| 57 | + expect(rootElement.webChat.breakpoint.incomingActivity).toHaveBeenCalledTimes(1); |
| 58 | + |
| 59 | + expect(rootElement.webChat.breakpoint.incomingActivity).toHaveBeenNthCalledWith( |
| 60 | + 1, |
| 61 | + { |
| 62 | + activities: [ |
| 63 | + { |
| 64 | + channelData: { |
| 65 | + 'webchat:internal:received-at': expect.any(Number), |
| 66 | + 'webchat:internal:local-id': expect.any(String), |
| 67 | + 'webchat:internal:position': 1000 |
| 68 | + }, |
| 69 | + from: { |
| 70 | + id: 'bot', |
| 71 | + role: 'bot' |
| 72 | + }, |
| 73 | + id: expect.any(String), |
| 74 | + text: 'Hello, World!', |
| 75 | + timestamp: expect.any(String), |
| 76 | + type: 'message' |
| 77 | + } |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + activity: { |
| 82 | + channelData: { |
| 83 | + 'webchat:internal:received-at': expect.any(Number), |
| 84 | + 'webchat:internal:local-id': expect.any(String) |
| 85 | + }, |
| 86 | + from: { |
| 87 | + id: 'bot', |
| 88 | + role: 'bot' |
| 89 | + }, |
| 90 | + id: expect.any(String), |
| 91 | + text: 'Hello, World!', |
| 92 | + timestamp: expect.any(String), |
| 93 | + type: 'message' |
| 94 | + } |
| 95 | + } |
| 96 | + ); |
| 97 | + |
| 98 | + rootElement.webChat.breakpoint.incomingActivity.mockRestore(); |
| 99 | + }); |
| 100 | + </script> |
| 101 | + </body> |
| 102 | +</html> |
0 commit comments