-
Notifications
You must be signed in to change notification settings - Fork 20
Add more tests #195
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
Merged
+146
−7
Merged
Add more tests #195
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47465de
Add tests
5566038
Remove coveralls dep
209cbce
Add tests for analytics and distance calc
1ddae37
This lockfile shouldn't have changed...
d4c5bb8
Add more tests
7cc1b4d
fix typo
6d3dfe9
Merge branch 'more-tests' of https://github.com/code4recovery/tsml-ui…
joshreisner 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 hidden or 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 hidden or 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,43 @@ | ||
import { fireEvent, render, screen, within } from '@testing-library/react'; | ||
import Button from './Button'; | ||
|
||
describe('<Button />', () => { | ||
it('passes props correctly', () => { | ||
const mockOnClick = jest.fn(); | ||
|
||
render( | ||
<Button | ||
className="foo" | ||
href="https://bar.com" | ||
icon="back" | ||
onClick={mockOnClick} | ||
text="baz" | ||
/> | ||
); | ||
|
||
const icon = screen.getByTestId('icon-back'); | ||
const button = screen.getByRole('link'); | ||
|
||
expect(icon).toBeInTheDocument(); | ||
expect(button).toHaveClass('foo'); | ||
expect(button).toHaveAttribute('href', 'https://bar.com'); | ||
expect(button).toHaveTextContent('baz'); | ||
|
||
fireEvent.click(button); | ||
|
||
expect(mockOnClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it('responds to small prop correctly', () => { | ||
render( | ||
// @ts-expect-error TODO: Fix params that should be optional in ts refactor. | ||
<Button small href="https://bar.com" icon="back" /> | ||
); | ||
|
||
const icon = screen.getByTestId('icon-back'); | ||
|
||
expect(icon).toHaveAttribute('height', '18'); | ||
expect(icon).toHaveAttribute('width', '18'); | ||
expect(icon).toHaveClass('me-1'); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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,50 @@ | ||
import { screen, render, fireEvent } from '@testing-library/react'; | ||
import { Meeting } from '../types/Meeting'; | ||
import Link from './Link'; | ||
import { settings } from '../helpers/settings'; | ||
|
||
jest.mock('../helpers/settings'); | ||
|
||
let mockSettings = jest.mocked(settings); | ||
|
||
const mockMeeting: Meeting = { | ||
name: 'Foo', | ||
types: ['M'], | ||
slug: 'bar-baz', | ||
} as Meeting; | ||
|
||
describe('<Link />', () => { | ||
it('works without props', () => { | ||
const { container } = render( | ||
<Link meeting={mockMeeting} state={null} setState={null} /> | ||
); | ||
|
||
expect(container.firstChild.nodeValue).toBe('Foo'); | ||
}); | ||
|
||
it('works with flags', () => { | ||
mockSettings.flags = ['M']; | ||
|
||
render(<Link meeting={mockMeeting} state={null} setState={null} />); | ||
|
||
expect(screen.getByText(/men/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('works with setState', () => { | ||
const mockSetState = jest.fn(); | ||
|
||
render(<Link meeting={mockMeeting} state={{}} setState={mockSetState} />); | ||
|
||
const link = screen.getByRole('link'); | ||
|
||
expect(link).toHaveAttribute('href', 'https://test.com/'); | ||
expect(link).toHaveTextContent(/foo/i); | ||
expect(screen.getByText(/men/i)).toBeInTheDocument(); | ||
|
||
fireEvent.click(link); | ||
|
||
expect(mockSetState).toHaveBeenCalledWith({ | ||
input: { meeting: 'bar-baz' }, | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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,7 @@ | ||
import renderer from 'react-test-renderer'; | ||
import Loading from './Loading'; | ||
|
||
test('<Loading />', () => { | ||
const tree = renderer.create(<Loading />).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); |
This file contains hidden or 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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<Loading /> 1`] = ` | ||
<div | ||
className="align-items-center d-flex flex-grow-1 h-100 justify-content-center loading" | ||
> | ||
<div | ||
className="m-5 spinner-border text-secondary" | ||
/> | ||
</div> | ||
`; |
This file contains hidden or 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
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.
Safe to assume this won't ever be null, since the ts compiler references the keys of the icons object