import * as React from 'react'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { ExpandableSection, ExpandableSectionVariant } from '../ExpandableSection'; import { ExpandableSectionToggle } from '../ExpandableSectionToggle'; const props = { contentId: 'content-id', toggleId: 'toggle-id' }; test('ExpandableSection', () => { const { asFragment } = render(test ); expect(asFragment()).toMatchSnapshot(); }); test('Renders ExpandableSection expanded', () => { const { asFragment } = render( {' '} test{' '} ); expect(asFragment()).toMatchSnapshot(); }); test('ExpandableSection onToggle called', async () => { const mockfn = jest.fn(); const user = userEvent.setup(); render( test ); await user.click(screen.getByRole('button')); expect(mockfn.mock.calls).toHaveLength(1); }); test('Renders Uncontrolled ExpandableSection', () => { const { asFragment } = render( {' '} test{' '} ); expect(asFragment()).toMatchSnapshot(); }); test('Detached ExpandableSection renders successfully', () => { const { asFragment } = render( test Toggle text ); expect(asFragment()).toMatchSnapshot(); }); test('Disclosure ExpandableSection', () => { const { asFragment } = render( test{' '} ); expect(asFragment()).toMatchSnapshot(); }); test('Renders ExpandableSection indented', () => { const { asFragment } = render( {' '} test{' '} ); expect(asFragment()).toMatchSnapshot(); }); test('Does not render with pf-m-truncate class when variant is not passed', () => { render(test); expect(screen.getByText('test').parentElement).not.toHaveClass('pf-m-truncate'); }); test('Does not render with pf-m-truncate class when variant is not truncate', () => { render(test); expect(screen.getByText('test').parentElement).not.toHaveClass('pf-m-truncate'); }); test('Renders with pf-m-truncate class when variant is truncate', () => { render(test); expect(screen.getByText('test').parentElement).toHaveClass('pf-m-truncate'); }); test('Renders with value passed to contentId', () => { render( Test ); const wrapper = screen.getByTestId('test-id'); const content = wrapper.querySelector('#custom-id'); expect(content).toBeInTheDocument(); }); test('Renders with value passed to toggleId', () => { render( Test ); const wrapper = screen.getByTestId('test-id'); const toggle = wrapper.querySelector('#custom-id'); expect(toggle).toBeVisible(); }); test('Renders with ARIA attributes when contentId and toggleId are passed', () => { render( Test ); const wrapper = screen.getByTestId('test-id'); expect(wrapper).toContainHTML('aria-labelledby="toggle-id"'); expect(wrapper).toContainHTML('aria-controls="content-id"'); });