MM-15582 Don't show forgot password link without email/username login (#2811)

This commit is contained in:
Harrison Healey 2019-05-22 11:55:27 -04:00 committed by Elias Nahum
parent 152e1fe264
commit fcd9e401f5
3 changed files with 100 additions and 10 deletions

View file

@ -364,6 +364,22 @@ export default class Login extends PureComponent {
);
}
let forgotPassword;
if (this.props.config.EnableSignInWithEmail === 'true' || this.props.config.EnableSignInWithUsername === 'true') {
forgotPassword = (
<Button
onPress={this.forgotPassword}
containerStyle={[style.forgotPasswordBtn]}
>
<FormattedText
id='login.forgot'
defaultMessage='I forgot my password'
style={style.forgotPasswordTxt}
/>
</Button>
);
}
return (
<View style={style.container}>
<StatusBar/>
@ -419,16 +435,7 @@ export default class Login extends PureComponent {
disableFullscreenUI={true}
/>
{proceed}
<Button
onPress={this.forgotPassword}
containerStyle={[style.forgotPasswordBtn]}
>
<FormattedText
id='login.forgot'
defaultMessage='I forgot my password'
style={style.forgotPasswordTxt}
/>
</Button>
{forgotPassword}
</KeyboardAwareScrollView>
</TouchableWithoutFeedback>
</View>

View file

@ -0,0 +1,75 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import FormattedText from 'app/components/formatted_text';
import {shallowWithIntl} from 'test/intl-test-helper';
import Login from './login';
describe('Login', () => {
const baseProps = {
config: {
EnableSignInWithEmail: 'true',
EnableSignInWithUsername: 'true',
},
license: {
IsLicensed: 'false',
},
loginId: '',
password: '',
loginRequest: {},
actions: {
handleLoginIdChanged: jest.fn(),
handlePasswordChanged: jest.fn(),
handleSuccessfulLogin: jest.fn(),
scheduleExpiredNotification: jest.fn(),
login: jest.fn(),
},
};
test('should show "I forgot my password" with only email login enabled', () => {
const props = {
...baseProps,
config: {
...baseProps.config,
EnableSignInWithUsername: 'false',
},
};
const wrapper = shallowWithIntl(<Login {...props}/>);
expect(wrapper.find(FormattedText).find({id: 'login.forgot'}).exists()).toBe(true);
});
test('should show "I forgot my password" with only username login enabled', () => {
const props = {
...baseProps,
config: {
...baseProps.config,
EnableSignInWithEmail: 'false',
},
};
const wrapper = shallowWithIntl(<Login {...props}/>);
expect(wrapper.find(FormattedText).find({id: 'login.forgot'}).exists()).toBe(true);
});
test('should not show "I forgot my password" without email or username login enabled', () => {
const props = {
...baseProps,
config: {
...baseProps.config,
EnableSignInWithEmail: 'false',
EnableSignInWithUsername: 'false',
},
};
const wrapper = shallowWithIntl(<Login {...props}/>);
expect(wrapper.find(FormattedText).find({id: 'login.forgot'}).exists()).toBe(false);
});
});

View file

@ -42,6 +42,14 @@ jest.mock('react-native-device-info', () => {
};
});
jest.mock('react-native-cookies', () => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
}));
let logs;
let warns;
let errors;