Skip to content

Commit 38a4a9d

Browse files
committed
test: assert pagination link names instead of ARIA snapshots
1 parent 2a4c0c3 commit 38a4a9d

1 file changed

Lines changed: 35 additions & 55 deletions

File tree

‎tests/integration/playwright/tests/listing-pagination.spec.ts‎

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ test.describe("Listing pagination accessibility", () => {
9999
await expect(nav(page, id).locator("li.active")).toHaveText("6");
100100
}
101101
const n = nav(page, id);
102-
await expect(n).toHaveAttribute("aria-label", "Page navigation");
102+
await expect(n).toHaveAttribute("aria-label", "Pagination");
103103

104104
const items = await n.locator("li.page-item").all();
105105
for (const item of items) {
@@ -144,68 +144,48 @@ test.describe("Listing pagination accessibility", () => {
144144
expect(texts).toEqual(["1", "4", "5", "6", "7", "8", "10"]);
145145
});
146146

147-
test("ARIA snapshot of the outer nav on page 1", async ({ page }) => {
147+
// Explicit assertions rather than toMatchAriaSnapshot: CI runs Playwright
148+
// with --ignore-snapshots, which turns snapshot assertions into no-ops.
149+
async function expectLinkNames(page: Page, names: string[]) {
150+
const links = nav(page, "outer").getByRole("link");
151+
await expect(links).toHaveCount(names.length);
152+
for (const [i, name] of names.entries()) {
153+
await expect(links.nth(i)).toHaveAccessibleName(name);
154+
}
155+
}
156+
157+
test("every listing has a pagination landmark", async ({ page }) => {
158+
await gotoReady(page);
159+
await expect(page.getByRole("navigation", { name: "Pagination" }))
160+
.toHaveCount(listingIds.length);
161+
});
162+
163+
test("the outer nav names its links on page 1", async ({ page }) => {
148164
await gotoReady(page);
149-
await expect(nav(page, "outer")).toMatchAriaSnapshot(`
150-
- navigation "Page navigation":
151-
- list:
152-
- listitem:
153-
- link "Page 1":
154-
- /url: "#"
155-
- text: "1"
156-
- listitem:
157-
- link "Page 2":
158-
- /url: "#"
159-
- text: "2"
160-
- listitem:
161-
- link "Page 3":
162-
- /url: "#"
163-
- text: "3"
164-
- listitem:
165-
- link "Page 10":
166-
- /url: "#"
167-
- text: "10"
168-
`);
165+
await expectLinkNames(page, ["Page 1", "Page 2", "Page 3", "Page 10"]);
166+
await expect(
167+
nav(page, "outer").getByRole("link", { name: "Page 1", exact: true }),
168+
).toHaveAttribute("aria-current", "page");
169169
});
170170

171-
test("ARIA snapshot of the outer nav on page 6", async ({ page }) => {
171+
test("the outer nav names its links on page 6", async ({ page }) => {
172172
await gotoReady(page);
173173
await page.evaluate(() => {
174174
window.location.hash = "#listing-outer-page=6";
175175
});
176176
await expect(nav(page, "outer").locator("li.active")).toHaveText("6");
177-
await expect(nav(page, "outer")).toMatchAriaSnapshot(`
178-
- navigation "Page navigation":
179-
- list:
180-
- listitem:
181-
- link "Page 1":
182-
- /url: "#"
183-
- text: "1"
184-
- listitem:
185-
- link "Page 4":
186-
- /url: "#"
187-
- text: "4"
188-
- listitem:
189-
- link "Page 5":
190-
- /url: "#"
191-
- text: "5"
192-
- listitem:
193-
- link "Page 6":
194-
- /url: "#"
195-
- text: "6"
196-
- listitem:
197-
- link "Page 7":
198-
- /url: "#"
199-
- text: "7"
200-
- listitem:
201-
- link "Page 8":
202-
- /url: "#"
203-
- text: "8"
204-
- listitem:
205-
- link "Page 10":
206-
- /url: "#"
207-
- text: "10"
208-
`);
177+
await expectLinkNames(page, [
178+
"Page 1",
179+
"Page 4",
180+
"Page 5",
181+
"Page 6",
182+
"Page 7",
183+
"Page 8",
184+
"Page 10",
185+
]);
186+
await expect(
187+
nav(page, "outer").getByRole("link", { name: "Page 6", exact: true }),
188+
).toHaveAttribute("aria-current", "page");
209189
});
210190

211191
// With five listings on one page, every nav shares one label, so axe reports

0 commit comments

Comments
 (0)