Skip to content

Commit

Permalink
Display error for all enterprise connections in the reset password sc…
Browse files Browse the repository at this point in the history
…reen
  • Loading branch information
luisrudge committed May 28, 2018
1 parent a28f31b commit 8b7a105
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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",
]
`;
45 changes: 45 additions & 0 deletions src/__tests__/connection/database/reset_password.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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', () => {
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();
});
});
4 changes: 2 additions & 2 deletions src/connection/database/reset_password.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -41,7 +41,7 @@ export default class ResetPassword extends Screen {
return i18n.str(m, 'forgotPasswordTitle');
}
isSubmitDisabled(m) {
const tryingToResetPasswordWithHRDEmail = isHRDDomain(m, databaseUsernameValue(m));
const tryingToResetPasswordWithHRDEmail = isEnterpriseDomain(m, databaseUsernameValue(m));
if (tryingToResetPasswordWithHRDEmail) {
swap(
updateEntity,
Expand Down

0 comments on commit 8b7a105

Please sign in to comment.