Merge branch 'main' into test-combo-box

This commit is contained in:
Ulf Gebhardt 2025-02-25 20:22:17 +01:00 committed by GitHub
commit 783b4d40a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 81 additions and 20 deletions

View File

@ -40,6 +40,7 @@ export default [
}),
typescript({
tsconfig: './tsconfig.json',
noEmitOnError: true,
}),
svg({ base64: true }),
],

View File

@ -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('<TextAreaInput />', () => {
let wrapper: ReturnType<typeof render>
const updateFormValue = vi.fn()
beforeEach(() => {
vi.clearAllMocks()
wrapper = render(<TextAreaInput defaultValue={''} updateFormValue={updateFormValue} />)
})
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(<TextAreaInput defaultValue={''} labelTitle='My Title' />)
expect(wrapper.container.firstChild).toMatchSnapshot()
})
})
})

View File

@ -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<string, string>
/**
* @category Input
*/
@ -33,14 +29,6 @@ export function TextAreaInput({
const ref = useRef<HTMLTextAreaElement>(null)
const [inputValue, setInputValue] = useState<string>(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])

View File

@ -0,0 +1,34 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`<TextAreaInput /> > labelTitle > sets label 1`] = `
<div
class="tw-form-control tw-w-full "
>
<label
class="tw-label"
>
<span
class="tw-label-text tw-text-base-content "
>
My Title
</span>
</label>
<textarea
class="tw-textarea tw-textarea-bordered tw-w-full tw-leading-5 "
placeholder=""
required=""
/>
</div>
`;
exports[`<TextAreaInput /> > renders properly 1`] = `
<div
class="tw-form-control tw-w-full "
>
<textarea
class="tw-textarea tw-textarea-bordered tw-w-full tw-leading-5 "
placeholder=""
required=""
/>
</div>
`;

View File

@ -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

View File

@ -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
})

View File

@ -18,8 +18,7 @@ export interface LayerProps {
markerShape: string
markerDefaultColor: string
markerDefaultColor2?: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
api?: ItemsApi<any>
api?: ItemsApi<Item>
itemType: ItemType
userProfileLayer?: boolean
customEditLink?: string

View File

@ -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,
},
},
},