Skip to content

Commit cc334ed

Browse files
committed
Add data-testid to Announcer component and update tests to exclude announcer elements
1 parent 77b6570 commit cc334ed

4 files changed

Lines changed: 23 additions & 20 deletions

File tree

packages/react-components/src/components/Announcer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const Announcer = (props: AnnouncerProps): JSX.Element => {
2626

2727
return (
2828
<Stack
29+
data-testid="announcer"
2930
aria-live={ariaLive}
3031
role={role}
3132
aria-atomic={true}

packages/react-components/src/components/InputBoxComponent.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ describe('InputBoxComponent should show mention popover', () => {
7575

7676
const checkExpectedSuggestions = async (): Promise<void> => {
7777
for (const suggestion of suggestions) {
78-
// Check that all suggestions are presented
79-
const contextMenuItem = await screen.findByText(suggestion.displayText);
80-
expect(contextMenuItem.classList.contains('ms-Persona-primaryText')).toBe(true);
78+
// Check that all suggestions are presented (use selector to exclude announcer elements)
79+
const contextMenuItem = await screen.findByText(suggestion.displayText, { selector: '.ms-Persona-primaryText' });
80+
expect(contextMenuItem).toBeTruthy();
8181
}
8282
};
8383

@@ -154,8 +154,9 @@ describe('InputBoxComponent should show mention popover for a custom trigger', (
154154

155155
const checkExpectedSuggestions = async (): Promise<void> => {
156156
for (const suggestion of suggestions) {
157-
const contextMenuItem = await screen.findByText(suggestion?.displayText);
158-
expect(contextMenuItem.classList.contains('ms-Persona-primaryText')).toBe(true);
157+
// Use selector to exclude announcer elements
158+
const contextMenuItem = await screen.findByText(suggestion?.displayText, { selector: '.ms-Persona-primaryText' });
159+
expect(contextMenuItem).toBeTruthy();
159160
}
160161
};
161162

@@ -266,7 +267,8 @@ describe('InputBoxComponent should hide mention popover', () => {
266267

267268
const checkSuggestionsNotShown = (): void => {
268269
for (const suggestion of suggestions) {
269-
const contextMenuItem = screen.queryByText(suggestion?.displayText);
270+
// Use selector to exclude announcer elements
271+
const contextMenuItem = screen.queryByText(suggestion?.displayText, { selector: '.ms-Persona-primaryText' });
270272
expect(contextMenuItem).toBeNull();
271273
}
272274
};
@@ -276,8 +278,8 @@ describe('InputBoxComponent should hide mention popover', () => {
276278
if (!firstSuggestionText) {
277279
throw new Error('Suggestion text is not defined');
278280
}
279-
const firstSuggestionMenuItem = await screen.findByText(firstSuggestionText);
280-
expect(firstSuggestionMenuItem.classList.contains('ms-Persona-primaryText')).toBe(true);
281+
// Use selector to exclude announcer elements
282+
const firstSuggestionMenuItem = await screen.findByText(firstSuggestionText, { selector: '.ms-Persona-primaryText' });
281283
return firstSuggestionMenuItem;
282284
};
283285

packages/react-components/src/components/MessageThread.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,13 @@ describe('Message should display Mention correctly', () => {
396396
await userEvent.keyboard(' @');
397397
});
398398

399-
// Check that Everyone is an option
400-
const everyoneMentionContextMenuItem = await screen.findByText('Everyone');
401-
expect(everyoneMentionContextMenuItem.classList.contains('ms-Persona-primaryText')).toBe(true);
399+
// Check that Everyone is an option (use selector to exclude announcer elements)
400+
const everyoneMentionContextMenuItem = await screen.findByText('Everyone', { selector: '.ms-Persona-primaryText' });
401+
expect(everyoneMentionContextMenuItem).toBeTruthy();
402402

403-
// Check that user1Name is an option
404-
const user1MentionContextMenuItem = await screen.findByText(user1Name);
405-
expect(user1MentionContextMenuItem.classList.contains('ms-Persona-primaryText')).toBe(true);
403+
// Check that user1Name is an option (use selector to exclude announcer elements)
404+
const user1MentionContextMenuItem = await screen.findByText(user1Name, { selector: '.ms-Persona-primaryText' });
405+
expect(user1MentionContextMenuItem).toBeTruthy();
406406

407407
// Select mention from popover for user1Name, verify plain text not contain mention html tag
408408
fireEvent.click(user1MentionContextMenuItem);

packages/react-components/src/components/SendBox.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ describe('SendBox should return correct value with a selected mention', () => {
6666
if (!suggestions[0]) {
6767
throw new Error('No suggestions found');
6868
}
69-
const contextMenuItem = await screen.findByText(suggestions[0].displayText);
70-
expect(contextMenuItem.classList.contains('ms-Persona-primaryText')).toBe(true);
69+
// Use selector to exclude announcer elements
70+
const contextMenuItem = await screen.findByText(suggestions[0].displayText, { selector: '.ms-Persona-primaryText' });
7171
contextMenuItem && fireEvent.click(contextMenuItem);
7272
};
7373

@@ -161,8 +161,8 @@ describe('Clicks/Touch should select mention', () => {
161161
if (!suggestions[0]) {
162162
throw new Error('No suggestions found');
163163
}
164-
const contextMenuItem = await screen.findByText(suggestions[0].displayText);
165-
expect(contextMenuItem.classList.contains('ms-Persona-primaryText')).toBe(true);
164+
// Use selector to exclude announcer elements
165+
const contextMenuItem = await screen.findByText(suggestions[0].displayText, { selector: '.ms-Persona-primaryText' });
166166
fireEvent.click(contextMenuItem);
167167
};
168168

@@ -421,8 +421,8 @@ describe('Keyboard events should be handled for mentions', () => {
421421
if (!suggestion) {
422422
throw new Error('Suggestion not found');
423423
}
424-
const contextMenuItem = await screen.findByText(suggestion.displayText);
425-
expect(contextMenuItem.classList.contains('ms-Persona-primaryText')).toBe(true);
424+
// Use selector to exclude announcer elements
425+
const contextMenuItem = await screen.findByText(suggestion.displayText, { selector: '.ms-Persona-primaryText' });
426426
fireEvent.click(contextMenuItem);
427427
};
428428

0 commit comments

Comments
 (0)