Files
go-sms-V2/web/tests/profit-view.spec.ts
T
Tory c5a062570f S3 前端收尾泳道收官(FE-6+结算页面族): 盘点修正=views 31 页 S1-B 已搬零残留(归档仓逐文件比对),实际交付四件——FE-D34 利润分析页(views/stats/profit 双 Tab+汇总条[应收/成本分摊/返点/平台净利]+正负着色+口径诚实标注常驻;路由 /stats/profit roles=后端平台门同口径;api settle.ts +profitUsers/profitChannels;vitest 2 件=api 契约+组件挂载);FE-6 Mock 下线(浏览器通道全链移除:main.ts worker 分支/mocks/browser.ts/mockServiceWorker.js/VITE_API_MODE/LoginView 演示提示/Makefile 口径;msw 移 devDependencies 仅存 vitest 层 138 用例不破;packageManager 钉 pnpm12.18.0+lockfile 同步);FE-6 权限矩阵走查(role-menu-matrix.spec.ts 五角色×33 菜单固化快照,未登记新菜单=红,8 件);FE-6 性能(manualChunks:主包 1.27MB/410KB→业务 entry ~19KB+element-plus 341KB+vue-vendor 62KB 全 gzip 逐 chunk<500KB;LCP 真浏览器实测受阻=本机 chromium newPage 即 Target crashed 3 轮全崩 dmesg 无痕,产物口径代替+诚实标注);FE-6 CI+镜像化(ci.yml +web-test job;web/Dockerfile=dist 产物镜像 nginx1.27——容器内 npm 带宽 22~49KiB/s 全量依赖不可行形态裁决,make web-image=宿主 build+nginx 打包;nginx.conf.template envsubst API_UPSTREAM/gzip/SPA fallback/资产强缓存;容器冒烟 root/SPA/反代401/gzip+immutable 全过 镜像50.2MB;deploy/k8s/web.yaml NodePort 30081 备档 kind 未装随 S5 apply);门禁 eslint0/vue-tsc0/vitest 148 全绿(26 文件;guard 菜单 31→32 显式更)/build 9.64s;真机 dev 重启无 msw 引用+proxy→gw 401 应答;验收单 s3-closeout.md(两项环境受阻如实标注)+CHANGELOG+memory-bank 回填
2026-11-15 00:11:37 +08:00

75 lines
3.2 KiB
TypeScript

// profit-view.spec.ts S3·FE-D34:利润分析页(msw 局部 handler,不动全局种子——
// 与 settle 页同策略:结算域端点走真库联调,组件测试用 server.use 注入契约)。
// 锁定:双端点参数契约(date_from/date_to/parent_id/channel_id)、汇总条渲染、
// 利润正负着色、口径说明常驻(诚实标注)。
import { describe, expect, it, afterEach } from 'vitest'
import { http, HttpResponse } from 'msw'
import { mount, flushPromises } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import { server } from '../mocks/node'
import StatsProfitView from '../src/views/stats/profit/index.vue'
import { settleApi } from '../src/api/settle'
const usersData = {
list: [
{ account_id: 1, username: 'root', role: 'group', success_count: 100, revenue: 10, cost: 4, rebate: 1.0, profit: 7 },
{ account_id: 12, username: 'a12', role: 'customer', success_count: 10, revenue: 0, cost: 0.4, rebate: 0, profit: -0.4 },
],
total: 2,
summary: { count: 2, total_revenue: 10, total_cost: 4.4, total_rebate: 1.0, platform_profit: 4.6 },
}
const channelsData = {
list: [{ channel_id: 9101, name: 'c1', upstream_id: 7, success_count: 150, revenue: 24, cost: 6, profit: 18 }],
total: 1,
}
let lastUsersQuery = ''
let lastChannelsQuery = ''
function stubProfit() {
server.use(
http.get('*/api/v1/stats/profit/users', ({ request }) => {
lastUsersQuery = request.url
return HttpResponse.json({ code: 'ISC:000', msg: '成功', data: usersData })
}),
http.get('*/api/v1/stats/profit/channels', ({ request }) => {
lastChannelsQuery = request.url
return HttpResponse.json({ code: 'ISC:000', msg: '成功', data: channelsData })
}),
)
}
afterEach(() => server.resetHandlers())
describe('FE-D34 利润分析', () => {
it('api 契约:用户/通道端点参数与响应结构', async () => {
stubProfit()
const users = await settleApi.profitUsers({ date_from: '2026-11-01', date_to: '2026-11-30', parent_id: 10 })
expect(users.summary.platform_profit).toBe(4.6)
expect(users.list[0].rebate).toBe(1.0)
expect(lastUsersQuery).toContain('date_from=2026-11-01')
expect(lastUsersQuery).toContain('parent_id=10')
const channels = await settleApi.profitChannels({ date_from: '2026-11-01', date_to: '2026-11-30', channel_id: 2 })
expect(channels.list[0].profit).toBe(18)
expect(lastChannelsQuery).toContain('channel_id=2')
})
it('组件:双 Tab 数据渲染+汇总条+利润正负着色+口径说明', async () => {
stubProfit()
const w = mount(StatsProfitView, { global: { plugins: [ElementPlus] } })
await flushPromises()
const text = w.text()
// 汇总条:平台净利 4.60 与账号数。
expect(text).toContain('平台净利')
expect(text).toContain('4.60')
// 用户行:正利润 7.00 / 负利润 -0.40(无价账号)。
expect(text).toContain('7.00')
expect(text).toContain('-0.40')
// 口径说明常驻(分摊/阶梯不进分析/返点 R4)。
expect(text).toContain('占比分摊')
expect(text).toContain('不进分析')
expect(w.find('.pf-neg').exists()).toBe(true)
// 通道 Tab 数据在挂载时一并加载。
expect(w.html()).toContain('18.00')
})
})