-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Testing Library setup and some boilerplate tests for current comp… #29
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 @@ | ||
// jest.config.js | ||
module.exports = { | ||
collectCoverageFrom: ['src/**/*.{js,jsx}'], | ||
coveragePathIgnorePatterns: [ | ||
'/node_modules/', | ||
'src/serviceWorker.js', | ||
'src/configureStore.js', | ||
'src/bees.js', | ||
'src/index.js', | ||
'src/tests/*.{js,jsx}', | ||
'src/__tests__/testing-helpers.js' | ||
] | ||
} |
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,10 +1,7 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import App from '../containers/App' | ||
import { renderWithRedux } from './testing-helpers' | ||
|
||
/** | ||
* This needs to be implemented to handle working with the Redux Store | ||
*/ | ||
it('renders the component on the DOM', () => { | ||
// To be implemented | ||
it('renders without crashing', () => { | ||
expect(renderWithRedux(<App />)) | ||
}) |
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,22 +1,31 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import AuthButton from '../containers/AuthButton' | ||
import { render } from '@testing-library/react' | ||
|
||
describe('<AuthButton />', () => { | ||
let defaultProps = { | ||
handleClick: () => {}, | ||
authorizationUrl: 'http://cloud.org/authorize' | ||
} | ||
|
||
it('renders without crashing', () => { | ||
expect(render(<AuthButton {...defaultProps} />)) | ||
}) | ||
|
||
it('renders the auth button', () => { | ||
const { getByTestId, debug } = render(<AuthButton {...defaultProps} />) | ||
expect(getByTestId('auth-button')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the Sign in', () => { | ||
// const wrapper = mount(<AuthButton {...defaultProps} />); | ||
// expect(wrapper).toBeTruthy; | ||
// expect(wrapper.text()).toEqual('Sign In'); | ||
const { getByTestId, debug } = render(<AuthButton {...defaultProps} />) | ||
expect(getByTestId('auth-button')).toHaveTextContent(/sign in/i) | ||
}) | ||
|
||
it('renders the Authorized', () => { | ||
// const wrapper = mount(<AuthButton disabled={true} {...defaultProps} />); | ||
// expect(wrapper).toBeTruthy; | ||
// expect(wrapper.text()).toEqual('Authorized'); | ||
const { getByTestId, debug } = render( | ||
<AuthButton {...defaultProps} disabled={true} /> | ||
) | ||
expect(getByTestId('auth-button')).toHaveTextContent(/authorized/i) | ||
}) | ||
}) |
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,5 +1,26 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import ResourceNode from '../containers/ResourceNode' | ||
import { render } from '@testing-library/react' | ||
|
||
it('renders the component on the DOM', () => {}) | ||
const mockDispatch = jest.fn() | ||
|
||
const defaultProps = { | ||
selected: false, | ||
label: 'Ima label', | ||
bytestream: { foo: 'bar ' }, | ||
dispatch: mockDispatch | ||
} | ||
|
||
it('renders without crashing', () => { | ||
expect(render(<ResourceNode {...defaultProps} />)) | ||
}) | ||
|
||
it('renders the resource node checkbox', () => { | ||
const { getByTestId } = render(<ResourceNode {...defaultProps} />) | ||
expect(getByTestId('resource-node-checkbox')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders expand/collapse button', () => { | ||
const { getByTestId } = render(<ResourceNode {...defaultProps} />) | ||
expect(getByTestId('expand-collapse-button')).toBeInTheDocument() | ||
}) |
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,5 +1,35 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import ResourceTree from '../containers/ResourceTree' | ||
import { render } from '@testing-library/react' | ||
|
||
it('renders the component on the DOM', () => {}) | ||
const mockDispatch = jest.fn() | ||
|
||
const defaultProps = { | ||
selected: false, | ||
root: false, | ||
label: 'Ima label', | ||
dispatch: mockDispatch, | ||
container: { foo: 'bar' } | ||
} | ||
|
||
it('renders without crashing', () => { | ||
expect(render(<ResourceTree {...defaultProps} />)) | ||
}) | ||
|
||
it('renders resource tree wrapper element', () => { | ||
const { getByTestId } = render(<ResourceTree {...defaultProps} />) | ||
expect(getByTestId('resource-tree-wrapper')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders primary checkbox', () => { | ||
const { getByTestId } = render(<ResourceTree {...defaultProps} />) | ||
expect(getByTestId('primary-checkbox')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders expand/collapse button', () => { | ||
const { getByTestId } = render(<ResourceTree {...defaultProps} />) | ||
expect(getByTestId('expand-collapse-button')).toBeInTheDocument() | ||
}) | ||
|
||
// Not really sure yet how to test <StyledChildResourceTree /> and | ||
// < ResourceNode /> presence in this component |
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,5 +1,25 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import SelectProvider from '../containers/SelectProvider' | ||
import { render } from '@testing-library/react' | ||
|
||
it('renders the component on the DOM', () => {}) | ||
const mockFn = jest.fn() | ||
|
||
const defaultProps = { | ||
selectedProvider: { foo: 'bar' }, | ||
providers: { items: [], id: 'ABC123', name: 'Ima provider 1' }, | ||
handleChange: mockFn | ||
} | ||
|
||
it('renders without crashing', () => { | ||
expect(render(<SelectProvider {...defaultProps} />)) | ||
}) | ||
|
||
it('renders the select provider form control', () => { | ||
const { getByTestId } = render(<SelectProvider {...defaultProps} />) | ||
expect(getByTestId('select-provider-wrapper')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the select element', () => { | ||
const { getByTestId } = render(<SelectProvider {...defaultProps} />) | ||
expect(getByTestId('select-provider')).toBeInTheDocument() | ||
}) |
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,5 +1,41 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import UploadForm from '../containers/UploadForm' | ||
import { render } from '@testing-library/react' | ||
|
||
it('renders the component on the DOM', () => {}) | ||
const mockOnUpload = jest.fn() | ||
const mockDispatch = jest.fn() | ||
|
||
const defaultProps = { | ||
selectedProvider: { foo: 'bar' }, | ||
providers: { items: [], id: 'ABC123', name: 'Ima provider 1' }, | ||
currentAuthToken: { foo: 'bar ' }, | ||
currentSession: {}, | ||
rootContainer: {}, | ||
currentUpload: {}, | ||
dispatch: mockDispatch, | ||
onUpload: mockOnUpload | ||
} | ||
|
||
it('renders without crashing', () => { | ||
expect(render(<UploadForm {...defaultProps} />)) | ||
}) | ||
|
||
it('renders the form', () => { | ||
const { getByTestId } = render(<UploadForm {...defaultProps} />) | ||
expect(getByTestId('upload-form')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the Select Providers section', () => { | ||
const { getByTestId } = render(<UploadForm {...defaultProps} />) | ||
expect(getByTestId('select-provider-wrapper')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the resource tree section', () => { | ||
const { getByTestId } = render(<UploadForm {...defaultProps} />) | ||
expect(getByTestId('resource-tree-wrapper')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the submit button', () => { | ||
const { getByTestId } = render(<UploadForm {...defaultProps} />) | ||
expect(getByTestId('upload-submit-button')).toBeInTheDocument() | ||
}) |
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,21 @@ | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { render } from '@testing-library/react' | ||
import reducer from '../reducers' | ||
import configureStore from '../configureStore' | ||
|
||
// this is a handy function that I normally make available for all my tests | ||
// that deal with connected components. | ||
// you can provide initialState for the entire store that the ui is rendered with | ||
export function renderWithRedux( | ||
ui, | ||
{ initialState, store = configureStore(initialState) } = {} | ||
) { | ||
return { | ||
...render(<Provider store={store}>{ui}</Provider>), | ||
// adding `store` to the returned utilities to allow us | ||
// to reference it in our tests (just try to avoid using | ||
// this to test implementation details). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
store | ||
} | ||
} |
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,36 +1,37 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import Button from '@material-ui/core/Button' | ||
import { makeStyles } from '@material-ui/core/styles' | ||
|
||
import Button from '@material-ui/core/Button'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
|
||
class AuthButton extends React.Component { | ||
render() { | ||
const textContent = this.props.disabled ? 'Authorized' : 'Sign In'; | ||
return ( | ||
<Button | ||
variant="contained" | ||
color="secondary" | ||
className={this.props.classes.root} | ||
onClick={this.props.handleClick} | ||
href={this.props.authorizationUrl} | ||
disabled={this.props.disabled}>{textContent} | ||
</Button> | ||
); | ||
const useStyles = makeStyles({ | ||
root: { | ||
alignSelf: 'center' | ||
} | ||
}) | ||
|
||
const AuthButton = ({ handleClick, authorizationUrl, disabled }) => { | ||
const classes = useStyles | ||
const textContent = disabled ? 'Authorized' : 'Sign In' | ||
|
||
return ( | ||
<Button | ||
data-testid="auth-button" | ||
variant="contained" | ||
color="secondary" | ||
className={classes.root} | ||
onClick={handleClick} | ||
href={authorizationUrl} | ||
disabled={disabled} | ||
> | ||
{textContent} | ||
</Button> | ||
) | ||
} | ||
|
||
AuthButton.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
handleClick: PropTypes.func.isRequired, | ||
authorizationUrl: PropTypes.string.isRequired, | ||
disabled: PropTypes.bool | ||
}; | ||
|
||
const styles = { | ||
root: { | ||
alignSelf: 'center' | ||
} | ||
}; | ||
} | ||
|
||
export default withStyles(styles)(AuthButton); | ||
export default AuthButton |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I can create an issue for this.