Files
frontend-miniapp/tests/unit/ExplainHallSelect.spec.ts
lyf 5a711377b0
Some checks failed
CI / verify (push) Has been cancelled
优化讲解展厅与对象列表视觉
2026-07-18 01:16:30 +08:00

95 lines
2.9 KiB
TypeScript

// @vitest-environment happy-dom
import { mount } from '@vue/test-utils'
import { describe, expect, it, vi } from 'vitest'
import ExplainHallSelect from '@/components/explain/ExplainHallSelect.vue'
vi.mock('@/utils/hostEnvironment', () => ({
isEmbeddedInWechatMiniProgram: () => false
}))
describe('讲解展厅选择列表', () => {
it('展厅卡片只显示讲解对象数量,不暴露业务单元契约', async () => {
const wrapper = mount(ExplainHallSelect, {
props: {
stage: 'hall',
halls: [
{
id: 'hall-evolution',
name: '生命演化厅',
explainCount: 6,
guideStopCount: 6,
searchText: '生命演化厅'
}
]
}
})
const cards = wrapper.findAll('.hall-card')
expect(cards).toHaveLength(1)
expect(wrapper.text()).toContain('生命演化厅')
expect(wrapper.text()).not.toContain('6 个讲解对象')
expect(wrapper.text()).not.toContain('业务单元')
await cards[0]?.trigger('tap')
expect(wrapper.emitted('hallClick')).toEqual([['hall-evolution']])
})
it('展厅阶段按主题色卡展示展厅名称和图标', () => {
const wrapper = mount(ExplainHallSelect, {
props: {
stage: 'hall',
halls: [{
id: 'hall-dinosaur',
name: '恐龙厅',
floorLabel: 'L-2',
explainCount: 35,
guideStopCount: 35,
searchText: '恐龙厅'
}]
}
})
const card = wrapper.get('.hall-overview-card')
expect(wrapper.get('.header-title').text()).toBe('展厅讲解')
expect(card.attributes('style')).toContain('--hall-card-color: #d9b06c')
expect(card.text()).toContain('恐龙厅')
expect(card.text()).not.toContain('Dinosaur Hall')
expect(card.text()).not.toContain('35 个讲解对象')
expect(card.find('.hall-go-entry').exists()).toBe(false)
})
it('READY 讲解点不显示可讲解标签,非 READY 讲解点保留图文标签和点击事件', async () => {
const readyStop = {
id: 'stop-ready',
name: '生命起源',
hallId: 'hall-evolution',
audioStatus: 'READY'
}
const textStop = {
id: 'stop-text',
name: '化石记录',
hallId: 'hall-evolution',
audioStatus: 'MISSING'
}
const wrapper = mount(ExplainHallSelect, {
props: {
stage: 'stop',
guideStops: [readyStop, textStop]
}
})
const cards = wrapper.findAll('.stop-card')
expect(cards).toHaveLength(2)
expect(wrapper.text()).toContain('生命起源')
expect(wrapper.text()).toContain('化石记录')
expect(wrapper.text()).not.toContain('可讲解')
expect(cards[0]?.find('.hall-meta-row').exists()).toBe(false)
expect(cards[1]?.find('.floor-badge').text()).toBe('图文')
await cards[0]?.trigger('tap')
await cards[1]?.trigger('tap')
expect(wrapper.emitted('guideStopClick')).toEqual([[readyStop], [textStop]])
})
})