recoveryOptionsModal.spec.jsx 2.8 KB

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