import { test, expect } from '@playwright/test' import { setDateInput, gotoPage } from './helpers' /** * 用户旅程 J-NAV(Edge cases):跨页导航与状态保持旅程 * * 用户目标:在三大功能页(黄历/排盘/运势)之间顺畅切换,且排盘数据跨页保持 * * 旅程步骤: * 1. 进入黄历页(首页),底部导航可见 * 2. 通过底部导航切换到排盘页 * 3. 通过底部导航切换到运势页 * 4. 导航往返(排盘 → 运势 → 黄历) * 5. 排盘数据跨页保持(排盘后运势页可读取) * * 异常恢复场景: * E1. 直接访问不存在的路由 → 应用可正常渲染(hash 路由容错) */ test.describe('旅程 J-NAV:跨页导航与状态保持旅程', () => { test.describe.configure({ mode: 'serial' }) test('STEP 1: 进入黄历页,底部导航三入口可见', async ({ page }) => { await gotoPage(page, '/pages/almanac-search/index') await expect(page.locator('.bottom-navigation')).toBeVisible() await expect(page.locator('.nav-item')).toHaveCount(3) await expect(page.locator('.page-title')).toBeVisible() }) test('STEP 2: 通过底部导航切换到排盘页', async ({ page }) => { await gotoPage(page, '/pages/almanac-search/index') await page.locator('.nav-item').nth(1).click() await page.waitForTimeout(1500) expect(page.url()).toContain('/#/pages/ziwei/index') await expect(page.locator('[data-test="birth-form"]')).toBeVisible() // 目标页必须有底部导航(回归防护:三 tab 页均需底部导航) await expect(page.locator('.bottom-navigation')).toBeVisible() await expect(page.locator('.nav-item')).toHaveCount(3) }) test('STEP 3: 通过底部导航切换到运势页', async ({ page }) => { await gotoPage(page, '/pages/almanac-search/index') await page.locator('.nav-item').nth(2).click() await page.waitForTimeout(1500) expect(page.url()).toContain('/#/pages/fortune/index') await expect(page.locator('[data-test="fortune-tabs"]')).toBeVisible() // 目标页必须有底部导航 await expect(page.locator('.bottom-navigation')).toBeVisible() await expect(page.locator('.nav-item')).toHaveCount(3) }) test('STEP 4: 导航往返(排盘 → 运势 → 黄历)', async ({ page }) => { await gotoPage(page, '/pages/ziwei/index') await gotoPage(page, '/pages/fortune/index') await expect(page.locator('[data-test="fortune-tabs"]')).toBeVisible() await gotoPage(page, '/pages/almanac-search/index') await expect(page.locator('.page-title')).toBeVisible() await expect(page.locator('.bottom-navigation')).toBeVisible() }) test('STEP 5: 排盘数据跨页保持', async ({ page }) => { // 排盘页生成排盘(写入 localStorage) await gotoPage(page, '/pages/ziwei/index') await setDateInput(page, 'input[type="date"]', '1990-01-01') await page.locator('[data-test="generate-btn"]').click() await page.waitForTimeout(1500) await expect(page.locator('.chart-result')).toBeVisible() // 跳转到运势页,验证能读取排盘数据 await gotoPage(page, '/pages/fortune/index') // 运势页能读取已持久化的排盘数据:不应显示"请先排盘"提示,且运势交互区正常渲染 await expect(page.locator('.no-chart-hint')).toHaveCount(0) await expect(page.locator('.daily-fortune')).toBeVisible() }) test('E1: 直接访问不存在的路由 → 应用正常渲染(hash 容错)', async ({ page }) => { await page.goto('/#/pages/nonexistent/index') await page.waitForLoadState('networkidle') await page.waitForTimeout(1000) // 应用不白屏,可正常导航回黄历页 await gotoPage(page, '/pages/almanac-search/index') await expect(page.locator('.page-title')).toBeVisible() }) })