f8daa764f86d6068a73c782ce26514c1cd8f9025
[arvados-workbench2.git] / src / views-components / auto-logout / auto-logout.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { configure, mount } from "enzyme";
7 import * as Adapter from 'enzyme-adapter-react-16';
8 import { AutoLogoutComponent, AutoLogoutProps } from './auto-logout';
9
10 configure({ adapter: new Adapter() });
11
12 describe('<AutoLogoutComponent />', () => {
13     let props: AutoLogoutProps;
14     const sessionIdleTimeout = 300;
15     const lastWarningDuration = 60;
16     jest.useFakeTimers();
17
18     beforeEach(() => {
19         props = {
20             sessionIdleTimeout: sessionIdleTimeout,
21             lastWarningDuration: lastWarningDuration,
22             doLogout: jest.fn(),
23             doWarn: jest.fn(),
24             doCloseWarn: jest.fn(),
25         };
26         mount(<div><AutoLogoutComponent {...props} /></div>);
27     });
28
29     it('should logout after idle timeout', () => {
30         jest.runTimersToTime((sessionIdleTimeout-1)*1000);
31         expect(props.doLogout).not.toBeCalled();
32         jest.runTimersToTime(1*1000);
33         expect(props.doLogout).toBeCalled();
34     });
35
36     it('should warn the user previous to close the session', () => {
37         jest.runTimersToTime((sessionIdleTimeout-lastWarningDuration-1)*1000);
38         expect(props.doWarn).not.toBeCalled();
39         jest.runTimersToTime(1*1000);
40         expect(props.doWarn).toBeCalled();
41     });
42 });