From 108f26a3874e5f8649bf4d128aa07c9b35aa6a10 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Fri, 6 Jun 2025 14:18:07 -0700 Subject: Add playwright tests --- tests/index.spec.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/index.spec.ts (limited to 'tests/index.spec.ts') diff --git a/tests/index.spec.ts b/tests/index.spec.ts new file mode 100644 index 0000000..b804a2a --- /dev/null +++ b/tests/index.spec.ts @@ -0,0 +1,48 @@ +import { + test, + expect, + type Locator, + type BrowserContext, +} from "@playwright/test"; + +test.beforeEach(async ({ page }) => { + await page.goto("/"); +}); + +test("has title", async ({ page }) => { + await expect(page).toHaveTitle("Anshul Gupta"); +}); + +test("has header", async ({ page }) => { + let header = page.locator("header"); + await expect(header).toBeVisible(); + await expect(header.locator("div").first()).toHaveText("ANSHUL GUPTA (7)"); + await expect(header.locator("div").last()).toHaveText("ANSHUL GUPTA (7)"); + await expect(header.locator("h1")).toHaveText( + "Miscellaneous Information Manual", + ); +}); + +test("has Email link", async ({ page }) => { + let emailLink = page.getByRole("link", { name: "ansg191@anshulg.com" }); + await expect(emailLink).toBeVisible(); + await expect(emailLink).toHaveText("ansg191@anshulg.com"); + await expect(emailLink).toHaveAttribute("href", "mailto:ansg191@anshulg.com"); +}); + +test("has GitHub link", async ({ page, context }) => { + let ghLink = page.getByRole("link", { name: "ansg191" }).nth(1); + await checkLinkNewTab(context, ghLink, "https://github.com/ansg191"); +}); + +async function checkLinkNewTab( + ctx: BrowserContext, + link: Locator, + expUrl: string, +) { + const pagePromise = ctx.waitForEvent("page"); + await expect(link).toBeVisible(); + await link.click(); + const newPage = await pagePromise; + await expect(newPage).toHaveURL(expUrl); +} -- cgit v1.2.3