|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 5 | + <style> |
| 6 | + /* The host page has a background image and shows it through Web Chat. */ |
| 7 | + body { |
| 8 | + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M0 8L8 0' stroke='%23808080' stroke-width='2'/%3E%3C/svg%3E"); |
| 9 | + } |
| 10 | + |
| 11 | + #webchat { |
| 12 | + background-color: transparent; |
| 13 | + } |
| 14 | + |
| 15 | + .fui-FluentProvider { |
| 16 | + height: 100%; |
| 17 | + } |
| 18 | + </style> |
| 19 | + </head> |
| 20 | + <body> |
| 21 | + <main id="webchat"></main> |
| 22 | + <script type="importmap"> |
| 23 | + { |
| 24 | + "imports": { |
| 25 | + "@fluentui/react-provider": "/__dist__/packages/test/test-assets/out/@fluentui/react-provider.js", |
| 26 | + "@fluentui/tokens": "/__dist__/packages/test/test-assets/out/@fluentui/tokens.js", |
| 27 | + "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", |
| 28 | + "botframework-webchat/": "/__dist__/packages/bundle/static/botframework-webchat/", |
| 29 | + "botframework-webchat-fluent-theme": "/__dist__/packages/fluent-theme/static/botframework-webchat-fluent-theme.js", |
| 30 | + "react": "/__dist__/packages/bundle/static/react.js", |
| 31 | + "react-dom": "/__dist__/packages/bundle/static/react-dom.js", |
| 32 | + "react-dom/client": "/__dist__/packages/bundle/static/react-dom/client.js", |
| 33 | + "react-jsx-runtime": "/__dist__/packages/bundle/static/react/jsx-runtime.js" |
| 34 | + } |
| 35 | + } |
| 36 | + </script> |
| 37 | + <script type="module"> |
| 38 | + import '/test-harness.mjs'; |
| 39 | + import '/test-page-object.mjs'; |
| 40 | + |
| 41 | + import { FluentProvider } from '@fluentui/react-provider'; |
| 42 | + import { webDarkTheme } from '@fluentui/tokens'; |
| 43 | + import { createStoreWithOptions, ReactWebChat } from 'botframework-webchat'; |
| 44 | + import { FluentThemeProvider, testIds } from 'botframework-webchat-fluent-theme'; |
| 45 | + import { createElement } from 'react'; |
| 46 | + import { createRoot } from 'react-dom/client'; |
| 47 | + |
| 48 | + // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. |
| 49 | + window.WebChat = { createStoreWithOptions }; |
| 50 | + |
| 51 | + run(async function () { |
| 52 | + const colorScheme = new URLSearchParams(location.search).get('fluent-theme') === 'dark' ? 'dark' : 'light'; |
| 53 | + |
| 54 | + // GIVEN: A light or dark high contrast theme (such as "Desert" or "Aquatic" on Windows) is active before Web Chat renders. |
| 55 | + await host.sendDevToolsCommand('Emulation.setEmulatedMedia', { |
| 56 | + features: [ |
| 57 | + { name: 'forced-colors', value: 'active' }, |
| 58 | + { name: 'prefers-color-scheme', value: colorScheme }, |
| 59 | + { name: 'prefers-reduced-motion', value: 'reduce' } |
| 60 | + ] |
| 61 | + }); |
| 62 | + |
| 63 | + expect(window.matchMedia(`(forced-colors: active) and (prefers-color-scheme: ${colorScheme})`).matches).toBe( |
| 64 | + true |
| 65 | + ); |
| 66 | + |
| 67 | + const { directLine, store } = testHelpers.createDirectLineEmulator(); |
| 68 | + |
| 69 | + const webChatElement = createElement( |
| 70 | + FluentThemeProvider, |
| 71 | + { variant: 'fluent' }, |
| 72 | + createElement(ReactWebChat, { directLine, store }) |
| 73 | + ); |
| 74 | + |
| 75 | + // GIVEN: With a dark color scheme, the page uses the dark Fluent UI theme. |
| 76 | + createRoot(document.getElementById('webchat')).render( |
| 77 | + colorScheme === 'dark' |
| 78 | + ? createElement( |
| 79 | + FluentProvider, |
| 80 | + { style: { backgroundColor: 'transparent' }, theme: webDarkTheme }, // Also shows the background image. |
| 81 | + webChatElement |
| 82 | + ) |
| 83 | + : webChatElement |
| 84 | + ); |
| 85 | + |
| 86 | + await pageConditions.uiConnected(); |
| 87 | + |
| 88 | + // WHEN: The bot sends a message with 2 suggested actions. |
| 89 | + await directLine.emulateIncomingActivity({ |
| 90 | + suggestedActions: { |
| 91 | + actions: [ |
| 92 | + { title: 'Checklist', type: 'imBack', value: 'Checklist' }, |
| 93 | + { title: 'Benefits overview', type: 'imBack', value: 'Benefits overview' } |
| 94 | + ], |
| 95 | + to: [] |
| 96 | + }, |
| 97 | + text: 'What would you like to do next?', |
| 98 | + type: 'message' |
| 99 | + }); |
| 100 | + |
| 101 | + await pageConditions.numActivitiesShown(1); |
| 102 | + |
| 103 | + // THEN: Both suggested actions should be shown. |
| 104 | + await expect( |
| 105 | + Promise.all( |
| 106 | + Array.from(document.querySelectorAll(`[data-testid="${testIds.sendBoxSuggestedAction}"]`)).map(element => |
| 107 | + testHelpers.getAccessibleName(element) |
| 108 | + ) |
| 109 | + ) |
| 110 | + ).resolves.toEqual(['Checklist', 'Benefits overview']); |
| 111 | + |
| 112 | + // THEN: Both suggested actions should have a solid button background, the background image should not show through them. |
| 113 | + await host.snapshot('local'); |
| 114 | + }); |
| 115 | + </script> |
| 116 | + </body> |
| 117 | +</html> |
0 commit comments