import { test, expect } from '@playwright/test' const LOGIN_PHONE = '13900000001' const LOGIN_PASSWORD = 'test123456' async function loginViaForm(page: any, phone: string, password: string) { await page.goto('/platform/login') await page.waitForSelector('input[placeholder="11位手机号"]', { timeout: 10000 }) await page.getByPlaceholder('11位手机号').fill(phone) await page.getByPlaceholder('输入密码').fill(password) // Click submit button (bg-primary button, not the tab) await page.locator('button.bg-primary').click() await page.waitForTimeout(3000) } async function loginAsAdmin(page: any) { // Inject auth directly via localStorage to bypass login flow await page.goto('/') await page.evaluate(() => { localStorage.setItem('hss_platform_user', JSON.stringify({ userId: '1', userName: '系统管理员', userRole: 'ADMIN', tenantId: '1', orgId: '1' })) localStorage.setItem('hss_token', 'test-token') }) } test.describe('平台登录与角色切换', () => { test('登录页可达', async ({ page }) => { await page.goto('/platform/login') await page.waitForSelector('input[placeholder="11位手机号"]', { timeout: 10000 }) await expect(page.locator('h1').filter({ hasText: '智慧医养' })).toBeVisible() await expect(page.getByPlaceholder('11位手机号')).toBeVisible() await expect(page.getByPlaceholder('输入密码')).toBeVisible() await expect(page.locator('button.bg-primary')).toBeVisible() }) test('表单登录进入工作台', async ({ page }) => { await loginViaForm(page, LOGIN_PHONE, LOGIN_PASSWORD) await page.waitForURL(/\/platform/, { timeout: 5000 }) await expect(page.getByRole('heading', { name: /工作台/ })).toBeVisible() }) test('工作台显示统计数字', async ({ page }) => { await loginAsAdmin(page) await page.goto('/platform') await page.waitForURL(/\/platform/, { timeout: 10000 }) await page.waitForTimeout(2000) const statCards = page.locator('.bg-white.rounded-xl.p-4') await expect(statCards.first()).toBeVisible({ timeout: 5000 }) }) test('未登录访问平台被重定向', async ({ page }) => { await page.goto('/platform') await page.waitForTimeout(2000) expect(page.url()).toContain('/platform/login') }) test('退出登录返回登录页', async ({ page }) => { await loginAsAdmin(page) await page.goto('/platform') await page.waitForTimeout(2000) // Try sidebar logout first, fall back to mobile logout const sidebarLogout = page.locator('aside button', { hasText: '退出' }) const mobileLogout = page.locator('button', { hasText: '退出' }) if (await sidebarLogout.isVisible().catch(() => false)) { await sidebarLogout.click() } else if (await mobileLogout.isVisible().catch(() => false)) { await mobileLogout.click() } await page.waitForTimeout(500) expect(page.url()).toContain('/platform/login') }) }) test.describe('服务申请管理', () => { test('申请管理页可达并显示列表', async ({ page }) => { await loginAsAdmin(page) await page.goto('/platform/applications') await page.waitForTimeout(3000) await expect(page.getByText('服务申请管理')).toBeVisible() }) test('打开新建申请表单', async ({ page }) => { await loginAsAdmin(page) await page.goto('/platform/applications') await page.waitForTimeout(2000) await page.getByText('新建申请').click() await expect(page.getByText('新建服务申请')).toBeVisible() await expect(page.getByPlaceholder('如 2001')).toBeVisible() }) test('创建新申请', async ({ page }) => { await loginAsAdmin(page) await page.goto('/platform/applications') await page.waitForTimeout(2000) await page.getByText('新建申请').click() await page.getByPlaceholder('如 2001').fill('2001') await page.getByPlaceholder('姓名').fill('PW测试') await page.getByPlaceholder('手机号').fill('13800000000') await page.getByPlaceholder('详细地址').fill('梅江区') await page.getByText('提交申请').click() await page.waitForTimeout(3000) // New application should appear in the table await expect(page.getByText('服务申请管理')).toBeVisible() }) }) test.describe('工单管理', () => { test('工单管理页可达', async ({ page }) => { await loginAsAdmin(page) await page.goto('/platform/work-orders') await page.waitForTimeout(3000) await expect(page.getByText('工单管理')).toBeVisible() }) })