test: add test for deleting store on autologout timeout, remove unused import

Signed-off-by: Juan Escalada <juanescalada175@gmail.com>
This commit is contained in:
Juan Escalada
2026-05-13 13:18:20 +09:00
parent 19b5047c12
commit e8c67ea82c
2 changed files with 22 additions and 1 deletions
@@ -21,7 +21,7 @@ import {
identityApiRef,
useApi,
} from '@backstage/core-plugin-api';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import {
EventsType,
IIdleTimer,
@@ -84,6 +84,27 @@ describe('useLogoutDisconnectedUserEffect', () => {
expect(mockTimestampStore.delete).toHaveBeenCalled();
});
it('should delete the store and sign out when idle timeout has passed', () => {
const staleStore = {
...mockTimestampStore,
get: jest.fn().mockReturnValue(new Date(Date.now() - 2000)),
};
const props: UseLogoutDisconnectedUserEffectProps = {
enableEffect: true,
autologoutIsEnabled: true,
isLoggedIn: true,
idleTimeoutSeconds: 1,
lastSeenOnlineStore: staleStore,
identityApi: mockIdentityApi,
};
renderHook(() => useLogoutDisconnectedUserEffect(props));
expect(staleStore.delete).toHaveBeenCalled();
expect(mockIdentityApi.signOut).toHaveBeenCalled();
expect(staleStore.save).not.toHaveBeenCalled();
});
it('should call signOut if idle timeout passed', () => {
jest.useFakeTimers();