Initial commit - Route Commerce platform
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// Login flow: credentials → /api/login JSON → redirect to /admin
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
test("login with valid credentials redirects to /admin and shows admin dashboard", async ({
|
||||
page,
|
||||
}) => {
|
||||
// Navigate to login page
|
||||
await page.goto("/login");
|
||||
|
||||
// Fill credentials
|
||||
await page.fill("#email", process.env.TEST_ADMIN_EMAIL!);
|
||||
await page.fill("#password", process.env.TEST_ADMIN_PASSWORD!);
|
||||
|
||||
// Submit form
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Wait for navigation to /admin — the JSON response + client nav must happen
|
||||
await page.waitForURL("**/admin", { timeout: 10000 });
|
||||
|
||||
// Admin dashboard must be rendered (Control Center heading or admin layout)
|
||||
await expect(page.locator("body")).not.toContainText("Access Denied");
|
||||
await expect(page.locator("body")).not.toContainText("Login failed");
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// Login failure: bad password shows error, stays on /login
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
test("login with wrong password shows error and stays on /login", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/login");
|
||||
|
||||
await page.fill("#email", process.env.TEST_ADMIN_EMAIL!);
|
||||
await page.fill("#password", "wrongpassword123!");
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Error message should appear
|
||||
await expect(page.locator('[role="alert"]')).toBeVisible({ timeout: 5000 });
|
||||
// Should NOT navigate away from login
|
||||
await expect(page).toHaveURL(/\/login/);
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// Login with missing fields shows validation error
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
test("login with missing email shows validation error", async ({ page }) => {
|
||||
await page.goto("/login");
|
||||
|
||||
// Don't fill email, only password
|
||||
await page.fill("#password", "something");
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Browser validation should fire (email required)
|
||||
await expect(page.locator("#email")).toHaveAttribute("required", "");
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// Session persistence: after login, navigating to /admin
|
||||
// should load without re-authenticating
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
test("admin session persists across page reloads", async ({ page }) => {
|
||||
// Login first
|
||||
await page.goto("/login");
|
||||
await page.fill("#email", process.env.TEST_ADMIN_EMAIL!);
|
||||
await page.fill("#password", process.env.TEST_ADMIN_PASSWORD!);
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForURL("**/admin", { timeout: 10000 });
|
||||
|
||||
// Reload the page
|
||||
await page.reload();
|
||||
|
||||
// Should still be on /admin (session cookie keeps user logged in)
|
||||
await expect(page).toHaveURL(/\/admin/);
|
||||
await expect(page.locator("body")).not.toContainText("Access Denied");
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
const BASE = process.env.PLAYWRIGHT_URL ?? "http://localhost:3000";
|
||||
|
||||
test.describe("Smoke Tests", () => {
|
||||
test("Login — dev_session platform_admin lands on admin dashboard", async ({ page }) => {
|
||||
await page.context().addCookies([
|
||||
{ name: "dev_session", value: "platform_admin", domain: "localhost", path: "/" },
|
||||
]);
|
||||
|
||||
await page.goto(`${BASE}/admin`);
|
||||
await expect(page).toHaveURL(/\/admin/, { timeout: 5000 });
|
||||
|
||||
// Admin sidebar nav should be loaded (sidebar is rendered by layout)
|
||||
await expect(page.locator("aside").first()).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
test("Admin Settings — page loads", async ({ page }) => {
|
||||
await page.context().addCookies([
|
||||
{ name: "dev_session", value: "platform_admin", domain: "localhost", path: "/" },
|
||||
]);
|
||||
|
||||
await page.goto(`${BASE}/admin/settings`);
|
||||
|
||||
// Wait for redirect to complete (may go to /login first)
|
||||
await page.waitForURL(/\/admin\/settings/, { timeout: 10000 });
|
||||
|
||||
// Page renders without crash — main content area should exist
|
||||
await expect(page.locator("main").first()).toBeVisible({ timeout: 8000 });
|
||||
});
|
||||
|
||||
test("Time Tracking — page loads", async ({ page }) => {
|
||||
await page.context().addCookies([
|
||||
{ name: "dev_session", value: "platform_admin", domain: "localhost", path: "/" },
|
||||
]);
|
||||
|
||||
await page.goto(`${BASE}/admin/time-tracking`);
|
||||
await expect(page).toHaveURL(/\/admin\/time-tracking/, { timeout: 5000 });
|
||||
await expect(page.locator("body")).toBeVisible();
|
||||
});
|
||||
|
||||
test("Tuxedo storefront — homepage loads without console errors", async ({ page }) => {
|
||||
const errors: string[] = [];
|
||||
page.on("console", (msg) => {
|
||||
if (msg.type() === "error") errors.push(msg.text());
|
||||
});
|
||||
|
||||
await page.goto(`${BASE}/tuxedo`);
|
||||
|
||||
// Hero brand name — use a more stable anchor
|
||||
await expect(page.locator("h1").first()).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// "Why Choose" section heading is a strong signal the page rendered correctly
|
||||
await expect(page.getByRole("heading", { name: /why choose/i })).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// No console errors (filter known non-critical)
|
||||
const criticalErrors = errors.filter(
|
||||
(e) => !e.includes("favicon") && !e.includes("Warning:")
|
||||
);
|
||||
expect(criticalErrors).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user