[app] SunsetPlace: Wire the town list, the guess and storage into the garden; e2e and offline cover it
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* Waits until the player's sunset town is written to IndexedDB. The garden shows a
|
||||
* choice before the write commits, so a test that reloads or closes the tab at once
|
||||
* races the write: it passed and failed on alternate runs before this existed.
|
||||
*/
|
||||
export async function storedTown(page: Page, name: string): Promise<void> {
|
||||
await page.waitForFunction(
|
||||
(expected) =>
|
||||
new Promise<boolean>((resolve) => {
|
||||
const req = indexedDB.open('rosea');
|
||||
req.onerror = () => resolve(false);
|
||||
req.onsuccess = () => {
|
||||
const db = req.result;
|
||||
if (!db.objectStoreNames.contains('profile')) {
|
||||
db.close();
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
const get = db.transaction('profile').objectStore('profile').get('sunsetPlace');
|
||||
get.onsuccess = () => {
|
||||
db.close();
|
||||
const value = get.result as { value?: { town?: { name?: string } } } | undefined;
|
||||
resolve(value?.value?.town?.name === expected);
|
||||
};
|
||||
get.onerror = () => {
|
||||
db.close();
|
||||
resolve(false);
|
||||
};
|
||||
};
|
||||
}),
|
||||
name,
|
||||
{ timeout: 5_000 }
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user