@microsoft/omnichannel-chat-components 1.1.17-main.9284e84 → 1.1.17-main.9b18f0e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom/extend-expect");
4
+ var _react = require("@testing-library/react");
5
+ var _BroadcastService = require("../../services/BroadcastService");
6
+ var _ChatButton = _interopRequireDefault(require("./ChatButton"));
7
+ var _LoadingPane = _interopRequireDefault(require("../loadingpane/LoadingPane"));
8
+ var _react2 = _interopRequireDefault(require("react"));
9
+ var _defaultChatButtonProps = require("./common/defaultProps/defaultChatButtonProps");
10
+ var _defaultLoadingPaneProps = require("../loadingpane/common/defaultProps/defaultLoadingPaneProps");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ /* eslint-disable @typescript-eslint/no-explicit-any */
13
+
14
+ /**
15
+ * Repro / catcher for internal tracking — screen reader announces hidden / irrelevant
16
+ * text such as "blank" while navigating the chat surface. NVDA / JAWS announce
17
+ * "blank" when they encounter:
18
+ * - an element with an announceable role (button, link, textbox, listitem,
19
+ * progressbar, etc.) that has an empty accessible name (no aria-label, no
20
+ * aria-labelledby, no associated <label>, and no own text content), OR
21
+ * - a live region (`aria-live="polite"` / `aria-live="assertive"`) that is
22
+ * mounted with empty text content (each tick announces "blank").
23
+ *
24
+ * This catcher walks several rendered LCW surfaces and asserts neither pattern
25
+ * is present. Deterministic DOM contract — no SR needed.
26
+ *
27
+ * Surfaces covered today:
28
+ * - ChatButton (default props) — regression guard; passes today.
29
+ * - ChatButton with notification bubble forced visible at unreadCount=0 —
30
+ * regression guard for the empty-live-region path; passes today.
31
+ * - LoadingPane (default props) — regression guard; passes today.
32
+ *
33
+ * Scope note: the original bug surfaces inside WebChat-rendered chat session
34
+ * content (message bubbles, attachments, agent-supplied HTML), which is not
35
+ * reachable from chat-components unit tests. The Playwright catcher
36
+ * `automation_tests/e2e/areas/accessibility/blankAnnouncements.spec.ts` on
37
+ * `chore/a11y-tooling-foundation` walks the full a11y tree of a built
38
+ * `dist/out.js` and is the right vehicle for enumerating per-offender fixes.
39
+ * Promote additional surfaces here as they are wired into the catcher harness.
40
+ */
41
+
42
+ beforeAll(() => {
43
+ (0, _BroadcastService.BroadcastServiceInitialize)("testChannel");
44
+ });
45
+ afterEach(() => {
46
+ (0, _react.cleanup)();
47
+ });
48
+ const ANNOUNCEABLE_ROLES = new Set(["button", "link", "textbox", "combobox", "listbox", "listitem", "menu", "menuitem", "checkbox", "radio", "switch", "tab", "treeitem", "option", "searchbox", "progressbar", "alert", "status"]);
49
+ const ANNOUNCEABLE_TAGS = new Set(["button", "a", "input", "select", "textarea"]);
50
+ const isInsideAriaHidden = el => {
51
+ let cursor = el;
52
+ while (cursor) {
53
+ if (cursor.getAttribute("aria-hidden") === "true") return true;
54
+ cursor = cursor.parentElement;
55
+ }
56
+ return false;
57
+ };
58
+ const accessibleNameOf = el => {
59
+ const ariaLabel = (el.getAttribute("aria-label") || "").trim();
60
+ if (ariaLabel) return ariaLabel;
61
+ const labelledBy = (el.getAttribute("aria-labelledby") || "").trim();
62
+ if (labelledBy) {
63
+ const referenced = labelledBy.split(/\s+/).map(id => {
64
+ var _document$getElementB;
65
+ return ((_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.textContent) || "";
66
+ }).join(" ").trim();
67
+ if (referenced) return referenced;
68
+ }
69
+ if (el.tagName.toLowerCase() === "input") {
70
+ const id = el.id;
71
+ if (id) {
72
+ var _label$textContent;
73
+ const label = document.querySelector(`label[for="${CSS.escape(id)}"]`);
74
+ const labelText = label === null || label === void 0 || (_label$textContent = label.textContent) === null || _label$textContent === void 0 ? void 0 : _label$textContent.trim();
75
+ if (labelText) return labelText;
76
+ }
77
+ const placeholder = (el.getAttribute("placeholder") || "").trim();
78
+ if (placeholder) return placeholder;
79
+ }
80
+ if (el.tagName.toLowerCase() === "a") {
81
+ const title = (el.getAttribute("title") || "").trim();
82
+ if (title) return title;
83
+ }
84
+ return (el.textContent || "").trim();
85
+ };
86
+ const isAnnounceable = el => {
87
+ if (isInsideAriaHidden(el)) return false;
88
+ const role = (el.getAttribute("role") || "").toLowerCase();
89
+ if (role === "presentation" || role === "none") return false;
90
+ if (role && ANNOUNCEABLE_ROLES.has(role)) return true;
91
+ if (ANNOUNCEABLE_TAGS.has(el.tagName.toLowerCase())) {
92
+ // <input type="hidden"> is not announceable.
93
+ if (el.tagName.toLowerCase() === "input" && (el.getAttribute("type") || "").toLowerCase() === "hidden") {
94
+ return false;
95
+ }
96
+ return true;
97
+ }
98
+ return false;
99
+ };
100
+ const findEmptyAnnounceable = root => {
101
+ return Array.from(root.querySelectorAll("*")).filter(el => isAnnounceable(el) && accessibleNameOf(el) === "");
102
+ };
103
+ const findEmptyLiveRegions = root => {
104
+ return Array.from(root.querySelectorAll("[aria-live]")).filter(el => {
105
+ if (isInsideAriaHidden(el)) return false;
106
+ const live = (el.getAttribute("aria-live") || "").toLowerCase();
107
+ if (live !== "polite" && live !== "assertive") return false;
108
+ return (el.textContent || "").trim() === "";
109
+ });
110
+ };
111
+ const summarize = offenders => offenders.map(el => ({
112
+ tag: el.tagName.toLowerCase(),
113
+ id: el.id,
114
+ role: el.getAttribute("role"),
115
+ ariaLabel: el.getAttribute("aria-label"),
116
+ ariaLabelledBy: el.getAttribute("aria-labelledby"),
117
+ classes: el.className
118
+ }));
119
+ describe("ChatButton — 'blank' / empty-name announcements (internal tracking regression guard)", () => {
120
+ it("no announceable role/tag in the chat-button subtree may have an empty accessible name", () => {
121
+ const {
122
+ container
123
+ } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
124
+ const button = container.firstElementChild;
125
+ expect(button).not.toBeNull();
126
+ expect(summarize(findEmptyAnnounceable(button))).toEqual([]);
127
+ });
128
+ it("no live region (aria-live=polite/assertive) in the chat-button subtree may be mounted with empty text", () => {
129
+ const props = {
130
+ ..._defaultChatButtonProps.defaultChatButtonProps,
131
+ controlProps: {
132
+ ..._defaultChatButtonProps.defaultChatButtonProps.controlProps,
133
+ unreadMessageCount: "0",
134
+ hideNotificationBubble: false
135
+ }
136
+ };
137
+ const {
138
+ container
139
+ } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, props));
140
+ const button = container.firstElementChild;
141
+ expect(button).not.toBeNull();
142
+ expect(summarize(findEmptyLiveRegions(button))).toEqual([]);
143
+ });
144
+ });
145
+ describe("LoadingPane — 'blank' / empty-name announcements (internal tracking regression guard)", () => {
146
+ it("no announceable role/tag in the loading-pane subtree may have an empty accessible name", () => {
147
+ const {
148
+ container
149
+ } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_LoadingPane.default, _defaultLoadingPaneProps.defaultLoadingPaneProps));
150
+ const pane = container.firstElementChild;
151
+ expect(pane).not.toBeNull();
152
+ expect(summarize(findEmptyAnnounceable(pane))).toEqual([]);
153
+ });
154
+ it("no live region (aria-live=polite/assertive) in the loading-pane subtree may be mounted with empty text", () => {
155
+ const {
156
+ container
157
+ } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_LoadingPane.default, _defaultLoadingPaneProps.defaultLoadingPaneProps));
158
+ const pane = container.firstElementChild;
159
+ expect(pane).not.toBeNull();
160
+ expect(summarize(findEmptyLiveRegions(pane))).toEqual([]);
161
+ });
162
+ });
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom/extend-expect");
4
+ var _react = require("@testing-library/react");
5
+ var _BroadcastService = require("../../services/BroadcastService");
6
+ var _ChatButton = _interopRequireDefault(require("./ChatButton"));
7
+ var _react2 = _interopRequireDefault(require("react"));
8
+ var _defaultChatButtonControlProps = require("./common/defaultProps/defaultChatButtonControlProps");
9
+ var _defaultChatButtonProps = require("./common/defaultProps/defaultChatButtonProps");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ /* eslint-disable @typescript-eslint/no-explicit-any */
12
+
13
+ const expectedTitle = _defaultChatButtonControlProps.defaultChatButtonControlProps.titleText;
14
+ const expectedSubtitle = _defaultChatButtonControlProps.defaultChatButtonControlProps.subtitleText;
15
+
16
+ /**
17
+ * Repro / catcher for internal tracking — NVDA / JAWS in browse mode (virtual cursor)
18
+ * land on "Let's Chat, We're Online" multiple times when navigating with the
19
+ * down-arrow key.
20
+ *
21
+ * Root cause in code: `ChatButton` renders a Fluent UI `<Stack role="button">`
22
+ * with `tabIndex={0}` whose accessible name is computed from its visible
23
+ * children — a `<Label>` for the title (e.g. "Let's Chat!") and a `<Label>`
24
+ * for the subtitle (e.g. "We're online."). In browse mode, NVDA / JAWS treat
25
+ * the button itself AND each inner text node as separate virtual-cursor stops,
26
+ * each carrying the same announceable name fragments. There is no
27
+ * `aria-label` set by default, and the inner labels are not marked
28
+ * `aria-hidden="true"` (which is what would collapse them into a single
29
+ * announcement under the button container).
30
+ *
31
+ * Catcher contract: the title / subtitle strings must NOT appear as
32
+ * additional announceable name sources in the chat-button subtree (only the
33
+ * single consolidated aria-label on the role=button container should name the
34
+ * button). An "announceable name source" here is:
35
+ * - an `aria-label` attribute on a focusable / role-bearing element, OR
36
+ * - a visible `<Label>` (or other text-bearing element) that is NOT
37
+ * `aria-hidden="true"` and is not nested inside an element that is
38
+ * `aria-hidden="true"`.
39
+ *
40
+ * Expected to FAIL today: the rendered DOM contains BOTH the title text node
41
+ * AND the subtitle text node as bare visible text, and the parent Stack has
42
+ * no `aria-label` to consolidate them. Browse-mode therefore sees three
43
+ * stops (button, title, subtitle) all carrying the same combined name.
44
+ */
45
+
46
+ beforeAll(() => {
47
+ (0, _BroadcastService.BroadcastServiceInitialize)("testChannel");
48
+ });
49
+ afterEach(() => {
50
+ (0, _react.cleanup)();
51
+ });
52
+ const isInsideAriaHidden = el => {
53
+ let cursor = el;
54
+ while (cursor) {
55
+ if (cursor.getAttribute("aria-hidden") === "true") return true;
56
+ cursor = cursor.parentElement;
57
+ }
58
+ return false;
59
+ };
60
+ const visibleTextElementsMatching = (root, text) => {
61
+ return Array.from(root.querySelectorAll("*")).filter(el => {
62
+ if (isInsideAriaHidden(el)) return false;
63
+ // Only count leaf-ish text-bearing elements (don't double-count
64
+ // ancestors whose textContent obviously aggregates children).
65
+ const ownText = Array.from(el.childNodes).filter(n => n.nodeType === Node.TEXT_NODE).map(n => (n.textContent || "").trim()).join(" ").trim();
66
+ return ownText === text;
67
+ });
68
+ };
69
+
70
+ /**
71
+ * SKIPPED until the source fix lands. Un-skip the describe below to validate
72
+ * the fix to internal tracking; the suite is expected to FAIL today against unfixed
73
+ * source. Mirrors the chat-widget `*.unfixed.a11y.spec.tsx` convention.
74
+ */
75
+ describe.skip("ChatButton — browse-mode duplicate stops (internal tracking)", () => {
76
+ it(`title text '${expectedTitle}' must NOT appear as a visible (non-aria-hidden) name source in the chat-button subtree`, () => {
77
+ const {
78
+ container
79
+ } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
80
+ const button = container.firstElementChild;
81
+ expect(button).not.toBeNull();
82
+ const titleStops = visibleTextElementsMatching(button, expectedTitle);
83
+ // The visible title should be excluded from the accessibility tree
84
+ // (e.g. via aria-hidden on the text container) so the announced name
85
+ // comes solely from the consolidated aria-label on the button. Any
86
+ // exposed text-bearing element with this exact text creates an
87
+ // additional browse-mode stop and reproduces internal tracking.
88
+ expect(titleStops.length).toBe(0);
89
+ });
90
+ it(`subtitle text '${expectedSubtitle}' must NOT appear as a visible (non-aria-hidden) name source in the chat-button subtree`, () => {
91
+ const {
92
+ container
93
+ } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
94
+ const button = container.firstElementChild;
95
+ expect(button).not.toBeNull();
96
+ const subtitleStops = visibleTextElementsMatching(button, expectedSubtitle);
97
+ expect(subtitleStops.length).toBe(0);
98
+ });
99
+ it("the chat-button container must own a single consolidated aria-label so browse mode lands on it once", () => {
100
+ const {
101
+ container
102
+ } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_ChatButton.default, _defaultChatButtonProps.defaultChatButtonProps));
103
+ const button = container.firstElementChild;
104
+ expect(button).not.toBeNull();
105
+ // Either the container has a non-empty aria-label, OR every inner
106
+ // text-bearing descendant is aria-hidden so the computed name comes
107
+ // from the inner text exactly once with no extra browse-mode stops.
108
+ const hasAriaLabel = !!(button.getAttribute("aria-label") || "").trim();
109
+ const innerVisibleText = visibleTextElementsMatching(button, expectedTitle).length + visibleTextElementsMatching(button, expectedSubtitle).length;
110
+ // Today: hasAriaLabel === false (default ariaLabel is undefined) AND
111
+ // innerVisibleText > 0. The catcher requires at least one of these
112
+ // to flip.
113
+ expect(hasAriaLabel || innerVisibleText === 0).toBe(true);
114
+ });
115
+ });
@@ -0,0 +1,159 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import "@testing-library/jest-dom/extend-expect";
3
+ import { cleanup, render } from "@testing-library/react";
4
+ import { BroadcastServiceInitialize } from "../../services/BroadcastService";
5
+ import ChatButton from "./ChatButton";
6
+ import LoadingPane from "../loadingpane/LoadingPane";
7
+ import React from "react";
8
+ import { defaultChatButtonProps } from "./common/defaultProps/defaultChatButtonProps";
9
+ import { defaultLoadingPaneProps } from "../loadingpane/common/defaultProps/defaultLoadingPaneProps";
10
+
11
+ /**
12
+ * Repro / catcher for internal tracking — screen reader announces hidden / irrelevant
13
+ * text such as "blank" while navigating the chat surface. NVDA / JAWS announce
14
+ * "blank" when they encounter:
15
+ * - an element with an announceable role (button, link, textbox, listitem,
16
+ * progressbar, etc.) that has an empty accessible name (no aria-label, no
17
+ * aria-labelledby, no associated <label>, and no own text content), OR
18
+ * - a live region (`aria-live="polite"` / `aria-live="assertive"`) that is
19
+ * mounted with empty text content (each tick announces "blank").
20
+ *
21
+ * This catcher walks several rendered LCW surfaces and asserts neither pattern
22
+ * is present. Deterministic DOM contract — no SR needed.
23
+ *
24
+ * Surfaces covered today:
25
+ * - ChatButton (default props) — regression guard; passes today.
26
+ * - ChatButton with notification bubble forced visible at unreadCount=0 —
27
+ * regression guard for the empty-live-region path; passes today.
28
+ * - LoadingPane (default props) — regression guard; passes today.
29
+ *
30
+ * Scope note: the original bug surfaces inside WebChat-rendered chat session
31
+ * content (message bubbles, attachments, agent-supplied HTML), which is not
32
+ * reachable from chat-components unit tests. The Playwright catcher
33
+ * `automation_tests/e2e/areas/accessibility/blankAnnouncements.spec.ts` on
34
+ * `chore/a11y-tooling-foundation` walks the full a11y tree of a built
35
+ * `dist/out.js` and is the right vehicle for enumerating per-offender fixes.
36
+ * Promote additional surfaces here as they are wired into the catcher harness.
37
+ */
38
+
39
+ beforeAll(() => {
40
+ BroadcastServiceInitialize("testChannel");
41
+ });
42
+ afterEach(() => {
43
+ cleanup();
44
+ });
45
+ const ANNOUNCEABLE_ROLES = new Set(["button", "link", "textbox", "combobox", "listbox", "listitem", "menu", "menuitem", "checkbox", "radio", "switch", "tab", "treeitem", "option", "searchbox", "progressbar", "alert", "status"]);
46
+ const ANNOUNCEABLE_TAGS = new Set(["button", "a", "input", "select", "textarea"]);
47
+ const isInsideAriaHidden = el => {
48
+ let cursor = el;
49
+ while (cursor) {
50
+ if (cursor.getAttribute("aria-hidden") === "true") return true;
51
+ cursor = cursor.parentElement;
52
+ }
53
+ return false;
54
+ };
55
+ const accessibleNameOf = el => {
56
+ const ariaLabel = (el.getAttribute("aria-label") || "").trim();
57
+ if (ariaLabel) return ariaLabel;
58
+ const labelledBy = (el.getAttribute("aria-labelledby") || "").trim();
59
+ if (labelledBy) {
60
+ const referenced = labelledBy.split(/\s+/).map(id => {
61
+ var _document$getElementB;
62
+ return ((_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.textContent) || "";
63
+ }).join(" ").trim();
64
+ if (referenced) return referenced;
65
+ }
66
+ if (el.tagName.toLowerCase() === "input") {
67
+ const id = el.id;
68
+ if (id) {
69
+ var _label$textContent;
70
+ const label = document.querySelector(`label[for="${CSS.escape(id)}"]`);
71
+ const labelText = label === null || label === void 0 || (_label$textContent = label.textContent) === null || _label$textContent === void 0 ? void 0 : _label$textContent.trim();
72
+ if (labelText) return labelText;
73
+ }
74
+ const placeholder = (el.getAttribute("placeholder") || "").trim();
75
+ if (placeholder) return placeholder;
76
+ }
77
+ if (el.tagName.toLowerCase() === "a") {
78
+ const title = (el.getAttribute("title") || "").trim();
79
+ if (title) return title;
80
+ }
81
+ return (el.textContent || "").trim();
82
+ };
83
+ const isAnnounceable = el => {
84
+ if (isInsideAriaHidden(el)) return false;
85
+ const role = (el.getAttribute("role") || "").toLowerCase();
86
+ if (role === "presentation" || role === "none") return false;
87
+ if (role && ANNOUNCEABLE_ROLES.has(role)) return true;
88
+ if (ANNOUNCEABLE_TAGS.has(el.tagName.toLowerCase())) {
89
+ // <input type="hidden"> is not announceable.
90
+ if (el.tagName.toLowerCase() === "input" && (el.getAttribute("type") || "").toLowerCase() === "hidden") {
91
+ return false;
92
+ }
93
+ return true;
94
+ }
95
+ return false;
96
+ };
97
+ const findEmptyAnnounceable = root => {
98
+ return Array.from(root.querySelectorAll("*")).filter(el => isAnnounceable(el) && accessibleNameOf(el) === "");
99
+ };
100
+ const findEmptyLiveRegions = root => {
101
+ return Array.from(root.querySelectorAll("[aria-live]")).filter(el => {
102
+ if (isInsideAriaHidden(el)) return false;
103
+ const live = (el.getAttribute("aria-live") || "").toLowerCase();
104
+ if (live !== "polite" && live !== "assertive") return false;
105
+ return (el.textContent || "").trim() === "";
106
+ });
107
+ };
108
+ const summarize = offenders => offenders.map(el => ({
109
+ tag: el.tagName.toLowerCase(),
110
+ id: el.id,
111
+ role: el.getAttribute("role"),
112
+ ariaLabel: el.getAttribute("aria-label"),
113
+ ariaLabelledBy: el.getAttribute("aria-labelledby"),
114
+ classes: el.className
115
+ }));
116
+ describe("ChatButton — 'blank' / empty-name announcements (internal tracking regression guard)", () => {
117
+ it("no announceable role/tag in the chat-button subtree may have an empty accessible name", () => {
118
+ const {
119
+ container
120
+ } = render(/*#__PURE__*/React.createElement(ChatButton, defaultChatButtonProps));
121
+ const button = container.firstElementChild;
122
+ expect(button).not.toBeNull();
123
+ expect(summarize(findEmptyAnnounceable(button))).toEqual([]);
124
+ });
125
+ it("no live region (aria-live=polite/assertive) in the chat-button subtree may be mounted with empty text", () => {
126
+ const props = {
127
+ ...defaultChatButtonProps,
128
+ controlProps: {
129
+ ...defaultChatButtonProps.controlProps,
130
+ unreadMessageCount: "0",
131
+ hideNotificationBubble: false
132
+ }
133
+ };
134
+ const {
135
+ container
136
+ } = render(/*#__PURE__*/React.createElement(ChatButton, props));
137
+ const button = container.firstElementChild;
138
+ expect(button).not.toBeNull();
139
+ expect(summarize(findEmptyLiveRegions(button))).toEqual([]);
140
+ });
141
+ });
142
+ describe("LoadingPane — 'blank' / empty-name announcements (internal tracking regression guard)", () => {
143
+ it("no announceable role/tag in the loading-pane subtree may have an empty accessible name", () => {
144
+ const {
145
+ container
146
+ } = render(/*#__PURE__*/React.createElement(LoadingPane, defaultLoadingPaneProps));
147
+ const pane = container.firstElementChild;
148
+ expect(pane).not.toBeNull();
149
+ expect(summarize(findEmptyAnnounceable(pane))).toEqual([]);
150
+ });
151
+ it("no live region (aria-live=polite/assertive) in the loading-pane subtree may be mounted with empty text", () => {
152
+ const {
153
+ container
154
+ } = render(/*#__PURE__*/React.createElement(LoadingPane, defaultLoadingPaneProps));
155
+ const pane = container.firstElementChild;
156
+ expect(pane).not.toBeNull();
157
+ expect(summarize(findEmptyLiveRegions(pane))).toEqual([]);
158
+ });
159
+ });
@@ -0,0 +1,111 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import "@testing-library/jest-dom/extend-expect";
3
+ import { cleanup, render } from "@testing-library/react";
4
+ import { BroadcastServiceInitialize } from "../../services/BroadcastService";
5
+ import ChatButton from "./ChatButton";
6
+ import React from "react";
7
+ import { defaultChatButtonControlProps } from "./common/defaultProps/defaultChatButtonControlProps";
8
+ import { defaultChatButtonProps } from "./common/defaultProps/defaultChatButtonProps";
9
+ const expectedTitle = defaultChatButtonControlProps.titleText;
10
+ const expectedSubtitle = defaultChatButtonControlProps.subtitleText;
11
+
12
+ /**
13
+ * Repro / catcher for internal tracking — NVDA / JAWS in browse mode (virtual cursor)
14
+ * land on "Let's Chat, We're Online" multiple times when navigating with the
15
+ * down-arrow key.
16
+ *
17
+ * Root cause in code: `ChatButton` renders a Fluent UI `<Stack role="button">`
18
+ * with `tabIndex={0}` whose accessible name is computed from its visible
19
+ * children — a `<Label>` for the title (e.g. "Let's Chat!") and a `<Label>`
20
+ * for the subtitle (e.g. "We're online."). In browse mode, NVDA / JAWS treat
21
+ * the button itself AND each inner text node as separate virtual-cursor stops,
22
+ * each carrying the same announceable name fragments. There is no
23
+ * `aria-label` set by default, and the inner labels are not marked
24
+ * `aria-hidden="true"` (which is what would collapse them into a single
25
+ * announcement under the button container).
26
+ *
27
+ * Catcher contract: the title / subtitle strings must NOT appear as
28
+ * additional announceable name sources in the chat-button subtree (only the
29
+ * single consolidated aria-label on the role=button container should name the
30
+ * button). An "announceable name source" here is:
31
+ * - an `aria-label` attribute on a focusable / role-bearing element, OR
32
+ * - a visible `<Label>` (or other text-bearing element) that is NOT
33
+ * `aria-hidden="true"` and is not nested inside an element that is
34
+ * `aria-hidden="true"`.
35
+ *
36
+ * Expected to FAIL today: the rendered DOM contains BOTH the title text node
37
+ * AND the subtitle text node as bare visible text, and the parent Stack has
38
+ * no `aria-label` to consolidate them. Browse-mode therefore sees three
39
+ * stops (button, title, subtitle) all carrying the same combined name.
40
+ */
41
+
42
+ beforeAll(() => {
43
+ BroadcastServiceInitialize("testChannel");
44
+ });
45
+ afterEach(() => {
46
+ cleanup();
47
+ });
48
+ const isInsideAriaHidden = el => {
49
+ let cursor = el;
50
+ while (cursor) {
51
+ if (cursor.getAttribute("aria-hidden") === "true") return true;
52
+ cursor = cursor.parentElement;
53
+ }
54
+ return false;
55
+ };
56
+ const visibleTextElementsMatching = (root, text) => {
57
+ return Array.from(root.querySelectorAll("*")).filter(el => {
58
+ if (isInsideAriaHidden(el)) return false;
59
+ // Only count leaf-ish text-bearing elements (don't double-count
60
+ // ancestors whose textContent obviously aggregates children).
61
+ const ownText = Array.from(el.childNodes).filter(n => n.nodeType === Node.TEXT_NODE).map(n => (n.textContent || "").trim()).join(" ").trim();
62
+ return ownText === text;
63
+ });
64
+ };
65
+
66
+ /**
67
+ * SKIPPED until the source fix lands. Un-skip the describe below to validate
68
+ * the fix to internal tracking; the suite is expected to FAIL today against unfixed
69
+ * source. Mirrors the chat-widget `*.unfixed.a11y.spec.tsx` convention.
70
+ */
71
+ describe.skip("ChatButton — browse-mode duplicate stops (internal tracking)", () => {
72
+ it(`title text '${expectedTitle}' must NOT appear as a visible (non-aria-hidden) name source in the chat-button subtree`, () => {
73
+ const {
74
+ container
75
+ } = render(/*#__PURE__*/React.createElement(ChatButton, defaultChatButtonProps));
76
+ const button = container.firstElementChild;
77
+ expect(button).not.toBeNull();
78
+ const titleStops = visibleTextElementsMatching(button, expectedTitle);
79
+ // The visible title should be excluded from the accessibility tree
80
+ // (e.g. via aria-hidden on the text container) so the announced name
81
+ // comes solely from the consolidated aria-label on the button. Any
82
+ // exposed text-bearing element with this exact text creates an
83
+ // additional browse-mode stop and reproduces internal tracking.
84
+ expect(titleStops.length).toBe(0);
85
+ });
86
+ it(`subtitle text '${expectedSubtitle}' must NOT appear as a visible (non-aria-hidden) name source in the chat-button subtree`, () => {
87
+ const {
88
+ container
89
+ } = render(/*#__PURE__*/React.createElement(ChatButton, defaultChatButtonProps));
90
+ const button = container.firstElementChild;
91
+ expect(button).not.toBeNull();
92
+ const subtitleStops = visibleTextElementsMatching(button, expectedSubtitle);
93
+ expect(subtitleStops.length).toBe(0);
94
+ });
95
+ it("the chat-button container must own a single consolidated aria-label so browse mode lands on it once", () => {
96
+ const {
97
+ container
98
+ } = render(/*#__PURE__*/React.createElement(ChatButton, defaultChatButtonProps));
99
+ const button = container.firstElementChild;
100
+ expect(button).not.toBeNull();
101
+ // Either the container has a non-empty aria-label, OR every inner
102
+ // text-bearing descendant is aria-hidden so the computed name comes
103
+ // from the inner text exactly once with no extra browse-mode stops.
104
+ const hasAriaLabel = !!(button.getAttribute("aria-label") || "").trim();
105
+ const innerVisibleText = visibleTextElementsMatching(button, expectedTitle).length + visibleTextElementsMatching(button, expectedSubtitle).length;
106
+ // Today: hasAriaLabel === false (default ariaLabel is undefined) AND
107
+ // innerVisibleText > 0. The catcher requires at least one of these
108
+ // to flip.
109
+ expect(hasAriaLabel || innerVisibleText === 0).toBe(true);
110
+ });
111
+ });
@@ -0,0 +1 @@
1
+ import "@testing-library/jest-dom/extend-expect";
@@ -0,0 +1 @@
1
+ import "@testing-library/jest-dom/extend-expect";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-components",
3
- "version": "1.1.17-main.9284e84",
3
+ "version": "1.1.17-main.9b18f0e",
4
4
  "description": "Microsoft Omnichannel Chat Components",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -57,10 +57,14 @@
57
57
  "eslint-plugin-storybook": "^0.5.3",
58
58
  "jest": "^27.3.1",
59
59
  "jest-dom": "^4.0.0",
60
+ "jest-axe": "^10.0.0",
60
61
  "jest-image-snapshot": "^4.5.1",
61
62
  "jest-transform-stub": "^2.0.0",
62
63
  "json": "^11.0.0",
63
64
  "playwright": "^1.16.3",
65
+ "@axe-core/playwright": "^4.10.2",
66
+ "@axe-core/react": "^4.10.2",
67
+ "accessibility-insights-scan": "^3.0.0",
64
68
  "postcss": "^8.3.9",
65
69
  "react": "^18.3.1",
66
70
  "react-dom": "^18.3.1",
@@ -79,7 +83,21 @@
79
83
  "build-storybook": "cross-env NODE_OPTIONS=--openssl-legacy-provider build-storybook",
80
84
  "build": "yarn eslint . && yarn build:esm && yarn build:cjs && tsc",
81
85
  "test:unit": "jest -c jest.config.unit.cjs --env=jsdom --runInBand --force-exit",
86
+ "test:a11y": "jest -c jest.config.a11y.cjs --runInBand --force-exit",
82
87
  "test:visual": "jest -c jest.config.visual.cjs",
88
+ "pretest:visual": "yarn playwright install",
89
+ "test:visual:mobile:ios": "cross-env STORYBOOK_BROWSERS=chromium STORYBOOK_SCREENSHOT_PROFILE=mobile-iphone yarn test:visual",
90
+ "test:visual:mobile:android": "cross-env STORYBOOK_BROWSERS=chromium STORYBOOK_SCREENSHOT_PROFILE=mobile-android yarn test:visual",
91
+ "test:visual:reflow": "cross-env STORYBOOK_BROWSERS=chromium STORYBOOK_SCREENSHOT_PROFILE=reflow-320 yarn test:visual",
92
+ "test:visual:zoom": "cross-env STORYBOOK_BROWSERS=chromium STORYBOOK_SCREENSHOT_PROFILE=zoom-200 yarn test:visual",
93
+ "test:visual:forced-colors": "cross-env STORYBOOK_BROWSERS=chromium STORYBOOK_SCREENSHOT_PROFILE=forced-colors yarn test:visual",
94
+ "test:visual:contrast-more": "cross-env STORYBOOK_BROWSERS=chromium STORYBOOK_SCREENSHOT_PROFILE=contrast-more yarn test:visual",
95
+ "scan:a11y:axe": "node ../tools/accessibility/axeScan.cjs",
96
+ "scan:a11y:axe:gated": "node ../tools/accessibility/axeScan.cjs --gate-rules image-alt,button-name",
97
+ "scan:a11y:axe:build": "yarn build-storybook && yarn scan:a11y:axe",
98
+ "scan:a11y:insights": "node ../tools/accessibility/insightsScan.cjs",
99
+ "scan:a11y:insights:build": "yarn build-storybook && yarn scan:a11y:insights",
100
+ "scan:a11y": "yarn build-storybook && yarn scan:a11y:axe && yarn scan:a11y:insights",
83
101
  "test:all": "yarn test:unit && yarn test:visual",
84
102
  "build:cjs": "babel ./src --config-file ./babel.config.json --out-dir lib/cjs --extensions .ts,.js,.tsx --ignore ./**/*.test.ts,./**/*.stories.ts,./**/*.stories.tsx,./**/*.test.tsx",
85
103
  "build:esm": "babel ./src --config-file ./babel.esm.config.json --out-dir lib/esm --extensions .ts,.js,.tsx --ignore ./**/*.test.ts,./**/*.stories.ts,./**/*.stories.tsx,./**/*.test.tsx",