Files
stock-manager/tests/e2e/inventory-items.spec.ts
T

60 lines
1.8 KiB
TypeScript

import { expect, type Page, test } from "@playwright/test"
async function setLocaleCookie(
page: Page,
locale: "en" | "es",
baseURL?: string,
) {
await page.context().addCookies([
{
name: "stock-manager-locale",
value: locale,
url: baseURL ?? "http://127.0.0.1:3100",
},
])
}
async function signInAsAdmin(page: Page, baseURL?: string) {
await setLocaleCookie(page, "en", baseURL)
await page.goto("/login")
await page.getByLabel("Username").fill("admin")
await page.getByLabel("Password").fill("admin-password")
await page.getByRole("button", { name: "Sign In" }).click()
await expect(page).toHaveURL("/")
}
test.describe("inventory items localization", () => {
test("renders item list and new form UI copy in Spanish", async ({
baseURL,
page,
}) => {
await signInAsAdmin(page, baseURL)
await setLocaleCookie(page, "es", baseURL)
await page.goto("/inventory/items")
await expect(page.locator("html")).toHaveAttribute("lang", "es")
await expect(page.getByRole("heading", { name: "Artículos" })).toBeVisible()
await expect(
page.getByRole("link", { name: /Agregar artículo/ }),
).toBeVisible()
await expect(page.getByText("No se encontraron artículos.")).toBeVisible()
await page.goto("/inventory/items/new")
await expect(
page.getByRole("heading", { name: "Nuevo artículo" }),
).toBeVisible()
await expect(page.getByLabel("Nombre")).toBeVisible()
await expect(page.getByPlaceholder("Nombre del artículo")).toBeVisible()
await expect(page.getByLabel("Categoría")).toBeVisible()
await expect(page.locator("select#categoryId")).toContainText(
"Selecciona una categoría",
)
await expect(page.getByLabel("Stock")).toBeVisible()
await expect(
page.getByRole("button", { name: "Crear artículo" }),
).toBeVisible()
})
})