-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 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,43 @@ | ||
import { ThemeProvider } from '@material-ui/core' | ||
import { render, screen, waitFor, within } from '@testing-library/react' | ||
import { db } from 'test/data' | ||
import theme from 'theme' | ||
import Armory from './Armory' | ||
|
||
describe('Armory', () => { | ||
describe.each([ | ||
['weapons', db.armory.get().weapons], | ||
['attachments', db.armory.get().attachments], | ||
['gear', db.armory.get().gear], | ||
['clothing', db.armory.get().clothing], | ||
])('%s', (resource, dbItems) => { | ||
it('should render the list with an add button', async () => { | ||
render( | ||
<ThemeProvider theme={theme}> | ||
<Armory /> | ||
</ThemeProvider> | ||
) | ||
|
||
expect(screen.getByTestId('loading-spinner')).toBeInTheDocument() | ||
await waitFor(() => | ||
expect(screen.queryByTestId('loading-spinner')).not.toBeInTheDocument() | ||
) | ||
|
||
const list = screen.getByLabelText(new RegExp(resource, 'i')) | ||
const listItems = within(list).getAllByRole('listitem') | ||
expect(listItems).toHaveLength(5) | ||
|
||
const addButton = within(list).getByRole('button', { name: 'add' }) | ||
expect(addButton).toBeInTheDocument() | ||
|
||
listItems.forEach((listItem, index) => { | ||
const item = dbItems[index] | ||
|
||
expect(within(listItem).getByText(item.platform)).toBeInTheDocument() | ||
expect(within(listItem).getByText(item.brand!)).toBeInTheDocument() | ||
|
||
expect(within(listItem).getByAltText(item.platform)).toBeInTheDocument() | ||
}) | ||
}) | ||
}) | ||
}) |