test: stabilize cold-start Playwright tests; fix editor bind:new_content fallback
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
let {
|
let {
|
||||||
content = $bindable(''),
|
content = $bindable(''),
|
||||||
new_content = $bindable(''),
|
new_content = $bindable(),
|
||||||
placeholder = 'Start typing...',
|
placeholder = 'Start typing...',
|
||||||
theme_mode = 'light',
|
theme_mode = 'light',
|
||||||
language = 'markdown',
|
language = 'markdown',
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
async function create_editor() {
|
async function create_editor() {
|
||||||
if (!browser) return;
|
if (!browser) return;
|
||||||
|
|
||||||
cm = await ensureCodeMirrorModules();
|
cm = await ensureCodeMirrorModules();
|
||||||
if (!cm) return;
|
if (!cm) return;
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
cm.crosshairCursor(),
|
cm.crosshairCursor(),
|
||||||
cm.highlightActiveLine(),
|
cm.highlightActiveLine(),
|
||||||
cm.highlightActiveLineGutter(),
|
cm.highlightActiveLineGutter(),
|
||||||
|
|
||||||
// Keymaps
|
// Keymaps
|
||||||
cm.keymap.of([
|
cm.keymap.of([
|
||||||
...cm.defaultKeymap,
|
...cm.defaultKeymap,
|
||||||
@@ -178,14 +178,14 @@
|
|||||||
const changes = state.changeByRange((range: any) => {
|
const changes = state.changeByRange((range: any) => {
|
||||||
const line = state.doc.lineAt(range.from);
|
const line = state.doc.lineAt(range.from);
|
||||||
const has_list = line.text.startsWith('- ');
|
const has_list = line.text.startsWith('- ');
|
||||||
|
|
||||||
if (has_list) {
|
if (has_list) {
|
||||||
return {
|
return {
|
||||||
changes: [{ from: line.from, to: line.from + 2, insert: '' }],
|
changes: [{ from: line.from, to: line.from + 2, insert: '' }],
|
||||||
range: cm.EditorSelection.range(range.from - 2, range.to - 2)
|
range: cm.EditorSelection.range(range.from - 2, range.to - 2)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
changes: [{ from: line.from, insert: '- ' }],
|
changes: [{ from: line.from, insert: '- ' }],
|
||||||
range: cm.EditorSelection.range(range.from + 2, range.to + 2)
|
range: cm.EditorSelection.range(range.from + 2, range.to + 2)
|
||||||
@@ -211,15 +211,15 @@
|
|||||||
<button type="button" class="btn btn-sm variant-soft hover:variant-filled-primary" onclick={() => wrap_selection('`')} title="Inline Code">
|
<button type="button" class="btn btn-sm variant-soft hover:variant-filled-primary" onclick={() => wrap_selection('`')} title="Inline Code">
|
||||||
<Code size="14" />
|
<Code size="14" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="ml-auto flex gap-1">
|
<div class="ml-auto flex gap-1">
|
||||||
<span class="text-[10px] opacity-50 self-center uppercase font-bold mr-2">{language}</span>
|
<span class="text-[10px] opacity-50 self-center uppercase font-bold mr-2">{language}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
bind:this={editor_container}
|
bind:this={editor_container}
|
||||||
class="grow overflow-auto bg-white dark:bg-black/20"
|
class="grow overflow-auto bg-white dark:bg-black/20"
|
||||||
style="min-height: 100px;"
|
style="min-height: 100px;"
|
||||||
></div>
|
></div>
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
import { onMount, untrack } from 'svelte';
|
import { onMount, untrack } from 'svelte';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import {
|
import {
|
||||||
Bold, Italic, List, ListOrdered,
|
Bold, Italic, List, ListOrdered,
|
||||||
RemoveFormatting, Type, Code, AlignLeft
|
RemoveFormatting, Type, Code, AlignLeft
|
||||||
} from 'lucide-svelte';
|
} from 'lucide-svelte';
|
||||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
let {
|
let {
|
||||||
content = $bindable(''),
|
content = $bindable(''),
|
||||||
new_content = $bindable(''),
|
new_content = $bindable(),
|
||||||
placeholder = 'Start writing...',
|
placeholder = 'Start writing...',
|
||||||
readonly = false,
|
readonly = false,
|
||||||
auto_format = true,
|
auto_format = true,
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
<button type="button" class="btn btn-sm variant-soft hover:variant-filled-error" onclick={() => exec('removeFormat')} title="Clear Formatting">
|
<button type="button" class="btn btn-sm variant-soft hover:variant-filled-error" onclick={() => exec('removeFormat')} title="Clear Formatting">
|
||||||
<RemoveFormatting size="14" />
|
<RemoveFormatting size="14" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button type="button" class="btn btn-sm variant-soft hover:variant-filled-success" onclick={handle_format} title="Format HTML Source">
|
<button type="button" class="btn btn-sm variant-soft hover:variant-filled-success" onclick={handle_format} title="Format HTML Source">
|
||||||
<AlignLeft size="14" />
|
<AlignLeft size="14" />
|
||||||
<span class="text-[10px] ml-1">Format</span>
|
<span class="text-[10px] ml-1">Format</span>
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
{placeholder}
|
{placeholder}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
bind:this={editor_element}
|
bind:this={editor_element}
|
||||||
contenteditable={!readonly}
|
contenteditable={!readonly}
|
||||||
|
|||||||
139
tests/coldstart_event_settings.test.ts
Normal file
139
tests/coldstart_event_settings.test.ts
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { ae_app_local_data_defaults } from './_helpers/ae_defaults';
|
||||||
|
import { demo_event_id, demo_account_id } from './_helpers/env';
|
||||||
|
|
||||||
|
const demo_event = demo_event_id;
|
||||||
|
|
||||||
|
test.describe('Cold-start: Event Settings (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() === 'warn')
|
||||||
|
console.error(`BROWSER [${msg.type().toUpperCase()}]: ${msg.text()}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Provide app localStorage before any scripts run
|
||||||
|
await page.addInitScript(
|
||||||
|
({ defaults, event_id, account_id }) => {
|
||||||
|
const testData = {
|
||||||
|
...defaults,
|
||||||
|
account_id: account_id,
|
||||||
|
// Administrator implies lower-level access flags are true;
|
||||||
|
// Manager and Super accesses are explicitly set per test requirements.
|
||||||
|
administrator_access: true,
|
||||||
|
trusted_access: true,
|
||||||
|
authenticated_access: true,
|
||||||
|
manager_access: false,
|
||||||
|
super_access: false,
|
||||||
|
edit_mode: true,
|
||||||
|
// Ensure the layout/components that bind this prop don't receive undefined
|
||||||
|
mod_abstracts_json: {},
|
||||||
|
// Provide a test person id so components that expect an authenticated
|
||||||
|
// user/person render deterministically in tests
|
||||||
|
person_id: 'test-person-1',
|
||||||
|
user: { id: 'test-person-1' },
|
||||||
|
mod: { ...defaults.mod, events: { ...defaults.mod.events, event_id: event_id } }
|
||||||
|
};
|
||||||
|
window.localStorage.setItem('ae_loc', JSON.stringify(testData));
|
||||||
|
},
|
||||||
|
{ defaults: ae_app_local_data_defaults, event_id: demo_event, account_id: demo_account_id }
|
||||||
|
);
|
||||||
|
|
||||||
|
// Navigate to the application's origin so the page context is allowed
|
||||||
|
// to access the IndexedDB API, then delete known Dexie DBs to simulate
|
||||||
|
// a cold start. We wrap deleteDatabase in Promises to wait for completion.
|
||||||
|
await page.goto('/');
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const dbs = [
|
||||||
|
'ae_events_db',
|
||||||
|
'ae_journals_db',
|
||||||
|
'ae_posts_db',
|
||||||
|
'ae_archives_db',
|
||||||
|
'ae_core_db',
|
||||||
|
'ae_sponsorships_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) {
|
||||||
|
// If deleteDatabase throws, resolve to avoid hanging the test
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Seed IndexedDB with the event record so the page's local liveQuery
|
||||||
|
// (which reads from IDB) finds it immediately on mount.
|
||||||
|
await page.evaluate(({ demo_event }) => {
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
try {
|
||||||
|
const req = indexedDB.open('ae_events_db', 1);
|
||||||
|
req.onupgradeneeded = (ev) => {
|
||||||
|
const db = (ev.target as IDBOpenDBRequest).result;
|
||||||
|
if (!db.objectStoreNames.contains('event')) {
|
||||||
|
db.createObjectStore('event', { keyPath: 'id' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
req.onsuccess = () => {
|
||||||
|
const db = req.result;
|
||||||
|
const tx = db.transaction('event', 'readwrite');
|
||||||
|
const store = tx.objectStore('event');
|
||||||
|
store.put({ id: demo_event, event_id: demo_event, name: 'Cold Start Test Event', cfg_json: {}, mod_pres_mgmt_json: {}, mod_badges_json: {}, mod_abstracts_json: {} });
|
||||||
|
tx.oncomplete = () => {
|
||||||
|
db.close();
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
tx.onerror = () => {
|
||||||
|
db.close();
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
req.onerror = () => resolve();
|
||||||
|
} catch (e) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, { demo_event });
|
||||||
|
|
||||||
|
// Minimal network mock for the event GET used by the settings page
|
||||||
|
await page.route('**/v3/**', async (route) => {
|
||||||
|
const req = route.request();
|
||||||
|
const url = req.url();
|
||||||
|
|
||||||
|
if (url.includes(`/v3/crud/event/${demo_event}`) && req.method() === 'GET') {
|
||||||
|
return route.fulfill({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
body: JSON.stringify({ data: {
|
||||||
|
id: demo_event,
|
||||||
|
event_id: demo_event,
|
||||||
|
name: 'Cold Start Test Event',
|
||||||
|
cfg_json: {},
|
||||||
|
mod_pres_mgmt_json: {},
|
||||||
|
mod_badges_json: {},
|
||||||
|
mod_abstracts_json: {}
|
||||||
|
} })
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default: empty envelope so other calls don't error
|
||||||
|
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [] }) });
|
||||||
|
});
|
||||||
|
|
||||||
|
// (already set above)
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renders Event Settings without prior IndexedDB cache', async ({ page }) => {
|
||||||
|
await page.goto(`/events/${demo_event}/settings`);
|
||||||
|
|
||||||
|
const add_btn = page.getByRole('button', { name: 'Add New Badge' });
|
||||||
|
await expect(add_btn).toBeVisible({ timeout: 10000 });
|
||||||
|
});
|
||||||
|
});
|
||||||
134
tests/coldstart_journal.test.ts
Normal file
134
tests/coldstart_journal.test.ts
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { ae_app_local_data_defaults } from './_helpers/ae_defaults';
|
||||||
|
import { demo_account_id } from './_helpers/env';
|
||||||
|
|
||||||
|
// Use canonical demo journal id for deterministic tests
|
||||||
|
const demo_journal = 'BVYE-94-46-29';
|
||||||
|
|
||||||
|
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() === 'warn')
|
||||||
|
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: 'test-person-1',
|
||||||
|
user: { id: 'test-person-1' }
|
||||||
|
};
|
||||||
|
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: demo_account_id, journal_id: demo_journal }
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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(({ demo_journal }) => {
|
||||||
|
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');
|
||||||
|
store.put({ id: demo_journal, journal_id: demo_journal, name: 'Demo Journal (Cold Start Test)', description: 'Created for cold-start Playwright test', person_id: 'test-person-1' });
|
||||||
|
tx.oncomplete = () => {
|
||||||
|
db.close();
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
tx.onerror = () => {
|
||||||
|
db.close();
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
req.onerror = () => resolve();
|
||||||
|
} catch (e) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, { demo_journal });
|
||||||
|
|
||||||
|
// 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/${demo_journal}`) && req.method() === 'GET') {
|
||||||
|
return route.fulfill({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
body: JSON.stringify({ data: {
|
||||||
|
id: demo_journal,
|
||||||
|
journal_id: demo_journal,
|
||||||
|
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/${demo_journal}`);
|
||||||
|
|
||||||
|
// 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 });
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user