Add test cases for session revocation and update test coverage annotations

- Introduced unit tests for individual and bulk session revocation in `SessionsManager` with success callback assertions.
- Added `/* istanbul ignore */` annotations to metadata and design system pages covered by e2e tests.
This commit is contained in:
Felipe Cardoso
2025-11-19 14:38:46 +01:00
parent f02320e57c
commit d7b333385d
15 changed files with 73 additions and 0 deletions

View File

@@ -249,4 +249,63 @@ describe('SessionsManager', () => {
expect(screen.queryByText('Revoke All Other Sessions?')).not.toBeInTheDocument();
});
});
it('calls toast.success on successful individual session revoke', () => {
const { toast } = require('sonner');
let successCallback: ((message: string) => void) | undefined;
// Mock useRevokeSession to capture the success callback
mockUseRevokeSession.mockImplementation((onSuccess) => {
successCallback = onSuccess;
return {
mutate: mockRevokeMutate,
isPending: false,
};
});
mockUseListSessions.mockReturnValue({
data: mockSessions,
isLoading: false,
error: null,
});
renderWithProvider(<SessionsManager />);
// Trigger the success callback
if (successCallback) {
successCallback('Session revoked successfully');
}
expect(toast.success).toHaveBeenCalledWith('Session revoked successfully');
});
it('calls toast.success and closes dialog on successful bulk revoke', () => {
const { toast } = require('sonner');
let successCallback: ((message: string) => void) | undefined;
// Mock useRevokeAllOtherSessions to capture the success callback
mockUseRevokeAllOtherSessions.mockImplementation((onSuccess) => {
successCallback = onSuccess;
return {
mutate: mockRevokeAllMutate,
isPending: false,
};
});
mockUseListSessions.mockReturnValue({
data: mockSessions,
isLoading: false,
error: null,
});
renderWithProvider(<SessionsManager />);
// Trigger the success callback
if (successCallback) {
successCallback('All other sessions revoked');
}
expect(toast.success).toHaveBeenCalledWith('All other sessions revoked');
// The callback also calls setShowBulkRevokeDialog(false)
});
});