From dd448d842eae378d645a21685ceaee93b0ba43fb Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Wed, 25 Jan 2017 15:14:21 +0200 Subject: [PATCH] Add auth form to correct pages --- src/Routes.js | 4 + .../AuthenticationPage/AuthenticationPage.js | 29 ++++-- .../AuthenticationPage.test.js | 6 +- .../AuthenticationPage.test.js.snap | 90 ++++++++++++++----- .../ChangeAccountPasswordForm.js | 2 - .../ChangeAccountPasswordForm.test.js | 8 +- .../ChangeAccountPasswordForm.test.js.snap | 13 --- .../ChangePasswordForm/ChangePasswordForm.js | 4 - .../ChangePasswordForm.test.js | 8 +- .../ChangePasswordForm.test.js.snap | 26 ------ .../CheckoutPage/CheckoutPage.test.js | 6 +- .../__snapshots__/CheckoutPage.test.js.snap | 4 - .../ContactDetailsPage.test.js | 6 +- .../ContactDetailsPage.test.js.snap | 4 - .../EditProfilePage/EditProfilePage.test.js | 6 +- .../EditProfilePage.test.js.snap | 4 - src/containers/InboxPage/InboxPage.test.js | 6 +- .../__snapshots__/InboxPage.test.js.snap | 4 - .../LandingPage/LandingPage.test.js | 11 +-- .../__snapshots__/LandingPage.test.js.snap | 4 - .../ListingPage/ListingPage.test.js | 6 +- .../__snapshots__/ListingPage.test.js.snap | 4 - src/containers/LoginForm/LoginForm.test.js | 8 +- .../ManageListingsPage.test.js | 6 +- .../ManageListingsPage.test.js.snap | 4 - .../NotFoundPage/NotFoundPage.test.js | 6 +- .../__snapshots__/NotFoundPage.test.js.snap | 4 - src/containers/OrderPage/OrderPage.test.js | 6 +- .../__snapshots__/OrderPage.test.js.snap | 4 - .../PasswordChangePage/PasswordChangePage.js | 14 ++- .../PasswordChangePage.test.js | 6 +- .../PasswordChangePage.test.js.snap | 38 +++++++- .../PasswordForgottenPage.js | 14 ++- .../PasswordForgottenPage.test.js | 6 +- .../PasswordForgottenPage.test.js.snap | 28 +++++- .../PayoutPreferencesPage.test.js | 6 +- .../PayoutPreferencesPage.test.js.snap | 4 - .../ProfilePage/ProfilePage.test.js | 6 +- .../__snapshots__/ProfilePage.test.js.snap | 4 - .../SalesConversationPage.test.js | 6 +- .../SalesConversationPage.test.js.snap | 4 - src/containers/SearchPage/SearchPage.test.js | 6 +- .../__snapshots__/SearchPage.test.js.snap | 4 - src/containers/SecurityPage/SecurityPage.js | 8 +- .../SecurityPage/SecurityPage.test.js | 6 +- .../__snapshots__/SecurityPage.test.js.snap | 57 ++++++++++-- src/containers/SignUpForm/SignUpForm.test.js | 8 +- src/containers/Topbar/Topbar.js | 2 +- src/util/test-helpers.js | 18 ++++ 49 files changed, 318 insertions(+), 220 deletions(-) create mode 100644 src/util/test-helpers.js diff --git a/src/Routes.js b/src/Routes.js index 77ed92b2..3938b7c8 100644 --- a/src/Routes.js +++ b/src/Routes.js @@ -10,10 +10,14 @@ import routesConfiguration, { flattenRoutes, pathByRouteName } from './routesCon export const fakeAuth = { isAuthenticated: false, authenticate(cb) { + // eslint-disable-next-line no-console + console.log('fakeAuth: authenticate'); this.isAuthenticated = true; window.setTimeout(cb, 100); // fake async }, signout(cb) { + // eslint-disable-next-line no-console + console.log('fakeAuth: signout'); this.isAuthenticated = false; cb(); window.setTimeout(cb, 100); // weird bug if async? diff --git a/src/containers/AuthenticationPage/AuthenticationPage.js b/src/containers/AuthenticationPage/AuthenticationPage.js index 452b9faf..6ab4e8f8 100644 --- a/src/containers/AuthenticationPage/AuthenticationPage.js +++ b/src/containers/AuthenticationPage/AuthenticationPage.js @@ -1,6 +1,7 @@ import React, { Component, PropTypes } from 'react'; import { Link, Redirect } from 'react-router'; import { PageLayout } from '../../components'; +import { LoginForm, SignUpForm } from '../../containers'; import { fakeAuth } from '../../Routes'; class AuthenticationPage extends Component { @@ -8,10 +9,21 @@ class AuthenticationPage extends Component { super(props); this.state = { redirectToReferrer: false }; - this.login = this.login.bind(this); + this.handleLogIn = this.handleLogIn.bind(this); + this.handleSignUp = this.handleSignUp.bind(this); } - login() { + handleLogIn(values) { + // eslint-disable-next-line no-console + console.log('log in with values:', values); + fakeAuth.authenticate(() => { + this.setState({ redirectToReferrer: true }); + }); + } + + handleSignUp(values) { + // eslint-disable-next-line no-console + console.log('sign up with values:', values); fakeAuth.authenticate(() => { this.setState({ redirectToReferrer: true }); }); @@ -20,7 +32,7 @@ class AuthenticationPage extends Component { render() { const from = this.props.location.state && this.props.location.state.from ? this.props.location.state.from - : '/'; + : null; const { redirectToReferrer } = this.state; const toLogin = Log in; @@ -28,9 +40,12 @@ class AuthenticationPage extends Component { Sign up ); const alternativeMethod = this.props.tab === 'login' ? toSignup : toLogin; - const currentMethod = this.props.tab === 'login' ? 'Log in' : 'Sign up'; - const fromLoginMsg = from ? ( + const form = this.props.tab === 'login' + ? + : ; + + const fromLoginMsg = from && from.pathname ? (

You must log in to view the page at {from.pathname} @@ -41,8 +56,8 @@ class AuthenticationPage extends Component { {redirectToReferrer ? : null} {fromLoginMsg} - -

or {alternativeMethod}

+ {form} + {alternativeMethod} ); } diff --git a/src/containers/AuthenticationPage/AuthenticationPage.test.js b/src/containers/AuthenticationPage/AuthenticationPage.test.js index c6fc46de..142ee30a 100644 --- a/src/containers/AuthenticationPage/AuthenticationPage.test.js +++ b/src/containers/AuthenticationPage/AuthenticationPage.test.js @@ -1,15 +1,15 @@ import React from 'react'; -import { BrowserRouter } from 'react-router'; import renderer from 'react-test-renderer'; +import { TestProvider } from '../../util/test-helpers'; import AuthenticationPage from './AuthenticationPage'; describe('AuthenticationPage', () => { it('matches snapshot', () => { const component = renderer.create( ( - + - + ), ); const tree = component.toJSON(); diff --git a/src/containers/AuthenticationPage/__snapshots__/AuthenticationPage.test.js.snap b/src/containers/AuthenticationPage/__snapshots__/AuthenticationPage.test.js.snap index 1e36f485..15ceb7ce 100644 --- a/src/containers/AuthenticationPage/__snapshots__/AuthenticationPage.test.js.snap +++ b/src/containers/AuthenticationPage/__snapshots__/AuthenticationPage.test.js.snap @@ -115,31 +115,77 @@ exports[`AuthenticationPage matches snapshot 1`] = ` style={Object {}}> Security -

Authentication page: signup tab

-

- You must log in to view the page at - -

- -

- or - - Log in - -

+
+ + + + + + + + +

+ By confirming I accept the booking terms and conditions. +

+ +
+ + Log in + `; diff --git a/src/containers/ChangeAccountPasswordForm/ChangeAccountPasswordForm.js b/src/containers/ChangeAccountPasswordForm/ChangeAccountPasswordForm.js index 2d6a4cf5..c99af0f2 100644 --- a/src/containers/ChangeAccountPasswordForm/ChangeAccountPasswordForm.js +++ b/src/containers/ChangeAccountPasswordForm/ChangeAccountPasswordForm.js @@ -5,8 +5,6 @@ const ChangeAccountPasswordForm = props => { const { handleSubmit, pristine, submitting } = props; return (
- - diff --git a/src/containers/ChangeAccountPasswordForm/ChangeAccountPasswordForm.test.js b/src/containers/ChangeAccountPasswordForm/ChangeAccountPasswordForm.test.js index cd31f15d..b24da87d 100644 --- a/src/containers/ChangeAccountPasswordForm/ChangeAccountPasswordForm.test.js +++ b/src/containers/ChangeAccountPasswordForm/ChangeAccountPasswordForm.test.js @@ -1,17 +1,15 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import { Provider } from 'react-redux'; -import configureStore from '../../store'; +import { TestProvider } from '../../util/test-helpers'; import ChangeAccountPasswordForm from './ChangeAccountPasswordForm'; describe('ChangeAccountPasswordForm', () => { it('matches snapshot', () => { - const store = configureStore(); const component = renderer.create( ( - + - + ), ); const tree = component.toJSON(); diff --git a/src/containers/ChangeAccountPasswordForm/__snapshots__/ChangeAccountPasswordForm.test.js.snap b/src/containers/ChangeAccountPasswordForm/__snapshots__/ChangeAccountPasswordForm.test.js.snap index 66b6a708..b38292b2 100644 --- a/src/containers/ChangeAccountPasswordForm/__snapshots__/ChangeAccountPasswordForm.test.js.snap +++ b/src/containers/ChangeAccountPasswordForm/__snapshots__/ChangeAccountPasswordForm.test.js.snap @@ -1,19 +1,6 @@ exports[`ChangeAccountPasswordForm matches snapshot 1`] = ` - -