recoveryOptionsModal.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {Modal} from 'react-bootstrap';
  2. import React from 'react';
  3. import {mount} from 'enzyme';
  4. import RecoveryOptionsModal from 'app/components/modals/recoveryOptionsModal';
  5. describe('RecoveryOptionsModal', function() {
  6. let closeModal = jest.fn();
  7. let onClose = jest.fn();
  8. let wrapper;
  9. beforeEach(function() {
  10. MockApiClient.clearMockResponses();
  11. MockApiClient.addMockResponse({
  12. url: '/users/me/authenticators/',
  13. method: 'GET',
  14. body: TestStubs.AllAuthenticators(),
  15. });
  16. wrapper = mount(
  17. <RecoveryOptionsModal
  18. Body={Modal.Body}
  19. Header={Modal.Header}
  20. authenticatorName="Authenticator App"
  21. closeModal={closeModal}
  22. onClose={onClose}
  23. />,
  24. TestStubs.routerContext()
  25. );
  26. });
  27. afterEach(function() {});
  28. it('can redirect to recovery codes if user skips backup phone setup', async function() {
  29. let getRecoveryCodes = 'RecoveryOptionsModal Button[name="getCodes"]';
  30. expect(wrapper.find(getRecoveryCodes)).toHaveLength(0);
  31. // skip backup phone setup
  32. wrapper.find('RecoveryOptionsModal Button[name="skipStep"]').simulate('click');
  33. expect(wrapper.find(getRecoveryCodes)).toHaveLength(1);
  34. let mockId = TestStubs.Authenticators().Recovery().authId;
  35. expect(
  36. wrapper.find('RecoveryOptionsModal Button[name="getCodes"]').prop('to')
  37. ).toMatch(`/settings/account/security/mfa/${mockId}/`);
  38. wrapper.find(getRecoveryCodes).simulate('click');
  39. expect(closeModal).toHaveBeenCalled();
  40. });
  41. it('can redirect to backup phone setup', async function() {
  42. let backupPhone = 'RecoveryOptionsModal Button[name="addPhone"]';
  43. expect(wrapper.find(backupPhone)).toHaveLength(1);
  44. expect(wrapper.find(backupPhone).prop('to')).toMatch(
  45. '/settings/account/security/mfa/sms/enroll/'
  46. );
  47. wrapper.find(backupPhone).simulate('click');
  48. expect(closeModal).toHaveBeenCalled();
  49. });
  50. it('skips backup phone setup if text message authenticator unavailable', async function() {
  51. MockApiClient.clearMockResponses();
  52. MockApiClient.addMockResponse({
  53. url: '/users/me/authenticators/',
  54. method: 'GET',
  55. body: [TestStubs.Authenticators().Totp(), TestStubs.Authenticators().Recovery()],
  56. });
  57. wrapper = mount(
  58. <RecoveryOptionsModal
  59. Body={Modal.Body}
  60. Header={Modal.Header}
  61. authenticatorName="Authenticator App"
  62. closeModal={closeModal}
  63. onClose={onClose}
  64. />,
  65. TestStubs.routerContext()
  66. );
  67. let mockId = TestStubs.Authenticators().Recovery().authId;
  68. expect(
  69. wrapper.find('RecoveryOptionsModal Button[name="getCodes"]').prop('to')
  70. ).toMatch(`/settings/account/security/mfa/${mockId}/`);
  71. expect(wrapper.find('RecoveryOptionsModal Button[name="skipStep"]')).toHaveLength(0);
  72. expect(wrapper.find('RecoveryOptionsModal Button[name="addPhone"]')).toHaveLength(0);
  73. });
  74. });