-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix post submission action error, improve post submission error handl…
…ing (#144)
- Loading branch information
Showing
4 changed files
with
83 additions
and
30 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
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,42 @@ | ||
import { renderHook, act } from '@testing-library/react'; | ||
import { usePostSubmissionAction } from './usePostSubmissionAction'; | ||
|
||
// Mock the getRegisteredPostSubmissionAction function | ||
jest.mock('../registry/registry', () => ({ | ||
getRegisteredPostSubmissionAction: jest.fn(), | ||
})); | ||
|
||
describe('usePostSubmissionAction', () => { | ||
// Mock the actual post-submission action function | ||
const mockPostAction = jest.fn(); | ||
|
||
// Sample action references | ||
const actionRefs = [ | ||
{ actionId: 'action1', config: { param1: 'value1' } }, | ||
{ actionId: 'action2', config: { param2: 'value2' } }, | ||
]; | ||
|
||
// Set up the mock implementation for getRegisteredPostSubmissionAction | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
jest.spyOn(global.console, 'error').mockImplementation(() => {}); | ||
jest.requireMock('../registry/registry').getRegisteredPostSubmissionAction.mockImplementation((actionId) => { | ||
if (actionId === 'action1') { | ||
return Promise.resolve(mockPostAction); | ||
} | ||
return Promise.resolve(null); | ||
}); | ||
}); | ||
|
||
it('should fetch post-submission actions and return them', async () => { | ||
const { result } = renderHook(() => usePostSubmissionAction(actionRefs)); | ||
|
||
// Wait for the effect to complete | ||
await act(async () => {}); | ||
|
||
expect(result.current).toEqual([ | ||
{ postAction: mockPostAction, config: { param1: 'value1' }, actionId: 'action1' }, | ||
{ postAction: null, config: { param2: 'value2' }, actionId: 'action2' }, | ||
]); | ||
}); | ||
}); |
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
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