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:
@@ -11,9 +11,9 @@
|
||||
* then interact with the print page controls.
|
||||
*/
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { ae_app_local_data_defaults } from './_helpers/ae_defaults';
|
||||
import { testing_event_id, testing_account_id, mock_site_domain } from './_helpers/env';
|
||||
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';
|
||||
|
||||
const event_id = testing_event_id;
|
||||
const badge_id = 'UIJT-73-63-61';
|
||||
@@ -55,47 +55,9 @@ const mock_template = {
|
||||
|
||||
test.describe('Badge Print Page — attendee print workflow', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
page.on('pageerror', (err) => console.error(`BROWSER ERROR: ${err.message}`));
|
||||
|
||||
await page.route('**/v3/**', async (route) => {
|
||||
const url = route.request().url();
|
||||
const method = route.request().method();
|
||||
|
||||
if (url.includes('site_domain/search')) {
|
||||
return route.fulfill({ status: 200, contentType: 'application/json',
|
||||
body: JSON.stringify({ data: [mock_site_domain] }) });
|
||||
}
|
||||
if (url.includes(`/v3/crud/event/${event_id}`) && !url.includes('event_badge') && method === 'GET') {
|
||||
return route.fulfill({ status: 200, contentType: 'application/json',
|
||||
body: JSON.stringify({ data: {
|
||||
id: event_id, event_id, name: 'Test Event',
|
||||
cfg_json: {}, mod_badges_json: {}, mod_pres_mgmt_json: {},
|
||||
mod_abstracts_json: {}, mod_exhibits_json: {}, mod_meetings_json: {},
|
||||
}}) });
|
||||
}
|
||||
// Badge PATCH — print_count update from the print button
|
||||
if (url.includes(`event_badge/${badge_id}`) && (method === 'PATCH' || method === 'PUT')) {
|
||||
const body = JSON.parse((await route.request().postData()) ?? '{}');
|
||||
return route.fulfill({ status: 200, contentType: 'application/json',
|
||||
body: JSON.stringify({ data: { ...mock_badge, ...body } }) });
|
||||
}
|
||||
return route.fulfill({ status: 200, contentType: 'application/json',
|
||||
body: JSON.stringify({ data: [] }) });
|
||||
});
|
||||
|
||||
await page.addInitScript(([defaults, e_id, a_id]) => {
|
||||
const data = {
|
||||
...defaults,
|
||||
account_id: a_id,
|
||||
allow_access: true,
|
||||
authenticated_access: true,
|
||||
trusted_access: true,
|
||||
manager_access: true,
|
||||
edit_mode: false,
|
||||
} as any;
|
||||
data.mod = { ...defaults.mod, events: { ...defaults.mod.events, event_id: e_id } };
|
||||
window.localStorage.setItem('ae_loc', JSON.stringify(data));
|
||||
}, [ae_app_local_data_defaults, event_id, testing_account_id] as const);
|
||||
await setup_badge_test_page(page, event_id);
|
||||
// attach_minimal_v3_routes (inside setup_badge_test_page) already handles
|
||||
// badge PATCH — returns { data: null } but tests only inspect the request body.
|
||||
});
|
||||
|
||||
test('print page renders badge name from IDB', async ({ page }) => {
|
||||
|
||||
Reference in New Issue
Block a user