Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display error for all enterprise connections in the reset password screen #1384

Merged
merged 3 commits into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
]
`;
46 changes: 46 additions & 0 deletions src/__tests__/connection/database/reset_password.test.jsx
Original file line number Diff line number Diff line change
@@ -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: () => '[email protected]'
}));

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();
});
});
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