UNPKG

@kadconsulting/dry

Version:
58 lines 2.93 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { useEffect, useRef, useState } from 'react'; import { render, screen, waitFor } from '@testing-library/react'; import MultiAccordion from './MultiAccordion'; const sampleFaqs = [ { title: 'FAQ 1', content: 'Content 1' }, { title: 'FAQ 2', content: 'Content 2' }, ]; describe('MultiAccordion', () => { it('renders with a dry-prepended className', () => { const { container } = render(_jsx(MultiAccordion, { faqs: sampleFaqs })); expect(container.firstChild).toHaveClass('dry-multiaccordion'); }); it('passes a ref to its outermost element', async () => { const Wrapper = () => { const ref = useRef(null); const [refWasPassed, setRefWasPassed] = useState(false); useEffect(() => { setRefWasPassed(!!ref.current); }, []); return (_jsxs(_Fragment, { children: [_jsx(MultiAccordion, { ref: ref, faqs: sampleFaqs }), refWasPassed && _jsx("div", { children: "Ref was passed!" })] })); }; render(_jsx(Wrapper, {})); await waitFor(() => screen.getByText('Ref was passed!')); }); it('passes a downstream id', () => { const id = 'test-id'; const testId = 'test-subject'; render(_jsx(MultiAccordion, { "data-testid": testId, id: id, faqs: sampleFaqs })); expect(screen.getByTestId(testId)).toHaveAttribute('id', id); }); it('passes any downstream className(s)', () => { const className = 'first second third'; const testId = 'test-subject'; render(_jsx(MultiAccordion, { "data-testid": testId, className: className, faqs: sampleFaqs })); expect(screen.getByTestId(testId)).toHaveClass('first'); expect(screen.getByTestId(testId)).toHaveClass('second'); expect(screen.getByTestId(testId)).toHaveClass('third'); }); it('passes any downstream inline style(s)', () => { const style = { color: 'red' }; const testId = 'test-subject'; render(_jsx(MultiAccordion, { "data-testid": testId, style: style, faqs: sampleFaqs })); expect(screen.getByTestId(testId)).toHaveStyle('color: red'); }); it('passes any downstream data-* attribute(s)', () => { const testId = 'test-subject'; const testValue = 'product-1234-abcd-5678-efgh'; render(_jsx(MultiAccordion, { "data-testid": testId, "data-product": testValue, faqs: sampleFaqs })); expect(screen.getByTestId(testId)).toHaveAttribute('data-product', testValue); }); it('supports downstream @testing-library `screen.getByTestId`', () => { const testId = 'test-subject'; render(_jsx(MultiAccordion, { "data-testid": testId, faqs: sampleFaqs })); expect(screen.getByTestId(testId)).toBeInTheDocument(); }); }); //# sourceMappingURL=MultiAccordion.test.js.map