checkout.couponAutoSelect.spec.js 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. import { readFileSync } from 'fs'
  2. import { resolve } from 'path'
  3. // 契约:shop.checkout.couponAutoSelect (SHOP-AFTERSALES-2026-11-13-V1 §S3-1/2/3)
  4. // 溯源·需求:docs/需求分析/2026-11-13-订单售后与购买体验优化需求变更.md §S3 优惠券最优选择与明显提示
  5. // 溯源·实现:cfc-frontend/pages/shop/checkout/checkout.vue
  6. //
  7. // 说明:源读取契约(与小程序既有 __tests__ 风格一致)。校验常规结算进入时自动选最优券、
  8. // 明显提示「有 N 张优惠券可抵,点击选择」、手动取消后本次不再自动选(_couponDismissed)。
  9. const CHECKOUT_VUE = resolve(__dirname, '../../../pages/shop/checkout/checkout.vue')
  10. const source = readFileSync(CHECKOUT_VUE, 'utf8')
  11. describe('checkout.vue 优惠券最优选择与明显提示(SHOP-AFTERSALES-2026-11-13-V1 S3)', () => {
  12. test('存在 autoSelectCoupon 自动选券方法(S3-1)', () => {
  13. expect(source).toMatch(/autoSelectCoupon\s*\(/)
  14. })
  15. test('常规结算进入自动选面额最优券(selectCoupon(best) + _autoSelected 防重复)', () => {
  16. expect(source).toMatch(/selectCoupon\s*\(\s*best\s*\)/)
  17. expect(source).toMatch(/_autoSelected/)
  18. })
  19. test('存在明显提示「有 N 张优惠券可抵,点击选择」(S3-2)', () => {
  20. expect(source).toMatch(/有 .*张优惠券可抵,点击选择/)
  21. })
  22. test('手动取消券后置 _couponDismissed=true,本次结算会话不再自动选(S3-3)', () => {
  23. expect(source).toMatch(/removeCoupon\s*\(/)
  24. expect(source).toMatch(/_couponDismissed/)
  25. expect(source).toMatch(/this\._couponDismissed\s*=\s*true/)
  26. })
  27. })