1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { AutoLogoutComponent, LAST_ACTIVE_TIMESTAMP } from './auto-logout';
8 describe('<AutoLogoutComponent />', () => {
10 const sessionIdleTimeout = 300;
11 const lastWarningDuration = 60;
12 const eventListeners = {};
16 window.addEventListener = cy.stub((event, cb) => {
17 eventListeners[event] = cb;
20 sessionIdleTimeout: sessionIdleTimeout,
21 lastWarningDuration: lastWarningDuration,
22 doLogout: cy.spy().as('doLogout'),
23 doWarn: cy.stub().as('doWarn'),
24 doCloseWarn: cy.stub(),
26 cy.mount(<div><AutoLogoutComponent {...props} /></div>);
30 cy.clock().invoke('restore');
33 it('should logout after idle timeout', () => {
34 cy.tick((sessionIdleTimeout-1)*1000);
35 cy.get('@doLogout').should('not.have.been.called');
37 cy.get('@doLogout').should('have.been.called');
40 it('should warn the user previous to close the session', () => {
41 cy.tick((sessionIdleTimeout-lastWarningDuration-1)*1000);
42 cy.get('@doWarn').should('not.have.been.called');
44 cy.get('@doWarn').should('have.been.called');
47 it('should reset the idle timer when activity event is received', () => {
48 cy.tick((sessionIdleTimeout-lastWarningDuration-1)*1000);
49 cy.get('@doWarn').should('not.have.been.called');
50 // Simulate activity from other window/tab
51 eventListeners.storage({
52 key: LAST_ACTIVE_TIMESTAMP,
53 newValue: '42' // value currently doesn't matter
56 // Warning should not appear because idle timer was reset
57 cy.get('@doWarn').should('not.have.been.called');