Skip to content

Commit 0a076c7

Browse files
committed
fix: update tests
1 parent c8f38e0 commit 0a076c7

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

site/src/components/Abbr/Abbr.test.tsx

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,12 @@
11
import { render, screen } from "@testing-library/react";
2-
import { Abbr, type Pronunciation } from "./Abbr";
2+
import { Abbr } from "./Abbr";
33

44
type AbbreviationData = {
55
abbreviation: string;
66
title: string;
77
expectedLabel: string;
88
};
99

10-
type AssertionInput = AbbreviationData & {
11-
pronunciation: Pronunciation;
12-
};
13-
14-
function assertAccessibleLabel({
15-
abbreviation,
16-
title,
17-
expectedLabel,
18-
pronunciation,
19-
}: AssertionInput) {
20-
const { unmount } = render(
21-
<Abbr title={title} pronunciation={pronunciation}>
22-
{abbreviation}
23-
</Abbr>,
24-
);
25-
26-
screen.getByLabelText(expectedLabel, { selector: "abbr" });
27-
unmount();
28-
}
29-
3010
describe(Abbr.name, () => {
3111
it("Has an aria-label that equals the title if the abbreviation is shorthand", () => {
3212
const sampleShorthands: AbbreviationData[] = [
@@ -43,7 +23,18 @@ describe(Abbr.name, () => {
4323
];
4424

4525
for (const shorthand of sampleShorthands) {
46-
assertAccessibleLabel({ ...shorthand, pronunciation: "shorthand" });
26+
const { unmount } = render(
27+
<Abbr title={shorthand.title} pronunciation="shorthand">
28+
{shorthand.abbreviation}
29+
</Abbr>,
30+
);
31+
32+
// The <abbr> element doesn't have any ARIA role semantics baked in,
33+
// so we have to get a little bit more creative with making sure the
34+
// expected content is on screen in an accessible way
35+
const element = screen.getByTitle(shorthand.title);
36+
expect(element).toHaveTextContent(shorthand.expectedLabel);
37+
unmount();
4738
}
4839
});
4940

@@ -67,7 +58,15 @@ describe(Abbr.name, () => {
6758
];
6859

6960
for (const acronym of sampleAcronyms) {
70-
assertAccessibleLabel({ ...acronym, pronunciation: "acronym" });
61+
const { unmount } = render(
62+
<Abbr title={acronym.title} pronunciation="acronym">
63+
{acronym.abbreviation}
64+
</Abbr>,
65+
);
66+
67+
const element = screen.getByTitle(acronym.title);
68+
expect(element).toHaveTextContent(acronym.expectedLabel);
69+
unmount();
7170
}
7271
});
7372

@@ -91,7 +90,15 @@ describe(Abbr.name, () => {
9190
];
9291

9392
for (const initialism of sampleInitialisms) {
94-
assertAccessibleLabel({ ...initialism, pronunciation: "initialism" });
93+
const { unmount } = render(
94+
<Abbr title={initialism.title} pronunciation="initialism">
95+
{initialism.abbreviation}
96+
</Abbr>,
97+
);
98+
99+
const element = screen.getByTitle(initialism.title);
100+
expect(element).toHaveTextContent(initialism.expectedLabel);
101+
unmount();
95102
}
96103
});
97104
});

0 commit comments

Comments
 (0)