|
| 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 | + { |
| 29 | + directLine, |
| 30 | + store, |
| 31 | + styleOptions: { botAvatarInitials: 'WC', hideSendBox: true, internalLiveRegionFadeAfter: 60000 } |
| 32 | + }, |
| 33 | + document.getElementById('webchat') |
| 34 | + ); |
| 35 | + |
| 36 | + await pageConditions.uiConnected(); |
| 37 | + |
| 38 | + // WHEN: Bot sends a message with an Adaptive Card, a hero card, a file, and a suggested action. |
| 39 | + await directLine.emulateIncomingActivity({ |
| 40 | + attachments: [ |
| 41 | + { |
| 42 | + content: { |
| 43 | + actions: [{ title: 'OK', type: 'Action.Submit' }], |
| 44 | + body: [{ text: 'Card 1', type: 'TextBlock' }], |
| 45 | + speak: 'Card 1', |
| 46 | + type: 'AdaptiveCard', |
| 47 | + version: '1.3' |
| 48 | + }, |
| 49 | + contentType: 'application/vnd.microsoft.card.adaptive' |
| 50 | + }, |
| 51 | + { |
| 52 | + content: { buttons: [{ title: 'Go', type: 'imBack', value: 'go' }], text: 'Hero text', title: 'Card 2' }, |
| 53 | + contentType: 'application/vnd.microsoft.card.hero' |
| 54 | + }, |
| 55 | + { contentType: 'application/octet-stream', name: 'report.zip' } |
| 56 | + ], |
| 57 | + from: { role: 'bot' }, |
| 58 | + suggestedActions: { actions: [{ title: 'Help', type: 'imBack', value: 'help' }] }, |
| 59 | + text: 'Here are 2 cards and a file.', |
| 60 | + type: 'message' |
| 61 | + }); |
| 62 | + |
| 63 | + await pageConditions.numActivitiesShown(1); |
| 64 | + |
| 65 | + const liveRegionActivity = await waitFor(() => { |
| 66 | + const element = pageElements.liveRegion().querySelector('.webchat__live-region-activity'); |
| 67 | + |
| 68 | + expect(element).toBeTruthy(); |
| 69 | + |
| 70 | + return element; |
| 71 | + }); |
| 72 | + |
| 73 | + // THEN: The live region should contain the text of the message, the suggested action, the cards, and the file. |
| 74 | + expect(liveRegionActivity.innerText).toBe( |
| 75 | + [ |
| 76 | + 'Bot WC said:', |
| 77 | + 'Here are 2 cards and a file.', |
| 78 | + '', // The suggested actions are in a `<p>`, `innerText` puts a blank line around it. |
| 79 | + 'Help', |
| 80 | + '', |
| 81 | + 'A card: Card 1', |
| 82 | + 'OK', |
| 83 | + 'A card: Card 2 Hero text', |
| 84 | + 'Go', |
| 85 | + 'A file: report.zip' |
| 86 | + ].join('\n') |
| 87 | + ); |
| 88 | + |
| 89 | + // THEN: The message should still be announced as a whole. |
| 90 | + expect(liveRegionActivity.getAttribute('aria-atomic')).toBe('true'); |
| 91 | + |
| 92 | + const accessibilityNodes = await Promise.all( |
| 93 | + [liveRegionActivity, ...liveRegionActivity.querySelectorAll('*')].map(element => |
| 94 | + testHelpers.getAccessibilityNode(element) |
| 95 | + ) |
| 96 | + ); |
| 97 | + |
| 98 | + // THEN: The message should be a generic container, not an article, screen readers would read "article" before it. |
| 99 | + expect(accessibilityNodes[0].role?.value).toBe('generic'); |
| 100 | + |
| 101 | + // THEN: Inside the message, only the copies of the buttons should be in the accessibility tree, besides the text. |
| 102 | + // On Windows, every other element is a "group" (including generic `<div>` and `<p>`), screen readers would read "group" before each line. |
| 103 | + expect( |
| 104 | + accessibilityNodes |
| 105 | + .slice(1) // The message itself keeps `aria-atomic`, which requires an element in the accessibility tree. |
| 106 | + .filter(({ ignored }) => !ignored) |
| 107 | + .map(({ name, role }) => `${role?.value} "${name?.value}"`) |
| 108 | + ).toEqual(['button "Help"', 'button "OK"', 'button "Go"']); |
| 109 | + |
| 110 | + await pageConditions.liveRegionStabilized(); |
| 111 | + |
| 112 | + // THEN: The live region (top) shows the message, "Help", "A card: Card 1", "OK", "A card: Card 2 Hero text", "Go" and "A file: report.zip", with no role words such as "article" or "group". |
| 113 | + await host.snapshot('local'); |
| 114 | + }); |
| 115 | + </script> |
| 116 | + </body> |
| 117 | +</html> |
0 commit comments