Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carsakiller committed Jul 15, 2024
1 parent 52f84bf commit 4ec04d9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default defineConfig({

/* Run your local dev server before starting the tests */
webServer: {
command: "npm run preview",
command: "pnpm preview",
url: "http://localhost:4321/",
timeout: 60 * 1000,
reuseExistingServer: !process.env.CI,
Expand Down
8 changes: 4 additions & 4 deletions src/layouts/WikiArticle.astro
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export interface Props {
<Layout title="Wiki" transition={true} displayFooter={false}>
<div class="columns">
<aside id="article-browser" class="sidebar">
<button class="open"><Icon name="newspaper" group="solid" /></button>
<button class="close"><Icon name="x" group="solid" /></button>
<button class="open"><Icon name="newspaper" group="solid" ariaLabel="Open article browser"/></button>
<button class="close"><Icon name="x" group="solid" ariaLabel="Close article browser" /></button>
<h2 class="title">Articles</h2>
<div class="content">
<nav>
Expand Down Expand Up @@ -91,8 +91,8 @@ export interface Props {
<Footer />
</div>
<aside id="outline" class="sidebar">
<button class="open"><Icon name="list" group="solid" /></button>
<button class="close"><Icon name="x" group="solid" /></button>
<button class="open"><Icon name="list" group="solid" ariaLabel="Open outline"/></button>
<button class="close"><Icon name="x" group="solid" ariaLabel="Close outline" /></button>
<h2 class="title">Outline</h2>
<nav class="content">
<ol>
Expand Down
13 changes: 8 additions & 5 deletions src/test/header.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { test, expect } from "@playwright/test";
import { test, expect, type Locator } from "@playwright/test";

test.describe("Header", () => {
let header: Locator;

test.beforeEach(async ({ page }) => {
await page.goto("/wiki/");
header = page.getByRole("banner")
});

test("Exists", async ({ page }) => {
await expect(page.getByRole("banner")).toBeVisible();
await expect(header).toBeVisible();
});

test("Home Link", async ({ page, baseURL }) => {
await page.getByRole("link", { name: "house" }).click();
await header.getByRole("link", { name: "home" }).click();
expect(page.url()).toBe(baseURL);
});

test("Wiki Link", async ({ page, baseURL }) => {
await page.getByRole("link", { name: "book" }).click();
await header.getByRole("link", {name: "wiki"}).click();
await page.waitForURL("/wiki/");
expect(page.url()).toBe(baseURL + "wiki/");
});

test("GitHub Link", async ({ page, context }) => {
const href = await page
const href = await header
.getByRole("link", { name: "github" })
.getAttribute("href");
expect(href).toBe("https://github.com/luals/lua-language-server");
Expand Down
2 changes: 1 addition & 1 deletion src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test.describe("Home Page", () => {
}
);

await page.goto("/", { waitUntil: "load", timeout: 3000 });
await page.goto("/", { waitUntil: "load" });
});

test("Metadata", async ({ page }) => {
Expand Down
34 changes: 18 additions & 16 deletions src/test/wiki_article.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import { test, expect } from "@playwright/test";

test.describe("Wiki Article", async () => {
test.beforeEach(async ({ page }) => {
await page.goto("/wiki/build/");
await page.goto("/wiki/diagnosis-report/");
});

test("Header Exists", async ({ page }) => {
await expect(page.getByRole("banner")).toBeVisible();
});

test("Article Loads", async ({ page }) => {
await expect(page.getByRole("heading", { name: "Build" })).toBeVisible();
await expect(
page.getByRole("heading", { name: "Diagnosis Report" })
).toBeVisible();
await expect(
page.getByText(
"Instructions for building the Lua Language Server from source."
"Generate a report containing diagnostics usually received by an LSP client."
)
).toBeVisible();
await expect(page.getByText("Last Modified:")).toBeVisible();
Expand All @@ -25,31 +27,31 @@ test.describe("Wiki Article", async () => {
test("Article Sidebar", async ({ page }) => {
const sidebar = page.locator("#article-browser");

await page.getByRole("button", { name: "newspaper" }).click();
await page.getByRole("button", { name: "Open article browser" }).click();
expect(await sidebar.getAttribute("open")).toBe("");

await sidebar.getByRole("button", { name: "x" }).click();
expect(await sidebar.getAttribute("open")).toBe(null);

await page.getByRole("button", { name: "newspaper" }).click();
const link = page.getByRole("link", { name: "Usage" });
const href = await link.getAttribute("href");
expect(href).toBe(`/wiki/usage/`);

await sidebar
.getByRole("button", { name: "Close article browser" })
.click();
expect(await sidebar.getAttribute("open")).toBe(null);
});

test("Outline Sidebar", async ({ page }) => {
const sidebar = page.locator("#outline");

await page.getByRole("button", { name: "list" }).click();
await page.getByRole("button", { name: "Open outline" }).click();
expect(await sidebar.getAttribute("open")).toBe("");

await sidebar.getByRole("button", { name: "x" }).click();
expect(await sidebar.getAttribute("open")).toBe(null);

await page.getByRole("button", { name: "list" }).click();
const link = sidebar.getByRole("link", { name: "Build" });
const link = sidebar.getByRole("link", { name: "Diagnosis Report" });
const href = await link.getAttribute("href");
expect(href).toBe(`#build`);
expect(href).toBe(`#diagnosis-report`);

await sidebar.getByRole("button", { name: "Close outline" }).click();
expect(await sidebar.getAttribute("open")).toBe(null);
});

test("Edit Page Button", async ({ page }) => {
Expand All @@ -58,7 +60,7 @@ test.describe("Wiki Article", async () => {

const href = await link.getAttribute("href");
expect(href).toBe(
"https://github.com/LuaLS/LuaLS.github.io/tree/main/src/content/wiki/build.mdx"
"https://github.com/LuaLS/LuaLS.github.io/tree/main/src/content/wiki/diagnosis-report.mdx"
);
});

Expand Down

0 comments on commit 4ec04d9

Please sign in to comment.