Expand left sidebar on home module entry
This commit is contained in:
1 parent
b7f50be87b
commit
1c39471156
4 files changed
+88
-2
No files matched your search
@@ -1,11 +1,12 @@
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
|
||||
import { MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { ModuleSwitcher } from '@/components/layout/ModuleSwitcher';
|
||||
import { ModuleSelection } from '@/pages/ModuleSelection';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { codingWorkspaceStore } from '@/stores/coding-workspace';
|
||||
import { useUserProfileStore } from '@/stores/user-profile';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
|
||||
const { hostApiFetchMock } = vi.hoisted(() => ({
|
||||
hostApiFetchMock: vi.fn(),
|
||||
@@ -20,9 +21,22 @@ function LocationProbe() {
|
||||
return <output data-testid="location-path">{location.pathname}</output>;
|
||||
}
|
||||
|
||||
function SidebarEntryProbe() {
|
||||
const collapsed = useSettingsStore((state) => state.sidebarCollapsed);
|
||||
const setCollapsed = useSettingsStore((state) => state.setSidebarCollapsed);
|
||||
const navigate = useNavigate();
|
||||
return <>
|
||||
<LocationProbe />
|
||||
<output data-testid="sidebar-state">{collapsed ? 'collapsed' : 'expanded'}</output>
|
||||
<button onClick={() => setCollapsed(!collapsed)}>Toggle sidebar</button>
|
||||
<button onClick={() => navigate('/module-select')}>Home</button>
|
||||
</>;
|
||||
}
|
||||
|
||||
describe('AI module navigation', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
useSettingsStore.setState({ sidebarCollapsed: true });
|
||||
useAuthStore.setState({
|
||||
initialized: true,
|
||||
loading: false,
|
||||
@@ -52,6 +66,32 @@ describe('AI module navigation', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
['programming', '/chat'],
|
||||
['cloud_agents', '/cloud-agents'],
|
||||
['painting', '/image-canvas'],
|
||||
])('expands %s on every home entry while allowing manual collapse', async (moduleId, route) => {
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/module-select']}>
|
||||
<Routes>
|
||||
<Route path="/module-select" element={<ModuleSelection />} />
|
||||
<Route path="*" element={<SidebarEntryProbe />} />
|
||||
</Routes>
|
||||
</MemoryRouter>,
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByTestId(`ai-module-option-${moduleId}`));
|
||||
expect(await screen.findByTestId('location-path')).toHaveTextContent(route);
|
||||
expect(screen.getByTestId('sidebar-state')).toHaveTextContent('expanded');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Toggle sidebar' }));
|
||||
expect(screen.getByTestId('sidebar-state')).toHaveTextContent('collapsed');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Home', exact: true }));
|
||||
expect(useSettingsStore.getState().sidebarCollapsed).toBe(true);
|
||||
fireEvent.click(screen.getByTestId(`ai-module-option-${moduleId}`));
|
||||
expect(await screen.findByTestId('sidebar-state')).toHaveTextContent('expanded');
|
||||
});
|
||||
|
||||
it('shows Agents, Code and Canvas on the home page and routes Canvas from the chooser', async () => {
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/module-select']}>
|
||||
@@ -144,6 +184,7 @@ describe('AI module navigation', () => {
|
||||
fireEvent.click(canvasOption);
|
||||
expect(screen.getByTestId('ai-module-selection-page')).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('location-path')).not.toBeInTheDocument();
|
||||
expect(useSettingsStore.getState().sidebarCollapsed).toBe(true);
|
||||
});
|
||||
|
||||
it('routes AI programming from the chooser to the project conversation entry', async () => {
|
||||
@@ -184,6 +225,7 @@ describe('AI module navigation', () => {
|
||||
|
||||
fireEvent.click(screen.getByTestId('ai-module-option-programming'));
|
||||
expect(await screen.findByTestId('location-path')).toHaveTextContent('/login');
|
||||
expect(useSettingsStore.getState().sidebarCollapsed).toBe(true);
|
||||
});
|
||||
|
||||
it('returns to the module chooser from the Sidebar entry', async () => {
|
||||
|
||||
Reference in new issue
Block a user