mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
fully test text input component
This commit is contained in:
parent
3a84b6db07
commit
22258a62ca
@ -1,11 +1,32 @@
|
||||
import { render } from '@testing-library/react'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
|
||||
import { TextInput } from './TextInput'
|
||||
|
||||
describe('<TextInput />', () => {
|
||||
let wrapper = render(<TextInput />)
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = render(<TextInput />)
|
||||
})
|
||||
|
||||
it('renders properly', () => {
|
||||
const wrapper = render(<TextInput />)
|
||||
expect(wrapper.container.firstChild).toMatchSnapshot()
|
||||
})
|
||||
|
||||
describe('handleChange', () => {
|
||||
it('calls updateFormValue with new value', () => {
|
||||
const updateFormValue = vi.fn()
|
||||
wrapper.rerender(<TextInput updateFormValue={updateFormValue} />)
|
||||
fireEvent.change(screen.getByRole('textbox'), { target: { value: 'test' } })
|
||||
expect(updateFormValue).toBeCalledWith('test')
|
||||
})
|
||||
})
|
||||
|
||||
describe('labelTitle', () => {
|
||||
it('sets label', () => {
|
||||
wrapper.rerender(<TextInput labelTitle='My Title' />)
|
||||
expect(wrapper.container.firstChild).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,5 +1,28 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`<TextInput /> > labelTitle > sets label 1`] = `
|
||||
<div
|
||||
class="tw-form-control undefined"
|
||||
>
|
||||
<label
|
||||
class="tw-label"
|
||||
>
|
||||
<span
|
||||
class="tw-label-text tw-text-base-content undefined"
|
||||
>
|
||||
My Title
|
||||
</span>
|
||||
</label>
|
||||
<input
|
||||
class="tw-input tw-input-bordered tw-w-full "
|
||||
placeholder=""
|
||||
required=""
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<TextInput /> > renders properly 1`] = `
|
||||
<div
|
||||
class="tw-form-control undefined"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user