diff --git a/src/Components/Input/ComboBoxInput.spec.tsx b/src/Components/Input/ComboBoxInput.spec.tsx new file mode 100644 index 00000000..86202f4b --- /dev/null +++ b/src/Components/Input/ComboBoxInput.spec.tsx @@ -0,0 +1,32 @@ +import { render, screen, fireEvent } from '@testing-library/react' +import { describe, it, expect, beforeEach, vi } from 'vitest' + +import ComboBoxInput from './ComboBoxInput' + +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('combobox'), { target: { value: 'Option 2' } }) + expect(updateFormValue).toBeCalledWith('Option 2') + }) + }) +}) diff --git a/src/Components/Input/SelectBox.tsx b/src/Components/Input/SelectBox.tsx deleted file mode 100644 index f91ed194..00000000 --- a/src/Components/Input/SelectBox.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import InformationCircleIcon from '@heroicons/react/24/outline/InformationCircleIcon' -import { useState } from 'react' - -interface SelectBoxProps { - labelTitle?: string - labelStyle?: string - type?: string - containerStyle?: string - defaultValue: string - placeholder?: string - - updateFormValue: (value: string) => void - - options: { name: string; value: string }[] - labelDescription?: string -} - -/** - * @category Input - */ -export function SelectBox(props: SelectBoxProps) { - const { - labelTitle, - labelDescription, - defaultValue, - containerStyle, - placeholder, - labelStyle, - options, - updateFormValue, - } = props - - const [value, setValue] = useState(defaultValue || '') - - const updateValue = (newValue: string) => { - updateFormValue(newValue) - setValue(newValue) - } - - return ( - - {labelTitle ? ( - - - {labelTitle} - {labelDescription && ( - - - - )} - - - ) : ( - '' - )} - updateValue(e.target.value)} - > - - {placeholder} - - {options.map((o, k) => { - return ( - - {o.name} - - ) - })} - - - ) -} 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__/ComboBoxInput.spec.tsx.snap b/src/Components/Input/__snapshots__/ComboBoxInput.spec.tsx.snap new file mode 100644 index 00000000..18ef547d --- /dev/null +++ b/src/Components/Input/__snapshots__/ComboBoxInput.spec.tsx.snap @@ -0,0 +1,18 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders properly 1`] = ` + + + Option 1 + + + Option 2 + + +`; 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`] = ` + + + + My Title + + + + +`; + +exports[` > renders properly 1`] = ` + + + +`; diff --git a/src/Components/Input/index.tsx b/src/Components/Input/index.tsx index ecce2b80..2c0c2064 100644 --- a/src/Components/Input/index.tsx +++ b/src/Components/Input/index.tsx @@ -1,3 +1,2 @@ export { TextAreaInput } from './TextAreaInput' export { TextInput } from './TextInput' -export { SelectBox } from './SelectBox' diff --git a/src/Components/Map/Subcomponents/ItemFormPopup.tsx b/src/Components/Map/Subcomponents/ItemFormPopup.tsx index ef191276..5a2ad79d 100644 --- a/src/Components/Map/Subcomponents/ItemFormPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemFormPopup.tsx @@ -53,6 +53,13 @@ export function ItemFormPopup(props: ItemFormPopupProps) { }) formItem.position = { type: 'Point', coordinates: [props.position.lng, props.position.lat] } evt.preventDefault() + + const name = formItem.name ? formItem.name : user?.first_name + if (!name) { + toast.error('Name is must be defined') + return + } + setSpinner(true) formItem.text && @@ -98,8 +105,8 @@ export function ItemFormPopup(props: ItemFormPopupProps) { ;(!props.layer.userProfileLayer || !item) && (await props.layer.api?.createItem!({ ...formItem, + name, id: uuid, - name: formItem.name ? formItem.name : user?.first_name, })) success = true // eslint-disable-next-line no-catch-all/no-catch-all diff --git a/src/Components/Map/UtopiaMapInner.tsx b/src/Components/Map/UtopiaMapInner.tsx index 58bb2b86..927a7865 100644 --- a/src/Components/Map/UtopiaMapInner.tsx +++ b/src/Components/Map/UtopiaMapInner.tsx @@ -32,7 +32,6 @@ import { GratitudeControl } from './Subcomponents/Controls/GratitudeControl' import { LayerControl } from './Subcomponents/Controls/LayerControl' import { SearchControl } from './Subcomponents/Controls/SearchControl' import { TagsControl } from './Subcomponents/Controls/TagsControl' -import { PopupButton } from './Subcomponents/ItemPopupComponents/PopupButton' import { TextView } from './Subcomponents/ItemPopupComponents/TextView' import { SelectPosition } from './Subcomponents/SelectPosition' @@ -80,7 +79,9 @@ export function UtopiaMapInner({ itemId='' rawText={'Support us building free opensource maps and help us grow 🌱☀️'} /> - + + Donate + >, { autoClose: false }, diff --git a/src/Components/Map/hooks/useItems.tsx b/src/Components/Map/hooks/useItems.tsx index bf8779fe..0fb1af78 100644 --- a/src/Components/Map/hooks/useItems.tsx +++ b/src/Components/Map/hooks/useItems.tsx @@ -82,7 +82,6 @@ function useItemsManager(initialItems: Item[]): { }, }) result.map((item) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment dispatch({ type: 'ADD', item: { ...item, layer } }) return null }) diff --git a/src/types/LayerProps.d.ts b/src/types/LayerProps.d.ts index 44f55a95..9c720bc4 100644 --- a/src/types/LayerProps.d.ts +++ b/src/types/LayerProps.d.ts @@ -18,8 +18,7 @@ export interface LayerProps { markerShape: string markerDefaultColor: string markerDefaultColor2?: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - api?: ItemsApi + api?: ItemsApi itemType: ItemType userProfileLayer?: boolean customEditLink?: string diff --git a/vite.config.ts b/vite.config.ts index fd583db2..c4ae05d2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -12,12 +12,12 @@ export default defineConfig({ coverage: { all: true, include: ['src/**/*.{js,jsx,ts,tsx}'], - exclude: [...configDefaults.exclude], + exclude: [...configDefaults.exclude, 'src/**/*.cy.tsx'], thresholds: { - lines: 0, - functions: 61, + lines: 1, + functions: 59, branches: 62, - statements: 0, + statements: 1, }, }, },