-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for generic components. Use queryAll instead of getAll to m…
…aintain consitency with 0 element queries.
- Loading branch information
Showing
5 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...[underscore][underscore]tests[underscore][underscore]/components/app/Actions.test.tsx.peb
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,17 @@ | ||
import { Actions } from '@components/Actions' | ||
import { render, screen } from '@testing-library/react' | ||
|
||
describe('Actions', () => { | ||
it('renders the provided action', () => { | ||
render( | ||
<Actions> | ||
<Actions.Action href="https://www.example.com">Do it</Actions.Action> | ||
</Actions> | ||
) | ||
expect(screen.queryAllByText('Do it')).toHaveLength(1) | ||
expect(screen.getByRole('link')).toHaveAttribute( | ||
'href', | ||
'https://www.example.com' | ||
) | ||
}) | ||
}) |
14 changes: 14 additions & 0 deletions
14
...-web/[underscore][underscore]tests[underscore][underscore]/components/app/Details.tsx.peb
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,14 @@ | ||
import { Details } from '@components/Details' | ||
import { render, screen } from '@testing-library/react' | ||
|
||
describe('Details', () => { | ||
it('renders the provided details', () => { | ||
render( | ||
<Details> | ||
<Details.Field label="Field">Value</Details.Field> | ||
</Details> | ||
) | ||
expect(screen.queryAllByText('Field')).toHaveLength(1) | ||
expect(screen.queryAllByText('Value')).toHaveLength(1) | ||
}) | ||
}) |
16 changes: 13 additions & 3 deletions
16
...b/[underscore][underscore]tests[underscore][underscore]/components/app/Error.test.tsx.peb
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,8 +1,18 @@ | ||
import { Error } from '@components/Error' | ||
import { render } from '@testing-library/react' | ||
import { render, screen } from '@testing-library/react' | ||
import { CombinedError } from 'urql' | ||
|
||
describe('Error', () => { | ||
it('renders without errors', () => { | ||
render(<Error value="some error" />) | ||
it('renders the provided error message if the value is a string', () => { | ||
render(<Error value="Error message" />) | ||
expect(screen.queryAllByText('Error message')).toHaveLength(1) | ||
}) | ||
|
||
it('renders the provided error message if the value is a combined error', () => { | ||
const combinedError = new CombinedError({ | ||
graphQLErrors: ['Error message'], | ||
}) | ||
render(<Error value={combinedError} />) | ||
expect(screen.queryAllByText('[GraphQL] Error message')).toHaveLength(1) | ||
}) | ||
}) |
16 changes: 16 additions & 0 deletions
16
...eb/[underscore][underscore]tests[underscore][underscore]/components/app/Form.test.tsx.peb
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,16 @@ | ||
import { Form } from '@components/Form' | ||
import { render, screen, within } from '@testing-library/react' | ||
|
||
describe('Form', () => { | ||
it('renders form with fields', () => { | ||
render( | ||
<Form> | ||
<Form.Field label="Field"> | ||
<Form.Text /> | ||
</Form.Field> | ||
</Form> | ||
) | ||
expect(screen.queryAllByText('Field')).toHaveLength(1) | ||
expect(screen.queryAllByRole('textbox')).toHaveLength(1) | ||
}) | ||
}) |
63 changes: 63 additions & 0 deletions
63
...eb/[underscore][underscore]tests[underscore][underscore]/components/app/List.test.tsx.peb
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,63 @@ | ||
import { List } from '@components/List' | ||
import { render, screen, within } from '@testing-library/react' | ||
|
||
describe('List', () => { | ||
it('renders the provided list', () => { | ||
render( | ||
<List | ||
fields={[{ name: 'field', label: 'Field' }]} | ||
data={[{ field: 'Value' }]} | ||
actions={() => ({})} | ||
/> | ||
) | ||
expect(screen.queryAllByText('Field')).toHaveLength(1) | ||
expect(screen.queryAllByText('Value')).toHaveLength(1) | ||
}) | ||
|
||
it('does not render actions if not provided', () => { | ||
render( | ||
<List | ||
fields={[{ name: 'field', label: 'Field' }]} | ||
data={[{ field: 'Value' }]} | ||
actions={() => ({})} | ||
/> | ||
) | ||
expect(screen.queryAllByText('Show')).toHaveLength(0) | ||
expect(screen.queryAllByText('Edit')).toHaveLength(0) | ||
expect(screen.queryAllByText('Delete')).toHaveLength(0) | ||
}) | ||
|
||
it('renders the provided actions', () => { | ||
let clicked = false | ||
render( | ||
<List | ||
fields={[{ name: 'field', label: 'Field' }]} | ||
data={[{ field: 'Value' }]} | ||
actions={() => ({ | ||
showHref: 'https://www.example1.com', | ||
editHref: 'https://www.example2.com', | ||
onDeleteClick: () => { | ||
clicked = true | ||
}, | ||
})} | ||
/> | ||
) | ||
expect(screen.queryAllByText('Show')).toHaveLength(1) | ||
expect(screen.queryAllByText('Edit')).toHaveLength(1) | ||
expect(screen.queryAllByText('Delete')).toHaveLength(1) | ||
|
||
expect(screen.getByText('Show')).toHaveAttribute( | ||
'href', | ||
'https://www.example1.com' | ||
) | ||
|
||
expect(screen.getByText('Edit')).toHaveAttribute( | ||
'href', | ||
'https://www.example2.com' | ||
) | ||
|
||
screen.getByText('Delete').click() | ||
|
||
expect(clicked).toBeTruthy() | ||
}) | ||
}) |