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 = '' }) 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) }) 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.') }) 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.') }) })