|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 5 | + <script> |
| 6 | + const warn = console.warn.bind(console); |
| 7 | + |
| 8 | + // We need to fake the mock ourselves without using jest-mock. |
| 9 | + // jest-mock is ESM and cannot mock before Web Chat. |
| 10 | + console.warn = (...args) => { |
| 11 | + console.warn.mock.calls.push(args); |
| 12 | + |
| 13 | + warn(...args); |
| 14 | + }; |
| 15 | + |
| 16 | + console.warn._isMockFunction = true; |
| 17 | + console.warn.getMockName = () => 'warn'; |
| 18 | + console.warn.mock = { calls: [] }; |
| 19 | + </script> |
| 20 | + <script type="importmap"> |
| 21 | + { |
| 22 | + "imports": { |
| 23 | + "jest-mock": "https://esm.sh/jest-mock", |
| 24 | + "react": "https://esm.sh/react@18.3.1", |
| 25 | + "react-dom": "https://esm.sh/react-dom@18.3.1", |
| 26 | + "react-dom/": "https://esm.sh/react-dom@18.3.1/" |
| 27 | + } |
| 28 | + } |
| 29 | + </script> |
| 30 | + <script crossorigin="anonymous" src="/test-harness.js"></script> |
| 31 | + <script crossorigin="anonymous" src="/test-page-object.js"></script> |
| 32 | + <script type="module"> |
| 33 | + import React from 'react'; |
| 34 | + window.React = React; |
| 35 | + </script> |
| 36 | + <script crossorigin="anonymous" defer src="/__dist__/webchat-es5.js"></script> |
| 37 | + <script crossorigin="anonymous" defer src="/__dist__/botframework-webchat-debug-theme.development.js"></script> |
| 38 | + <style type="text/css"> |
| 39 | + .webchat > .error-box { |
| 40 | + border: solid 1px red; |
| 41 | + } |
| 42 | + </style> |
| 43 | + </head> |
| 44 | + <body> |
| 45 | + <main id="webchat"></main> |
| 46 | + <script type="module"> |
| 47 | + import { fn, spyOn } from 'jest-mock'; |
| 48 | + import { createElement, Fragment, memo } from 'react'; |
| 49 | + import { createRoot } from 'react-dom/client'; |
| 50 | + |
| 51 | + run(async function () { |
| 52 | + const { |
| 53 | + testHelpers: { createDirectLineEmulator }, |
| 54 | + WebChat: { |
| 55 | + Components: { Composer, ThemeProvider }, |
| 56 | + DebugProvider, |
| 57 | + middleware: { ErrorBoxPolymiddlewareProxy }, |
| 58 | + ReactWebChat |
| 59 | + } |
| 60 | + } = window; |
| 61 | + |
| 62 | + const { directLine, store } = createDirectLineEmulator(); |
| 63 | + |
| 64 | + const SystemUnderTest = () => |
| 65 | + createElement( |
| 66 | + 'div', |
| 67 | + { className: 'error-box' }, |
| 68 | + createElement(ErrorBoxPolymiddlewareProxy, { error: new Error('Hello, World!'), where: 'Artificial' }) |
| 69 | + ); |
| 70 | + |
| 71 | + const hasDebugProvider = !new URL(location.href).searchParams.has('no-debug-provider'); |
| 72 | + const onTelemetry = fn(); |
| 73 | + |
| 74 | + createRoot(document.getElementById('webchat')).render( |
| 75 | + createElement( |
| 76 | + hasDebugProvider ? DebugProvider : Fragment, |
| 77 | + {}, |
| 78 | + createElement( |
| 79 | + Composer, |
| 80 | + { |
| 81 | + directLine, |
| 82 | + onTelemetry, |
| 83 | + store |
| 84 | + }, |
| 85 | + createElement(SystemUnderTest) |
| 86 | + ) |
| 87 | + ) |
| 88 | + ); |
| 89 | + |
| 90 | + await pageConditions.uiConnected(); |
| 91 | + |
| 92 | + // THEN: Should emit as exception event. |
| 93 | + const exceptionEvent = onTelemetry.mock.calls.find(call => call[0]?.type === 'exception'); |
| 94 | + |
| 95 | + expect(exceptionEvent).toBeTruthy(); |
| 96 | + expect(exceptionEvent[0].error.message).toBe('Hello, World!'); |
| 97 | + |
| 98 | + // THEN: Should render a red box with DebugProvider. |
| 99 | + await host.snapshot('local'); |
| 100 | + |
| 101 | + // THEN: Should not warn with RCoR fallthrough. |
| 102 | + expect(console.warn).not.toHaveBeenCalledWith( |
| 103 | + expect.stringContaining('the request has fall through all middleware, set "fallbackComponent" as a catchall'), |
| 104 | + expect.anything() |
| 105 | + ); |
| 106 | + }); |
| 107 | + </script> |
| 108 | + </body> |
| 109 | +</html> |
0 commit comments