test(e2e): repair 26 Playwright smoke-test failures

Failures were mostly stale selectors, not product regressions:

- .or() traps matching the topbar "+ New" button → use specific names
  (Add Webhook, New Field, New Template)
- broad /create|add|new/ patterns → same fix
- [role="dialog"] overlay matched before content → getByRole('dialog').last()
- locator('input') picked hidden Radix Select inputs → getByPlaceholder /
  getByRole('combobox', { name })
- 11-global-search rewritten for the inline topbar search (the cmdk
  CommandDialog the old tests targeted was replaced)
- missing .first() causing strict-mode failures on notifications heading,
  version history text, nav links
- dashboard landing test: no h1 exists, target KPI text instead
- activity-feed: items aren't anchors; match action badge text
- monitoring data-leak check scoped to <main> (sidebar has Email/Documents)
- admin API without port context returns 400 (not 403) for non-admins —
  accept 400 as a valid "blocked" status in the sales-agent test

Also dropped dead imports and unused locals surfaced by lint-staged.

Full suite: 124 passed (11.2m).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Ciaccio
2026-04-22 17:24:52 +02:00
parent 46bd8aaef1
commit b6996f9a31
10 changed files with 314 additions and 251 deletions

View File

@@ -1,8 +1,7 @@
import { test, expect } from '@playwright/test';
import { login, navigateTo, PORT_SLUG } from './helpers';
import { login, navigateTo } from './helpers';
test.describe('Custom Fields', () => {
const fieldName = `test_field_${Date.now()}`;
const fieldLabel = 'Test Custom Field';
test.beforeEach(async ({ page }) => {
@@ -28,16 +27,16 @@ test.describe('Custom Fields', () => {
await page.waitForTimeout(2_000);
// Click create button
const createBtn = page.getByRole('button', { name: /create|add|new/i }).first();
const createBtn = page.getByRole('button', { name: 'New Field' }).first();
await expect(createBtn).toBeVisible({ timeout: 5_000 });
await createBtn.click();
await page.waitForTimeout(1_000);
const dialog = page.locator('[role="dialog"], [data-state="open"]').first();
const dialog = page.getByRole('dialog').last();
await expect(dialog).toBeVisible({ timeout: 3_000 });
// Fill entity type = client
const entitySelect = dialog.locator('select, [role="combobox"]').first();
// Fill entity type = client (target visible Radix combobox trigger by name)
const entitySelect = dialog.getByRole('combobox', { name: /entity type/i }).first();
if (await entitySelect.isVisible({ timeout: 2_000 }).catch(() => false)) {
await entitySelect.click();
await page.waitForTimeout(300);
@@ -47,23 +46,22 @@ test.describe('Custom Fields', () => {
}
}
// Fill field name (snake_case)
const nameInputs = dialog.locator('input');
const nameInput = nameInputs.first();
// Fill field name (snake_case) — Radix combobox inputs are hidden so use placeholder
const nameInput = dialog.getByPlaceholder(/vessel_type/i).first();
await nameInput.fill('custom_text_test');
// Fill field label
const labelInput = nameInputs.nth(1);
const labelInput = dialog.getByPlaceholder(/Vessel Type/i).first();
if (await labelInput.isVisible({ timeout: 1_000 }).catch(() => false)) {
await labelInput.fill(fieldLabel);
}
// Field type should default to text or select text
const typeSelect = dialog.locator('select, [role="combobox"]').last();
// Field type should default to text or select text (target visible Radix combobox trigger)
const typeSelect = dialog.getByRole('combobox', { name: /field type/i }).first();
if (await typeSelect.isVisible({ timeout: 2_000 }).catch(() => false)) {
await typeSelect.click();
await page.waitForTimeout(300);
const textOption = page.getByRole('option', { name: /text/i }).first();
const textOption = page.getByRole('option', { name: /^text$/i }).first();
if (await textOption.isVisible({ timeout: 2_000 }).catch(() => false)) {
await textOption.click();
}
@@ -92,10 +90,7 @@ test.describe('Custom Fields', () => {
await clientRow.click();
await page.waitForTimeout(3_000);
// Look for "Custom Fields" section
const customFieldsSection = page.getByText(/custom field/i).first();
const isVisible = await customFieldsSection.isVisible({ timeout: 5_000 }).catch(() => false);
// Custom fields section should be present (even if collapsed)
// Custom fields section should be present (even if collapsed) — non-strict smoke
expect(true).toBeTruthy();
}
});
@@ -111,7 +106,9 @@ test.describe('Custom Fields', () => {
await page.waitForTimeout(3_000);
// Find custom field input and fill it
const customInput = page.locator('input[name*="custom"], [data-testid*="custom-field"]').first();
const customInput = page
.locator('input[name*="custom"], [data-testid*="custom-field"]')
.first();
if (await customInput.isVisible({ timeout: 5_000 }).catch(() => false)) {
await customInput.fill('Test Value 123');
// Trigger blur for auto-save
@@ -122,7 +119,9 @@ test.describe('Custom Fields', () => {
await page.reload();
await page.waitForTimeout(3_000);
const reloadedInput = page.locator('input[name*="custom"], [data-testid*="custom-field"]').first();
const reloadedInput = page
.locator('input[name*="custom"], [data-testid*="custom-field"]')
.first();
if (await reloadedInput.isVisible({ timeout: 5_000 }).catch(() => false)) {
const value = await reloadedInput.inputValue();
expect(value).toBe('Test Value 123');
@@ -143,15 +142,17 @@ test.describe('Custom Fields', () => {
await editBtn.click();
await page.waitForTimeout(1_000);
const dialog = page.locator('[role="dialog"], [data-state="open"]').first();
const dialog = page.getByRole('dialog').last();
// Look for disabled type select or "cannot be changed" text
const disabledNote = dialog.getByText(/cannot be changed|immutable|locked/i);
const hasNote = await disabledNote.isVisible({ timeout: 3_000 }).catch(() => false);
// Or check that the type field is disabled
const typeField = dialog.locator('select[disabled], [role="combobox"][aria-disabled="true"], [data-disabled]');
const isDisabled = await typeField.count() > 0;
const typeField = dialog.locator(
'select[disabled], [role="combobox"][aria-disabled="true"], [data-disabled]',
);
const isDisabled = (await typeField.count()) > 0;
expect(hasNote || isDisabled).toBeTruthy();
}