📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
add: test for Select
kruzhambusd27cb2a603d9
diff --git a/src/ui/Select.tsx b/src/ui/Select.tsxindex 1694414cd..29a4a1a37 100644--- a/src/ui/Select.tsx+++ b/src/ui/Select.tsx@@ -1,4 +1,4 @@-import { Fragment, memo } from 'react'+import React, { Fragment, memo } from 'react'import cx from 'clsx'import PropTypes from 'prop-types'import { Listbox, Transition } from '@headlessui/react'diff --git a/src/ui/__test__/Select.test.tsx b/src/ui/__test__/Select.test.tsxnew file mode 100644index 000000000..a50704127--- /dev/null+++ b/src/ui/__test__/Select.test.tsx@@ -0,0 +1,60 @@+/* eslint-disable testing-library/prefer-screen-queries */+/* eslint-disable import/no-extraneous-dependencies */+import React from 'react'+import { fireEvent, render } from '@testing-library/react'+import _forEach from 'lodash/forEach'+import Select from '../Select'++describe('Select', () => {+ const defaultProps: {+ title: string,+ label: string,+ className?: string,+ items: any[],+ id?: string,+ labelExtractor?: (item: any, index: number) => string,+ keyExtractor?: (item: any, index: number) => string,+ iconExtractor?: (item: any, index: number) => JSX.Element | null,+ onSelect: (item: any) => void,+ } = {+ title: 'Select Title',+ label: 'Select',+ items: [],+ onSelect: () => {},+ }++ afterEach(() => {+ jest.resetAllMocks()+ })++ it('should render without errors', () => {+ const { getByText } = render(<Select {...defaultProps} />)+ expect(getByText(defaultProps.label)).toBeInTheDocument()+ })++ it('should render the title when provided', () => {+ const title = 'Select Title'+ const { getByText } = render(<Select {...defaultProps} title={title} />)+ expect(getByText(title)).toBeInTheDocument()+ })++ it('should render the description when provided', () => {+ const description = 'Select description'+ const { getByText } = render(<Select {...defaultProps} label={description} />)+ expect(getByText(description)).toBeInTheDocument()+ })++ it('should render the items when provided', () => {+ const items = ['Item 1', 'Item 2', 'Item 3']+ const { getByText } = render(<Select {...defaultProps} items={items} />)+ fireEvent.click(getByText(defaultProps.title))+ _forEach(items, (item) => {+ expect(getByText(item)).toBeInTheDocument()+ })+ })++ it('snapshot', () => {+ const { container } = render(<Select {...defaultProps} />)+ expect(container).toMatchSnapshot()+ })+})diff --git a/src/ui/__test__/__snapshots__/Select.test.tsx.snap b/src/ui/__test__/__snapshots__/Select.test.tsx.snapnew file mode 100644index 000000000..0699bd754--- /dev/null+++ b/src/ui/__test__/__snapshots__/Select.test.tsx.snap@@ -0,0 +1,49 @@+// Jest Snapshot v1, https://goo.gl/fbAQLP++exports[`Select snapshot 1`] = `+<div>+ <label+ class="block text-sm whitespace-pre-line font-medium text-gray-700 dark:text-gray-100"+ data-headlessui-state=""+ id="headlessui-listbox-label-:rc:"+ >+ Select+ </label>+ <div+ class="mt-1 relative"+ >+ <button+ aria-expanded="false"+ aria-haspopup="listbox"+ aria-labelledby="headlessui-listbox-label-:rc: headlessui-listbox-button-:rd:"+ class="relative w-full bg-white border border-gray-300 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"+ data-headlessui-state=""+ id="headlessui-listbox-button-:rd:"+ type="button"+ >+ <span+ class="block truncate first-letter:capitalize"+ >+ Select Title+ </span>+ <span+ class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none"+ >+ <svg+ aria-hidden="true"+ class="h-5 w-5 text-gray-400"+ fill="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ clip-rule="evenodd"+ d="M11.47 4.72a.75.75 0 011.06 0l3.75 3.75a.75.75 0 01-1.06 1.06L12 6.31 8.78 9.53a.75.75 0 01-1.06-1.06l3.75-3.75zm-3.75 9.75a.75.75 0 011.06 0L12 17.69l3.22-3.22a.75.75 0 111.06 1.06l-3.75 3.75a.75.75 0 01-1.06 0l-3.75-3.75a.75.75 0 010-1.06z"+ fill-rule="evenodd"+ />+ </svg>+ </span>+ </button>+ </div>+</div>+`;