|
1 | 1 | import { test, expect } from "@playwright/test"; |
2 | 2 |
|
3 | | -test.describe("External links in default listing", () => { |
4 | | - test("External listing item has target=_blank attribute", async ({ page }) => { |
5 | | - await page.goto("./listings/external-links/_site/index.html"); |
| 3 | +const listingTypes = [ |
| 4 | + { |
| 5 | + name: "default", |
| 6 | + page: "index.html", |
| 7 | + containerSelector: ".quarto-listing-default", |
| 8 | + externalLinkSelector: |
| 9 | + '.quarto-listing-default a[href="https://example.com/external-article"]', |
| 10 | + }, |
| 11 | + { |
| 12 | + name: "grid", |
| 13 | + page: "grid.html", |
| 14 | + containerSelector: ".quarto-listing-container-grid", |
| 15 | + externalLinkSelector: |
| 16 | + '.quarto-listing-container-grid a[href="https://example.com/external-article"]', |
| 17 | + }, |
| 18 | + { |
| 19 | + name: "table", |
| 20 | + page: "table.html", |
| 21 | + containerSelector: ".quarto-listing-table", |
| 22 | + externalLinkSelector: |
| 23 | + '.quarto-listing-table a[href="https://example.com/external-article"]', |
| 24 | + }, |
| 25 | +]; |
6 | 26 |
|
7 | | - // Find the link to the external article in the default listing |
8 | | - const externalLink = page.locator( |
9 | | - '.quarto-listing-default a[href="https://example.com/external-article"]' |
10 | | - ); |
| 27 | +listingTypes.forEach(({ name, page, containerSelector, externalLinkSelector }) => { |
| 28 | + test.describe(`External links in ${name} listing`, () => { |
| 29 | + test("External listing item has target=_blank attribute", async ({ |
| 30 | + page: browserPage, |
| 31 | + }) => { |
| 32 | + await browserPage.goto(`./listings/external-links/_site/${page}`); |
11 | 33 |
|
12 | | - await expect(externalLink.first()).toHaveAttribute("target", "_blank"); |
13 | | - }); |
| 34 | + // Wait for the listing to be visible |
| 35 | + await browserPage.waitForSelector(containerSelector); |
14 | 36 |
|
15 | | - test("External listing item has rel=noopener attribute", async ({ page }) => { |
16 | | - await page.goto("./listings/external-links/_site/index.html"); |
| 37 | + // Find the link to the external article |
| 38 | + const externalLink = browserPage.locator(externalLinkSelector); |
17 | 39 |
|
18 | | - // Find the link to the external article in the default listing |
19 | | - const externalLink = page.locator( |
20 | | - '.quarto-listing-default a[href="https://example.com/external-article"]' |
21 | | - ); |
| 40 | + await expect(externalLink.first()).toHaveAttribute("target", "_blank"); |
| 41 | + }); |
22 | 42 |
|
23 | | - await expect(externalLink.first()).toHaveAttribute("rel", "noopener"); |
24 | | - }); |
| 43 | + test("External listing item has rel=noopener attribute", async ({ |
| 44 | + page: browserPage, |
| 45 | + }) => { |
| 46 | + await browserPage.goto(`./listings/external-links/_site/${page}`); |
| 47 | + |
| 48 | + // Wait for the listing to be visible |
| 49 | + await browserPage.waitForSelector(containerSelector); |
| 50 | + |
| 51 | + // Find the link to the external article |
| 52 | + const externalLink = browserPage.locator(externalLinkSelector); |
| 53 | + |
| 54 | + await expect(externalLink.first()).toHaveAttribute("rel", "noopener"); |
| 55 | + }); |
25 | 56 |
|
26 | | - test("Internal listing item does NOT have target=_blank attribute", async ({ |
27 | | - page, |
28 | | - }) => { |
29 | | - await page.goto("./listings/external-links/_site/index.html"); |
| 57 | + test("Internal listing item does NOT have target=_blank attribute", async ({ |
| 58 | + page: browserPage, |
| 59 | + }) => { |
| 60 | + await browserPage.goto(`./listings/external-links/_site/${page}`); |
30 | 61 |
|
31 | | - // Wait for the listing to be visible |
32 | | - await page.waitForSelector(".quarto-listing-default"); |
| 62 | + // Wait for the listing to be visible |
| 63 | + await browserPage.waitForSelector(containerSelector); |
33 | 64 |
|
34 | | - // Find the link to the local post by its text content |
35 | | - const internalLink = page.getByRole("link", { name: "Local Post" }).first(); |
| 65 | + // Find the link to the local post by its text content |
| 66 | + const internalLink = browserPage |
| 67 | + .getByRole("link", { name: "Local Post" }) |
| 68 | + .first(); |
36 | 69 |
|
37 | | - // Verify the link exists |
38 | | - await expect(internalLink).toBeVisible(); |
| 70 | + // Verify the link exists |
| 71 | + await expect(internalLink).toBeVisible(); |
39 | 72 |
|
40 | | - // Internal links should not have target="_blank" |
41 | | - await expect(internalLink).not.toHaveAttribute("target", "_blank"); |
| 73 | + // Internal links should not have target="_blank" |
| 74 | + await expect(internalLink).not.toHaveAttribute("target", "_blank"); |
| 75 | + }); |
42 | 76 | }); |
43 | 77 | }); |
0 commit comments