test: add error handling for URL generation and popup blocking in InviteUserButton
This commit is contained in:
@@ -262,5 +262,41 @@ describe('InviteUserButton', () => {
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('should handle URL generation errors gracefully', async () => {
|
||||
mockGetExternalUserMngLinkUrl.mockImplementation(() => {
|
||||
throw new Error('URL generation failed');
|
||||
});
|
||||
|
||||
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const user = userEvent.setup();
|
||||
|
||||
render(<InviteUserButton />);
|
||||
|
||||
// Should not crash when URL generation fails
|
||||
await user.click(screen.getByRole('button', { name: /invite user/i }));
|
||||
|
||||
expect(consoleSpy).toHaveBeenCalledWith('Failed to handle button click:', expect.any(Error));
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('should handle popup blocking gracefully', async () => {
|
||||
mockWindowOpen.mockImplementation(() => {
|
||||
throw new Error('Popup blocked');
|
||||
});
|
||||
|
||||
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const user = userEvent.setup();
|
||||
|
||||
render(<InviteUserButton />);
|
||||
|
||||
// Should not crash when popup is blocked
|
||||
await user.click(screen.getByRole('button', { name: /invite user/i }));
|
||||
|
||||
expect(consoleSpy).toHaveBeenCalledWith('Failed to handle button click:', expect.any(Error));
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user