Files

33 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

import { describe, expect, it } from 'vitest'
import { mountSuspended, mockNuxtImport } from '@nuxt/test-utils/runtime'
import { ref } from 'vue'
import LanguageSwitch from '~/components/LanguageSwitch.vue'
const langSwitchState = ref({ available: true, fallback: '/en/blog' })
mockNuxtImport('useRoute', () => () => ({ path: '/blog/mio-slug' }))
mockNuxtImport('useLocale', () => () => ref('it'))
mockNuxtImport('useLangSwitchState', () => () => langSwitchState)
describe('LanguageSwitch', () => {
it('shows the current language as non-interactive and the other as a link to /en', async () => {
langSwitchState.value = { available: true, fallback: '/en/blog' }
const wrapper = await mountSuspended(LanguageSwitch)
expect(wrapper.find('.lang-option.is-current').text()).toBe('Italiano')
expect(wrapper.find('.lang-option.is-current').attributes('aria-current')).toBe('true')
const link = wrapper.find('a.lang-option')
expect(link.text()).toBe('English')
expect(link.attributes('href')).toBe('/en/blog/mio-slug')
})
it('falls back to the given path when the current content has no translation', async () => {
langSwitchState.value = { available: false, fallback: '/en/blog' }
const wrapper = await mountSuspended(LanguageSwitch)
expect(wrapper.find('a.lang-option').attributes('href')).toBe('/en/blog')
})
})