-
Notifications
You must be signed in to change notification settings - Fork 23
/
RandomSeedInput.test.js
35 lines (25 loc) · 1012 Bytes
/
RandomSeedInput.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React from 'react'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import FarmhandContext from '../Farmhand/Farmhand.context'
import { RandomSeedInput } from './RandomSeedInput'
const mockHandleRNGSeedChange = jest.fn()
const MockRandomSeedInput = props => (
<FarmhandContext.Provider
value={{ handlers: { handleRNGSeedChange: mockHandleRNGSeedChange } }}
>
<RandomSeedInput {...props} />
</FarmhandContext.Provider>
)
describe('RandomSeedInput', () => {
test('gets initial value from query param', () => {
render(<MockRandomSeedInput search="?seed=123" />)
expect(screen.getByDisplayValue('123')).toBeInTheDocument()
})
test('updates query param', () => {
render(<MockRandomSeedInput search="?seed=123" />)
const input = screen.getByDisplayValue('123')
userEvent.type(input, '[Backspace][Backspace][Backspace]456[Enter]')
expect(mockHandleRNGSeedChange).toHaveBeenCalledWith('456')
})
})