Created
June 6, 2018 19:09
-
-
Save m1cl/59751a3ce111152d36362b1a7d85a691 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import PropTypes from 'prop-types' | |
import Login from '../../pages/login/Login' | |
import s from './LoginComponent.scss'; // eslint-disable-line | |
export class LoginComponent extends React.Component { | |
return ( | |
<div className={s.root}> | |
<Login | |
login={this.state.login} | |
email={this.state.email} | |
password={this.state.password} | |
isFetching={this.state.isFetching} | |
changeLogin={this.changeLogin} | |
changePassword={this.changePassword} | |
handleOnChange={this.onChange} | |
handleLogin={this.loginMutation} | |
failed={this.state.failed} | |
/> | |
</div> | |
) | |
} | |
} | |
const authenticateUserMutation = gql` | |
mutation authenticate($token: String!){ | |
authenticate(token: $token) { | |
user { | |
first_name, | |
last_name, | |
email, | |
client_id, | |
id, | |
} | |
} | |
} | |
` | |
const signInUserMutation = gql` | |
mutation loginUser( | |
$email: String!, | |
$password: String!, | |
) { | |
loginUser( | |
email: $email, | |
password: $password, | |
){ | |
ok, | |
token, | |
refreshToken, | |
user { | |
first_name, | |
first_visit, | |
last_name, | |
email, | |
client_id, | |
id, | |
} | |
} | |
} | |
` | |
const AddLoginWithMutation = compose( | |
graphql(signInUserMutation, { name: 'handleLogin' }), | |
graphql(authenticateUserMutation, { name: 'authenticate' }), | |
)(LoginComponent) | |
function mapStateToProps(state) { | |
return { | |
isFetching: state.auth.isFetching, | |
isAuthenticated: state.auth.isAuthenticated, | |
errorMessage: state.auth.errorMessage, | |
} | |
} | |
export default withRouter(connect(mapStateToProps)(withStyles(s)(AddLoginWithMutation))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {expect} from 'chai' | |
import Enzyme, { shallow, mount } from 'enzyme' | |
import React, { Component } from 'react' | |
import Adapter from 'enzyme-adapter-react-16' | |
import { LoginComponent } from '../src/components/LoginComponent/LoginComponent' | |
import { Login } from '../src/pages/login/Login' | |
Enzyme.configure({ adapter: new Adapter() }) | |
describe("<LoginComponent />", () => { | |
it("should not blow up", () => { | |
const wrapper = shallow(<LoginComponent />) | |
expect(wrapper.length).to.eql(1) | |
}) | |
it('should contain a div element', () => { | |
const wrapper = shallow(<LoginComponent />) | |
expect(wrapper.containsMatchingElement( | |
<div> | |
<Login /> | |
</div> | |
)).to.be.true | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment