From 22258a62caf0d3efb9835cd93fcb1320c6ab9e0d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 3 Feb 2025 22:40:06 +0100 Subject: [PATCH] fully test text input component --- src/Components/Input/TextInput.spec.tsx | 27 ++++++++++++++++--- .../__snapshots__/TextInput.spec.tsx.snap | 23 ++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Components/Input/TextInput.spec.tsx b/src/Components/Input/TextInput.spec.tsx index 95035b42..a1ab4989 100644 --- a/src/Components/Input/TextInput.spec.tsx +++ b/src/Components/Input/TextInput.spec.tsx @@ -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('', () => { + let wrapper = render() + + beforeEach(() => { + wrapper = render() + }) + it('renders properly', () => { - const wrapper = render() expect(wrapper.container.firstChild).toMatchSnapshot() }) + + describe('handleChange', () => { + it('calls updateFormValue with new value', () => { + const updateFormValue = vi.fn() + wrapper.rerender() + fireEvent.change(screen.getByRole('textbox'), { target: { value: 'test' } }) + expect(updateFormValue).toBeCalledWith('test') + }) + }) + + describe('labelTitle', () => { + it('sets label', () => { + wrapper.rerender() + expect(wrapper.container.firstChild).toMatchSnapshot() + }) + }) }) diff --git a/src/Components/Input/__snapshots__/TextInput.spec.tsx.snap b/src/Components/Input/__snapshots__/TextInput.spec.tsx.snap index cd4f09a0..21393baa 100644 --- a/src/Components/Input/__snapshots__/TextInput.spec.tsx.snap +++ b/src/Components/Input/__snapshots__/TextInput.spec.tsx.snap @@ -1,5 +1,28 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[` > labelTitle > sets label 1`] = ` +
+ + +
+`; + exports[` > renders properly 1`] = `