diff --git a/src/Components/Input/TextAreaInput.spec.tsx b/src/Components/Input/TextAreaInput.spec.tsx new file mode 100644 index 00000000..0fe0a40f --- /dev/null +++ b/src/Components/Input/TextAreaInput.spec.tsx @@ -0,0 +1,33 @@ +import { render, screen, fireEvent } from '@testing-library/react' +import { describe, it, expect, beforeEach, vi } from 'vitest' + +import { TextAreaInput } from './TextAreaInput' + +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/TextAreaInput.tsx b/src/Components/Input/TextAreaInput.tsx index 05549a36..660b0990 100644 --- a/src/Components/Input/TextAreaInput.tsx +++ b/src/Components/Input/TextAreaInput.tsx @@ -1,7 +1,5 @@ import { useEffect, useRef, useState } from 'react' -import { useTags } from '#components/Map/hooks/useTags' - interface TextAreaProps { labelTitle?: string labelStyle?: string @@ -14,8 +12,6 @@ interface TextAreaProps { updateFormValue?: (value: string) => void } -type KeyValue = Record - /** * @category Input */ @@ -33,14 +29,6 @@ export function TextAreaInput({ const ref = useRef(null) const [inputValue, setInputValue] = useState(defaultValue) - const tags = useTags() - - const values: KeyValue[] = [] - - tags.forEach((tag) => { - values.push({ key: tag.name, value: tag.name, color: tag.color }) - }) - useEffect(() => { setInputValue(defaultValue) }, [defaultValue]) 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`] = ` +
+ +