|
| 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 snapshot shows the copy sent to screen readers. --> |
| 6 | + <link href="/assets/accessibility.liveRegionAttachment.css" rel="stylesheet" type="text/css" /> |
| 7 | + <script crossorigin="anonymous" src="/test-harness.js"></script> |
| 8 | + <script crossorigin="anonymous" src="/test-page-object.js"></script> |
| 9 | + <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> |
| 10 | + </head> |
| 11 | + <body> |
| 12 | + <main id="webchat"></main> |
| 13 | + <script type="importmap"> |
| 14 | + { |
| 15 | + "imports": { |
| 16 | + "@testduet/wait-for": "https://esm.sh/@testduet/wait-for" |
| 17 | + } |
| 18 | + } |
| 19 | + </script> |
| 20 | + <script type="module"> |
| 21 | + import { waitFor } from '@testduet/wait-for'; |
| 22 | + |
| 23 | + run(async function () { |
| 24 | + const { directLine, store } = testHelpers.createDirectLineEmulator(); |
| 25 | + |
| 26 | + // GIVEN: Web Chat keeps the live region copy of new messages, so it can be seen in the snapshot. |
| 27 | + WebChat.renderWebChat( |
| 28 | + { directLine, store, styleOptions: { hideSendBox: true, internalLiveRegionFadeAfter: 60000 } }, |
| 29 | + document.getElementById('webchat') |
| 30 | + ); |
| 31 | + |
| 32 | + await pageConditions.uiConnected(); |
| 33 | + |
| 34 | + // WHEN: Bot sends 2 Adaptive Cards without "speak", so the card has no label: one without inputs and one with inputs. |
| 35 | + await directLine.emulateIncomingActivity({ |
| 36 | + attachments: [ |
| 37 | + { |
| 38 | + content: { |
| 39 | + $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', |
| 40 | + body: [{ text: 'Sunny, 21°C', type: 'TextBlock' }], |
| 41 | + type: 'AdaptiveCard', |
| 42 | + version: '1.5' |
| 43 | + }, |
| 44 | + contentType: 'application/vnd.microsoft.card.adaptive' |
| 45 | + }, |
| 46 | + { |
| 47 | + content: { |
| 48 | + $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', |
| 49 | + actions: [{ title: 'Submit', type: 'Action.Submit' }], |
| 50 | + body: [ |
| 51 | + { |
| 52 | + id: 'name', |
| 53 | + label: 'What is your full name', |
| 54 | + placeholder: 'For example, John Doe', // The live region copy names inputs by their placeholder until #5913 (by their label). |
| 55 | + type: 'Input.Text' |
| 56 | + } |
| 57 | + ], |
| 58 | + type: 'AdaptiveCard', |
| 59 | + version: '1.5' |
| 60 | + }, |
| 61 | + contentType: 'application/vnd.microsoft.card.adaptive' |
| 62 | + } |
| 63 | + ], |
| 64 | + type: 'message' |
| 65 | + }); |
| 66 | + |
| 67 | + await pageConditions.numActivitiesShown(1); |
| 68 | + await waitFor(() => expect(document.querySelectorAll('.ac-adaptiveCard')).toHaveLength(2)); |
| 69 | + |
| 70 | + const cardElements = Array.from(document.querySelectorAll('.ac-adaptiveCard')); |
| 71 | + |
| 72 | + // THEN: Both cards should have no label. |
| 73 | + expect(cardElements.map(cardElement => cardElement.getAttribute('aria-label'))).toEqual([null, null]); |
| 74 | + |
| 75 | + // THEN: Both cards should have no role, as "figure" and "form" without a name are announced without their content. |
| 76 | + expect(cardElements.map(cardElement => cardElement.getAttribute('role'))).toEqual([null, null]); |
| 77 | + |
| 78 | + const cardRoles = ( |
| 79 | + await Promise.all(cardElements.map(cardElement => testHelpers.getAccessibilityNode(cardElement))) |
| 80 | + ).map(({ role }) => role?.value); |
| 81 | + |
| 82 | + // THEN: Neither card should be a "figure" or a "form" in the accessibility tree. |
| 83 | + // Without a role, Chrome may leave the card out of the accessibility tree (role "none") and expose its content directly. |
| 84 | + expect(cardRoles).not.toContain('figure'); |
| 85 | + expect(cardRoles).not.toContain('form'); |
| 86 | + |
| 87 | + await pageConditions.liveRegionStabilized(); |
| 88 | + |
| 89 | + // THEN: The live region shows what screen readers announce: "Bot said:", "A card:" with the text of each card, then the input and the "Submit" button of the second card. |
| 90 | + await host.snapshot('local'); |
| 91 | + }); |
| 92 | + </script> |
| 93 | + </body> |
| 94 | +</html> |
0 commit comments