95 lines
3.6 KiB
TypeScript
95 lines
3.6 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { MainLayout } from '@/components/layout/MainLayout';
|
|
import { useSettingsStore } from '@/stores/settings';
|
|
|
|
const routeRenderMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock('@/components/layout/Sidebar', () => ({
|
|
Sidebar: ({ hideOnCompact = false }: { hideOnCompact?: boolean }) => (
|
|
<aside data-testid="sidebar-stub" data-hide-on-compact={String(hideOnCompact)} />
|
|
),
|
|
}));
|
|
vi.mock('@/components/layout/TitleBar', () => ({
|
|
TitleBar: ({ integrated = false, overlay = false, showSidebarControls = true, pageTitle }: { integrated?: boolean; overlay?: boolean; showSidebarControls?: boolean; pageTitle?: string }) => (
|
|
<header
|
|
data-testid="titlebar-stub"
|
|
data-integrated={integrated ? 'true' : 'false'}
|
|
data-overlay={overlay ? 'true' : 'false'}
|
|
data-sidebar-controls={showSidebarControls ? 'true' : 'false'}
|
|
data-page-title={pageTitle ?? ''}
|
|
/>
|
|
),
|
|
}));
|
|
|
|
function RouteContent() {
|
|
routeRenderMock();
|
|
return <div data-testid="route-content" />;
|
|
}
|
|
|
|
function renderLayout(path: string) {
|
|
return render(
|
|
<MemoryRouter initialEntries={[path]}>
|
|
<Routes>
|
|
<Route element={<MainLayout />}>
|
|
<Route path="*" element={<RouteContent />} />
|
|
</Route>
|
|
</Routes>
|
|
</MemoryRouter>,
|
|
);
|
|
}
|
|
|
|
describe('MainLayout module isolation', () => {
|
|
beforeEach(() => {
|
|
routeRenderMock.mockReset();
|
|
useSettingsStore.setState({ sidebarCollapsed: false });
|
|
});
|
|
|
|
it('does not overlay the local project initialization gate on AI painting', () => {
|
|
renderLayout('/image-canvas');
|
|
|
|
expect(screen.getByTestId('route-content')).toBeVisible();
|
|
expect(screen.queryByTestId('project-initialization-gate')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('uses the full-height workspace shell with the shared left project sidebar for AI painting', () => {
|
|
renderLayout('/image-canvas');
|
|
|
|
expect(screen.getByTestId('main-content')).toHaveClass('basis-0', 'h-full', 'overflow-hidden', 'p-0');
|
|
expect(screen.getByTestId('main-content')).not.toHaveClass('p-5', 'sm:p-6');
|
|
expect(screen.getByTestId('titlebar-stub')).toHaveAttribute('data-overlay', 'true');
|
|
expect(screen.getByTestId('titlebar-stub')).toHaveAttribute('data-sidebar-controls', 'true');
|
|
expect(screen.getByTestId('sidebar-stub')).toHaveAttribute('data-hide-on-compact', 'true');
|
|
});
|
|
|
|
it('does not overlay the local project initialization gate on AI hardware', () => {
|
|
renderLayout('/ai-hardware');
|
|
|
|
expect(screen.getByTestId('route-content')).toBeVisible();
|
|
expect(screen.queryByTestId('project-initialization-gate')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('does not restore the removed project initialization gate on AI programming routes', () => {
|
|
renderLayout('/chat');
|
|
|
|
expect(screen.getByTestId('route-content')).toBeVisible();
|
|
expect(screen.queryByTestId('project-initialization-gate')).not.toBeInTheDocument();
|
|
expect(screen.getByTestId('titlebar-stub')).toHaveAttribute('data-overlay', 'false');
|
|
});
|
|
|
|
it('keeps the project-settings plugin workspace outside the local project initialization gate', () => {
|
|
renderLayout('/project-config/plugins');
|
|
|
|
expect(screen.getByTestId('route-content')).toBeVisible();
|
|
expect(screen.queryByTestId('project-initialization-gate')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('keeps the programming workspace padding compensation separate from painting', () => {
|
|
renderLayout('/chat');
|
|
|
|
expect(screen.getByTestId('main-content')).toHaveClass('basis-0', 'overflow-hidden', 'p-0', 'sm:p-6');
|
|
});
|
|
|
|
});
|