From 36069bb43dcf509b8e7e7819396a3a60095b518a Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 24 Feb 2025 19:56:40 +0100 Subject: [PATCH] unit tests for text area input component --- src/Components/Input/TextAreaInput.spec.tsx | 55 +++++++++++++++++++ .../__snapshots__/TextAreaInput.spec.tsx.snap | 34 ++++++++++++ vite.config.ts | 8 +-- 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/Components/Input/TextAreaInput.spec.tsx create mode 100644 src/Components/Input/__snapshots__/TextAreaInput.spec.tsx.snap diff --git a/src/Components/Input/TextAreaInput.spec.tsx b/src/Components/Input/TextAreaInput.spec.tsx new file mode 100644 index 00000000..ab906fb2 --- /dev/null +++ b/src/Components/Input/TextAreaInput.spec.tsx @@ -0,0 +1,55 @@ +import { render, screen, fireEvent } from '@testing-library/react' +import { describe, it, expect, beforeEach, vi } from 'vitest' + +import { TagsProvider } from '#components/Map/hooks/useTags' + +import { TextAreaInput } from './TextAreaInput' + +// import { useTags } from '#components/Map/hooks/useTags' + +// vi.mock('#components/Map/hooks/useTags') + +describe('', () => { + let wrapper: ReturnType + + const updateFormValue = vi.fn() + + beforeEach(() => { + vi.clearAllMocks() + wrapper = render( + + + , + ) + }) + + it('renders properly', () => { + expect(wrapper.container.firstChild).toMatchSnapshot() + }) + + describe('handleChange', () => { + it('calls updateFormValue with new value', () => { + 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__/TextAreaInput.spec.tsx.snap b/src/Components/Input/__snapshots__/TextAreaInput.spec.tsx.snap new file mode 100644 index 00000000..48991cae --- /dev/null +++ b/src/Components/Input/__snapshots__/TextAreaInput.spec.tsx.snap @@ -0,0 +1,34 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > labelTitle > sets label 1`] = ` +
+ +