UNPKG

@navinc/base-react-components

Version:
43 lines 2.28 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { describe, expect, it } from 'vitest'; import { screen } from '@testing-library/react'; import { InputWrapper } from './input-wrapper.js'; import { testComponentRef, testComponentCommonStandards } from '@navinc/test-helpers'; import { renderWithContext } from '../../tests/with-app-context.js'; const renderComponent = (props = {}) => (_jsx(InputWrapper, Object.assign({}, props, { children: _jsx("input", {}) }))); describe('<InputWrapper />', () => { testComponentRef(InputWrapper); testComponentCommonStandards(InputWrapper); it('renders empty divs without props', () => { renderWithContext(renderComponent()); expect(screen.queryByTestId('helper-text')).not.toBeInTheDocument(); expect(screen.getByTestId('label')).toHaveTextContent(''); expect(screen.getByRole('textbox')); }); it('renders label, input, and helper text', () => { const label = 'All the potatoes are mine'; const helperText = 'Give me more potatoes'; renderWithContext(renderComponent({ label, helperText })); expect(screen.getByTestId('label')).toHaveTextContent(label); expect(screen.getByTestId('helper-text')).toHaveTextContent(helperText); expect(screen.getByRole('textbox')); }); it('renders label, input, and error text', () => { const label = 'All the potatoes are mine'; const errorText = 'Give me more potatoes'; renderWithContext(renderComponent({ label, errorText })); expect(screen.getByTestId('label')).toHaveTextContent(label); expect(screen.getByTestId('helper-text')).toHaveTextContent(errorText); expect(screen.getByRole('textbox')); }); it('renders error text over helper text', () => { const label = 'All the potatoes are mine'; const helperText = 'Give me more potatoes'; const errorText = 'You need more potatoes'; renderWithContext(renderComponent({ label, errorText, helperText })); expect(screen.getByTestId('label')).toHaveTextContent(label); expect(screen.getByTestId('helper-text')).toHaveTextContent(errorText); expect(screen.getByRole('textbox')); }); }); //# sourceMappingURL=input-wrapper.spec.js.map