Skip to content

Commit

Permalink
Improve AddReview test performance with paste
Browse files Browse the repository at this point in the history
Typing with user-event appears to have been slow for a
long time [1]. AddReview tests a large combination of
separately tested components. There is little harm in using
paste instead of typing assuming the lower level components
are tested well.

[1] testing-library/user-event#577
  • Loading branch information
mgynther committed Oct 18, 2024
1 parent 4342d5e commit fa0bf62
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions frontend/src/components/review/AddReview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,16 @@ const unusedStorageIf = {
}

async function addReview(getByPlaceholderText: (
text: string) => Element,
text: string) => HTMLElement,
getByRole: (text: string, props?: Record<string, unknown>) => HTMLElement,
user: UserEvent
) {
const smellInput = getByPlaceholderText('Smell')
await act(async () => await user.type(smellInput, smellText))
smellInput.focus()
userEvent.paste(smellText)
const tasteInput = getByPlaceholderText('Taste')
await act(async () => await user.type(tasteInput, tasteText))
tasteInput.focus()
await user.paste(tasteText)
const ratingInput = getByRole('slider')
ratingInput.click()
const addButton = getByRole('button', { name: 'Add' })
Expand Down Expand Up @@ -199,7 +201,8 @@ test('adds review', async () => {
act(() => selects[0].click())
const beerSearch = getByPlaceholderText('Search beer')
expect(beerSearch).toBeDefined()
await user.type(beerSearch, 'Seve')
beerSearch.focus()
await user.paste('Seve')
const beerButton = await findByRole(
'button',
{ name: 'Severin (Koskipanimo)' }
Expand Down

0 comments on commit fa0bf62

Please sign in to comment.