|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 5 | + <style> |
| 6 | + .fui-FluentProvider { |
| 7 | + height: 100%; |
| 8 | + } |
| 9 | + </style> |
| 10 | + </head> |
| 11 | + <body> |
| 12 | + <main id="webchat"></main> |
| 13 | + <script type="importmap"> |
| 14 | + { |
| 15 | + "imports": { |
| 16 | + "@fluentui/react-provider": "/__dist__/packages/test/test-assets/out/@fluentui/react-provider.js", |
| 17 | + "@fluentui/tokens": "/__dist__/packages/test/test-assets/out/@fluentui/tokens.js", |
| 18 | + "@testduet/wait-for": "https://esm.sh/@testduet/wait-for", |
| 19 | + "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", |
| 20 | + "botframework-webchat/": "/__dist__/packages/bundle/static/botframework-webchat/", |
| 21 | + "botframework-webchat-fluent-theme": "/__dist__/packages/fluent-theme/static/botframework-webchat-fluent-theme.js", |
| 22 | + "react": "/__dist__/packages/bundle/static/react.js", |
| 23 | + "react-dom": "/__dist__/packages/bundle/static/react-dom.js", |
| 24 | + "react-dom/client": "/__dist__/packages/bundle/static/react-dom/client.js", |
| 25 | + "react-jsx-runtime": "/__dist__/packages/bundle/static/react/jsx-runtime.js" |
| 26 | + } |
| 27 | + } |
| 28 | + </script> |
| 29 | + <script type="module"> |
| 30 | + import '/test-harness.mjs'; |
| 31 | + import '/test-page-object.mjs'; |
| 32 | + |
| 33 | + import { FluentProvider } from '@fluentui/react-provider'; |
| 34 | + import { webDarkTheme } from '@fluentui/tokens'; |
| 35 | + import { waitFor } from '@testduet/wait-for'; |
| 36 | + import { createStoreWithOptions, ReactWebChat } from 'botframework-webchat'; |
| 37 | + import { FluentThemeProvider, testIds } from 'botframework-webchat-fluent-theme'; |
| 38 | + import { createElement } from 'react'; |
| 39 | + import { createRoot } from 'react-dom/client'; |
| 40 | + |
| 41 | + // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. |
| 42 | + window.WebChat = { createStoreWithOptions }; |
| 43 | + |
| 44 | + run(async function () { |
| 45 | + const colorScheme = new URLSearchParams(location.search).get('fluent-theme') === 'dark' ? 'dark' : 'light'; |
| 46 | + |
| 47 | + // GIVEN: A light or dark high contrast theme (such as "Desert" or "Aquatic" on Windows) is active before Web Chat renders. |
| 48 | + await host.sendDevToolsCommand('Emulation.setEmulatedMedia', { |
| 49 | + features: [ |
| 50 | + { name: 'forced-colors', value: 'active' }, |
| 51 | + { name: 'prefers-color-scheme', value: colorScheme }, |
| 52 | + { name: 'prefers-reduced-motion', value: 'reduce' } |
| 53 | + ] |
| 54 | + }); |
| 55 | + |
| 56 | + expect(window.matchMedia(`(forced-colors: active) and (prefers-color-scheme: ${colorScheme})`).matches).toBe( |
| 57 | + true |
| 58 | + ); |
| 59 | + |
| 60 | + const { directLine, store } = testHelpers.createDirectLineEmulator(); |
| 61 | + |
| 62 | + const webChatElement = createElement( |
| 63 | + FluentThemeProvider, |
| 64 | + { variant: 'fluent' }, |
| 65 | + createElement(ReactWebChat, { directLine, store, styleOptions: { hideTelephoneKeypadButton: false } }) |
| 66 | + ); |
| 67 | + |
| 68 | + // GIVEN: With a dark color scheme, the page uses the dark Fluent UI theme. |
| 69 | + createRoot(document.getElementById('webchat')).render( |
| 70 | + colorScheme === 'dark' |
| 71 | + ? createElement(FluentProvider, { theme: webDarkTheme }, webChatElement) |
| 72 | + : webChatElement |
| 73 | + ); |
| 74 | + |
| 75 | + await pageConditions.uiConnected(); |
| 76 | + |
| 77 | + // WHEN: The bot sends a pre-chat message with a starter prompt with an image. |
| 78 | + await directLine.emulateIncomingActivity({ |
| 79 | + entities: [ |
| 80 | + { |
| 81 | + '@context': 'https://schema.org', |
| 82 | + '@id': '', |
| 83 | + '@type': 'Message', |
| 84 | + author: { |
| 85 | + '@context': 'https://schema.org', |
| 86 | + '@type': 'Person', |
| 87 | + description: 'Select one of the suggestions below to get started.', |
| 88 | + image: '/assets/bot-avatar.jpg', |
| 89 | + name: 'Onboarding Buddy', |
| 90 | + type: 'https://schema.org/Person' |
| 91 | + }, |
| 92 | + keywords: ['PreChatMessage'], |
| 93 | + type: 'https://schema.org/Message' |
| 94 | + } |
| 95 | + ], |
| 96 | + suggestedActions: { |
| 97 | + actions: [ |
| 98 | + { |
| 99 | + image: `data:image/svg+xml;utf8,${encodeURIComponent('<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M2 4.5C2 4.22 2.22 4 2.5 4h11c.28 0 .5.22.5.5s-.22.5-.5.5h-11a.5.5 0 0 1-.5-.5Zm0 5c0-.28.22-.5.5-.5h15c.28 0 .5.22.5.5s-.22.5-.5.5h-15a.5.5 0 0 1-.5-.5Zm.5 4.5a.5.5 0 0 0 0 1h9a.5.5 0 0 0 0-1h-9Z" fill="#707070"/></svg>')}`, |
| 100 | + text: 'Track new hire tasks.', |
| 101 | + title: 'Checklist', |
| 102 | + type: 'messageBack' |
| 103 | + } |
| 104 | + ], |
| 105 | + to: [] |
| 106 | + }, |
| 107 | + type: 'message' |
| 108 | + }); |
| 109 | + |
| 110 | + await pageConditions.numActivitiesShown(1); |
| 111 | + |
| 112 | + // THEN: The send box should show the "Telephone keypad", "Upload file", and "Send" buttons. |
| 113 | + await expect( |
| 114 | + Promise.all( |
| 115 | + [testIds.sendBoxTelephoneKeypadToolbarButton, testIds.sendBoxUploadButton, testIds.sendBoxSendButton].map( |
| 116 | + testId => testHelpers.getAccessibleName(document.querySelector(`[data-testid="${testId}"]`)) |
| 117 | + ) |
| 118 | + ) |
| 119 | + ).resolves.toEqual(['Telephone keypad', 'Upload file', 'Send']); |
| 120 | + |
| 121 | + // THEN: The icons of the starter prompt and of the send box buttons should be visible. |
| 122 | + await host.snapshot('local'); |
| 123 | + |
| 124 | + // WHEN: A file is dragged into the page. |
| 125 | + const dataTransfer = new DataTransfer(); |
| 126 | + |
| 127 | + dataTransfer.items.add(new File(['Hello, World!'], 'hello.txt', { type: 'text/plain' })); |
| 128 | + document.dispatchEvent(new DragEvent('dragenter', { bubbles: true, dataTransfer })); |
| 129 | + |
| 130 | + // THEN: The drop zone should be shown. |
| 131 | + await waitFor(() => |
| 132 | + expect(document.querySelector(`[data-testid="${testIds.sendBoxDropZone}"]`)).toHaveProperty( |
| 133 | + 'textContent', |
| 134 | + 'Drop files' |
| 135 | + ) |
| 136 | + ); |
| 137 | + |
| 138 | + // THEN: The icon of the drop zone should be visible. |
| 139 | + await host.snapshot('local'); |
| 140 | + }); |
| 141 | + </script> |
| 142 | + </body> |
| 143 | +</html> |
0 commit comments