|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 5 | + <!-- Shows the live region, so the snapshots show the copy sent to screen readers. --> |
| 6 | + <link href="/assets/accessibility.liveRegionAttachment.css" rel="stylesheet" type="text/css" /> |
| 7 | + </head> |
| 8 | + <body> |
| 9 | + <main id="webchat"></main> |
| 10 | + <script type="importmap"> |
| 11 | + { |
| 12 | + "imports": { |
| 13 | + "@testduet/wait-for": "https://esm.sh/@testduet/wait-for", |
| 14 | + "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", |
| 15 | + "botframework-webchat/": "/__dist__/packages/bundle/static/botframework-webchat/", |
| 16 | + "react": "/__dist__/packages/bundle/static/react.js", |
| 17 | + "react-dom": "/__dist__/packages/bundle/static/react-dom.js", |
| 18 | + "react-dom/client": "/__dist__/packages/bundle/static/react-dom/client.js" |
| 19 | + } |
| 20 | + } |
| 21 | + </script> |
| 22 | + <script type="module"> |
| 23 | + import '/test-harness.mjs'; |
| 24 | + import '/test-page-object.mjs'; |
| 25 | + |
| 26 | + import { waitFor } from '@testduet/wait-for'; |
| 27 | + import { createStoreWithOptions, ReactWebChat } from 'botframework-webchat'; |
| 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 root = createRoot(document.getElementById('webchat')); |
| 37 | + const render = props => |
| 38 | + root.render( |
| 39 | + createElement(ReactWebChat, { |
| 40 | + directLine, |
| 41 | + store, |
| 42 | + // Keeps the live region copy of new messages, so it can be seen in the snapshots. |
| 43 | + styleOptions: { hideSendBox: true, internalLiveRegionFadeAfter: 60000 }, |
| 44 | + ...props |
| 45 | + }) |
| 46 | + ); |
| 47 | + |
| 48 | + // Role descriptions of the message and attachments, per activity. |
| 49 | + // Selects by role, not by the attribute, so an element missing its role description shows up as null. |
| 50 | + const getRoleDescriptions = () => |
| 51 | + pageElements |
| 52 | + .activities() |
| 53 | + .map(activity => |
| 54 | + Array.from(activity.querySelectorAll('[role="group"], [role="listitem"]'), element => |
| 55 | + element.getAttribute('aria-roledescription') |
| 56 | + ) |
| 57 | + ); |
| 58 | + |
| 59 | + // GIVEN: Web Chat in the default locale (en-US). |
| 60 | + render({}); |
| 61 | + |
| 62 | + await pageConditions.uiConnected(); |
| 63 | + |
| 64 | + // GIVEN: A message with text and 2 attachments in each attachment layout. |
| 65 | + for (const attachmentLayout of ['list', 'carousel']) { |
| 66 | + await directLine.emulateIncomingActivity({ |
| 67 | + attachmentLayout, |
| 68 | + attachments: [1, 2].map(index => ({ |
| 69 | + content: { title: `Card ${index} (${attachmentLayout})` }, |
| 70 | + contentType: 'application/vnd.microsoft.card.hero' |
| 71 | + })), |
| 72 | + from: { role: 'bot' }, |
| 73 | + text: `Message with ${attachmentLayout} attachments`, |
| 74 | + type: 'message' |
| 75 | + }); |
| 76 | + } |
| 77 | + |
| 78 | + await pageConditions.numActivitiesShown(2); |
| 79 | + await pageConditions.liveRegionStabilized(); |
| 80 | + |
| 81 | + // THEN: A stacked message, then a carousel message, each with its text and 2 cards. |
| 82 | + // THEN: The live region (top) shows what screen readers announce for each: "Bot said:", the text, and "A card:" per card, without role descriptions. |
| 83 | + await host.snapshot('local'); |
| 84 | + |
| 85 | + // THEN: Message and attachments are described in English. |
| 86 | + expect(getRoleDescriptions()).toEqual([ |
| 87 | + ['message', 'attachment', 'attachment'], |
| 88 | + ['message', 'attachment', 'attachment'] |
| 89 | + ]); |
| 90 | + |
| 91 | + // WHEN: The host switches to German and provides the strings (no translation in de-DE yet). |
| 92 | + render({ |
| 93 | + locale: 'de-DE', |
| 94 | + overrideLocalizedStrings: { |
| 95 | + ACTIVITY_ATTACHMENT_ARIA_ROLE_ALT: 'Anhang', |
| 96 | + ACTIVITY_MESSAGE_ARIA_ROLE_ALT: 'Nachricht' |
| 97 | + } |
| 98 | + }); |
| 99 | + |
| 100 | + // THEN: Message and attachments are described in German. |
| 101 | + await waitFor(() => |
| 102 | + expect(getRoleDescriptions()).toEqual([ |
| 103 | + ['Nachricht', 'Anhang', 'Anhang'], |
| 104 | + ['Nachricht', 'Anhang', 'Anhang'] |
| 105 | + ]) |
| 106 | + ); |
| 107 | + |
| 108 | + // WHEN: The bot sends another message. |
| 109 | + await directLine.emulateIncomingActivity({ |
| 110 | + attachments: [{ content: { title: 'Card 3' }, contentType: 'application/vnd.microsoft.card.hero' }], |
| 111 | + from: { role: 'bot' }, |
| 112 | + text: 'Message after switching to German', |
| 113 | + type: 'message' |
| 114 | + }); |
| 115 | + |
| 116 | + await pageConditions.numActivitiesShown(3); |
| 117 | + await pageConditions.liveRegionStabilized(); |
| 118 | + |
| 119 | + // THEN: The live region shows the new message announced in German ("Bot sagte:", "Eine Karte:", from de-DE); the earlier copies are re-rendered in German too. |
| 120 | + await host.snapshot('local'); |
| 121 | + }); |
| 122 | + </script> |
| 123 | + </body> |
| 124 | +</html> |
0 commit comments