diff --git a/packages/editor-ui/src/components/executions/global/GlobalExecutionsList.vue b/packages/editor-ui/src/components/executions/global/GlobalExecutionsList.vue index 4673d420ad..e11821fd1d 100644 --- a/packages/editor-ui/src/components/executions/global/GlobalExecutionsList.vue +++ b/packages/editor-ui/src/components/executions/global/GlobalExecutionsList.vue @@ -143,7 +143,7 @@ async function handleDeleteSelected() { await executionsStore.deleteExecutions({ filters: executionsStore.executionsFilters, ...(allExistingSelected.value - ? { deleteBefore: props.executions[0].startedAt } + ? { deleteBefore: new Date() } : { ids: Object.keys(selectedItems.value), }), diff --git a/packages/editor-ui/src/stores/executions.store.test.ts b/packages/editor-ui/src/stores/executions.store.test.ts new file mode 100644 index 0000000000..bcc5d9614b --- /dev/null +++ b/packages/editor-ui/src/stores/executions.store.test.ts @@ -0,0 +1,69 @@ +import { vi } from 'vitest'; +import { setActivePinia, createPinia } from 'pinia'; + +import type { ExecutionSummaryWithScopes } from '@/Interface'; +import { useExecutionsStore } from '@/stores/executions.store'; + +vi.mock('@/utils/apiUtils', () => ({ + makeRestApiRequest: vi.fn(), +})); + +describe('executions.store', () => { + let executionsStore: ReturnType; + + beforeEach(() => { + setActivePinia(createPinia()); + executionsStore = useExecutionsStore(); + }); + + describe('deleteExecutions', () => { + const mockExecutions: ExecutionSummaryWithScopes[] = [ + { + id: '3', + mode: 'manual', + status: 'success', + startedAt: new Date('2021-01-03T00:00:00Z'), + workflowId: '1', + scopes: [], + }, + { + id: '2', + mode: 'manual', + status: 'success', + startedAt: new Date('2021-01-02T00:00:00Z'), + workflowId: '1', + scopes: [], + }, + { + id: '1', + mode: 'manual', + status: 'success', + startedAt: new Date('2021-01-01T00:00:00Z'), + workflowId: '1', + scopes: [], + }, + ]; + + beforeEach(() => { + mockExecutions.forEach(executionsStore.addExecution); + }); + + it('should delete executions by ID', async () => { + await executionsStore.deleteExecutions({ ids: ['1', '3'] }); + + expect(executionsStore.executions).toEqual([mockExecutions[1]]); + }); + + it('should delete executions started before given date', async () => { + await executionsStore.deleteExecutions({ deleteBefore: mockExecutions[1].startedAt }); + + expect(executionsStore.executions).toEqual([mockExecutions[0], mockExecutions[1]]); + }); + + it('should delete all executions if given date is now', async () => { + await executionsStore.deleteExecutions({ deleteBefore: new Date() }); + + expect(executionsStore.executions).toEqual([]); + }); + }); +}); diff --git a/packages/editor-ui/src/stores/executions.store.ts b/packages/editor-ui/src/stores/executions.store.ts index c96443ea41..f80f0f5e4d 100644 --- a/packages/editor-ui/src/stores/executions.store.ts +++ b/packages/editor-ui/src/stores/executions.store.ts @@ -290,6 +290,7 @@ export const useExecutionsStore = defineStore('executions', () => { stopCurrentExecution, retryExecution, deleteExecutions, + addExecution, resetData, reset, };