Skip to content

Instantly share code, notes, and snippets.

@m1cl
Created June 6, 2018 19:09
Show Gist options
  • Save m1cl/59751a3ce111152d36362b1a7d85a691 to your computer and use it in GitHub Desktop.
Save m1cl/59751a3ce111152d36362b1a7d85a691 to your computer and use it in GitHub Desktop.
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)))
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