diff --git a/src/__tests__/connection/database/__snapshots__/reset_password.test.jsx.snap b/src/__tests__/connection/database/__snapshots__/reset_password.test.jsx.snap new file mode 100644 index 000000000..08cf5d063 --- /dev/null +++ b/src/__tests__/connection/database/__snapshots__/reset_password.test.jsx.snap @@ -0,0 +1,20 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ResetPasswordScreen isSubmitDisabled returns false when \`isEnterpriseDomain\` is false 1`] = ` +Array [ + "updateEntity", + "lock", + "id", + "clearGlobalError", +] +`; + +exports[`ResetPasswordScreen isSubmitDisabled returns true when \`isEnterpriseDomain\` is true 1`] = ` +Array [ + "updateEntity", + "lock", + "id", + "setGlobalError", + "error,forgotPassword,enterprise_email", +] +`; diff --git a/src/__tests__/connection/database/reset_password.test.jsx b/src/__tests__/connection/database/reset_password.test.jsx new file mode 100644 index 000000000..2aa732c87 --- /dev/null +++ b/src/__tests__/connection/database/reset_password.test.jsx @@ -0,0 +1,46 @@ +import React from 'react'; +import { mount } from 'enzyme'; + +const getScreen = () => { + const ResetPasswordScreen = require('connection/database/reset_password').default; + return new ResetPasswordScreen(); +}; + +describe('ResetPasswordScreen', () => { + beforeEach(() => { + jest.resetModules(); + + jest.mock('connection/database/index', () => ({ + databaseUsernameValue: () => 'foo@test.com' + })); + + jest.mock('connection/enterprise', () => ({ + isEnterpriseDomain: () => true + })); + + jest.mock('i18n', () => ({ str: (_, keys) => keys.join(',') })); + + jest.mock('core/index', () => ({ + id: () => 'id', + setGlobalError: 'setGlobalError', + clearGlobalError: 'clearGlobalError' + })); + + jest.mock('store/index', () => ({ + swap: jest.fn(), + updateEntity: 'updateEntity' + })); + }); + it('isSubmitDisabled returns true when `isEnterpriseDomain` is true', () => { + require('connection/enterprise').isEnterpriseDomain = () => true; + const screen = getScreen(); + expect(screen.isSubmitDisabled()).toBe(true); + expect(require('store/index').swap.mock.calls[0]).toMatchSnapshot(); + }); + it('isSubmitDisabled returns false when `isEnterpriseDomain` is false', () => { + require('connection/enterprise').isEnterpriseDomain = () => false; + const screen = getScreen(); + expect(screen.isSubmitDisabled()).toBe(false); + expect(require('store/index').swap.mock.calls[0]).toMatchSnapshot(); + }); +}); diff --git a/src/connection/database/reset_password.jsx b/src/connection/database/reset_password.jsx index 9ed4fef63..fab502db5 100644 --- a/src/connection/database/reset_password.jsx +++ b/src/connection/database/reset_password.jsx @@ -5,7 +5,7 @@ import { authWithUsername, hasScreen } from './index'; import { cancelResetPassword, resetPassword } from './actions'; import { renderPasswordResetConfirmation } from './password_reset_confirmation'; import { databaseUsernameValue } from '../../connection/database/index'; -import { isHRDDomain } from '../../connection/enterprise'; +import { isEnterpriseDomain } from '../../connection/enterprise'; import * as i18n from '../../i18n'; import * as l from '../../core/index'; import { swap, updateEntity } from '../../store/index'; @@ -41,8 +41,11 @@ export default class ResetPassword extends Screen { return i18n.str(m, 'forgotPasswordTitle'); } isSubmitDisabled(m) { - const tryingToResetPasswordWithHRDEmail = isHRDDomain(m, databaseUsernameValue(m)); - if (tryingToResetPasswordWithHRDEmail) { + const tryingToResetPasswordWithEnterpriseEmail = isEnterpriseDomain( + m, + databaseUsernameValue(m) + ); + if (tryingToResetPasswordWithEnterpriseEmail) { swap( updateEntity, 'lock', @@ -53,7 +56,7 @@ export default class ResetPassword extends Screen { } else { swap(updateEntity, 'lock', l.id(m), l.clearGlobalError); } - return tryingToResetPasswordWithHRDEmail; + return tryingToResetPasswordWithEnterpriseEmail; } submitHandler() {