Files
QuantEngineByItz/oms-wms-erp/tests/e2e/authentication.spec.ts
T
kjh2064 b34b0dd7d6
Validators (Pushes and Pull Requests) / UI & Storage Validation (pull_request) Failing after 12s
Validators (Pushes and Pull Requests) / Database & Schema Validation (pull_request) Successful in 13s
Validators (Pushes and Pull Requests) / Core Validators & Database Setup (pull_request) Failing after 28s
Validators (Pushes and Pull Requests) / WBS & Audit Validations (pull_request) Has been skipped
Validators (Pushes and Pull Requests) / .NET Contracts (pull_request) Has been skipped
Validators (Pushes and Pull Requests) / Calibration & Performance (pull_request) Has been skipped
Validators (Pushes and Pull Requests) / Operational Report & Decision Packet (pull_request) Has been skipped
Validators (Pushes and Pull Requests) / CI Workflow Lint (pull_request) Failing after 10s
Validators (Pushes and Pull Requests) / Security & Secrets (pull_request) Successful in 12s
Validators (Pushes and Pull Requests) / Notify PR Results (pull_request) Successful in 2s
Frontend CI Pipeline / ci-frontend-8-steps (pull_request) Failing after 2m50s
Add OMS WMS ERP platform
2026-07-27 00:45:39 +09:00

113 lines
3.8 KiB
TypeScript

import { test, expect } from "@playwright/test"
test.describe("Authentication System", () => {
test("Redirect to login when not authenticated", async ({ page }) => {
// Try to access admin page without login
await page.goto("http://localhost:5173/admin/dashboard")
// Should redirect to login
await expect(page).toHaveURL(/login/)
console.log("✅ Not authenticated users redirected to login")
})
test("Login with valid credentials", async ({ page }) => {
// Go to login page
await page.goto("http://localhost:5173/login")
// Fill login form
await page.fill("input[type='text']", "admin")
await page.fill("input[type='password']", "password")
// Submit
await page.click("button[type='submit']")
// Should redirect to dashboard
await page.waitForURL(/admin\/dashboard/, { timeout: 5000 })
console.log("✅ Login successful")
// Check if dashboard loads
const dashboard = await page.locator("h1, .dashboard-title").first().isVisible().catch(() => false)
console.log("✅ Dashboard visible after login")
})
test("Access admin pages after login", async ({ page }) => {
// Login first
await page.goto("http://localhost:5173/login")
await page.fill("input[type='text']", "admin")
await page.fill("input[type='password']", "password")
await page.click("button[type='submit']")
await page.waitForURL(/admin\/dashboard/)
// Check sidebar is visible
const sidebar = await page.locator(".sidebar").isVisible()
expect(sidebar).toBeTruthy()
console.log("✅ Sidebar visible")
// Check user info in sidebar
const userInfo = await page.locator(".user-info").isVisible()
expect(userInfo).toBeTruthy()
console.log("✅ User info displayed in sidebar")
// Check logout button
const logoutBtn = await page.locator(".logout-btn").isVisible()
expect(logoutBtn).toBeTruthy()
console.log("✅ Logout button visible")
// Navigate to Orders page
await page.click("text=Orders")
await page.waitForURL(/admin\/orders/)
console.log("✅ Can navigate to Orders page")
// Navigate to Products page
await page.click("text=Products")
await page.waitForURL(/admin\/products/)
console.log("✅ Can navigate to Products page")
})
test("Logout functionality", async ({ page }) => {
// Login first
await page.goto("http://localhost:5173/login")
await page.fill("input[type='text']", "admin")
await page.fill("input[type='password']", "password")
await page.click("button[type='submit']")
await page.waitForURL(/admin\/dashboard/)
// Register dialog handler BEFORE clicking logout (timing-critical)
page.once("dialog", async (dialog) => {
console.log(`Dialog: ${dialog.message()}`)
await dialog.accept()
})
// Click logout
await page.click(".logout-btn")
// Should redirect to login
await page.waitForURL(/login/, { timeout: 5000 })
console.log("✅ Logout successful")
})
test("Session persistence", async ({ page, context }) => {
// Login
await page.goto("http://localhost:5173/login")
await page.fill("input[type='text']", "admin")
await page.fill("input[type='password']", "password")
await page.click("button[type='submit']")
await page.waitForURL(/admin\/dashboard/)
// Check localStorage
const token = await page.evaluate(() => localStorage.getItem("auth-token"))
expect(token).toBeTruthy()
console.log("✅ Auth token stored in localStorage")
// Open new page in same context (shares storage)
const page2 = await context.newPage()
await page2.goto("http://localhost:5173/admin/dashboard")
// Should be authenticated
await expect(page2).toHaveURL(/admin\/dashboard/)
console.log("✅ Session persists across pages")
await page2.close()
})
})