34 lines
1.5 KiB
TypeScript
34 lines
1.5 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
|
|
import { LearningSidebar } from '@/components/layout/LearningSidebar';
|
|
|
|
function LocationProbe() {
|
|
const location = useLocation();
|
|
return <output data-testid="location-path">{location.pathname}</output>;
|
|
}
|
|
|
|
describe('LearningSidebar', () => {
|
|
it('shows only the new project catalog navigation and returns detail pages to the list', () => {
|
|
render(
|
|
<MemoryRouter initialEntries={['/learning/project/project-1']}>
|
|
<Routes>
|
|
<Route path="*" element={<><LearningSidebar sidebarCollapsed={false} /><LocationProbe /></>} />
|
|
</Routes>
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
expect(screen.getByRole('navigation', { name: 'AI 学习导航' })).toHaveTextContent('学习项目');
|
|
expect(screen.queryByText('生成课程')).not.toBeInTheDocument();
|
|
expect(screen.queryByText('我的课程')).not.toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole('button', { name: '学习项目' }));
|
|
expect(screen.getByTestId('location-path')).toHaveTextContent('/learning');
|
|
});
|
|
|
|
it('keeps the collapsed navigation compact', () => {
|
|
render(<MemoryRouter><LearningSidebar sidebarCollapsed /></MemoryRouter>);
|
|
expect(screen.getByRole('button', { name: '学习项目' })).toBeInTheDocument();
|
|
expect(screen.queryByText('阅读项目说明并下载到电脑实践。')).not.toBeInTheDocument();
|
|
});
|
|
});
|