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, forceExpanded = false, sidebarPeekOpen = false, onSidebarPeekChange }: {
hideOnCompact?: boolean;
forceExpanded?: boolean;
sidebarPeekOpen?: boolean;
onSidebarPeekChange?: (open: boolean, source: 'toggle' | 'focus' | 'sidebar' | 'titlebar') => void;
}) => (
),
}));
vi.mock('@/components/layout/TitleBar', () => ({
TitleBar: ({ integrated = false, overlay = false, showSidebarControls = true, pageTitle, sidebarPeekOpen = false, onSidebarPeekChange }: {
integrated?: boolean;
overlay?: boolean;
showSidebarControls?: boolean;
pageTitle?: string;
sidebarPeekOpen?: boolean;
onSidebarPeekChange?: (open: boolean, source: 'toggle' | 'focus' | 'sidebar' | 'titlebar') => void;
}) => (
),
}));
function RouteContent() {
routeRenderMock();
return
;
}
function renderLayout(path: string) {
return render(
}>
} />
,
);
}
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', () => {
useSettingsStore.setState({ sidebarCollapsed: true });
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', 'false');
expect(screen.getByTestId('titlebar-stub')).toHaveAttribute('data-peek-open', 'false');
expect(screen.getByTestId('titlebar-stub')).toHaveAttribute('data-has-peek-handler', 'false');
expect(screen.getByTestId('sidebar-stub')).toHaveAttribute('data-hide-on-compact', 'true');
expect(screen.getByTestId('sidebar-stub')).toHaveAttribute('data-force-expanded', 'true');
expect(screen.getByTestId('sidebar-stub')).toHaveAttribute('data-peek-open', 'false');
expect(screen.getByTestId('sidebar-stub')).toHaveAttribute('data-has-peek-handler', 'false');
});
it('gives cloud Agents the full desktop content area and an account workspace title', () => {
renderLayout('/cloud-agents');
expect(screen.getByTestId('main-content')).toHaveClass('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-page-title', '智能体工作区');
expect(screen.getByTestId('titlebar-stub')).toHaveAttribute('data-overlay', 'false');
expect(screen.getByTestId('sidebar-stub')).toHaveAttribute('data-hide-on-compact', 'false');
});
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');
});
});