Commit 3fccde3e authored by Jesse Hallam's avatar Jesse Hallam Committed by Harrison Healey
Browse files

MM-12757: discard session expiry on form submit (#2011)

* MM-12757: discard session expiry on form submit

* simplify unit tests
parent 71eefcf7
......@@ -178,6 +178,9 @@ class LoginController extends React.Component {
preSubmit = (e) => {
e.preventDefault();
// Discard any session expiry notice once the user interacts with the login page.
this.onDismissSessionExpired();
const {location} = this.props;
const newQuery = location.search.replace(/(extra=password_change)&?/i, '');
if (newQuery !== location.search) {
......@@ -186,14 +189,20 @@ class LoginController extends React.Component {
// password managers don't always call onInput handlers for form fields so it's possible
// for the state to get out of sync with what the user sees in the browser
let loginId = this.refs.loginId.value;
if (loginId !== this.state.loginId) {
this.setState({loginId});
let loginId = this.state.loginId;
if (this.refs.loginId) {
loginId = this.refs.loginId.value;
if (loginId !== this.state.loginId) {
this.setState({loginId});
}
}
const password = this.refs.password.value;
if (password !== this.state.password) {
this.setState({password});
let password = this.state.password;
if (this.refs.password) {
password = this.refs.password.value;
if (password !== this.state.password) {
this.setState({password});
}
}
// don't trim the password since we support spaces in passwords
......
......@@ -99,4 +99,25 @@ describe('components/login/LoginController', () => {
expect(wrapper).toMatchSnapshot();
});
it('should discard session expiry notification on failed sign in', () => {
const props = {
...baseProps,
initializing: false,
location: {
search: '?extra=' + Constants.SIGNIN_CHANGE,
},
};
const wrapper = shallowWithIntl(
<LoginController {...props}/>
).dive();
wrapper.setState({sessionExpired: true});
const e = {preventDefault: jest.fn()};
wrapper.instance().preSubmit(e);
expect(wrapper.state('sessionExpired')).toBe(false);
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment