|
| 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> |
| 11 | + const { searchParams } = new URL(location.href); |
| 12 | + const variant = searchParams.get('variant') || 'minimal'; |
| 13 | + |
| 14 | + function loadScript(src) { |
| 15 | + return new Promise((resolve, reject) => { |
| 16 | + const scriptElement = document.createElement('script'); |
| 17 | + |
| 18 | + scriptElement.setAttribute('crossorigin', 'anonymous'); |
| 19 | + scriptElement.setAttribute('src', src); |
| 20 | + |
| 21 | + scriptElement.addEventListener('error', reject); |
| 22 | + scriptElement.addEventListener('load', resolve); |
| 23 | + |
| 24 | + document.head.append(scriptElement); |
| 25 | + }); |
| 26 | + } |
| 27 | + |
| 28 | + run(async function () { |
| 29 | + const bundleName = |
| 30 | + variant === 'full' ? 'webchat.js' : variant === 'full-es5' ? 'webchat-es5.js' : 'webchat-minimal.js'; |
| 31 | + |
| 32 | + await loadScript(`/__dist__/${bundleName}`); |
| 33 | + |
| 34 | + const { WebChat } = window; |
| 35 | + |
| 36 | + // THEN: It should have bits from "core" package. |
| 37 | + expect(WebChat).toHaveProperty('Constants', expect.any(Object)); |
| 38 | + |
| 39 | + // THEN: It should have bits from "api" package. |
| 40 | + expect(WebChat).toHaveProperty('concatMiddleware', expect.any(Function)); |
| 41 | + |
| 42 | + // THEN: It should have bits from "api/decorator" package. |
| 43 | + expect(WebChat).toHaveProperty('decorator', expect.any(Object)); |
| 44 | + expect(WebChat).toHaveProperty('decorator.ActivityGroupingDecorator', expect.any(Object)); |
| 45 | + |
| 46 | + // THEN: It should have bits from "api/middleware" package. |
| 47 | + expect(WebChat).toHaveProperty('middleware', expect.any(Object)); |
| 48 | + expect(WebChat).toHaveProperty('middleware.activityComponent', expect.any(Function)); |
| 49 | + |
| 50 | + // THEN: It should have bits from "component" package. |
| 51 | + expect(WebChat).toHaveProperty('Components', expect.any(Object)); |
| 52 | + expect(WebChat).toHaveProperty('Components.BasicWebChat', expect.any(Object)); |
| 53 | + |
| 54 | + // THEN: It should have bits from "component/decorator" package. |
| 55 | + expect(WebChat).toHaveProperty('decorator.BorderFlair', expect.any(Object)); |
| 56 | + |
| 57 | + // THEN: It should have bits from "bundle/minimal" package. |
| 58 | + expect(WebChat).toHaveProperty('createBrowserWebSpeechPonyfillFactory', expect.any(Function)); |
| 59 | + |
| 60 | + if (variant === 'full' || variant === 'full-es5') { |
| 61 | + // THEN: It should have bits from "bundle/full" package. |
| 62 | + expect(WebChat).toHaveProperty('Components.AdaptiveCardContent', expect.any(Object)); |
| 63 | + } else { |
| 64 | + // THEN: It should not have bits from "bundle/full" package. |
| 65 | + expect(WebChat.Components.AdaptiveCardContent).toBeUndefined(); |
| 66 | + } |
| 67 | + |
| 68 | + // THEN: `buildInfo.moduleFromat` should be "global". |
| 69 | + expect(WebChat).toHaveProperty('buildInfo.moduleFormat', 'global'); // Bundle |
| 70 | + |
| 71 | + // THEN: `buildInfo.variant` should match. |
| 72 | + expect(WebChat).toHaveProperty('buildInfo.variant', variant); |
| 73 | + }); |
| 74 | + </script> |
| 75 | + </body> |
| 76 | +</html> |
0 commit comments