58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
|
import App from '../../src/App.vue'
|
|
import NotFoundView from '../../src/views/NotFoundView.vue'
|
|
import { setNavigation } from '../../src/state/useNavigation'
|
|
import { navigationFixture } from '../fixtures/typed'
|
|
import { resetState, routerAt, signIn } from '../helpers'
|
|
|
|
async function mountAt(path: string) {
|
|
const router = await routerAt(path)
|
|
const wrapper = mount(App, { global: { plugins: [router] } })
|
|
await flushPromises()
|
|
return { wrapper, router }
|
|
}
|
|
|
|
beforeEach(() => {
|
|
resetState()
|
|
})
|
|
|
|
afterEach(() => {
|
|
document.body.innerHTML = ''
|
|
document.title = ''
|
|
})
|
|
|
|
enableAutoUnmount(afterEach)
|
|
|
|
describe('app root', () => {
|
|
it('renders the login route outside the shell', async () => {
|
|
const { wrapper } = await mountAt('/login')
|
|
expect(wrapper.find('nav[aria-label="Wtyczki"]').exists()).toBe(false)
|
|
expect(wrapper.find('form').exists()).toBe(true)
|
|
expect(document.title).toBe('Witaj ponownie | SummerCMS')
|
|
})
|
|
|
|
it('renders shell routes inside the shell and an unknown path as not found', async () => {
|
|
await signIn()
|
|
setNavigation(navigationFixture.data)
|
|
const { wrapper } = await mountAt('/nowhere')
|
|
expect(wrapper.find('nav[aria-label="Wtyczki"]').exists()).toBe(true)
|
|
expect(wrapper.findComponent(NotFoundView).exists()).toBe(true)
|
|
expect(wrapper.find('main h1').text()).toBe('Nie znaleziono strony.')
|
|
expect(document.title).toBe('Nie znaleziono strony. | SummerCMS')
|
|
})
|
|
|
|
it('says so when the admin may open no plugin', async () => {
|
|
await signIn()
|
|
const { wrapper } = await mountAt('/')
|
|
expect(wrapper.find('main h1').text()).toBe('Brak dostępnych sekcji.')
|
|
})
|
|
})
|
|
|
|
describe('not found view', () => {
|
|
it('switches its message by the home prop', () => {
|
|
expect(mount(NotFoundView).find('h1').text()).toBe('Nie znaleziono strony.')
|
|
expect(mount(NotFoundView, { props: { home: true } }).find('h1').text()).toBe('Brak dostępnych sekcji.')
|
|
})
|
|
})
|