test: add error handling for URL generation and popup blocking in InviteUserButton

This commit is contained in:
Eric Hilse
2025-11-26 08:57:02 -07:00
parent 922ddd080b
commit a3b6f0e757
@@ -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();
});
});
});