|
32 | 32 |
|
33 | 33 | await pageConditions.uiConnected(); |
34 | 34 |
|
35 | | - // WHEN: Bot sends a message with an Adaptive Card, a hero card, and a file. |
| 35 | + // WHEN: Bot sends a message with an Adaptive Card, a hero card, a file, and a suggested action. |
36 | 36 | await directLine.emulateIncomingActivity({ |
37 | 37 | attachments: [ |
38 | 38 | { |
|
52 | 52 | { contentType: 'application/octet-stream', name: 'report.zip' } |
53 | 53 | ], |
54 | 54 | from: { role: 'bot' }, |
| 55 | + suggestedActions: { actions: [{ title: 'Help', type: 'imBack', value: 'help' }] }, |
55 | 56 | text: 'Here are 2 cards and a file.', |
56 | 57 | type: 'message' |
57 | 58 | }); |
58 | 59 |
|
59 | 60 | await pageConditions.numActivitiesShown(1); |
60 | 61 |
|
61 | | - await waitFor(() => |
62 | | - expect(pageElements.liveRegion().querySelector('.webchat__live-region-activity')).toBeTruthy() |
63 | | - ); |
| 62 | + const liveRegionActivity = await waitFor(() => { |
| 63 | + const element = pageElements.liveRegion().querySelector('.webchat__live-region-activity'); |
| 64 | + |
| 65 | + expect(element).toBeTruthy(); |
64 | 66 |
|
65 | | - const liveRegionActivity = pageElements.liveRegion().querySelector('.webchat__live-region-activity'); |
| 67 | + return element; |
| 68 | + }); |
66 | 69 |
|
67 | | - // THEN: The live region should contain the text of the message, the cards, and the file. |
| 70 | + // THEN: The live region should contain the text of the message, the suggested action, the cards, and the file. |
68 | 71 | expect(liveRegionActivity.innerText).toBe( |
69 | 72 | [ |
70 | 73 | 'Bot WC said:', |
71 | 74 | 'Here are 2 cards and a file.', |
| 75 | + '', // The suggested actions are in a `<p>`, `innerText` puts a blank line around it. |
| 76 | + 'Help', |
| 77 | + '', |
72 | 78 | 'A card: Card 1', |
73 | 79 | 'OK', |
74 | 80 | 'A card: Card 2 Hero text', |
|
80 | 86 | // THEN: The message should still be announced as a whole. |
81 | 87 | expect(liveRegionActivity.getAttribute('aria-atomic')).toBe('true'); |
82 | 88 |
|
83 | | - // THEN: The message and its attachments should not be articles, screen readers would read "article" before each of them. |
84 | 89 | const accessibilityNodes = await Promise.all( |
85 | 90 | [liveRegionActivity, ...liveRegionActivity.querySelectorAll('*')].map(element => |
86 | 91 | testHelpers.getAccessibilityNode(element) |
87 | 92 | ) |
88 | 93 | ); |
89 | 94 |
|
90 | | - expect(accessibilityNodes.map(({ role }) => role?.value)).not.toContain('article'); |
91 | | - expect(liveRegionActivity.querySelectorAll('article')).toHaveLength(0); |
| 95 | + // THEN: The message should be a generic container, not an article, screen readers would read "article" before it. |
| 96 | + expect(accessibilityNodes[0].role?.value).toBe('generic'); |
| 97 | + |
| 98 | + // THEN: Inside the message, only the copies of the buttons should be in the accessibility tree, besides the text. |
| 99 | + // On Windows, every other element is a "group" (including generic `<div>` and `<p>`), screen readers would read "group" before each line. |
| 100 | + expect( |
| 101 | + accessibilityNodes |
| 102 | + .slice(1) // The message itself keeps `aria-atomic`, which requires an element in the accessibility tree. |
| 103 | + .filter(({ ignored }) => !ignored) |
| 104 | + .map(({ name, role }) => `${role?.value} "${name?.value}"`) |
| 105 | + ).toEqual(['button "Help"', 'button "OK"', 'button "Go"']); |
92 | 106 | }); |
93 | 107 | </script> |
94 | 108 | </body> |
|
0 commit comments