123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import {Modal} from 'react-bootstrap';
- import React from 'react';
- import {mount} from 'enzyme';
- import RecoveryOptionsModal from 'app/components/modals/recoveryOptionsModal';
- describe('RecoveryOptionsModal', function() {
- let closeModal = jest.fn();
- let onClose = jest.fn();
- let wrapper;
- beforeEach(function() {
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: '/users/me/authenticators/',
- method: 'GET',
- body: TestStubs.AllAuthenticators(),
- });
- wrapper = mount(
- <RecoveryOptionsModal
- Body={Modal.Body}
- Header={Modal.Header}
- authenticatorName="Authenticator App"
- closeModal={closeModal}
- onClose={onClose}
- />,
- TestStubs.routerContext()
- );
- });
- afterEach(function() {});
- it('can redirect to recovery codes if user skips backup phone setup', async function() {
- let getRecoveryCodes = 'RecoveryOptionsModal Button[name="getCodes"]';
- expect(wrapper.find(getRecoveryCodes)).toHaveLength(0);
- // skip backup phone setup
- wrapper.find('RecoveryOptionsModal Button[name="skipStep"]').simulate('click');
- expect(wrapper.find(getRecoveryCodes)).toHaveLength(1);
- let mockId = TestStubs.Authenticators().Recovery().authId;
- expect(
- wrapper.find('RecoveryOptionsModal Button[name="getCodes"]').prop('to')
- ).toMatch(`/settings/account/security/mfa/${mockId}/`);
- wrapper.find(getRecoveryCodes).simulate('click');
- expect(closeModal).toHaveBeenCalled();
- });
- it('can redirect to backup phone setup', async function() {
- let backupPhone = 'RecoveryOptionsModal Button[name="addPhone"]';
- expect(wrapper.find(backupPhone)).toHaveLength(1);
- expect(wrapper.find(backupPhone).prop('to')).toMatch(
- '/settings/account/security/mfa/sms/enroll/'
- );
- wrapper.find(backupPhone).simulate('click');
- expect(closeModal).toHaveBeenCalled();
- });
- it('skips backup phone setup if text message authenticator unavailable', async function() {
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: '/users/me/authenticators/',
- method: 'GET',
- body: [TestStubs.Authenticators().Totp(), TestStubs.Authenticators().Recovery()],
- });
- wrapper = mount(
- <RecoveryOptionsModal
- Body={Modal.Body}
- Header={Modal.Header}
- authenticatorName="Authenticator App"
- closeModal={closeModal}
- onClose={onClose}
- />,
- TestStubs.routerContext()
- );
- let mockId = TestStubs.Authenticators().Recovery().authId;
- expect(
- wrapper.find('RecoveryOptionsModal Button[name="getCodes"]').prop('to')
- ).toMatch(`/settings/account/security/mfa/${mockId}/`);
- expect(wrapper.find('RecoveryOptionsModal Button[name="skipStep"]')).toHaveLength(0);
- expect(wrapper.find('RecoveryOptionsModal Button[name="addPhone"]')).toHaveLength(0);
- });
- });
|