assetsEntry.contract.test.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * 契约级单测(静态结构契约)——能力键 ui.profile.assetsEntry
  3. *
  4. * 溯源 / 变更说明:
  5. * 本文件替代已退役的 achievement.fiveCol.test.js 与 achievementLayout.contract.test.js。
  6. * 那两个用例守护的是「我的成就」固定五列(需求变更 D / SC-A-27 / SC-P-96)。
  7. * 2026-11-28「我的」页收敛重设计(主动健康生活方式 · 极致简单)明确:
  8. * * 我的成就(5 宫格)、我的订单(5+2 宫格)、卡券中心(2 宫格)
  9. * → 收敛为「我的资产」单卡内 3 汇总入口(订单 / 卡券 / 成就),明细进二级页;
  10. * * 因此「成就固定五列」能力被本页目标结构取代,原两个五列用例失效退役,
  11. * 由本文件守护新结构。若后续需求侧要求恢复五列,应以新用例另行守护,
  12. * 不得直接复活旧用例(旧用例同时断言了已删除的 order/coupon 网格布局)。
  13. *
  14. * 契约要点(本文件守护的破坏):
  15. * 1) 「我的资产」入口存在,且为单卡 + 3 宫格(订单 / 卡券 / 成就),每入口有明确跳转;
  16. * 2) 收敛彻底性:模板不得残留五列成就网格、订单五宫格、卡券宫格;
  17. * 样式不得残留 .achievement-grid.cols-5 / .order-* 规则;
  18. * 3) 双邀请入口治理:浮动邀请按钮(.share-qr-float)已删,团队网格「邀请成员」
  19. * 分享项(.ach-item-share + open-type="share")保留,全页仅剩一个邀请入口;
  20. * 4) 死方法清理:goToTasks / goToAppointments(模板未引用的历史死方法)已删;
  21. * 5) 访客态登录引导复用共享 LoginGuideCard,不再内联 gp-guide 结构;
  22. * 6) 订单入口展示四态合计汇总数(computed orderTotal),不再逐态铺 5 个徽标。
  23. *
  24. * 断言口径(静态结构契约,读真实 SFC 源码,不依赖渲染引擎):
  25. * cfc-frontend jest.config.js 仅 transform .js,未装 vue-jest/jsdom 组件环境——
  26. * 沿用既有约定:读取真实 SFC 源码做结构契约断言
  27. * (同目录 bottomMenuOverflow.contract.test.js 的读源法)。本文件不修改 pages/ 业务代码。
  28. */
  29. import fs from 'fs'
  30. import path from 'path'
  31. const PAGE_PATH = path.join(__dirname, '../../../pages/profile-main/profile.vue')
  32. const SRC = fs.readFileSync(PAGE_PATH, 'utf8')
  33. function templateOf(src) {
  34. const m = src.match(/<template>([\s\S]*?)<\/template>/)
  35. return m ? m[1] : ''
  36. }
  37. function scriptOf(src) {
  38. const m = src.match(/<script>([\s\S]*?)<\/script>/)
  39. return m ? m[1] : ''
  40. }
  41. function styleOf(src) {
  42. const m = src.match(/<style[^>]*>([\s\S]*?)<\/style>/)
  43. return m ? m[1] : ''
  44. }
  45. const TEMPLATE = templateOf(SRC)
  46. const SCRIPT = scriptOf(SRC)
  47. const STYLE = styleOf(SRC)
  48. /** 取模板中「我的资产」区块:从 assets-section 到 team 之前的片段 */
  49. function assetsSection(src) {
  50. const t = templateOf(src)
  51. const start = t.indexOf('assets-section')
  52. if (start < 0) return ''
  53. // 资产区之后紧接团队区(achievement-section / team-grid)或无其它
  54. const next = t.indexOf('team-grid', start)
  55. return t.slice(start, next > 0 ? next : t.length)
  56. }
  57. const ASSETS = assetsSection(SRC)
  58. describe('ui.profile.assetsEntry · 「我的」页资产入口收敛(订单/卡券/成就 3 宫格)', () => {
  59. test('TC-AE-01 资产入口区存在,且以共享 BaseCard 单卡承载', () => {
  60. expect(ASSETS).not.toBe('')
  61. expect(TEMPLATE).toMatch(/<BaseCard[^>]*class="assets-card"/)
  62. expect(TEMPLATE).toMatch(/class="assets-title"[^>]*>我的资产</)
  63. })
  64. test('TC-AE-02 资产卡内恰 3 个宫格入口,文案与跳转方法齐备', () => {
  65. const cells = ASSETS.match(/class="asset-cell"/g) || []
  66. expect(cells.length).toBe(3)
  67. const map = [
  68. { handler: 'goToOrders', label: '订单', expr: 'orderTotal' },
  69. { handler: 'goToCoupons', label: '卡券', expr: 'couponCount' },
  70. { handler: 'goToBadges', label: '成就', expr: 'badgesCollected' }
  71. ]
  72. map.forEach((item) => {
  73. expect(ASSETS).toMatch(new RegExp('@click="' + item.handler + '"'))
  74. // 文案与汇总数同属一个 cell
  75. expect(ASSETS).toMatch(new RegExp(item.handler + '[\\s\\S]*?' + item.label))
  76. expect(ASSETS).toMatch(new RegExp(item.handler + '[\\s\\S]*?\\{\\{\\s*' + item.expr + '\\s*\\}\\}'))
  77. })
  78. })
  79. test('TC-AE-03 收敛彻底性:模板不再有五列成就网格 / 订单五宫格 / 卡券宫格', () => {
  80. expect(TEMPLATE).not.toMatch(/achievement-grid\s+cols-5/)
  81. expect(TEMPLATE).not.toMatch(/class="order-grid"|class="order-grid-item"|class="order-section"|class="order-card"/)
  82. expect(TEMPLATE).not.toMatch(/class="order-icon-wrap"|class="order-extra-item"/)
  83. // 原「我的成就 / 卡券中心」独立区块标题不应再出现
  84. expect(TEMPLATE).not.toMatch(/我的成就/)
  85. expect(TEMPLATE).not.toMatch(/卡券中心/)
  86. })
  87. test('TC-AE-04 收敛彻底性:样式不再残留五列 / 订单宫格规则,且有资产卡样式', () => {
  88. expect(STYLE).not.toMatch(/\.achievement-grid\.cols-5/)
  89. expect(STYLE).not.toMatch(/\.order-grid\b|\.order-card\b|\.order-icon-wrap\b|\.order-extra-item\b/)
  90. expect(STYLE).toMatch(/\.assets-grid\b/)
  91. expect(STYLE).toMatch(/\.asset-cell\b/)
  92. expect(STYLE).toMatch(/\.asset-ic-order\b/)
  93. expect(STYLE).toMatch(/\.asset-ic-coupon\b/)
  94. expect(STYLE).toMatch(/\.asset-ic-achieve\b/)
  95. })
  96. test('TC-AE-05 订单汇总入口用 computed orderTotal(四态合计),不再逐态徽标', () => {
  97. expect(SCRIPT).toMatch(/orderTotal\(\)/)
  98. expect(SCRIPT).toMatch(/orderPending \+ this\.orderUnpaid \+ this\.orderShipped \+ this\.orderAfterSale/)
  99. // 逐态跳转方法已随订单五宫格一起删除
  100. expect(SCRIPT).not.toMatch(/goToOrderStatus/)
  101. // 购物车 / 收货地址 入口随订单附加行删除
  102. expect(SCRIPT).not.toMatch(/goToCart|goToAddress|loadCartCount/)
  103. })
  104. test('TC-AE-06 双邀请入口治理:浮动邀请已删,团队网格分享项唯一保留', () => {
  105. // 浮动二维码邀请按钮整块删除
  106. expect(TEMPLATE).not.toMatch(/share-qr-float|qr-glyph|qr-eye/)
  107. expect(STYLE).not.toMatch(/\.share-qr-float\b|\.qr-glyph\b/)
  108. // 团队「邀请成员」分享项保留,且全页仅剩一个 open-type="share"
  109. expect(TEMPLATE).toMatch(/class="ach-item ach-item-share"[\s\S]*?open-type="share"/)
  110. const shareButtons = TEMPLATE.match(/open-type="share"/g) || []
  111. expect(shareButtons.length).toBe(1)
  112. // 团队网格三入口仍在
  113. expect(TEMPLATE).toMatch(/team-grid/)
  114. })
  115. test('TC-AE-07 死方法清理:goToTasks / goToAppointments 已删', () => {
  116. expect(SCRIPT).not.toMatch(/goToTasks/)
  117. expect(SCRIPT).not.toMatch(/goToAppointments/)
  118. // 连带失效的五宫格成就 / 卡券二级跳转方法亦应清理
  119. expect(SCRIPT).not.toMatch(/goToStreak|goToTaskHistory|goToGrowth|goToChallenges|goToWishes/)
  120. })
  121. test('TC-AE-08 访客态登录引导复用 LoginGuideCard,不再内联实现', () => {
  122. expect(TEMPLATE).toMatch(/<LoginGuideCard/)
  123. // 内联登录引导的自绘结构(标题/清单/勾选/按钮)必须清除;
  124. // .gp-guide 仅保留为外层横向边距容器(与 .gg-guide/.gh-guide 同款),故不在禁用项内
  125. 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/)
  126. expect(STYLE).not.toMatch(/\.gp-guide-(head|title|list|item|check|ic|btn|text|desc)\b/)
  127. // 外层边距容器存在(保持与本页其它访客卡同宽)
  128. expect(STYLE).toMatch(/\.gp-guide\s*\{\s*margin:\s*0 32rpx 8rpx/)
  129. // 组件已注册
  130. expect(SCRIPT).toMatch(/components:\s*\{[^}]*LoginGuideCard/)
  131. })
  132. })
  133. // ---------------------------------------------------------------------------
  134. // 权限流:资产入口区为已登录态统一展示,无角色门禁分支
  135. // (规划师服务中心另有 v-if 门禁,不在本契约范围)。显式记录不适用项。
  136. // ---------------------------------------------------------------------------
  137. describe.skip('权限流:资产入口区无角色门禁,不适用', () => {
  138. it('占位:资产入口对所有已登录用户一致展示(详见汇报)', () => {})
  139. })