| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- /**
- * Tests for cfc-frontend utils/bundle-pricing.js
- *
- * 验证购物车套餐offer展示辅助:comboOfferOf 命中/未激活语义;formatComboOfferText 提示文案;
- * 总价不再被自动扣减(纯展示,权威计算在后端 POST /api/cart/combo-offer)。
- */
- const {
- comboOfferOf,
- formatComboOfferText
- } = require('@/utils/bundle-pricing')
- describe('comboOfferOf', () => {
- it('null/undefined → null', () => {
- expect(comboOfferOf(null)).toBeNull()
- expect(comboOfferOf(undefined)).toBeNull()
- })
- it('active 非 true → null', () => {
- expect(comboOfferOf({ active: false, comboName: '套餐X' })).toBeNull()
- expect(comboOfferOf({})).toBeNull()
- })
- it('active=true → 返回 offer(纯展示,不篡改总价)', () => {
- const offer = { active: true, comboName: '套餐X', comboPrice: 15000, saving: 2000, groups: 1 }
- expect(comboOfferOf(offer)).toBe(offer)
- })
- })
- describe('formatComboOfferText', () => {
- it('无 offer → 空串', () => {
- expect(formatComboOfferText(null)).toBe('')
- expect(formatComboOfferText({ active: false })).toBe('')
- })
- it('有 offer → 「这N件组成套餐「XX」,套餐价 ¥Y(省 ¥Z)」', () => {
- const txt = formatComboOfferText({ active: true, comboName: '豪华套餐', comboPrice: 15000, saving: 2000 }, 3)
- expect(txt).toContain('3 件')
- expect(txt).toContain('豪华套餐')
- expect(txt).toContain('150.00')
- expect(txt).toContain('20.00')
- })
- it('有 offer 无 checkedCount → 用 groups 兜底;saving=0 不显示省', () => {
- const txt = formatComboOfferText({ active: true, comboName: '豪华套餐', comboPrice: 15000, saving: 0, groups: 2 })
- expect(txt).toContain('2 件')
- expect(txt).not.toContain('省')
- })
- })
|