feat: remove a saved game & redirect on missing/deleted game (#20)
CI / build + unit + e2e (pull_request) Successful in 1m14s
CI / build + unit + e2e (pull_request) Successful in 1m14s
- DELETE /api/games/:id route + Db.delete() (404 when absent) - PresetPicker: per-saved-game trash button + confirm dialog (Cancel/Delete) - App: runDeleteGame; useSse onError -> goHome on 'deleted'/'not found' (a deleted/missing game now returns the live tab and any deep link home) - DeleteGameResponse in shared/protocol.ts; api.deleteGame() - unit test (Db.delete) + 2 e2e tests (home-screen delete; in-flight delete returns the active tab home and a fresh deep link lands on home) - version 0.7.0 -> 0.8.0 + changelog Fixes #20
This commit is contained in:
@@ -560,3 +560,86 @@ test.describe('History — Advisor thinking indicator (#15)', () => {
|
||||
await expect(page.getByTestId('status-indicator')).toHaveText(/Idle/);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Remove a saved game (#20): a saved game can be deleted from the home screen
|
||||
* (with a confirmation dialog), and loading a non-existent / deleted game id
|
||||
* (directly or via a stale open tab) returns the user to the home screen.
|
||||
*/
|
||||
test.describe('History — remove a saved game & redirect (#20)', () => {
|
||||
test('deleting a saved game from the home screen removes it (with confirmation)', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(90000);
|
||||
const id = await createUkGame(page);
|
||||
await expect(page.getByTestId('world-map')).toBeVisible();
|
||||
|
||||
// Back to the home screen, where the just-created game appears in "Saved games".
|
||||
await page.getByTestId('back-to-scenarios').click();
|
||||
await expect(page.getByTestId('saved-games')).toBeVisible({ timeout: 15000 });
|
||||
const card = page.locator(`[data-game-id="${id}"]`);
|
||||
await expect(card).toBeVisible();
|
||||
|
||||
// Opening the confirm dialog…
|
||||
await card.getByTestId('delete-game').click();
|
||||
const dialog = page.getByTestId('delete-game-confirm-dialog');
|
||||
await expect(dialog).toBeVisible();
|
||||
|
||||
// …and cancelling leaves the game in place.
|
||||
await page.getByTestId('delete-game-cancel').click();
|
||||
await expect(dialog).toHaveCount(0);
|
||||
await expect(card).toBeVisible();
|
||||
|
||||
// Confirming the delete removes it: the DELETE succeeds, the card disappears,
|
||||
// and a subsequent fetch reports the game gone.
|
||||
await card.getByTestId('delete-game').click();
|
||||
await expect(page.getByTestId('delete-game-confirm-dialog')).toBeVisible();
|
||||
const [resp] = await Promise.all([
|
||||
page.waitForResponse(
|
||||
(r) =>
|
||||
r.request().method() === 'DELETE' &&
|
||||
new URL(r.url()).pathname === `/api/games/${id}`,
|
||||
),
|
||||
page.getByTestId('delete-game-confirm').click(),
|
||||
]);
|
||||
expect((await resp.json()) as { deleted: boolean }).toEqual({ deleted: true });
|
||||
await expect(page.getByTestId('delete-game-confirm-dialog')).toHaveCount(0);
|
||||
await expect(card).toHaveCount(0);
|
||||
|
||||
// The game is gone from the server too.
|
||||
const status = await page.evaluate(async (gid) => {
|
||||
const r = await fetch(`/api/games/${gid}`);
|
||||
return r.status;
|
||||
}, id);
|
||||
expect(status).toBe(404);
|
||||
});
|
||||
|
||||
test('deleting an open game sends the active tab home; a deep link lands on home', async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
test.setTimeout(90000);
|
||||
const id = await createUkGame(page);
|
||||
await expect(page.getByTestId('world-map')).toBeVisible();
|
||||
await expect(page.getByTestId('turn-count')).toHaveText('1');
|
||||
const origin = await page.evaluate(() => location.origin);
|
||||
|
||||
// Delete the game straight through the API while its tab is open. The server
|
||||
// broadcasts an SSE `error` and the client's useSse onError handler returns
|
||||
// this live tab to the home screen.
|
||||
const delStatus = await page.evaluate(
|
||||
async (gid) => (await fetch(`/api/games/${gid}`, { method: 'DELETE' })).status,
|
||||
id,
|
||||
);
|
||||
expect(delStatus).toBe(200);
|
||||
await expect(page.getByTestId('preset-card').first()).toBeVisible({ timeout: 20000 });
|
||||
await waitHash(page, '#/');
|
||||
|
||||
// A brand-new page deep-linking to the now-deleted id also lands on home.
|
||||
const page2 = await context.newPage();
|
||||
await page2.goto(`${origin}/#/game/${id}`);
|
||||
await expect(page2.getByTestId('preset-card').first()).toBeVisible({ timeout: 20000 });
|
||||
await waitHash(page2, '#/');
|
||||
await page2.close();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user