Files
OSIT-AE-App-Svelte/tests/coldstart_journal.test.ts
Scott Idem 73597cb8b4 chore: svelte-check cleanup — fix Svelte 5 patterns in events/pres_mgmt, badges, launcher, and tests
Source changes (0 errors, 175 warnings after):
- api_post__crud_obj_v3: add backward-compat migration aliases (for_obj_type/id, obj_type/id) to nested CRUD funcs
- ae_events__event_device/presenter/session: make event_id/presentation_id optional; fall back to store value
- element_ae_obj_field_editor_v3: import type Snippet properly; mark current_value as $bindable()
- ae_comp__badge_obj_view: fix $derived(() => false) → $derived(false) for show_receipt/show_tickets
- badge templates: pass explicit event_id param to delete/update calls
- launcher/+page: capture URL params as stable consts; pass event_id to update_ae_obj__event_device
- ae_comp__event_device_obj_li: wrap setInterval in $effect; onDestroy cleanup always registered
- ae_comp__event_device_obj_li_wrapper: move console.log to $effect; fix self-closing tag
- presenter form/menu/view/list: add missing event_presentation_id to all update/delete calls
- reports/locations/presenter/+page: move store assignments into $effect + untrack; ae_acct → $derived
- session/+page: add Comp_event_presenter_form_agree import; cast for type compat
- session_view: wrap <img onclick> in <button> for accessibility/validity
- ae_comp__event_presentation_obj_li: remove unneeded event_id/session_id from create_ae_obj__event_presenter
- ae_comp__event_session_obj_li: make lq prop optional; add plain-array fallback prop
- location/+page: refactor to $derived ae_acct, $effect+untrack for stores, simplified session/file sections
- location_page_menu: add optional data prop; export interface

Tests:
- Rename ae_events__event_badge.spec.ts → ae_events__event_badge.test.ts (extended coverage)
- All test files: 'warn' → 'warning' (Playwright API), addInitScript array-destructure pattern, import type fixes
- ae_defaults: remove duplicate hide_app_cfg key; meaningful sponsorship cfg_id placeholder
- create_event_badge.spec: fix import path to use $lib alias
- event_presenter.test: fix test URL to use /presenter/:id route

NOTE: location/+page.svelte — Element_manage_event_file_li_wrap no longer receives
allow_basic/allow_moderator (now default false); file list shows but management
actions may be restricted. Follow-up needed to restore auth__kv-based access.
2026-03-05 20:05:35 -05:00

136 lines
5.2 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { ae_app_local_data_defaults } from './_helpers/ae_defaults';
import { testing_account_id } from './_helpers/env';
// Use canonical demo journal id for deterministic tests
const journal_id = 'BVYE-94-46-29'; // Per README test data
test.describe('Cold-start: Journal view (IndexedDB empty)', () => {
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()}`);
});
// Provide app localStorage context (account + journal selection) BEFORE
// any navigation so app scripts see the expected `ae_loc` values.
await page.addInitScript(
({ defaults, account_id, journal_id }) => {
const testData = {
...defaults,
account_id: account_id,
// Administrator mode for tests: ensures trusted/authenticated fallthrough
administrator_access: true,
trusted_access: true,
authenticated_access: true,
manager_access: false,
super_access: false,
edit_mode: true,
// Ensure abstract module prop is present for layout/components
mod_abstracts_json: {},
// Provide a test person id so owner-only pages render in tests
person_id: 'QWODAPCNLQU', // Per README test data
user: { id: 'QWODAPCNLQU' } // Per README test data
};
window.localStorage.setItem('ae_loc', JSON.stringify(testData));
// Also set a lightweight selection object used by pages
window.localStorage.setItem('ae_slct', JSON.stringify({ journal_id: journal_id }));
},
{ defaults: ae_app_local_data_defaults, account_id: testing_account_id, journal_id: journal_id }
);
// Navigate to the app origin so IndexedDB is available in the page
// context, then delete known Dexie DBs to simulate a cold start.
await page.goto('/');
await page.evaluate(() => {
const dbs = [
'ae_journals_db',
'ae_events_db',
'ae_posts_db',
'ae_archives_db',
'ae_core_db'
];
return Promise.all(
dbs.map((name) =>
new Promise((resolve) => {
try {
const req = indexedDB.deleteDatabase(name);
req.onsuccess = () => resolve(true);
req.onerror = () => resolve(false);
req.onblocked = () => resolve(false);
} catch (e) {
resolve(false);
}
})
)
);
});
// Seed IndexedDB with the journal record so local liveQuery finds it
await page.evaluate(({ journal_id }) => {
return new Promise<void>((resolve) => {
try {
const req = indexedDB.open('ae_journals_db', 1);
req.onupgradeneeded = (ev) => {
const db = (ev.target as IDBOpenDBRequest).result;
if (!db.objectStoreNames.contains('journal')) {
db.createObjectStore('journal', { keyPath: 'id' });
}
};
req.onsuccess = () => {
const db = req.result;
const tx = db.transaction('journal', 'readwrite');
const store = tx.objectStore('journal');
// Why are both the id and journal_id fields being set?
store.put({ id: journal_id, journal_id: journal_id, name: 'Demo Journal (Cold Start Test)', description: 'Created for cold-start Playwright test', person_id: 'QWODAPCNLQU' }); // Per README test data
tx.oncomplete = () => {
db.close();
resolve();
};
tx.onerror = () => {
db.close();
resolve();
};
};
req.onerror = () => resolve();
} catch (e) {
resolve();
}
});
}, { journal_id });
// Mock the journal GET endpoint used by the journal page
await page.route('**/v3/**', async (route) => {
const req = route.request();
const url = req.url();
if (url.includes(`/v3/crud/journal/${journal_id}`) && req.method() === 'GET') {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ data: {
id: journal_id, // Why are both the id and journal_id fields being set?
journal_id: journal_id, // Why are both the id and journal_id fields being set?
name: 'Demo Journal (Cold Start Test)',
description: 'Created for cold-start Playwright test'
} })
});
}
// Default: empty envelope
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [] }) });
});
// (already set above)
});
test('renders Journal page without prior IndexedDB cache', async ({ page }) => {
await page.goto(`/journals/${journal_id}`);
// The journal title appears in the journal component header
const journal_name = page.locator('h2.journal__name');
await expect(journal_name).toContainText('Demo Journal (Cold Start Test)', { timeout: 10000 });
});
});