Saving more code clean up and removal
This commit is contained in:
@@ -32,7 +32,7 @@ Shared test helpers (`tests/_helpers/`)
|
||||
| `env.ts` | Constants: `testing_event_id`, `testing_account_id`, `mock_site_domain` |
|
||||
| `ae_defaults.ts` | `ae_app_local_data_defaults` — full localStorage seed object with `__version` |
|
||||
| `idb_helpers.ts` | `inject_badge_and_template()` — write badge + template records into IndexedDB |
|
||||
| `minimal_v3_mocks.ts` | `attach_minimal_v3_routes()`, `seed_trusted_session()`, `setup_badge_test_page()` |
|
||||
| `minimal_ae_api_mocks.ts` | `attach_minimal_routes()`, `seed_trusted_session()`, `setup_badge_test_page()` |
|
||||
|
||||
**`setup_badge_test_page(page, event_id)`** is the one-call `beforeEach` for any badge/event print page test. It wires the pageerror listener, all V3 API mocks, and the trusted auth localStorage seed in one call.
|
||||
|
||||
@@ -44,7 +44,7 @@ Writing / modifying tests
|
||||
```ts
|
||||
import { testing_event_id } from './_helpers/env';
|
||||
import { inject_badge_and_template } from './_helpers/idb_helpers'; // only if IDB needed
|
||||
import { setup_badge_test_page } from './_helpers/minimal_v3_mocks';
|
||||
import { setup_badge_test_page } from './_helpers/minimal_ae_api_mocks';
|
||||
|
||||
const event_id = testing_event_id;
|
||||
|
||||
@@ -54,7 +54,7 @@ test.beforeEach(async ({ page }) => {
|
||||
```
|
||||
|
||||
- If you need IDB data (badge, template), use the inject-then-reload pattern (see Hard-Won Lessons below).
|
||||
- Use `page.route('**/v3/**', handler)` to mock backend responses. `attach_minimal_v3_routes` covers the common cases; add inline `page.route()` calls only for test-specific overrides.
|
||||
- Use `page.route('**/v3/**', handler)` to mock backend responses. `attach_minimal_routes` covers the common cases; add inline `page.route()` calls only for test-specific overrides.
|
||||
|
||||
Adding new tests
|
||||
- Create a new file `tests/my_feature.test.ts`.
|
||||
|
||||
@@ -17,7 +17,7 @@ export const testing_person_id = 'QWODAPCNLQU'; // (49) "Osiris Idem"
|
||||
|
||||
/**
|
||||
* Mock site_domain object for Playwright tests.
|
||||
* Matches the structure expected by +layout.ts lookup_site_domain_v3()
|
||||
* Matches the structure expected by +layout.ts lookup_site_domain()
|
||||
*/
|
||||
export const mock_site_domain = {
|
||||
id: testing_site_domain_id,
|
||||
|
||||
@@ -29,7 +29,7 @@ export const minimal_badge = (overrides: Record<string, any> = {}) => ({
|
||||
* - Responds to event GET, badge search/create/update/delete, and a simple site_domain/search.
|
||||
* - Keeps created badge state in-memory for the page session.
|
||||
*/
|
||||
export async function attach_minimal_v3_routes(page: Page, event_id: string) {
|
||||
export async function attach_minimal_routes(page: Page, event_id: string) {
|
||||
let created_badge: any = null;
|
||||
|
||||
await page.route('**/v3/**', async (route) => {
|
||||
@@ -112,13 +112,13 @@ export async function seed_trusted_session(
|
||||
*
|
||||
* Wires:
|
||||
* - page.on('pageerror') → stderr
|
||||
* - attach_minimal_v3_routes() — mock all /v3/ API calls
|
||||
* - attach_minimal_routes() — mock all /v3/ API calls
|
||||
* - seed_trusted_session() — seed ae_loc localStorage with trusted auth
|
||||
*/
|
||||
export async function setup_badge_test_page(page: Page, event_id: string): Promise<void> {
|
||||
page.on('pageerror', (err) => console.error(`BROWSER ERROR: ${err.message}`));
|
||||
await attach_minimal_v3_routes(page, event_id);
|
||||
await attach_minimal_routes(page, event_id);
|
||||
await seed_trusted_session(page, event_id);
|
||||
}
|
||||
|
||||
export default { minimal_event, minimal_badge, attach_minimal_v3_routes, seed_trusted_session, setup_badge_test_page };
|
||||
export default { minimal_event, minimal_badge, attach_minimal_routes, seed_trusted_session, setup_badge_test_page };
|
||||
@@ -13,7 +13,7 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { testing_event_id } from './_helpers/env';
|
||||
import { inject_badge_and_template } from './_helpers/idb_helpers';
|
||||
import { setup_badge_test_page } from './_helpers/minimal_v3_mocks';
|
||||
import { setup_badge_test_page } from './_helpers/minimal_ae_api_mocks';
|
||||
|
||||
const event_id = testing_event_id;
|
||||
const badge_id = 'UIJT-73-63-61';
|
||||
@@ -56,7 +56,7 @@ const mock_template = {
|
||||
test.describe('Badge Print Page — attendee print workflow', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await setup_badge_test_page(page, event_id);
|
||||
// attach_minimal_v3_routes (inside setup_badge_test_page) already handles
|
||||
// attach_minimal_routes (inside setup_badge_test_page) already handles
|
||||
// badge PATCH — returns { data: null } but tests only inspect the request body.
|
||||
});
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { testing_event_id } from './_helpers/env';
|
||||
import { inject_badge_and_template } from './_helpers/idb_helpers';
|
||||
import { setup_badge_test_page } from './_helpers/minimal_v3_mocks';
|
||||
import { setup_badge_test_page } from './_helpers/minimal_ae_api_mocks';
|
||||
|
||||
const event_id = testing_event_id;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { testing_event_id } from './_helpers/env';
|
||||
import { inject_badge_and_template } from './_helpers/idb_helpers';
|
||||
import { setup_badge_test_page } from './_helpers/minimal_v3_mocks';
|
||||
import { setup_badge_test_page } from './_helpers/minimal_ae_api_mocks';
|
||||
|
||||
const event_id = testing_event_id;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { testing_event_id } from './_helpers/env';
|
||||
import { setup_badge_test_page } from './_helpers/minimal_v3_mocks';
|
||||
import { setup_badge_test_page } from './_helpers/minimal_ae_api_mocks';
|
||||
|
||||
const event_id = testing_event_id;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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 { attach_minimal_routes } from './_helpers/minimal_ae_api_mocks';
|
||||
|
||||
const event_id = testing_event_id;
|
||||
|
||||
@@ -12,7 +12,7 @@ test.describe('Event Presenter Page - smoke', () => {
|
||||
if (msg.type() === 'error' || msg.type() === 'warning') console.error(`BROWSER [${msg.type().toUpperCase()}]: ${msg.text()}`);
|
||||
});
|
||||
|
||||
await attach_minimal_v3_routes(page, event_id);
|
||||
await attach_minimal_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;
|
||||
|
||||
Reference in New Issue
Block a user