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

73 lines
2.4 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 assets localization", () => {
test("renders asset list and new form UI/status copy in Spanish", async ({
baseURL,
page,
}) => {
await signInAsAdmin(page, baseURL)
await setLocaleCookie(page, "es", baseURL)
await page.goto("/inventory/assets")
await expect(page.locator("html")).toHaveAttribute("lang", "es")
await expect(page.getByRole("heading", { name: "Activos" })).toBeVisible()
await expect(
page.getByRole("link", { name: /Agregar activo/ }),
).toBeVisible()
await expect(page.getByText("No se encontraron activos.")).toBeVisible()
await page.goto("/inventory/assets/new")
await expect(
page.getByRole("heading", { name: "Nuevo activo" }),
).toBeVisible()
await expect(page.getByLabel("Artículo")).toBeVisible()
await expect(page.locator("select#itemId")).toContainText(
"Selecciona un artículo",
)
await expect(page.getByLabel("Número de serie")).toBeVisible()
await expect(page.getByPlaceholder("Número de serie")).toBeVisible()
await expect(page.getByLabel("Albarán")).toBeVisible()
await expect(page.getByPlaceholder("Albarán")).toBeVisible()
await expect(page.getByLabel("Estado")).toBeVisible()
await expect(page.locator("select#status")).toContainText("Disponible")
await expect(page.locator("select#status")).toContainText("Asignado")
await expect(page.locator("option[value='AVAILABLE']")).toHaveText(
"Disponible",
)
await expect(page.locator("option[value='ASSIGNED']")).toHaveText(
"Asignado",
)
await expect(
page.getByRole("button", { name: "Crear activo" }),
).toBeVisible()
await expect(
page.getByRole("button", { name: /Eliminar activo/i }),
).toHaveCount(0)
})
})