修复任务侧栏空页签跳转
保留用户手动选择的空排队生成中页签。
补充任务侧栏空页签回归测试。
(cherry picked from commit a6e3aef5b2)
This commit is contained in:
@@ -172,45 +172,45 @@ describe('ImageCanvasTaskSidebarView', () => {
|
||||
const completedAt = new Date(Date.now() - 20_000).toISOString();
|
||||
listExternalGenerationTasksMock.mockImplementation(
|
||||
(options: Parameters<typeof listExternalGenerationTasks>[0] = {}) =>
|
||||
Promise.resolve({
|
||||
overview: {
|
||||
pendingCount: 0,
|
||||
runningCount: 1,
|
||||
unacknowledgedTerminalCount: 1,
|
||||
updatedAtMicros: 1,
|
||||
},
|
||||
tasks: options.statuses?.includes('running')
|
||||
? [
|
||||
createExternalTask({
|
||||
jobId: 'active-current',
|
||||
startedAt,
|
||||
}),
|
||||
createExternalTask({
|
||||
jobId: 'active-other-project',
|
||||
sourceEntityId: 'project-other',
|
||||
requestPrompt: '不该显示的外部项目任务',
|
||||
}),
|
||||
]
|
||||
: [
|
||||
createExternalTask({
|
||||
jobId: 'done-current',
|
||||
status: 'completed',
|
||||
requestPrompt: '已完成提示词',
|
||||
startedAt: new Date(Date.now() - 90_000).toISOString(),
|
||||
completedAt,
|
||||
updatedAt: completedAt,
|
||||
progress: 100,
|
||||
phaseDetail: '生成已完成。',
|
||||
}),
|
||||
createExternalTask({
|
||||
jobId: 'done-other-project',
|
||||
sourceEntityId: 'project-other',
|
||||
status: 'completed',
|
||||
requestPrompt: '另一个项目的已完成任务',
|
||||
completedAt,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Promise.resolve({
|
||||
overview: {
|
||||
pendingCount: 0,
|
||||
runningCount: 1,
|
||||
unacknowledgedTerminalCount: 1,
|
||||
updatedAtMicros: 1,
|
||||
},
|
||||
tasks: options.statuses?.includes('running')
|
||||
? [
|
||||
createExternalTask({
|
||||
jobId: 'active-current',
|
||||
startedAt,
|
||||
}),
|
||||
createExternalTask({
|
||||
jobId: 'active-other-project',
|
||||
sourceEntityId: 'project-other',
|
||||
requestPrompt: '不该显示的外部项目任务',
|
||||
}),
|
||||
]
|
||||
: [
|
||||
createExternalTask({
|
||||
jobId: 'done-current',
|
||||
status: 'completed',
|
||||
requestPrompt: '已完成提示词',
|
||||
startedAt: new Date(Date.now() - 90_000).toISOString(),
|
||||
completedAt,
|
||||
updatedAt: completedAt,
|
||||
progress: 100,
|
||||
phaseDetail: '生成已完成。',
|
||||
}),
|
||||
createExternalTask({
|
||||
jobId: 'done-other-project',
|
||||
sourceEntityId: 'project-other',
|
||||
status: 'completed',
|
||||
requestPrompt: '另一个项目的已完成任务',
|
||||
completedAt,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
render(
|
||||
@@ -237,4 +237,56 @@ describe('ImageCanvasTaskSidebarView', () => {
|
||||
expect(screen.getByText(/完成于/u)).toBeTruthy();
|
||||
expect(screen.queryByText(/另一个项目的已完成任务/u)).toBeNull();
|
||||
});
|
||||
|
||||
it('keeps the empty active tab selected after manual tab click', async () => {
|
||||
const completedAt = new Date(Date.now() - 20_000).toISOString();
|
||||
listExternalGenerationTasksMock.mockImplementation(
|
||||
(options: Parameters<typeof listExternalGenerationTasks>[0] = {}) =>
|
||||
Promise.resolve({
|
||||
overview: {
|
||||
pendingCount: 0,
|
||||
runningCount: 0,
|
||||
unacknowledgedTerminalCount: 1,
|
||||
updatedAtMicros: 1,
|
||||
},
|
||||
tasks: options.statuses?.includes('running')
|
||||
? []
|
||||
: [
|
||||
createExternalTask({
|
||||
jobId: 'done-current',
|
||||
status: 'completed',
|
||||
requestPrompt: '已完成提示词',
|
||||
completedAt,
|
||||
updatedAt: completedAt,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
render(
|
||||
<ImageCanvasTaskSidebarView
|
||||
projectId="project-1"
|
||||
generationDialogs={[]}
|
||||
backgroundRemovalTasks={[]}
|
||||
open
|
||||
onToggleOpen={vi.fn()}
|
||||
onFocusGenerationDialog={vi.fn()}
|
||||
onFocusLayer={vi.fn()}
|
||||
onFocusExternalTask={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
await screen.findByText('暂无任务');
|
||||
const activeTab = screen.getByRole('tab', { name: /排队\/生成中/u });
|
||||
const completedTab = screen.getByRole('tab', { name: /已完成/u });
|
||||
|
||||
fireEvent.click(completedTab);
|
||||
expect(await screen.findByText(/已完成提示词/u)).toBeTruthy();
|
||||
|
||||
fireEvent.click(activeTab);
|
||||
|
||||
expect(activeTab.getAttribute('aria-selected')).toBe('true');
|
||||
expect(screen.getByText('暂无任务')).toBeTruthy();
|
||||
expect(screen.queryByText(/已完成提示词/u)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -555,15 +555,9 @@ export function ImageCanvasTaskSidebarView({
|
||||
const previousActiveItemCount = previousActiveItemCountRef.current;
|
||||
if (activeItems.length > previousActiveItemCount) {
|
||||
setActiveTab('active');
|
||||
} else if (
|
||||
activeItems.length === 0 &&
|
||||
activeTab === 'active' &&
|
||||
completedItems.length > 0
|
||||
) {
|
||||
setActiveTab('completed');
|
||||
}
|
||||
previousActiveItemCountRef.current = activeItems.length;
|
||||
}, [activeItems.length, activeTab, completedItems.length]);
|
||||
}, [activeItems.length]);
|
||||
|
||||
const visibleItems = activeTab === 'active' ? activeItems : completedItems;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user