diff --git a/muse-studio/e2e/account-usage.spec.ts b/muse-studio/e2e/account-usage.spec.ts new file mode 100644 index 00000000..918283f0 --- /dev/null +++ b/muse-studio/e2e/account-usage.spec.ts @@ -0,0 +1,57 @@ +import { expect, test, type Page } from '@playwright/test'; + +/** + * 账户中心「权益与配额 / 归属分布」(UsageStats 用量统计)e2e(真实后端,MSW off)。 + * + * 前置:vite VITE_API_MOCK=false、真实 muse-server 48080。 + * 目的:验个人中心 UsageStats 真后端读通——GET /account/entitlements(套餐/权益/配额/发布能力) + * + GET /account/usage(Token 用量/按模型/按归属分布),区块渲染。 + * 反假绿:live-read.spec 仅断言 profile nickname、未覆盖 UsageStats,这两端读路此前无专门 e2e。 + * 不依赖具体数值(随账号用量变动),只断言契约(200/code:0)与区块存在。 + */ +const TOKEN = 'test1'; + +async function seedToken(page: Page): Promise { + await page.addInitScript((t) => { + window.localStorage.setItem('accessToken', t); + window.localStorage.setItem('tenantId', '1'); + }, TOKEN); +} + +test('账户中心展示权益与配额(真实后端)', async ({ page }) => { + await seedToken(page); + + // 进个人中心,捕获真实权益/配额读响应(打真后端,非 mock)。 + const [resp] = await Promise.all([ + page.waitForResponse( + (r) => /\/account\/entitlements/.test(r.url()) && r.request().method() === 'GET', + { timeout: 15_000 } + ), + page.goto('/account'), + ]); + + expect(resp.status()).toBe(200); + expect((await resp.json()).code).toBe(0); + + // UsageStats「权益与配额」区(套餐/配额/发布能力)渲染。 + await expect(page.getByRole('heading', { name: '权益与配额' })).toBeVisible({ timeout: 15_000 }); +}); + +test('账户中心展示用量归属分布(真实后端)', async ({ page }) => { + await seedToken(page); + + // 进个人中心,捕获真实用量读响应(打真后端,非 mock)。 + const [resp] = await Promise.all([ + page.waitForResponse( + (r) => /\/account\/usage/.test(r.url()) && r.request().method() === 'GET', + { timeout: 15_000 } + ), + page.goto('/account'), + ]); + + expect(resp.status()).toBe(200); + expect((await resp.json()).code).toBe(0); + + // UsageStats「归属分布」区(按归属维度的 Token 用量)渲染。 + await expect(page.getByRole('heading', { name: '归属分布' })).toBeVisible({ timeout: 15_000 }); +});