|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 5 | + <script crossorigin="anonymous" src="/test-harness.js"></script> |
| 6 | + <script crossorigin="anonymous" src="/test-page-object.js"></script> |
| 7 | + <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> |
| 8 | + </head> |
| 9 | + <body> |
| 10 | + <main id="webchat"></main> |
| 11 | + <script type="importmap"> |
| 12 | + { |
| 13 | + "imports": { |
| 14 | + "@testduet/wait-for": "https://esm.sh/@testduet/wait-for" |
| 15 | + } |
| 16 | + } |
| 17 | + </script> |
| 18 | + <script type="module"> |
| 19 | + import { waitFor } from '@testduet/wait-for'; |
| 20 | + |
| 21 | + async function getAccessibilityNodes(imageElements) { |
| 22 | + return ( |
| 23 | + await Promise.all(imageElements.map(imageElement => testHelpers.getAccessibilityNode(imageElement))) |
| 24 | + ).map(({ ignored, name, role }) => (ignored ? { ignored } : { ignored, name: name?.value, role: role?.value })); |
| 25 | + } |
| 26 | + |
| 27 | + run(async function () { |
| 28 | + const { directLine, store } = testHelpers.createDirectLineEmulator(); |
| 29 | + |
| 30 | + WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat')); |
| 31 | + |
| 32 | + await pageConditions.uiConnected(); |
| 33 | + |
| 34 | + // WHEN: Bot sends cards with images with empty alternate text and with alternate text. |
| 35 | + await directLine.emulateIncomingActivity({ |
| 36 | + attachments: [ |
| 37 | + { |
| 38 | + content: { images: [{ alt: '', url: '/assets/bot-avatar.jpg' }], title: 'Hero card with empty alt' }, |
| 39 | + contentType: 'application/vnd.microsoft.card.hero' |
| 40 | + }, |
| 41 | + { |
| 42 | + content: { |
| 43 | + images: [{ alt: 'Bot avatar', url: '/assets/bot-avatar.jpg' }], |
| 44 | + title: 'Hero card with alt' |
| 45 | + }, |
| 46 | + contentType: 'application/vnd.microsoft.card.hero' |
| 47 | + }, |
| 48 | + { |
| 49 | + content: { |
| 50 | + images: [{ alt: '', url: '/assets/bot-avatar.jpg' }], |
| 51 | + title: 'Thumbnail card with empty alt' |
| 52 | + }, |
| 53 | + contentType: 'application/vnd.microsoft.card.thumbnail' |
| 54 | + }, |
| 55 | + { |
| 56 | + content: { |
| 57 | + $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', |
| 58 | + body: [ |
| 59 | + { altText: '', type: 'Image', url: '/assets/bot-avatar.jpg' }, |
| 60 | + { altText: 'Bot avatar', type: 'Image', url: '/assets/bot-avatar.jpg' }, |
| 61 | + { images: [{ altText: '', type: 'Image', url: '/assets/bot-avatar.jpg' }], type: 'ImageSet' }, |
| 62 | + { |
| 63 | + columns: [ |
| 64 | + { items: [{ altText: '', type: 'Image', url: '/assets/bot-avatar.jpg' }], type: 'Column' } |
| 65 | + ], |
| 66 | + type: 'ColumnSet' |
| 67 | + }, |
| 68 | + { |
| 69 | + altText: '', |
| 70 | + selectAction: { title: 'Open image', type: 'Action.Submit' }, |
| 71 | + type: 'Image', |
| 72 | + url: '/assets/bot-avatar.jpg' |
| 73 | + } |
| 74 | + ], |
| 75 | + type: 'AdaptiveCard', |
| 76 | + version: '1.5' |
| 77 | + }, |
| 78 | + contentType: 'application/vnd.microsoft.card.adaptive' |
| 79 | + } |
| 80 | + ], |
| 81 | + type: 'message' |
| 82 | + }); |
| 83 | + |
| 84 | + await pageConditions.numActivitiesShown(1); |
| 85 | + await waitFor(() => expect(pageElements.activities()[0].querySelectorAll('img.ac-image')).toHaveLength(8)); |
| 86 | + await pageConditions.allImagesLoaded(); |
| 87 | + |
| 88 | + const imageElements = Array.from(pageElements.activities()[0].querySelectorAll('img.ac-image')); |
| 89 | + |
| 90 | + // THEN: Images with empty alternate text should have `alt=""`, except image with select action. |
| 91 | + // Image with select action is a button named by the action title (`aria-label`), it is not decorative. |
| 92 | + // `alt=""` would not change its name, and axe would report `presentation-role-conflict` on it. |
| 93 | + expect(imageElements.map(imageElement => imageElement.getAttribute('alt'))).toEqual([ |
| 94 | + '', // Hero card with empty alt. |
| 95 | + 'Bot avatar', // Hero card with alt. |
| 96 | + '', // Thumbnail card with empty alt. |
| 97 | + '', // Adaptive Card: Image with empty alt. |
| 98 | + 'Bot avatar', // Adaptive Card: Image with alt. |
| 99 | + '', // Adaptive Card: Image with empty alt inside ImageSet. |
| 100 | + '', // Adaptive Card: Image with empty alt inside ColumnSet. |
| 101 | + null // Adaptive Card: Image with empty alt and select action, `alt` is untouched. |
| 102 | + ]); |
| 103 | + |
| 104 | + // THEN: Images with empty alternate text should be decorative, image with select action should be a button. |
| 105 | + expect(await getAccessibilityNodes(imageElements)).toEqual([ |
| 106 | + { ignored: true }, // Hero card with empty alt. |
| 107 | + { ignored: false, name: 'Bot avatar', role: 'image' }, // Hero card with alt. |
| 108 | + { ignored: true }, // Thumbnail card with empty alt. |
| 109 | + { ignored: true }, // Adaptive Card: Image with empty alt. |
| 110 | + { ignored: false, name: 'Bot avatar', role: 'image' }, // Adaptive Card: Image with alt. |
| 111 | + { ignored: true }, // Adaptive Card: Image with empty alt inside ImageSet. |
| 112 | + { ignored: true }, // Adaptive Card: Image with empty alt inside ColumnSet. |
| 113 | + { ignored: false, name: 'Open image', role: 'button' } // Adaptive Card: Image with empty alt and select action. |
| 114 | + ]); |
| 115 | + }); |
| 116 | + </script> |
| 117 | + </body> |
| 118 | +</html> |
0 commit comments