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:
@@ -23,9 +23,9 @@
|
||||
* Standard fanfold badges are two-sided. Confirms the default is duplex-on.
|
||||
*/
|
||||
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;
|
||||
|
||||
@@ -80,41 +80,7 @@ function make_template(template_id: string, overrides: Record<string, any> = {})
|
||||
|
||||
test.describe('Badge Render — content and visibility', () => {
|
||||
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: {},
|
||||
}}) });
|
||||
}
|
||||
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);
|
||||
});
|
||||
|
||||
test('full_name_override renders in preference to full_name', async ({ page }) => {
|
||||
|
||||
Reference in New Issue
Block a user