import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import { createPinia } from 'pinia';
import { createVuetify } from 'vuetify';
import { createRouter, createMemoryHistory } from 'vue-router';
import AppShell from '../../resources/js/components/AppShell.vue';
// AppShell — layout-mapper по route.meta.layout: 'app' (default) → AppLayout, 'auth' → AuthLayout.
const mountWithRouter = async (path: string) => {
const router = createRouter({
history: createMemoryHistory(),
routes: [
{ path: '/', redirect: '/dashboard' },
{ path: '/dashboard', component: { template: '
dashboard
' }, meta: { layout: 'app' } },
{ path: '/login', component: { template: 'login stub
' }, meta: { layout: 'auth' } },
// Stub'ы для всех nav-targets AppLayout, чтобы избежать router-warn'ов.
{ path: '/deals', component: { template: '' } },
{ path: '/kanban', component: { template: '' } },
{ path: '/reminders', component: { template: '' } },
{ path: '/billing', component: { template: '' } },
{ path: '/reports', component: { template: '' } },
{ path: '/managers', component: { template: '' } },
{ path: '/settings', component: { template: '' } },
],
});
await router.push(path);
await router.isReady();
return mount(AppShell, {
global: { plugins: [createPinia(), createVuetify(), router] },
});
};
describe('AppShell.vue', () => {
it('монтируется без ошибок', async () => {
const wrapper = await mountWithRouter('/dashboard');
expect(wrapper.exists()).toBe(true);
});
it('рендерит AppLayout на default-layout (sidebar с brand + nav)', async () => {
const wrapper = await mountWithRouter('/dashboard');
expect(wrapper.text()).toContain('Лидерра');
// Sidebar nav-группы и пункты — признак AppLayout.
expect(wrapper.text()).toContain('Дашборд');
expect(wrapper.text()).toContain('Сделки');
});
it('переключается на AuthLayout при meta.layout = auth', async () => {
const wrapper = await mountWithRouter('/login');
// На auth-layout sidebar не рендерится — нет nav-пунктов «Сделки»/«Дашборд».
expect(wrapper.text()).not.toContain('Сделки');
expect(wrapper.text()).not.toContain('Дашборд');
});
});