diff --git a/package.json b/package.json index dd31e6de..84fbc74b 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "license": "MIT", "scripts": { "lint": "npm run lint:css && npm run lint:js", - "lint:css": "stylelint src/*.scss src/**/*.scss shlink-web-component/*.scss shlink-web-component/**/*.scss", - "lint:js": "eslint --ext .js,.ts,.tsx src shlink-web-component test", + "lint:css": "stylelint src/*.scss src/**/*.scss shlink-web-component/*.scss shlink-web-component/**/*.scss shlink-frontend-kit/*.scss shlink-frontend-kit/**/*.scss", + "lint:js": "eslint --ext .js,.ts,.tsx src shlink-web-component shlink-frontend-kit test", "lint:fix": "npm run lint:css:fix && npm run lint:js:fix", "lint:css:fix": "npm run lint:css -- --fix", "lint:js:fix": "npm run lint:js -- --fix", diff --git a/shlink-frontend-kit/src/block/SimpleCard.tsx b/shlink-frontend-kit/src/block/SimpleCard.tsx index 20d85d89..eea80173 100644 --- a/shlink-frontend-kit/src/block/SimpleCard.tsx +++ b/shlink-frontend-kit/src/block/SimpleCard.tsx @@ -2,10 +2,10 @@ import type { ReactNode } from 'react'; import type { CardProps } from 'reactstrap'; import { Card, CardBody, CardHeader } from 'reactstrap'; -interface SimpleCardProps extends Omit { +export type SimpleCardProps = Omit & { title?: ReactNode; bodyClassName?: string; -} +}; export const SimpleCard = ({ title, children, bodyClassName, ...rest }: SimpleCardProps) => ( diff --git a/shlink-frontend-kit/src/form/BooleanControl.tsx b/shlink-frontend-kit/src/form/BooleanControl.tsx index f5f12f4e..1beb4039 100644 --- a/shlink-frontend-kit/src/form/BooleanControl.tsx +++ b/shlink-frontend-kit/src/form/BooleanControl.tsx @@ -10,9 +10,9 @@ export type BooleanControlProps = PropsWithChildren<{ inline?: boolean; }>; -interface BooleanControlWithTypeProps extends BooleanControlProps { +type BooleanControlWithTypeProps = BooleanControlProps & { type: 'switch' | 'checkbox'; -} +}; export const BooleanControl: FC = ( { checked = false, onChange = identity, className, children, type, inline = false }, diff --git a/shlink-frontend-kit/src/form/SearchField.tsx b/shlink-frontend-kit/src/form/SearchField.tsx index 4c8a742b..e1d3a75c 100644 --- a/shlink-frontend-kit/src/form/SearchField.tsx +++ b/shlink-frontend-kit/src/form/SearchField.tsx @@ -7,13 +7,13 @@ import './SearchField.scss'; const DEFAULT_SEARCH_INTERVAL = 500; let timer: NodeJS.Timeout | null; -interface SearchFieldProps { +type SearchFieldProps = { onChange: (value: string) => void; className?: string; large?: boolean; noBorder?: boolean; initialValue?: string; -} +}; export const SearchField = ({ onChange, className, large = true, noBorder = false, initialValue = '' }: SearchFieldProps) => { const [searchTerm, setSearchTerm] = useState(initialValue); diff --git a/shlink-frontend-kit/src/ordering/OrderingDropdown.tsx b/shlink-frontend-kit/src/ordering/OrderingDropdown.tsx index f60b3a05..cd87e22d 100644 --- a/shlink-frontend-kit/src/ordering/OrderingDropdown.tsx +++ b/shlink-frontend-kit/src/ordering/OrderingDropdown.tsx @@ -7,14 +7,14 @@ import type { Order, OrderDir } from './ordering'; import { determineOrderDir } from './ordering'; import './OrderingDropdown.scss'; -export interface OrderingDropdownProps { +export type OrderingDropdownProps = { items: Record; order: Order; onChange: (orderField?: T, orderDir?: OrderDir) => void; isButton?: boolean; right?: boolean; prefixed?: boolean; -} +}; export function OrderingDropdown( { items, order, onChange, isButton = true, right = false, prefixed = true }: OrderingDropdownProps, diff --git a/shlink-frontend-kit/src/ordering/ordering.ts b/shlink-frontend-kit/src/ordering/ordering.ts index 06ac3608..77ac4ffc 100644 --- a/shlink-frontend-kit/src/ordering/ordering.ts +++ b/shlink-frontend-kit/src/ordering/ordering.ts @@ -1,9 +1,9 @@ export type OrderDir = 'ASC' | 'DESC' | undefined; -export interface Order { +export type Order = { field?: Fields; dir?: OrderDir; -} +}; export const determineOrderDir = ( currentField: T, diff --git a/shlink-frontend-kit/test/__helpers__/setUpTest.ts b/shlink-frontend-kit/test/__helpers__/setUpTest.ts new file mode 100644 index 00000000..60b2026c --- /dev/null +++ b/shlink-frontend-kit/test/__helpers__/setUpTest.ts @@ -0,0 +1,8 @@ +import { render } from '@testing-library/react'; +import userEvent from '@testing-library/user-event/index'; +import type { ReactElement } from 'react'; + +export const renderWithEvents = (element: ReactElement) => ({ + user: userEvent.setup(), + ...render(element), +}); diff --git a/test/utils/Message.test.tsx b/shlink-frontend-kit/test/block/Message.test.tsx similarity index 92% rename from test/utils/Message.test.tsx rename to shlink-frontend-kit/test/block/Message.test.tsx index 3b5bb783..101542c8 100644 --- a/test/utils/Message.test.tsx +++ b/shlink-frontend-kit/test/block/Message.test.tsx @@ -1,7 +1,7 @@ import { render, screen } from '@testing-library/react'; import type { PropsWithChildren } from 'react'; -import type { MessageProps } from '../../shlink-frontend-kit/src/block/Message'; -import { Message } from '../../shlink-frontend-kit/src/block/Message'; +import type { MessageProps } from '../../src'; +import { Message } from '../../src'; describe('', () => { const setUp = (props: PropsWithChildren = {}) => render(); diff --git a/test/utils/Result.test.tsx b/shlink-frontend-kit/test/block/Result.test.tsx similarity index 87% rename from test/utils/Result.test.tsx rename to shlink-frontend-kit/test/block/Result.test.tsx index 4ff4d5d5..2747c746 100644 --- a/test/utils/Result.test.tsx +++ b/shlink-frontend-kit/test/block/Result.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from '@testing-library/react'; -import type { ResultProps, ResultType } from '../../shlink-frontend-kit/src/block/Result'; -import { Result } from '../../shlink-frontend-kit/src/block/Result'; +import type { ResultProps, ResultType } from '../../src'; +import { Result } from '../../src'; describe('', () => { const setUp = (props: ResultProps) => render(); diff --git a/test/utils/SimpleCard.test.tsx b/shlink-frontend-kit/test/block/SimpleCard.test.tsx similarity index 62% rename from test/utils/SimpleCard.test.tsx rename to shlink-frontend-kit/test/block/SimpleCard.test.tsx index 9cce1929..1ca051f0 100644 --- a/test/utils/SimpleCard.test.tsx +++ b/shlink-frontend-kit/test/block/SimpleCard.test.tsx @@ -1,24 +1,27 @@ import { render, screen } from '@testing-library/react'; -import { SimpleCard } from '../../shlink-frontend-kit/src/block/SimpleCard'; +import type { SimpleCardProps } from '../../src'; +import { SimpleCard } from '../../src'; + +const setUp = ({ children, ...rest }: SimpleCardProps = {}) => render({children}); describe('', () => { it('does not render title if not provided', () => { - render(); + setUp(); expect(screen.queryByRole('heading')).not.toBeInTheDocument(); }); it('renders provided title', () => { - render(); + setUp({ title: 'Cool title' }); expect(screen.getByRole('heading')).toHaveTextContent('Cool title'); }); it('renders children inside body', () => { - render(Hello world); + setUp({ children: 'Hello world' }); expect(screen.getByText('Hello world')).toBeInTheDocument(); }); it.each(['primary', 'danger', 'warning'])('passes extra props to nested card', (color) => { - const { container } = render(Hello world); + const { container } = setUp({ className: 'foo', color, children: 'Hello world' }); expect(container.firstChild).toHaveAttribute('class', `foo card bg-${color}`); }); }); diff --git a/test/utils/Checkbox.test.tsx b/shlink-frontend-kit/test/form/Checkbox.test.tsx similarity index 95% rename from test/utils/Checkbox.test.tsx rename to shlink-frontend-kit/test/form/Checkbox.test.tsx index 27d1c56c..302d32be 100644 --- a/test/utils/Checkbox.test.tsx +++ b/shlink-frontend-kit/test/form/Checkbox.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '@testing-library/react'; -import { Checkbox } from '../../shlink-frontend-kit/src/form/Checkbox'; +import { Checkbox } from '../../src'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { diff --git a/test/utils/DropdownBtn.test.tsx b/shlink-frontend-kit/test/navigation/DropdownBtn.test.tsx similarity index 90% rename from test/utils/DropdownBtn.test.tsx rename to shlink-frontend-kit/test/navigation/DropdownBtn.test.tsx index 42cb8f82..d51caef5 100644 --- a/test/utils/DropdownBtn.test.tsx +++ b/shlink-frontend-kit/test/navigation/DropdownBtn.test.tsx @@ -1,7 +1,7 @@ import { screen } from '@testing-library/react'; import type { PropsWithChildren } from 'react'; -import type { DropdownBtnProps } from '../../shlink-frontend-kit/src/navigation/DropdownBtn'; -import { DropdownBtn } from '../../shlink-frontend-kit/src/navigation/DropdownBtn'; +import type { DropdownBtnProps } from '../../src'; +import { DropdownBtn } from '../../src'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { diff --git a/test/utils/NavPills.test.tsx b/shlink-frontend-kit/test/navigation/NavPills.test.tsx similarity index 94% rename from test/utils/NavPills.test.tsx rename to shlink-frontend-kit/test/navigation/NavPills.test.tsx index 4718d335..a23b3dcb 100644 --- a/test/utils/NavPills.test.tsx +++ b/shlink-frontend-kit/test/navigation/NavPills.test.tsx @@ -1,7 +1,7 @@ /* eslint-disable no-console */ import { render, screen } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; -import { NavPillItem, NavPills } from '../../shlink-frontend-kit/src/navigation/NavPills'; +import { NavPillItem, NavPills } from '../../src'; describe('', () => { let originalError: typeof console.error; diff --git a/test/utils/RowDropdownBtn.test.tsx b/shlink-frontend-kit/test/navigation/RowDropdownBtn.test.tsx similarity index 81% rename from test/utils/RowDropdownBtn.test.tsx rename to shlink-frontend-kit/test/navigation/RowDropdownBtn.test.tsx index 862f2611..62cd6de9 100644 --- a/test/utils/RowDropdownBtn.test.tsx +++ b/shlink-frontend-kit/test/navigation/RowDropdownBtn.test.tsx @@ -1,7 +1,7 @@ import { screen } from '@testing-library/react'; import { fromPartial } from '@total-typescript/shoehorn'; -import type { DropdownBtnMenuProps } from '../../shlink-frontend-kit/src/navigation/RowDropdownBtn'; -import { RowDropdownBtn } from '../../shlink-frontend-kit/src/navigation/RowDropdownBtn'; +import type { DropdownBtnMenuProps } from '../../src'; +import { RowDropdownBtn } from '../../src'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { diff --git a/test/utils/OrderingDropdown.test.tsx b/shlink-frontend-kit/test/ordering/OrderingDropdown.test.tsx similarity index 93% rename from test/utils/OrderingDropdown.test.tsx rename to shlink-frontend-kit/test/ordering/OrderingDropdown.test.tsx index 79c0b703..9b5aedf2 100644 --- a/test/utils/OrderingDropdown.test.tsx +++ b/shlink-frontend-kit/test/ordering/OrderingDropdown.test.tsx @@ -1,8 +1,7 @@ import { screen } from '@testing-library/react'; import { values } from 'ramda'; -import type { OrderDir } from '../../shlink-frontend-kit/src/ordering/ordering'; -import type { OrderingDropdownProps } from '../../shlink-frontend-kit/src/ordering/OrderingDropdown'; -import { OrderingDropdown } from '../../shlink-frontend-kit/src/ordering/OrderingDropdown'; +import type { OrderDir, OrderingDropdownProps } from '../../src'; +import { OrderingDropdown } from '../../src'; import { renderWithEvents } from '../__helpers__/setUpTest'; describe('', () => { diff --git a/test/utils/helpers/ordering.test.ts b/shlink-frontend-kit/test/ordering/ordering.test.ts similarity index 92% rename from test/utils/helpers/ordering.test.ts rename to shlink-frontend-kit/test/ordering/ordering.test.ts index f1ce3c21..899eb8ae 100644 --- a/test/utils/helpers/ordering.test.ts +++ b/shlink-frontend-kit/test/ordering/ordering.test.ts @@ -1,5 +1,5 @@ -import type { OrderDir } from '../../../shlink-frontend-kit/src/ordering/ordering'; -import { determineOrderDir, orderToString, stringToOrder } from '../../../shlink-frontend-kit/src/ordering/ordering'; +import type { OrderDir } from '../../src'; +import { determineOrderDir, orderToString, stringToOrder } from '../../src'; describe('ordering', () => { describe('determineOrderDir', () => { diff --git a/vite.config.ts b/vite.config.ts index 0dd5f21a..c2b76e1b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -36,6 +36,7 @@ export default defineConfig({ include: [ 'src/**/*.{ts,tsx}', 'shlink-web-component/**/*.{ts,tsx}', + 'shlink-frontend-kit/**/*.{ts,tsx}', '!src/*.{ts,tsx}', '!src/reducers/index.ts', '!src/**/provideServices.ts',