Files
collective-lists/apps/web/tests/e2e/session.test.ts
Oier Bravo Urtasun 4ce24a4145 feat(fase-18): CreateListModal replaces empty-create-then-rename flow
`CreateListModal.svelte` is the new entry point for "New list" — opens
on the masthead button click, prefills the input with
`currentCollective.default_list_title` (Fase 18.3.1), shows an inline
autocomplete dropdown via `fetchTitleSuggestions`, and renders a
"Sugerencia: Compra #6" chip when (a) the typed value exactly matches a
catalog-curated prefix case-insensitively and (b) `computeNextNumber`
resolves a value (Fase 18.3.2). Submit is disabled while the trimmed
value is empty or creation is in flight (Fase 18.3.3). On submit, if the
catalog match still holds, the modal auto-suffixes "#N" before
inserting and the lists page shows a transient toast confirming the
final name (Fase 18.3.4).

The prefill effect is gated by a `wasOpen` edge-tracker — a naive
`$effect(() => { if (open) value = default })` re-runs whenever
`$currentCollective` updates (e.g. a realtime UPDATE landing after the
user typed something), which clobbered the typed value and froze the
submit button as disabled. The edge guard limits the prefill to the
false→true transition.

`/lists/+page.svelte`: the masthead "New list" button now opens the
modal instead of calling `createList(collective, '', user)` and goto-ing
to the detail page for inline rename. The legacy flow was nice for
quick creates but couldn't enforce a required title or surface the
catalog. Existing per-list actions are unchanged.

15 new i18n strings (en + es) for the modal, the suggestion chip, the
auto-numbered toast, and the manage-page subsection that ships in the
next commit.

Updated existing e2e specs: `lists.test.ts`'s `createList()` helper +
the C-13 guest path now drive the modal instead of the legacy
placeholder input; `session.test.ts` S-03 uses the modal for the
fresh-list setup. New `tests/e2e/list-title-flow.test.ts` adds LTF-01
(default prefill end-to-end with a Supabase-driven setDefaultListTitle
since the manage UI lands in the next commit) and LTF-03 (empty input
keeps submit disabled, even with whitespace).

Tests: 4 lists + 3 session + 2 new LTF specs all green (9/9).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-19 02:29:17 +02:00

86 lines
3.5 KiB
TypeScript

/**
* S-series (Modo Compra) — Fase 2b.3
*
* Full-screen shopping session at `/lists/[id]/session`. Large tap targets,
* flip animation moving items between TO BUY / CHECKED, and a confirmation
* modal for "Finish shopping" that marks the list completed and returns to
* `/lists`.
*/
import { test, expect } from '@playwright/test';
import { USERS } from '../fixtures/users.js';
import { loginAs } from '../fixtures/login.js';
const SEED_LIST_ID = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb';
const SEED_LIST_PATH = `/lists/${SEED_LIST_ID}`;
const SESSION_PATH = `${SEED_LIST_PATH}/session`;
test.describe('Shopping session — full-screen mode', () => {
test.beforeEach(async ({ page }) => {
await loginAs(page, USERS.borja);
});
test('S-01: navigating to /lists/[id]/session shows the full-screen container', async ({
page
}) => {
await page.goto(SESSION_PATH);
await expect(page.getByTestId('shopping-session')).toBeVisible({ timeout: 15_000 });
// The finish CTA must be visible — it's the whole point of the view.
await expect(page.getByRole('button', { name: /finish shopping|terminar compra/i })).toBeVisible();
});
test('S-02: checking an item moves it into the CHECKED section', async ({ page }) => {
// Ensure at least one unchecked item exists by creating one from the
// regular list page (simpler than seeding items in the session view).
await page.goto(SEED_LIST_PATH);
await expect(page.getByPlaceholder(/add item|añadir producto/i)).toBeVisible({
timeout: 15_000
});
const itemName = `S-02-${Date.now()}`;
await page.getByPlaceholder(/add item|añadir producto/i).fill(itemName);
await page.getByPlaceholder(/add item|añadir producto/i).press('Enter');
await expect(page.getByText(itemName)).toBeVisible({ timeout: 5_000 });
// Now go to the session view and check the item
await page.goto(SESSION_PATH);
await expect(page.getByTestId('shopping-session')).toBeVisible({ timeout: 15_000 });
const row = page.locator('[role="listitem"]').filter({ hasText: itemName });
await row.getByRole('button', { name: /toggle item/i }).click();
// The row's toggle now has aria-label "Uncheck item" (in CHECKED section)
await expect(
page.locator('[role="listitem"]').filter({ hasText: itemName }).getByRole('button', {
name: /uncheck item/i
})
).toBeVisible({ timeout: 5_000 });
});
test('S-03: Finish shopping → confirm → list is completed and we return to /lists', async ({
page
}) => {
// Need a fresh list so completing it doesn't affect shared seed state.
// Fase 18: masthead "New list" → modal opens → fill + submit → lands
// on the detail view at /lists/[id].
await page.goto('/lists');
await page
.getByRole('button', { name: /new list|nueva lista/i })
.click();
const listName = `S-03-list-${Date.now()}`;
await page.getByTestId('create-list-modal-name').fill(listName);
await page.getByTestId('create-list-modal-submit').click();
await expect(page).toHaveURL(/\/lists\/[0-9a-f-]+$/, { timeout: 10_000 });
// Open session mode
await page.getByTestId('start-session').click();
await expect(page.getByTestId('shopping-session')).toBeVisible({ timeout: 15_000 });
// Finish shopping → confirm
await page.getByRole('button', { name: /finish shopping|terminar compra/i }).click();
await page.getByRole('button', { name: /yes, finish|sí, terminar/i }).click();
// Redirected back to /lists, and the completed list is not in the
// active grid anymore (it moves to "Completed").
await expect(page).toHaveURL(/\/lists\/?$/, { timeout: 10_000 });
});
});