Skip to content

Commit fc98aa3

Browse files
committed
test: add external links test suite
1 parent 96a0419 commit fc98aa3

5 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
**/*.quarto_ipynb
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project:
2+
type: website
3+
4+
website:
5+
title: "Testing external links in listings"
6+
7+
link-external-newwindow: true
8+
9+
format: html
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "External Links Test - Default"
3+
listing:
4+
id: external-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: default
13+
---
14+
15+
::: {#external-listing}
16+
:::
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Local Post"
3+
---
4+
5+
Local content.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { test, expect } from "@playwright/test";
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");
6+
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+
);
11+
12+
await expect(externalLink.first()).toHaveAttribute("target", "_blank");
13+
});
14+
15+
test("External listing item has rel=noopener attribute", async ({ page }) => {
16+
await page.goto("./listings/external-links/_site/index.html");
17+
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+
);
22+
23+
await expect(externalLink.first()).toHaveAttribute("rel", "noopener");
24+
});
25+
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");
30+
31+
// Wait for the listing to be visible
32+
await page.waitForSelector(".quarto-listing-default");
33+
34+
// Find the link to the local post by its text content
35+
const internalLink = page.getByRole("link", { name: "Local Post" }).first();
36+
37+
// Verify the link exists
38+
await expect(internalLink).toBeVisible();
39+
40+
// Internal links should not have target="_blank"
41+
await expect(internalLink).not.toHaveAttribute("target", "_blank");
42+
});
43+
});

0 commit comments

Comments
 (0)