Files
th-hotel-simple/client/src/tests/ReservationStatusBadge.spec.ts
2026-07-09 11:59:34 +08:00

42 lines
1.0 KiB
TypeScript

import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import { createI18n } from 'vue-i18n'
import ReservationStatusBadge from '@/components/reservation/ReservationStatusBadge.vue'
import zhCN from '@/i18n/locales/zh-CN'
function mountWithI18n(status: string) {
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
messages: {
'zh-CN': zhCN,
},
})
return mount(ReservationStatusBadge, {
props: {
status,
},
global: {
plugins: [i18n],
},
})
}
describe('ReservationStatusBadge', () => {
it('renders stable status code through i18n label', () => {
const wrapper = mountWithI18n('PENDING_CONFIRM')
expect(wrapper.text()).toContain('待确认')
expect(wrapper.classes()).toContain('status-badge--info')
})
it('falls back to a localized unknown status label', () => {
const wrapper = mountWithI18n('UNKNOWN_STATUS')
expect(wrapper.text()).toContain('未知状态')
expect(wrapper.text()).not.toContain('UNKNOWN_STATUS')
})
})