Last active
March 10, 2020 23:23
-
-
Save estrattonbailey/4135b8cfd996d85c7f7536677c90bbea to your computer and use it in GitHub Desktop.
Observer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable */ | |
import * as React from 'react'; | |
import { act } from 'react-dom/test-utils'; | |
import { mount } from 'enzyme'; | |
import { Provider } from 'react-redux'; | |
import store from '@services/store'; | |
import { AUTH_HYDRATE, AUTH_SET_IS_LOGGED_IN } from '@services/reducers/auth/types'; | |
import { UserRole } from '@api/auth/types'; | |
import { AuthObserver } from '@components/AuthObserver'; | |
jest.useFakeTimers(); | |
jest.mock('@api/auth', () => ({ | |
isLoggedIn() { | |
return false; | |
} | |
})); | |
const hydrateAction = { | |
type: AUTH_HYDRATE, | |
payload: { | |
id: 0, | |
email: '', | |
username: '', | |
firstName: '', | |
role: UserRole.VERIFIER, | |
token: '', | |
intercomToken: '', | |
companyInfo: {}, | |
usesTwoFactorAuth: false, | |
needsTwoFactorVerification: false, | |
twoFactorAuthDevices: [], | |
isVerifier: true, | |
isEmployer: false, | |
isHRResponder: false, | |
isEmployerType: false, | |
isEmployee: false, | |
} | |
}; | |
describe('@components/AuthObserver', () => { | |
it('idle timeout', async done => { | |
let wrapper: any; | |
act(() => { | |
wrapper = mount( | |
<Provider store={store}> | |
<AuthObserver /> | |
</Provider> | |
); | |
}); | |
const initial = store.getState(); | |
expect(initial.auth).toEqual(null); | |
store.dispatch(hydrateAction); | |
store.dispatch({ | |
type: AUTH_SET_IS_LOGGED_IN, | |
payload: { | |
isLoggedIn: true, | |
}, | |
}); | |
const loggedIn = store.getState(); | |
// @ts-ignore | |
expect(loggedIn.auth.id).toEqual(0); | |
wrapper.update(); | |
act(() => { | |
jest.advanceTimersByTime(5 * 60 * 1000); | |
}); | |
const loggedOut = store.getState(); | |
expect(loggedOut.auth).toEqual(null); | |
done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment