Simplify Code and Canvas project sidebars

This commit is contained in:
鲨鱼辣椒 committed 2026-10-14 12:12:17 +08:00
1 parent 049e34cc77
commit f980827200
7 files changed
+66 -38

No files matched your search

+14 -3
View File
@@ -189,12 +189,23 @@ describe('ImageWorkspaceSidebar', () => {
expect(actions.renameProject).not.toHaveBeenCalled();
});
it('selects a project by its workspace identity from the project row', () => {
const { target, actions } = prepareProjects();
it('shows only project titles under My Projects and keeps recent-first selection by workspace identity', () => {
const { workspace, target, actions } = prepareProjects();
renderSidebar();
const sidebar = screen.getByTestId('sidebar-image-workspace');
fireEvent.click(within(sidebar).getByRole('button', { name: new RegExp(`^${target.title}`) }));
expect(within(sidebar).getByText('我的项目', { exact: true })).toBeInTheDocument();
expect(within(sidebar).queryByText('设计项目', { exact: true })).not.toBeInTheDocument();
expect(sidebar).not.toHaveTextContent('设计版本');
const activeProject = within(sidebar).getByRole('button', { name: workspace.workspace.title, exact: true });
const newerProject = within(sidebar).getByRole('button', { name: target.title, exact: true });
expect(activeProject.textContent).toBe(workspace.workspace.title);
expect(newerProject.textContent).toBe(target.title);
expect(activeProject).toHaveAttribute('aria-current', 'page');
// The September project is newer than the active August project, despite
// arriving second in bootstrap. Removing its date must not change order.
expect(newerProject.compareDocumentPosition(activeProject)).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
fireEvent.click(newerProject);
expect(actions.selectProject).toHaveBeenCalledExactlyOnceWith(target.workspaceId);
expect(screen.getByLabelText('当前页面')).toHaveTextContent('/image-canvas');