refactor: extract seed_trusted_session + setup_badge_test_page into shared test helpers

All 4 badge test files had identical ~35-line beforeEach blocks (pageerror listener,
inline V3 route mocks, addInitScript localStorage seed). Replaced with two helpers
in minimal_v3_mocks.ts:

  seed_trusted_session(page, event_id, account_id?)
    — seeds ae_loc localStorage with trusted/manager auth via addInitScript;
      account_id defaults to testing_account_id

  setup_badge_test_page(page, event_id)
    — one-call beforeEach: pageerror listener + attach_minimal_v3_routes +
      seed_trusted_session

Each test file's beforeEach is now 1-3 lines. All 12 tests still pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-03-18 17:05:22 -04:00
parent 7f17b3b9a1
commit 81741919a8
5 changed files with 62 additions and 130 deletions

View File

@@ -1,24 +1,15 @@
import { test, expect } from '@playwright/test';
import { ae_app_local_data_defaults } from './_helpers/ae_defaults';
import { testing_event_id, testing_account_id } from './_helpers/env';
import { attach_minimal_v3_routes } from './_helpers/minimal_v3_mocks';
import { testing_event_id } from './_helpers/env';
import { setup_badge_test_page } from './_helpers/minimal_v3_mocks';
const event_id = testing_event_id;
test.describe('Event Badge — smoke', () => {
test.beforeEach(async ({ page }) => {
page.on('pageerror', (err) => console.error(`BROWSER ERROR: ${err.message}`));
page.on('console', (msg) => {
if (msg.type() === 'error' || msg.type() === 'warning') console.error(`BROWSER [${msg.type().toUpperCase()}]: ${msg.text()}`);
});
await attach_minimal_v3_routes(page, event_id);
await page.addInitScript(([defaults, event_id, account_id]) => {
const test_data = { ...defaults, account_id: account_id, manager_access: true } as any;
test_data.mod = { ...defaults.mod, events: { ...defaults.mod.events, event_id } };
window.localStorage.setItem('ae_loc', JSON.stringify(test_data));
}, [ae_app_local_data_defaults, event_id, testing_account_id] as const);
await setup_badge_test_page(page, event_id);
});
test('loads badges list without console errors', async ({ page }) => {