118 lines
4.7 KiB
TypeScript
118 lines
4.7 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import {
|
|
DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG,
|
|
dedupeOrderServiceBottomGuideImages,
|
|
canAccessOrderServiceMaterial,
|
|
isOrderServiceAgeGateOpen,
|
|
mergeOrderServiceAgeGateConfig,
|
|
parseOrderServiceAgeGateContent,
|
|
selectFirstOrderServiceAgeGate,
|
|
resolveOrderServiceAgeGateDecision,
|
|
shouldRequireOrderServiceAgeGate,
|
|
} from '../src/utils/order-service-age-gate.ts'
|
|
|
|
test('只有启用且存在待补资料商品时才要求未成年确认', () => {
|
|
assert.equal(shouldRequireOrderServiceAgeGate({ enabled: true, pendingCount: 1 }), true)
|
|
assert.equal(shouldRequireOrderServiceAgeGate({ enabled: false, pendingCount: 1 }), false)
|
|
assert.equal(shouldRequireOrderServiceAgeGate({ enabled: true, pendingCount: 0 }), false)
|
|
assert.equal(shouldRequireOrderServiceAgeGate({ pendingCount: 1 }), false)
|
|
})
|
|
|
|
test('已成年可以通过,未成年和未选择不能进入资料表单', () => {
|
|
assert.equal(canAccessOrderServiceMaterial({ required: true, decision: 'adult' }), true)
|
|
assert.equal(canAccessOrderServiceMaterial({ required: true, decision: 'minor' }), false)
|
|
assert.equal(canAccessOrderServiceMaterial({ required: true, decision: 'pending' }), false)
|
|
assert.equal(canAccessOrderServiceMaterial({ required: false, decision: 'minor' }), true)
|
|
})
|
|
|
|
test('切换订单号后恢复为未确认状态', () => {
|
|
const state = { orderNo: 'order-a', decision: 'adult' as const }
|
|
assert.equal(resolveOrderServiceAgeGateDecision(state, 'order-a'), 'adult')
|
|
assert.equal(resolveOrderServiceAgeGateDecision(state, 'order-b'), 'pending')
|
|
})
|
|
|
|
test('配置页默认值直接可填,不依赖灰色 placeholder', () => {
|
|
assert.equal(DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG.enabled, false)
|
|
assert.equal(DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG.title, '购买前必读')
|
|
assert.match(DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG.content, /购买商品和角色信息有没有错误/)
|
|
assert.match(DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG.importantNotice, /冒充本店售后专员/)
|
|
})
|
|
|
|
test('读取到旧配置空字段时仍用默认文案填充', () => {
|
|
const config = mergeOrderServiceAgeGateConfig({
|
|
enabled: true,
|
|
title: '',
|
|
warningText: ' ',
|
|
content: '',
|
|
importantNotice: '',
|
|
adultButtonText: '',
|
|
minorButtonText: '',
|
|
minorBlockedTitle: '',
|
|
minorBlockedContent: '',
|
|
})
|
|
|
|
assert.equal(config.enabled, true)
|
|
assert.equal(config.title, '购买前必读')
|
|
assert.equal(config.warningText, '无法向未成年人操作发货,请认真阅读作答!!!')
|
|
assert.match(config.content, /购买商品和角色信息有没有错误/)
|
|
assert.equal(config.adultButtonText, '我已成年')
|
|
assert.equal(config.minorButtonText, '我是未成年')
|
|
assert.equal(config.minorBlockedTitle, '未成年不能购买')
|
|
})
|
|
|
|
test('弹窗正文按编号拆分为标题和说明,保证编号加粗布局', () => {
|
|
const blocks = parseOrderServiceAgeGateContent(DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG.content)
|
|
assert.equal(blocks.length, 6)
|
|
assert.equal(blocks[0]?.number, '1')
|
|
assert.equal(blocks[0]?.title, '购买商品和角色信息有没有错误')
|
|
assert.deepEqual(blocks[0]?.lines, [
|
|
'角色名/系统/区服有无遗漏',
|
|
'如未核对导致送错,本店概不负责哦~',
|
|
])
|
|
assert.equal(blocks[5]?.number, '6')
|
|
assert.match(blocks[5]?.title || '', /禁止私自交易/)
|
|
})
|
|
|
|
test('弹窗打开时整页内容必须隐藏,已成年后才恢复', () => {
|
|
assert.equal(isOrderServiceAgeGateOpen({ required: true, decision: 'pending' }), true)
|
|
assert.equal(isOrderServiceAgeGateOpen({ required: true, decision: 'minor' }), true)
|
|
assert.equal(isOrderServiceAgeGateOpen({ required: true, decision: 'adult' }), false)
|
|
assert.equal(isOrderServiceAgeGateOpen({ required: false, decision: 'pending' }), false)
|
|
})
|
|
|
|
test('多商品只选第一个未成年提示配置,底部引导图按图片去重', () => {
|
|
const gateA = {
|
|
enabled: true,
|
|
title: 'A',
|
|
warningText: 'A',
|
|
content: 'A',
|
|
importantNotice: 'A',
|
|
adultButtonText: '我已成年',
|
|
minorButtonText: '我是未成年',
|
|
minorBlockedTitle: '不能购买',
|
|
minorBlockedContent: '停止',
|
|
}
|
|
const gateB = { ...gateA, title: 'B' }
|
|
const image = {
|
|
objectKey: 'order-service-guide/a.png',
|
|
url: '/a.png',
|
|
thumbnailUrl: '/a.png',
|
|
mediumUrl: '/a.png',
|
|
filename: 'a.png',
|
|
contentType: 'image/png',
|
|
size: 1,
|
|
}
|
|
|
|
assert.equal(selectFirstOrderServiceAgeGate([{ ageGate: gateA }, { ageGate: gateB }])?.title, 'A')
|
|
assert.equal(
|
|
dedupeOrderServiceBottomGuideImages([
|
|
{ bottomGuideImage: { enabled: true, image } },
|
|
{ bottomGuideImage: { enabled: true, image } },
|
|
{ bottomGuideImage: { enabled: false, image } },
|
|
]).length,
|
|
1,
|
|
)
|
|
})
|