Skip to content

Commit 9810225

Browse files
committed
test: increase coverage with other listing types
1 parent fc98aa3 commit 9810225

3 files changed

Lines changed: 96 additions & 29 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "External Links Test - Grid"
3+
listing:
4+
id: grid-listing
5+
contents:
6+
- path: https://example.com/external-article
7+
title: "External Article"
8+
description: "An external article that should open in new window."
9+
- path: local-post.qmd
10+
title: "Local Post"
11+
description: "A local post that should NOT open in new window."
12+
type: grid
13+
---
14+
15+
::: {#grid-listing}
16+
:::
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: "External Links Test - Table"
3+
listing:
4+
id: table-listing
5+
contents:
6+
- path: https://example.com/external-article
7+
title: "External Article"
8+
description: "An external article that should open in new window."
9+
- path: local-post.qmd
10+
title: "Local Post"
11+
description: "A local post that should NOT open in new window."
12+
type: table
13+
fields: [title, description]
14+
---
15+
16+
::: {#table-listing}
17+
:::
Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,77 @@
11
import { test, expect } from "@playwright/test";
22

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+
];
626

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}`);
1133

12-
await expect(externalLink.first()).toHaveAttribute("target", "_blank");
13-
});
34+
// Wait for the listing to be visible
35+
await browserPage.waitForSelector(containerSelector);
1436

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);
1739

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+
});
2242

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+
});
2556

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}`);
3061

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);
3364

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();
3669

37-
// Verify the link exists
38-
await expect(internalLink).toBeVisible();
70+
// Verify the link exists
71+
await expect(internalLink).toBeVisible();
3972

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+
});
4276
});
4377
});

0 commit comments

Comments
 (0)