fix(agents): open cards from home and align sidebar navigation
This commit is contained in:
1 parent
e5d79bf37a
commit
5e99804bc2
13 files changed
+460
-27
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import type { ReactElement } from 'react';
|
||||
import { act, fireEvent, render as renderComponent, screen, waitFor } from '@testing-library/react';
|
||||
import { act, fireEvent, render as renderComponent, screen, waitFor, within } from '@testing-library/react';
|
||||
import { MemoryRouter, useLocation } from 'react-router-dom';
|
||||
import { TitleBar } from '@/components/layout/TitleBar';
|
||||
import { CodingConversationHeader } from '@/pages/Chat/CodingConversationHeader';
|
||||
@@ -28,6 +28,64 @@ describe('TitleBar platform behavior', () => {
|
||||
useSettingsStore.setState({ sidebarCollapsed: false, classroomSidebarWidth: 171 });
|
||||
});
|
||||
|
||||
it.each([
|
||||
['darwin', 168, 'pl-[88px]'],
|
||||
['win32', 88, 'pl-3'],
|
||||
['linux', 88, 'pl-3'],
|
||||
] as const)('keeps Agents return and collapse together and reachable on %s', (platform, collapsedWidth, inset) => {
|
||||
window.electron.platform = platform;
|
||||
renderComponent(<MemoryRouter initialEntries={['/cloud-agents?view=mine']}>
|
||||
<TitleBar integrated showModuleReturn pageTitle="我的智能体" />
|
||||
<LocationPath />
|
||||
</MemoryRouter>);
|
||||
const navigation = screen.getByTestId('agent-titlebar-navigation');
|
||||
const back = within(navigation).getByRole('button', { name: '返回首页' });
|
||||
const toggle = within(navigation).getByRole('button', { name: '折叠侧栏' });
|
||||
expect(navigation).toHaveClass('flex', 'items-center', inset);
|
||||
expect(back).toHaveClass('text-brand', 'rounded-full');
|
||||
expect(back).not.toHaveTextContent('Agents');
|
||||
expect(screen.getAllByRole('button', { name: '返回首页' })).toHaveLength(1);
|
||||
expect(screen.getByTestId('titlebar-sidebar-surface')).toHaveStyle({ width: '256px' });
|
||||
expect(toggle).toHaveClass('right-2');
|
||||
fireEvent.click(toggle);
|
||||
expect(screen.getByTestId('titlebar-sidebar-toggle-layer')).toHaveStyle({ width: `${collapsedWidth}px` });
|
||||
expect(back).toBeVisible();
|
||||
fireEvent.click(within(navigation).getByRole('button', { name: '展开侧栏' }));
|
||||
expect(useSettingsStore.getState().sidebarCollapsed).toBe(false);
|
||||
fireEvent.click(back);
|
||||
expect(screen.getByTestId('location-path')).toHaveTextContent('/module-select');
|
||||
});
|
||||
|
||||
it('uses the compact Agents navigation inset in macOS fullscreen', async () => {
|
||||
window.electron.platform = 'darwin';
|
||||
invokeIpcMock.mockResolvedValue(true);
|
||||
useSettingsStore.setState({ sidebarCollapsed: true });
|
||||
renderComponent(<MemoryRouter initialEntries={['/cloud-agents']}>
|
||||
<TitleBar integrated showModuleReturn />
|
||||
</MemoryRouter>);
|
||||
await waitFor(() => expect(screen.getByTestId('agent-titlebar-navigation')).toHaveClass('pl-3'));
|
||||
expect(screen.getByTestId('titlebar-sidebar-toggle-layer')).toHaveStyle({ width: '88px' });
|
||||
});
|
||||
|
||||
it('keeps Agents keyboard preview open between return and expand controls', () => {
|
||||
window.electron.platform = 'darwin';
|
||||
useSettingsStore.setState({ sidebarCollapsed: true });
|
||||
const onPeek = vi.fn();
|
||||
renderComponent(<MemoryRouter initialEntries={['/cloud-agents']}>
|
||||
<TitleBar integrated showModuleReturn sidebarPeekOpen onSidebarPeekChange={onPeek} />
|
||||
</MemoryRouter>);
|
||||
const back = screen.getByRole('button', { name: '返回首页' });
|
||||
const toggle = screen.getByRole('button', { name: '固定侧栏' });
|
||||
fireEvent.focus(back);
|
||||
expect(onPeek).toHaveBeenLastCalledWith(true, 'focus');
|
||||
onPeek.mockClear();
|
||||
fireEvent.blur(back, { relatedTarget: toggle });
|
||||
expect(onPeek).not.toHaveBeenCalled();
|
||||
fireEvent.blur(toggle, { relatedTarget: null });
|
||||
expect(onPeek).toHaveBeenLastCalledWith(false, 'focus');
|
||||
expect(screen.getByTestId('titlebar-sidebar-toggle-layer')).toHaveStyle({ width: '256px' });
|
||||
});
|
||||
|
||||
it('extends the product surfaces through the macOS title bar', () => {
|
||||
window.electron.platform = 'darwin';
|
||||
|
||||
|
||||
Reference in new issue
Block a user