|
| 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