/account had no site header and no links of any kind, so once a customer opened it the only way out was the browser's back button or editing the URL. It is now a modal rendered over whatever the customer was looking at, while staying a real route. Opening it from the header pushes /account and names the current page as the backdrop, so closing returns there with filters and scroll position intact, and the browser's Back button does the same thing as the close control. Entering /account directly — a bookmark, the link in a verification email, or the redirect after registering — has no page behind it, so it falls back to rendering the storefront as the backdrop. Closing therefore always lands somewhere real rather than on nothing. Keeping it a route rather than view state means the URL still works: it can be bookmarked, shared, and refreshed with the account view still open, which is what the existing header link and the four post-authentication redirects already depend on. Also scopes the account switch locator in the favorites spec to the modal. The storefront now renders behind the account view and has a theme switch of its own, so an unscoped switch locator was only picking the right control by DOM accident. Verified with 68 end-to-end tests, 5 of them new, all passing, and type checking clean. No backend changes. Closes #48
99 lines
3.8 KiB
TypeScript
99 lines
3.8 KiB
TypeScript
import { test, expect, Page } from '@playwright/test';
|
|
|
|
const PASSWORD = 'supersecret123';
|
|
|
|
const uniqueEmail = () => `account-${Date.now().toString(36)}${Math.random().toString(36).slice(2, 7)}@example.com`;
|
|
|
|
// Registering lands on /account, which is now the modal over the storefront.
|
|
// Returns the address so a test can assert the right account is shown.
|
|
async function registerAndCloseAccount(page: Page): Promise<string> {
|
|
const email = uniqueEmail();
|
|
await page.goto('/register');
|
|
await page.getByRole('textbox', { name: 'Email' }).fill(email);
|
|
await page.getByLabel('Password').fill(PASSWORD);
|
|
await page.getByRole('button', { name: 'Create account' }).click();
|
|
await expect(page).toHaveURL(/\/account/);
|
|
await closeAccount(page);
|
|
return email;
|
|
}
|
|
|
|
const accountModal = (page: Page) => page.getByRole('dialog', { name: 'My Account' });
|
|
|
|
async function closeAccount(page: Page) {
|
|
await accountModal(page).getByRole('button', { name: 'Close' }).click();
|
|
await expect(accountModal(page)).toBeHidden();
|
|
}
|
|
|
|
test.describe('My Account opens as a modal', () => {
|
|
test('opens over the storefront and closes back to it, filters and all', async ({ page }) => {
|
|
await registerAndCloseAccount(page);
|
|
|
|
// A filtered view, to prove closing restores where the customer actually
|
|
// was rather than a bare storefront.
|
|
await page.goto('/?max_price=50000');
|
|
await expect(page.getByRole('button', { name: 'My Account' })).toBeVisible();
|
|
|
|
await page.getByRole('button', { name: 'My Account' }).click();
|
|
await expect(accountModal(page)).toBeVisible();
|
|
// Still a real, linkable URL rather than hidden view state.
|
|
await expect(page).toHaveURL(/\/account/);
|
|
|
|
await closeAccount(page);
|
|
await expect(page).toHaveURL(/max_price=50000/);
|
|
});
|
|
|
|
test('the browser back button closes it, the same as the close control', async ({ page }) => {
|
|
await registerAndCloseAccount(page);
|
|
|
|
await page.goto('/?max_price=50000');
|
|
await page.getByRole('button', { name: 'My Account' }).click();
|
|
await expect(accountModal(page)).toBeVisible();
|
|
|
|
await page.goBack();
|
|
|
|
await expect(accountModal(page)).toBeHidden();
|
|
await expect(page).toHaveURL(/max_price=50000/);
|
|
});
|
|
|
|
test('a direct visit renders the storefront behind it, so closing lands somewhere real', async ({ page }) => {
|
|
await registerAndCloseAccount(page);
|
|
|
|
// A bookmark, or the link in a verification email. There is no page behind
|
|
// in this case, which is what used to make /account a dead end.
|
|
await page.goto('/account');
|
|
|
|
await expect(accountModal(page)).toBeVisible();
|
|
await expect(page.getByRole('heading', { name: 'Redefined Designs' })).toBeVisible();
|
|
|
|
await closeAccount(page);
|
|
await expect(page).toHaveURL(/\/$/);
|
|
await expect(page.getByRole('button', { name: 'My Account' })).toBeVisible();
|
|
});
|
|
|
|
test('survives a reload, since it is a route rather than view state', async ({ page }) => {
|
|
const email = await registerAndCloseAccount(page);
|
|
|
|
await page.goto('/?max_price=50000');
|
|
await page.getByRole('button', { name: 'My Account' }).click();
|
|
await expect(accountModal(page)).toBeVisible();
|
|
|
|
await page.reload();
|
|
|
|
await expect(accountModal(page)).toBeVisible();
|
|
await expect(accountModal(page)).toContainText(email);
|
|
});
|
|
|
|
test('shows the signed-in account and its settings', async ({ page }) => {
|
|
const email = await registerAndCloseAccount(page);
|
|
|
|
await page.goto('/account');
|
|
|
|
const modal = accountModal(page);
|
|
await expect(modal).toContainText(email);
|
|
await expect(modal).toContainText('Order History');
|
|
// Scoped to the modal: the storefront behind it has a theme switch of its
|
|
// own, so an unscoped switch locator would be ambiguous.
|
|
await expect(modal.getByRole('switch')).toHaveCount(2);
|
|
});
|
|
});
|