Skip to content

Commit

Permalink
Added tests and removed with router
Browse files Browse the repository at this point in the history
  • Loading branch information
codesankalp committed Mar 14, 2021
1 parent dfe38a8 commit 46387d7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
9 changes: 0 additions & 9 deletions src/App.test.js

This file was deleted.

17 changes: 7 additions & 10 deletions src/components/GitHubAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import GitHubLogin from 'react-github-login';
import { postGithubCode } from '../actions/login';
import { withRouter } from 'react-router';
import { Icon, Message } from 'semantic-ui-react';

class GitHubAuth extends Component {
Expand All @@ -20,7 +19,6 @@ class GitHubAuth extends Component {
}

postCode = (response) => {
console.log(response.code);
this.setState({
code: response.code,
});
Expand All @@ -39,7 +37,6 @@ class GitHubAuth extends Component {
posted: true,
errorText: 'Server Error: try again.',
});
console.log(this.state.error, this.state.posted);
if (!this.state.error) {
this.props.history.push('/');
}
Expand All @@ -51,10 +48,12 @@ class GitHubAuth extends Component {
}, 4000);
};

icon = () => {
githubIcon = () => {
return (
<React.Fragment>
<Icon name="github" /> Log in with GitHub
<div data-testid="GitHubLoginButton">
<Icon name="github" /> Log in with GitHub
</div>
</React.Fragment>
);
};
Expand All @@ -74,7 +73,7 @@ class GitHubAuth extends Component {
}, 4000);
};

UNSAFE_componentWillMount() {
componentDidMount() {
this.setState({
code: '',
error: null,
Expand Down Expand Up @@ -109,7 +108,7 @@ class GitHubAuth extends Component {
redirectUri={`${REACT_APP_GITHUB_CALLBACK_URL}`}
className="ui fluid button"
>
{this.icon()}
{this.githubIcon()}
</GitHubLogin>
)}
</>
Expand All @@ -126,6 +125,4 @@ const mapStateToProps = (state) => ({
loginerror: state.login.loginerror,
});

export default connect(mapStateToProps, { postGithubCode })(
withRouter(GitHubAuth)
);
export default connect(mapStateToProps, { postGithubCode })(GitHubAuth);
25 changes: 25 additions & 0 deletions src/tests/GitHubAuth.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import { render, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom';
import GitHubAuth from '../components/GitHubAuth';
import loginReducer from '../reducers/login';

afterEach(cleanup);

function renderWithRedux(
component,
{ initialState, store = createStore(loginReducer, initialState) } = {}
) {
return {
...render(<Provider store={store}>{component}</Provider>),
};
}

it('Renders GitHub Login Button', () => {
const { getByTestId } = renderWithRedux(<GitHubAuth />);
expect(getByTestId('GitHubLoginButton')).toHaveTextContent(
'Log in with GitHub'
);
});

0 comments on commit 46387d7

Please sign in to comment.