|
| 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 | + </head> |
| 8 | + <body> |
| 9 | + <main id="webchat"></main> |
| 10 | + <script type="importmap"> |
| 11 | + { |
| 12 | + "imports": { |
| 13 | + "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", |
| 14 | + "botframework-webchat/": "/__dist__/packages/bundle/static/botframework-webchat/", |
| 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 { createStoreWithOptions, ReactWebChat } from 'botframework-webchat'; |
| 26 | + import { createElement } from 'react'; |
| 27 | + import { createRoot } from 'react-dom/client'; |
| 28 | + |
| 29 | + // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. |
| 30 | + window.WebChat = { createStoreWithOptions }; |
| 31 | + |
| 32 | + run(async function () { |
| 33 | + const { directLine, store } = testHelpers.createDirectLineEmulator(); |
| 34 | + |
| 35 | + // GIVEN: Web Chat keeps the live region copy of new messages, so it can be checked and seen in the snapshot. |
| 36 | + createRoot(document.getElementById('webchat')).render( |
| 37 | + createElement(ReactWebChat, { |
| 38 | + directLine, |
| 39 | + store, |
| 40 | + styleOptions: { hideSendBox: true, internalLiveRegionFadeAfter: 60000 } |
| 41 | + }) |
| 42 | + ); |
| 43 | + |
| 44 | + await pageConditions.uiConnected(); |
| 45 | + |
| 46 | + // WHEN: The bot sends an Adaptive Card with a Markdown text block (bold, a link, and a bullet list), and without "speak". |
| 47 | + await directLine.emulateIncomingActivity({ |
| 48 | + attachments: [ |
| 49 | + { |
| 50 | + content: { |
| 51 | + $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', |
| 52 | + body: [ |
| 53 | + { |
| 54 | + text: 'Today is **sunny**, see [docs](https://example.com).\n\n- Umbrella: no\n- Sunscreen: yes', |
| 55 | + type: 'TextBlock', |
| 56 | + wrap: true |
| 57 | + } |
| 58 | + ], |
| 59 | + type: 'AdaptiveCard', |
| 60 | + version: '1.5' |
| 61 | + }, |
| 62 | + contentType: 'application/vnd.microsoft.card.adaptive' |
| 63 | + } |
| 64 | + ], |
| 65 | + from: { role: 'bot' }, |
| 66 | + type: 'message' |
| 67 | + }); |
| 68 | + |
| 69 | + await pageConditions.numActivitiesShown(1); |
| 70 | + await pageConditions.liveRegionStabilized(); |
| 71 | + |
| 72 | + // The card shows the list items on separate lines, the live region reads them as one line. |
| 73 | + const cardText = pageElements |
| 74 | + .activities()[0] |
| 75 | + .querySelector('.ac-textBlock') |
| 76 | + .textContent.replace(/\s+/gu, ' ') |
| 77 | + .trim(); |
| 78 | + |
| 79 | + // THEN: The card shows the text without Markdown syntax ("**", "[", "](", "- "). |
| 80 | + expect(cardText).toEqual( |
| 81 | + expect.stringMatching(/^Today is sunny, see .*docs.*\. Umbrella: no Sunscreen: yes$/u) |
| 82 | + ); |
| 83 | + |
| 84 | + // THEN: The live region copy reads the same text as the card. |
| 85 | + expect( |
| 86 | + testHelpers |
| 87 | + .getAllTextContents(pageElements.liveRegion().querySelector('.webchat__live-region-activity')) |
| 88 | + .map(text => text.trim()) |
| 89 | + ).toEqual(['Bot said:', `A card: ${cardText}`]); |
| 90 | + |
| 91 | + // THEN: The card shows bold "sunny", a "docs" link and a bullet list; the live region above shows the same words without Markdown syntax. |
| 92 | + await host.snapshot('local'); |
| 93 | + }); |
| 94 | + </script> |
| 95 | + </body> |
| 96 | +</html> |
0 commit comments