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