import { expect, test } from '@playwright/test'; const username = process.env.TEST_USERNAME; const password = process.env.TEST_PASSWORD; // Lightweight fixture: every test starts logged in as an admin. test.beforeEach(async ({ page }) => { test.skip(!username || !password, 'TEST_USERNAME/TEST_PASSWORD not set'); await page.goto('/login'); await page.getByLabel(/username/i).fill(username!); await page.getByLabel(/password/i).fill(password!); await page.getByRole('button', { name: /sign in|log in/i }).click(); await expect(page).toHaveURL(/\/(?!login)/, { timeout: 10_000 }); }); test.describe('parts', () => { test('lists parts with working search', async ({ page }) => { await page.goto('/parts'); await expect(page.getByRole('heading', { name: /parts/i })).toBeVisible(); const search = page.getByPlaceholder(/search/i); if (await search.count()) { await search.fill('nonexistent-serial-xxxxxxx'); // Search debounces — give it a beat. await page.waitForTimeout(600); await expect(page.getByText(/no parts|no results|empty/i).first()).toBeVisible(); } }); test('opens the create part dialog', async ({ page }) => { await page.goto('/parts'); const newBtn = page.getByRole('button', { name: /new part|add part|\+ part/i }).first(); if (await newBtn.count()) { await newBtn.click(); await expect(page.getByRole('dialog')).toBeVisible(); } }); });