-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GetStarted comp and user info query
- Loading branch information
Showing
7 changed files
with
194 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import createBackgroundProxy from 'react-cosmos-background-proxy'; | ||
import createRouterProxy from 'react-cosmos-router-proxy'; | ||
|
||
export default [createBackgroundProxy(), createRouterProxy()]; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,85 @@ | ||
/* eslint-disable no-return-assign */ | ||
|
||
import React from 'react'; | ||
import React, { Fragment } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import gql from 'graphql-tag'; | ||
import { Query } from 'react-apollo'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import LoadingMessage from '../LoadingMessage'; | ||
import Error from '../Error'; | ||
import Button from '../Button'; | ||
import style from './style.css'; | ||
|
||
export function GetStarted({ data }) { | ||
console.log(data); | ||
return <div className={style.container} />; | ||
export function GetStarted({ data, loading, error, refetch, networkStatus }) { | ||
const renderContent = () => { | ||
if (loading || networkStatus === 4) { | ||
return <LoadingMessage message="Loading your Github profile..." />; | ||
} | ||
|
||
if (error) { | ||
return ( | ||
<div> | ||
<Error | ||
message={ | ||
'Failed to load your Github profile from the Github API. Please try again later.' | ||
} | ||
/> | ||
<Button onClick={refetch}>Retry</Button> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<Fragment> | ||
<p className={style.success}> | ||
Successfully signed in as <strong>{data.viewer.login}</strong>! | ||
</p> | ||
<p className={style.continue}> | ||
Now its time to select the Github repos that you would like to monitor | ||
with Pullp. | ||
</p> | ||
<Link to="/app/selectRepos"> | ||
<Button className={style.button}>Let's get started</Button> | ||
</Link> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
return <div className={style.container}>{renderContent()}</div>; | ||
} | ||
|
||
GetStarted.propTypes = { | ||
data: PropTypes.shape({}).isRequired, | ||
loading: PropTypes.bool.isRequired, | ||
error: PropTypes.shape({}), | ||
refetch: PropTypes.func.isRequired, | ||
networkStatus: PropTypes.number.isRequired, | ||
}; | ||
|
||
// GetStarted.defaultProps = { | ||
|
||
// }; | ||
GetStarted.defaultProps = { | ||
error: null, | ||
}; | ||
|
||
const GET_CURRENT_USER = gql(` | ||
query { | ||
viewer { | ||
login | ||
avatarUrl | ||
url | ||
} | ||
} | ||
`); | ||
|
||
export default function GetStartedContainer() { | ||
return ( | ||
<Query query={GET_CURRENT_USER}> | ||
{({ data, client }) => <GetStarted data={data} client={client} />} | ||
<Query | ||
query={GET_CURRENT_USER} | ||
notifyOnNetworkStatusChange | ||
fetchPolicy="network-only" | ||
> | ||
{props => { | ||
console.log('props are', props); | ||
return <GetStarted {...props} />; | ||
}} | ||
</Query> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
@import "../../css/colors.css"; | ||
@import "../../css/units.css"; | ||
|
||
.signInContainer { | ||
text-align: center; | ||
.container { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
text-align: center; | ||
} | ||
|
||
.welcome { | ||
.success { | ||
font-weight: bold; | ||
color: var(--primary-medium); | ||
font-size: 1.8rem; | ||
margin-top: 0; | ||
} | ||
|
||
.begin { | ||
.continue { | ||
margin: 3rem auto; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,107 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { Link } from 'react-router-dom'; | ||
import { GetStarted } from '.'; | ||
import LoadingMessage from '../LoadingMessage'; | ||
import Error from '../Error'; | ||
import Button from '../Button'; | ||
|
||
describe('<GetStarted/>', () => { | ||
const defaultProps = { | ||
data: { | ||
viewer: { | ||
login: 'test', | ||
avatarUrl: '/avatar/url', | ||
}, | ||
}, | ||
loading: false, | ||
error: null, | ||
refetch: () => {}, | ||
networkStatus: 1, | ||
}; | ||
|
||
it('renders successfully', () => { | ||
const component = shallow(<GetStarted />); | ||
const component = shallow(<GetStarted {...defaultProps} />); | ||
expect(component.length).toBe(1); | ||
}); | ||
|
||
describe('when loading is true', () => { | ||
it('renders a <LoadingMessage/> with correct message', () => { | ||
const component = shallow(<GetStarted {...defaultProps} loading />); | ||
const loadingMessage = component.find(LoadingMessage); | ||
expect(loadingMessage.length).toBe(1); | ||
expect(loadingMessage.props().message).toBe( | ||
'Loading your Github profile...', | ||
); | ||
}); | ||
}); | ||
|
||
describe('when network status === 4 (refetching)', () => { | ||
it('renders a <LoadingMessage/> with correct message', () => { | ||
const component = shallow( | ||
<GetStarted {...defaultProps} networkStatus={4} />, | ||
); | ||
const loadingMessage = component.find(LoadingMessage); | ||
expect(loadingMessage.length).toBe(1); | ||
expect(loadingMessage.props().message).toBe( | ||
'Loading your Github profile...', | ||
); | ||
}); | ||
}); | ||
|
||
describe('when error is truthy', () => { | ||
let component; | ||
const refetchMock = jest.fn(); | ||
|
||
beforeAll(() => { | ||
component = shallow( | ||
<GetStarted | ||
{...defaultProps} | ||
error={{ borked: true }} | ||
refetch={refetchMock} | ||
/>, | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
refetchMock.mockClear(); | ||
}); | ||
|
||
it('renders an <Error /> with the correct message', () => { | ||
const error = component.find(Error); | ||
expect(error.length).toBe(1); | ||
expect(error.props().message).toBe( | ||
'Failed to load your Github profile from the Github API. Please try again later.', | ||
); | ||
}); | ||
|
||
it('renders a retry button', () => { | ||
const button = component.find(Button); | ||
expect(button.length).toBe(1); | ||
expect(button.props().children).toBe('Retry'); | ||
}); | ||
|
||
describe('retry button onClick', () => { | ||
it('calls the refetch function', () => { | ||
expect(refetchMock).not.toHaveBeenCalled(); | ||
const button = component.find(Button); | ||
button.props().onClick(); | ||
expect(refetchMock).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when data is received', () => { | ||
let component; | ||
|
||
beforeAll(() => { | ||
component = shallow(<GetStarted {...defaultProps} />); | ||
}); | ||
|
||
it('renders an <Link /> to /app/selectRepos', () => { | ||
const link = component.find(Link); | ||
expect(link.length).toBe(1); | ||
expect(link.props().to).toBe('/app/selectRepos'); | ||
}); | ||
}); | ||
}); |
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
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