57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
|
|
import { test, expect, type Page } from "@playwright/test";
|
|||
|
|
|
|||
|
|
const BASE = "http://localhost:3000";
|
|||
|
|
|
|||
|
|
// Collects browser console errors and page errors for the duration of a test.
|
|||
|
|
function trackErrors(page: Page): string[] {
|
|||
|
|
const errors: string[] = [];
|
|||
|
|
page.on("console", (msg) => {
|
|||
|
|
if (msg.type() === "error") {
|
|||
|
|
errors.push(msg.text());
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
page.on("pageerror", (err) => {
|
|||
|
|
errors.push(String(err));
|
|||
|
|
});
|
|||
|
|
return errors;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
test("home page: campaign name, version, nav", async ({ page }) => {
|
|||
|
|
const errors = trackErrors(page);
|
|||
|
|
await page.goto(`${BASE}/`);
|
|||
|
|
|
|||
|
|
await expect(page.locator("#campaign-name")).toHaveValue("В Поисках Дмитрия Шардалина");
|
|||
|
|
await expect(page.locator(".version")).toContainText("aex");
|
|||
|
|
await expect(page.locator(".main-nav a")).toHaveCount(3);
|
|||
|
|
await expect(page.locator(".main-nav")).toContainText("Персонаж");
|
|||
|
|
await expect(page.locator(".main-nav")).toContainText("Инвентарь");
|
|||
|
|
await expect(page.locator(".main-nav")).toContainText("Информация");
|
|||
|
|
|
|||
|
|
expect(errors).toEqual([]);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
test("inventories page: personal and common sections", async ({ page }) => {
|
|||
|
|
const errors = trackErrors(page);
|
|||
|
|
await page.goto(`${BASE}/inv`);
|
|||
|
|
|
|||
|
|
await expect(page.locator(".inventory-personal")).toHaveCount(1);
|
|||
|
|
await expect(page.locator(".inventory-common")).toHaveCount(1);
|
|||
|
|
// each section has one balance block with five currency inputs
|
|||
|
|
await expect(page.locator(".inventory-personal .balance .numput")).toHaveCount(5);
|
|||
|
|
await expect(page.locator(".inventory-common .balance .numput")).toHaveCount(5);
|
|||
|
|
// and at least one item row each
|
|||
|
|
await expect(page.locator(".inventory-personal .item").first()).toBeVisible();
|
|||
|
|
await expect(page.locator(".inventory-common .item").first()).toBeVisible();
|
|||
|
|
|
|||
|
|
expect(errors).toEqual([]);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
test("wiki page: stub renders", async ({ page }) => {
|
|||
|
|
const errors = trackErrors(page);
|
|||
|
|
await page.goto(`${BASE}/wiki`);
|
|||
|
|
|
|||
|
|
await expect(page.locator("body")).toContainText("books");
|
|||
|
|
|
|||
|
|
expect(errors).toEqual([]);
|
|||
|
|
});
|