- 使用真实讲解编号解析接口替换本地演示映射 - 成功后复用现有详情页并自动播放讲解 - 增加查询状态、业务错误提示和相关测试 Made-with: Proma
This commit is contained in:
34
tests/unit/ExplainCodeEntry.spec.ts
Normal file
34
tests/unit/ExplainCodeEntry.spec.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
explainCodeDetailUrl,
|
||||
explainCodeErrorMessage,
|
||||
normalizeExplainCode
|
||||
} from '@/utils/explainCodeEntry'
|
||||
|
||||
describe('讲解编号入口', () => {
|
||||
it('清理首尾空格但保留编号前导零', () => {
|
||||
expect(normalizeExplainCode(' 0231 ')).toBe('0231')
|
||||
})
|
||||
|
||||
it.each([
|
||||
[1020007000, '请输入有效的 4 位讲解编号'],
|
||||
[1020007001, '未找到该讲解编号,请确认后重试'],
|
||||
[1020007002, '该编号的讲解内容暂不可用'],
|
||||
[429, '查询过于频繁,请稍后再试']
|
||||
])('将业务错误码 %s 转换为明确提示', (code, message) => {
|
||||
expect(explainCodeErrorMessage({ code })).toBe(message)
|
||||
})
|
||||
|
||||
it('未知错误使用网络重试提示', () => {
|
||||
expect(explainCodeErrorMessage(new Error('offline'))).toBe('编号查询失败,请检查网络后重试')
|
||||
})
|
||||
|
||||
it('详情路由携带讲解点和自动播放意图', () => {
|
||||
const url = explainCodeDetailUrl({ code: '1001', stopId: '865546652298080256' })
|
||||
expect(url.split('?')[0]).toBe('/pages/exhibit/detail')
|
||||
expect(url).toContain('stopId=865546652298080256')
|
||||
expect(url).toContain('autoplay=1')
|
||||
expect(url).toContain('entry=code')
|
||||
expect(url).toContain('guideCode=1001')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user