|
| 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 | + "@testduet/wait-for": "https://esm.sh/@testduet/wait-for", |
| 12 | + "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", |
| 13 | + "botframework-webchat/": "/__dist__/packages/bundle/static/botframework-webchat/", |
| 14 | + "botframework-webchat-fluent-theme": "/__dist__/packages/fluent-theme/static/botframework-webchat-fluent-theme.js", |
| 15 | + "react": "/__dist__/packages/bundle/static/react.js", |
| 16 | + "react-dom": "/__dist__/packages/bundle/static/react-dom.js", |
| 17 | + "react-dom/client": "/__dist__/packages/bundle/static/react-dom/client.js" |
| 18 | + } |
| 19 | + } |
| 20 | + </script> |
| 21 | + <script type="module"> |
| 22 | + import '/test-harness.mjs'; |
| 23 | + import '/test-page-object.mjs'; |
| 24 | + |
| 25 | + import { waitFor } from '@testduet/wait-for'; |
| 26 | + import { createStoreWithOptions, ReactWebChat } from 'botframework-webchat'; |
| 27 | + import { FluentThemeProvider } from 'botframework-webchat-fluent-theme'; |
| 28 | + import { createElement } from 'react'; |
| 29 | + import { createRoot } from 'react-dom/client'; |
| 30 | + |
| 31 | + // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. |
| 32 | + window.WebChat = { createStoreWithOptions }; |
| 33 | + |
| 34 | + run(async function () { |
| 35 | + const { directLine, store } = testHelpers.createDirectLineEmulator(); |
| 36 | + const variant = new URLSearchParams(location.search).get('variant'); |
| 37 | + const webChatElement = createElement(ReactWebChat, { directLine, store }); |
| 38 | + |
| 39 | + createRoot(document.getElementById('webchat')).render( |
| 40 | + variant ? createElement(FluentThemeProvider, { variant }, webChatElement) : webChatElement |
| 41 | + ); |
| 42 | + |
| 43 | + await pageConditions.uiConnected(); |
| 44 | + |
| 45 | + await directLine.emulateIncomingActivity({ |
| 46 | + attachmentLayout: 'carousel', |
| 47 | + attachments: [1, 2, 3, 4].map(index => ({ |
| 48 | + content: { |
| 49 | + buttons: [{ title: `Buy item ${index}`, type: 'imBack', value: `Buy item ${index}` }], |
| 50 | + subtitle: 'This is the subtitle', |
| 51 | + text: 'Price: $XXX.XX USD', |
| 52 | + title: `Details about item ${index}` |
| 53 | + }, |
| 54 | + contentType: 'application/vnd.microsoft.card.hero' |
| 55 | + })), |
| 56 | + from: { role: 'bot' }, |
| 57 | + type: 'message' |
| 58 | + }); |
| 59 | + |
| 60 | + await pageConditions.numActivitiesShown(1); |
| 61 | + |
| 62 | + const nextFlipper = document.querySelector('.carousel-layout button[aria-label="Next"]'); |
| 63 | + const previousFlipper = document.querySelector('.carousel-layout button[aria-label="Previous"]'); |
| 64 | + |
| 65 | + const getFocusIndicatorStyle = flipper => { |
| 66 | + const { boxShadow, outlineColor, outlineOffset, outlineStyle, outlineWidth } = getComputedStyle( |
| 67 | + flipper.querySelector('.react-film__flipper__body') |
| 68 | + ); |
| 69 | + |
| 70 | + return { boxShadow, outlineColor, outlineOffset, outlineStyle, outlineWidth }; |
| 71 | + }; |
| 72 | + |
| 73 | + // The flipper is shown when its body has slid into the center of the flipper button. |
| 74 | + const getFlipperBodyOffset = flipper => { |
| 75 | + const bodyRect = flipper.querySelector('.react-film__flipper__body').getBoundingClientRect(); |
| 76 | + const buttonRect = flipper.getBoundingClientRect(); |
| 77 | + |
| 78 | + return Math.round(bodyRect.left + bodyRect.width / 2 - (buttonRect.left + buttonRect.width / 2)); |
| 79 | + }; |
| 80 | + |
| 81 | + // Two-tone focus indicator: an outer ring in the transcript keyboard indicator color (black, 2px), |
| 82 | + // separated from the flipper by a band in the flipper foreground color (white, 2px). |
| 83 | + // It has at least 3:1 contrast against the flipper and against any content behind it. |
| 84 | + const visibleFocusIndicatorStyle = { |
| 85 | + boxShadow: 'rgb(255, 255, 255) 0px 0px 0px 2px', |
| 86 | + outlineColor: 'rgb(0, 0, 0)', |
| 87 | + outlineOffset: '2px', |
| 88 | + outlineStyle: 'solid', |
| 89 | + outlineWidth: '2px' |
| 90 | + }; |
| 91 | + |
| 92 | + // GIVEN: The carousel is scrolled to the start, the "Previous" flipper is hidden. |
| 93 | + expect(document.querySelector('.carousel-filmstrip').scrollLeft).toBe(0); |
| 94 | + expect(previousFlipper.querySelector('.react-film__main__slider--hide')).toBeTruthy(); |
| 95 | + |
| 96 | + // WHEN: Focus on the first attachment of the carousel via keyboard. |
| 97 | + pageObjects.focusTranscript(); |
| 98 | + await host.sendKeys('ENTER'); |
| 99 | + |
| 100 | + // WHEN: Press SHIFT-TAB to move focus to the "Next" flipper. |
| 101 | + await host.sendShiftTab(); |
| 102 | + |
| 103 | + // THEN: The "Next" flipper should be shown with a visible focus indicator. |
| 104 | + expect(document.activeElement).toBe(nextFlipper); |
| 105 | + expect(nextFlipper.matches(':focus-visible')).toBe(true); |
| 106 | + await waitFor(() => expect(getFlipperBodyOffset(nextFlipper)).toBe(0)); |
| 107 | + expect(getFocusIndicatorStyle(nextFlipper)).toEqual(visibleFocusIndicatorStyle); |
| 108 | + |
| 109 | + await host.snapshot('local'); |
| 110 | + |
| 111 | + // WHEN: Press SHIFT-TAB to move focus to the "Previous" flipper. |
| 112 | + await host.sendShiftTab(); |
| 113 | + |
| 114 | + // THEN: The "Previous" flipper should be shown with a visible focus indicator, although the carousel cannot scroll back. |
| 115 | + expect(document.activeElement).toBe(previousFlipper); |
| 116 | + expect(previousFlipper.matches(':focus-visible')).toBe(true); |
| 117 | + await waitFor(() => expect(getFlipperBodyOffset(previousFlipper)).toBe(0)); |
| 118 | + expect(getFocusIndicatorStyle(previousFlipper)).toEqual(visibleFocusIndicatorStyle); |
| 119 | + |
| 120 | + // THEN: The "Next" flipper should not show the focus indicator after losing focus. |
| 121 | + expect(getFocusIndicatorStyle(nextFlipper)).toHaveProperty('outlineStyle', 'none'); |
| 122 | + |
| 123 | + // THEN: The "Next" flipper should auto-hide after losing focus (1s delay, then 300ms slide out). |
| 124 | + await waitFor(() => expect(getFlipperBodyOffset(nextFlipper)).toBe(50), { timeout: 2000 }); |
| 125 | + |
| 126 | + await host.snapshot('local'); |
| 127 | + }); |
| 128 | + </script> |
| 129 | + </body> |
| 130 | +</html> |
0 commit comments