diff --git a/app/screens/login/login.js b/app/screens/login/login.js index 79d5e867c..f05979b5d 100644 --- a/app/screens/login/login.js +++ b/app/screens/login/login.js @@ -364,6 +364,22 @@ export default class Login extends PureComponent { ); } + let forgotPassword; + if (this.props.config.EnableSignInWithEmail === 'true' || this.props.config.EnableSignInWithUsername === 'true') { + forgotPassword = ( + + ); + } + return ( @@ -419,16 +435,7 @@ export default class Login extends PureComponent { disableFullscreenUI={true} /> {proceed} - + {forgotPassword} diff --git a/app/screens/login/login.test.js b/app/screens/login/login.test.js new file mode 100644 index 000000000..e2ed4935a --- /dev/null +++ b/app/screens/login/login.test.js @@ -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(); + + 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(); + + 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(); + + expect(wrapper.find(FormattedText).find({id: 'login.forgot'}).exists()).toBe(false); + }); +}); diff --git a/test/setup.js b/test/setup.js index 2b5d84bfc..dd30a9374 100644 --- a/test/setup.js +++ b/test/setup.js @@ -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;