diff --git a/package.json b/package.json index 8a3f1ed944f..371f500ab32 100644 --- a/package.json +++ b/package.json @@ -175,6 +175,7 @@ "postcss-reporter": "6.0.1", "prettier": "2.2.1", "react-hot-loader": "4.8.0", + "react-select-event": "^5.1.0", "react-test-renderer": "16.12.0", "redux-mock-store": "1.5.4", "regexp-replace-loader": "1.0.1", @@ -216,7 +217,6 @@ "@types/react-virtualized-auto-sizer": "1.0.0", "@types/sockjs-client": "^1.1.1", "@types/uuid": "8.3.0", - "@types/hoist-non-react-statics": "3.3.1", "@welldone-software/why-did-you-render": "4.0.6", "abortcontroller-polyfill": "1.4.0", "angular": "1.8.2", diff --git a/packages/grafana-ui/src/components/Forms/Field.test.tsx b/packages/grafana-ui/src/components/Forms/Field.test.tsx new file mode 100644 index 00000000000..970985fa95c --- /dev/null +++ b/packages/grafana-ui/src/components/Forms/Field.test.tsx @@ -0,0 +1,37 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { Input } from '../Input/Input'; +import { Field } from './Field'; +import { Select } from '../Select/Select'; + +describe('Field', () => { + it('renders the label', () => { + render( + + + + ); + + expect(screen.getByText('My label')).toBeInTheDocument(); + }); + + it('renders with the id of its children', () => { + render( + + + + ); + + expect(screen.getByLabelText('My label')).toBeInTheDocument(); + }); + + it('renders with the inputId of its children', () => { + render( + + + + ); + + expect(screen.getByText('My label')).toBeInTheDocument(); + }); + + it('renders with the id of its children', () => { + render( + + + + ); + + expect(screen.getByLabelText('My label')).toBeInTheDocument(); + }); + + it('renders with the inputId of its children', () => { + render( + + ` using its matching label, such as the label assigned with the `inputId` prop. Use the `react-select-event` package to select values from the options. + +```tsx +import { render, screen } from '@testing-library/react'; +import selectEvent from 'react-select-event'; +import { Select } from '@grafana/ui'; + +it('should call onChange', () => { + const onChange = jest.fn(); + + render( + <> + +