| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /**
- * 契约级单测(静态结构契约)——能力键 ui.profile.assetsEntry
- *
- * 溯源 / 变更说明:
- * 本文件替代已退役的 achievement.fiveCol.test.js 与 achievementLayout.contract.test.js。
- * 那两个用例守护的是「我的成就」固定五列(需求变更 D / SC-A-27 / SC-P-96)。
- * 2026-11-28「我的」页收敛重设计(主动健康生活方式 · 极致简单)明确:
- * * 我的成就(5 宫格)、我的订单(5+2 宫格)、卡券中心(2 宫格)
- * → 收敛为「我的资产」单卡内 3 汇总入口(订单 / 卡券 / 成就),明细进二级页;
- * * 因此「成就固定五列」能力被本页目标结构取代,原两个五列用例失效退役,
- * 由本文件守护新结构。若后续需求侧要求恢复五列,应以新用例另行守护,
- * 不得直接复活旧用例(旧用例同时断言了已删除的 order/coupon 网格布局)。
- *
- * 契约要点(本文件守护的破坏):
- * 1) 「我的资产」入口存在,且为单卡 + 3 宫格(订单 / 卡券 / 成就),每入口有明确跳转;
- * 2) 收敛彻底性:模板不得残留五列成就网格、订单五宫格、卡券宫格;
- * 样式不得残留 .achievement-grid.cols-5 / .order-* 规则;
- * 3) 双邀请入口治理:浮动邀请按钮(.share-qr-float)已删,团队网格「邀请成员」
- * 分享项(.ach-item-share + open-type="share")保留,全页仅剩一个邀请入口;
- * 4) 死方法清理:goToTasks / goToAppointments(模板未引用的历史死方法)已删;
- * 5) 访客态登录引导复用共享 LoginGuideCard,不再内联 gp-guide 结构;
- * 6) 订单入口展示四态合计汇总数(computed orderTotal),不再逐态铺 5 个徽标。
- *
- * 断言口径(静态结构契约,读真实 SFC 源码,不依赖渲染引擎):
- * cfc-frontend jest.config.js 仅 transform .js,未装 vue-jest/jsdom 组件环境——
- * 沿用既有约定:读取真实 SFC 源码做结构契约断言
- * (同目录 bottomMenuOverflow.contract.test.js 的读源法)。本文件不修改 pages/ 业务代码。
- */
- import fs from 'fs'
- import path from 'path'
- const PAGE_PATH = path.join(__dirname, '../../../pages/profile-main/profile.vue')
- const SRC = fs.readFileSync(PAGE_PATH, 'utf8')
- function templateOf(src) {
- const m = src.match(/<template>([\s\S]*?)<\/template>/)
- return m ? m[1] : ''
- }
- function scriptOf(src) {
- const m = src.match(/<script>([\s\S]*?)<\/script>/)
- return m ? m[1] : ''
- }
- function styleOf(src) {
- const m = src.match(/<style[^>]*>([\s\S]*?)<\/style>/)
- return m ? m[1] : ''
- }
- const TEMPLATE = templateOf(SRC)
- const SCRIPT = scriptOf(SRC)
- const STYLE = styleOf(SRC)
- /** 取模板中「我的资产」区块:从 assets-section 到 team 之前的片段 */
- function assetsSection(src) {
- const t = templateOf(src)
- const start = t.indexOf('assets-section')
- if (start < 0) return ''
- // 资产区之后紧接团队区(achievement-section / team-grid)或无其它
- const next = t.indexOf('team-grid', start)
- return t.slice(start, next > 0 ? next : t.length)
- }
- const ASSETS = assetsSection(SRC)
- describe('ui.profile.assetsEntry · 「我的」页资产入口收敛(订单/卡券/成就 3 宫格)', () => {
- test('TC-AE-01 资产入口区存在,且以共享 BaseCard 单卡承载', () => {
- expect(ASSETS).not.toBe('')
- expect(TEMPLATE).toMatch(/<BaseCard[^>]*class="assets-card"/)
- expect(TEMPLATE).toMatch(/class="assets-title"[^>]*>我的资产</)
- })
- test('TC-AE-02 资产卡内恰 3 个宫格入口,文案与跳转方法齐备', () => {
- const cells = ASSETS.match(/class="asset-cell"/g) || []
- expect(cells.length).toBe(3)
- const map = [
- { handler: 'goToOrders', label: '订单', expr: 'orderTotal' },
- { handler: 'goToCoupons', label: '卡券', expr: 'couponCount' },
- { handler: 'goToBadges', label: '成就', expr: 'badgesCollected' }
- ]
- map.forEach((item) => {
- expect(ASSETS).toMatch(new RegExp('@click="' + item.handler + '"'))
- // 文案与汇总数同属一个 cell
- expect(ASSETS).toMatch(new RegExp(item.handler + '[\\s\\S]*?' + item.label))
- expect(ASSETS).toMatch(new RegExp(item.handler + '[\\s\\S]*?\\{\\{\\s*' + item.expr + '\\s*\\}\\}'))
- })
- })
- test('TC-AE-03 收敛彻底性:模板不再有五列成就网格 / 订单五宫格 / 卡券宫格', () => {
- expect(TEMPLATE).not.toMatch(/achievement-grid\s+cols-5/)
- expect(TEMPLATE).not.toMatch(/class="order-grid"|class="order-grid-item"|class="order-section"|class="order-card"/)
- expect(TEMPLATE).not.toMatch(/class="order-icon-wrap"|class="order-extra-item"/)
- // 原「我的成就 / 卡券中心」独立区块标题不应再出现
- expect(TEMPLATE).not.toMatch(/我的成就/)
- expect(TEMPLATE).not.toMatch(/卡券中心/)
- })
- test('TC-AE-04 收敛彻底性:样式不再残留五列 / 订单宫格规则,且有资产卡样式', () => {
- expect(STYLE).not.toMatch(/\.achievement-grid\.cols-5/)
- expect(STYLE).not.toMatch(/\.order-grid\b|\.order-card\b|\.order-icon-wrap\b|\.order-extra-item\b/)
- expect(STYLE).toMatch(/\.assets-grid\b/)
- expect(STYLE).toMatch(/\.asset-cell\b/)
- expect(STYLE).toMatch(/\.asset-ic-order\b/)
- expect(STYLE).toMatch(/\.asset-ic-coupon\b/)
- expect(STYLE).toMatch(/\.asset-ic-achieve\b/)
- })
- test('TC-AE-05 订单汇总入口用 computed orderTotal(四态合计),不再逐态徽标', () => {
- expect(SCRIPT).toMatch(/orderTotal\(\)/)
- expect(SCRIPT).toMatch(/orderPending \+ this\.orderUnpaid \+ this\.orderShipped \+ this\.orderAfterSale/)
- // 逐态跳转方法已随订单五宫格一起删除
- expect(SCRIPT).not.toMatch(/goToOrderStatus/)
- // 购物车 / 收货地址 入口随订单附加行删除
- expect(SCRIPT).not.toMatch(/goToCart|goToAddress|loadCartCount/)
- })
- test('TC-AE-06 双邀请入口治理:浮动邀请已删,团队网格分享项唯一保留', () => {
- // 浮动二维码邀请按钮整块删除
- expect(TEMPLATE).not.toMatch(/share-qr-float|qr-glyph|qr-eye/)
- expect(STYLE).not.toMatch(/\.share-qr-float\b|\.qr-glyph\b/)
- // 团队「邀请成员」分享项保留,且全页仅剩一个 open-type="share"
- expect(TEMPLATE).toMatch(/class="ach-item ach-item-share"[\s\S]*?open-type="share"/)
- const shareButtons = TEMPLATE.match(/open-type="share"/g) || []
- expect(shareButtons.length).toBe(1)
- // 团队网格三入口仍在
- expect(TEMPLATE).toMatch(/team-grid/)
- })
- test('TC-AE-07 死方法清理:goToTasks / goToAppointments 已删', () => {
- expect(SCRIPT).not.toMatch(/goToTasks/)
- expect(SCRIPT).not.toMatch(/goToAppointments/)
- // 连带失效的五宫格成就 / 卡券二级跳转方法亦应清理
- expect(SCRIPT).not.toMatch(/goToStreak|goToTaskHistory|goToGrowth|goToChallenges|goToWishes/)
- })
- test('TC-AE-08 访客态登录引导复用 LoginGuideCard,不再内联实现', () => {
- expect(TEMPLATE).toMatch(/<LoginGuideCard/)
- // 内联登录引导的自绘结构(标题/清单/勾选/按钮)必须清除;
- // .gp-guide 仅保留为外层横向边距容器(与 .gg-guide/.gh-guide 同款),故不在禁用项内
- expect(TEMPLATE).not.toMatch(/gp-guide-head|gp-guide-title|gp-guide-list|gp-guide-item|gp-guide-check|gp-guide-ic\b|gp-guide-btn|gp-guide-text|gp-guide-desc/)
- expect(STYLE).not.toMatch(/\.gp-guide-(head|title|list|item|check|ic|btn|text|desc)\b/)
- // 外层边距容器存在(保持与本页其它访客卡同宽)
- expect(STYLE).toMatch(/\.gp-guide\s*\{\s*margin:\s*0 32rpx 8rpx/)
- // 组件已注册
- expect(SCRIPT).toMatch(/components:\s*\{[^}]*LoginGuideCard/)
- })
- })
- // ---------------------------------------------------------------------------
- // 权限流:资产入口区为已登录态统一展示,无角色门禁分支
- // (规划师服务中心另有 v-if 门禁,不在本契约范围)。显式记录不适用项。
- // ---------------------------------------------------------------------------
- describe.skip('权限流:资产入口区无角色门禁,不适用', () => {
- it('占位:资产入口对所有已登录用户一致展示(详见汇报)', () => {})
- })
|