1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-12-22 09:13:35 +01:00
This commit is contained in:
Matthias Kretschmann 2023-11-05 18:57:53 +00:00
parent e6d5e504b0
commit d31feb15c3
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 11 additions and 8 deletions

View File

@ -1,25 +1,29 @@
import { fireEvent, render, screen } from '@testing-library/react'
import { describe, it, expect, vi } from 'vitest'
import { describe, it, expect } from 'vitest'
import { InputGroup } from '.'
const setAmount = vi.fn()
describe('InputGroup', () => {
it('renders without crashing', async () => {
render(<InputGroup amount="1" setAmount={setAmount} isDisabled={false} />)
render(<InputGroup isDisabled={false} error={undefined} />)
const input = await screen.findByRole('textbox')
const button = await screen.findByRole('button')
fireEvent.change(input, { target: { value: '3' } })
fireEvent.click(button)
expect(setAmount).toHaveBeenCalled()
})
it('renders disabled', async () => {
render(<InputGroup amount="1" setAmount={setAmount} isDisabled={true} />)
render(<InputGroup isDisabled={true} error={undefined} />)
const input = await screen.findByRole('textbox')
expect(input).toBeDefined()
expect(input.attributes.getNamedItem('disabled')).toBeDefined()
})
it('renders error', async () => {
render(<InputGroup isDisabled={false} error={'Hello Error'} />)
const errorItem = await screen.findByText('Hello Error')
expect(errorItem).toBeDefined()
})
})

View File

@ -23,6 +23,7 @@ export function TokenSelect() {
function handleValueChange(value: `0x${string}`) {
const token = tokens?.find((token) => token.address === value)
if (!token) return
$setSelectedToken(token)
}
@ -31,9 +32,7 @@ export function TokenSelect() {
useEffect(() => {
if (selectedToken?.address || !tokens || !tokens?.length) return
console.log(tokens)
handleValueChange('0x0')
console.log('auto-select 0x0')
}, [tokens, selectedToken])
return tokens && address ? (