-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
130 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/twenty-front/src/modules/workflow/hooks/__tests__/useDeleteStep.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { useDeleteStep } from '@/workflow/hooks/useDeleteStep'; | ||
|
||
const mockCloseRightDrawer = jest.fn(); | ||
const mockCreateNewWorkflowVersion = jest.fn(); | ||
const mockDeleteWorkflowVersionStep = jest.fn(); | ||
|
||
jest.mock('recoil', () => ({ | ||
useRecoilValue: () => 'parent-step-id', | ||
useSetRecoilState: () => jest.fn(), | ||
atom: (params: any) => params, | ||
})); | ||
|
||
jest.mock('@/ui/layout/right-drawer/hooks/useRightDrawer', () => ({ | ||
useRightDrawer: () => ({ | ||
closeRightDrawer: mockCloseRightDrawer, | ||
}), | ||
})); | ||
|
||
jest.mock('@/workflow/hooks/useDeleteWorkflowVersionStep', () => ({ | ||
useDeleteWorkflowVersionStep: () => ({ | ||
deleteWorkflowVersionStep: mockDeleteWorkflowVersionStep, | ||
}), | ||
})); | ||
|
||
jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({ | ||
useCreateNewWorkflowVersion: () => ({ | ||
createNewWorkflowVersion: mockCreateNewWorkflowVersion, | ||
}), | ||
})); | ||
|
||
describe('useDeleteStep', () => { | ||
const mockWorkflow = { | ||
id: '123', | ||
currentVersion: { | ||
id: '456', | ||
status: 'DRAFT', | ||
steps: [], | ||
trigger: { type: 'manual' }, | ||
}, | ||
versions: [], | ||
}; | ||
|
||
it('should delete step in draft version', async () => { | ||
const { result } = renderHook(() => | ||
useDeleteStep({ | ||
workflow: mockWorkflow as unknown as WorkflowWithCurrentVersion, | ||
}), | ||
); | ||
await result.current.deleteStep('1'); | ||
|
||
expect(mockDeleteWorkflowVersionStep).toHaveBeenCalled(); | ||
}); | ||
}); |
69 changes: 69 additions & 0 deletions
69
packages/twenty-front/src/modules/workflow/hooks/__tests__/useUpdateStep.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { useUpdateStep } from '@/workflow/hooks/useUpdateStep'; | ||
|
||
const mockCreateNewWorkflowVersion = jest.fn(); | ||
const mockUpdateWorkflowVersionStep = jest.fn(); | ||
|
||
jest.mock('recoil', () => ({ | ||
useRecoilValue: () => 'parent-step-id', | ||
useSetRecoilState: () => jest.fn(), | ||
atom: (params: any) => params, | ||
})); | ||
|
||
jest.mock('@/workflow/hooks/useUpdateWorkflowVersionStep', () => ({ | ||
useUpdateWorkflowVersionStep: () => ({ | ||
updateWorkflowVersionStep: mockUpdateWorkflowVersionStep, | ||
}), | ||
})); | ||
|
||
jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({ | ||
useCreateNewWorkflowVersion: () => ({ | ||
createNewWorkflowVersion: mockCreateNewWorkflowVersion, | ||
}), | ||
})); | ||
|
||
describe('useUpdateStep', () => { | ||
const mockWorkflow = { | ||
id: '123', | ||
currentVersion: { | ||
id: '456', | ||
status: 'DRAFT', | ||
steps: [], | ||
trigger: { type: 'manual' }, | ||
}, | ||
versions: [], | ||
}; | ||
|
||
it('should update step in draft version', async () => { | ||
const { result } = renderHook(() => | ||
useUpdateStep({ | ||
workflow: mockWorkflow as unknown as WorkflowWithCurrentVersion, | ||
}), | ||
); | ||
await result.current.updateStep({ | ||
id: '1', | ||
name: 'name', | ||
valid: true, | ||
type: 'CODE', | ||
settings: { | ||
input: { | ||
serverlessFunctionId: 'id', | ||
serverlessFunctionVersion: '1', | ||
serverlessFunctionInput: {}, | ||
}, | ||
outputSchema: {}, | ||
errorHandlingOptions: { | ||
retryOnFailure: { | ||
value: true, | ||
}, | ||
continueOnFailure: { | ||
value: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(mockUpdateWorkflowVersionStep).toHaveBeenCalled(); | ||
}); | ||
}); |