Skip to content

Commit

Permalink
add basic armory list check
Browse files Browse the repository at this point in the history
  • Loading branch information
Seqi committed Apr 29, 2022
1 parent ffd3d78 commit 9d082e4
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions web/src/app/features/armory/components/Armory.spec.tsx
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()
})
})
})
})

0 comments on commit 9d082e4

Please sign in to comment.