Skip to content

Commit

Permalink
tests:add ExpandableGroup
Browse files Browse the repository at this point in the history
Signed-off-by: capyq <quentin.capy@rte-france.com>
  • Loading branch information
capyq authored Dec 18, 2024
1 parent 67093c0 commit 9ffb6d4
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/components/expandableGroup/tests/ExpandableGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import { ExpandableGroup } from '../ExpandableGroup';

describe('ExpandableGroup', () => {
it('renders the header correctly', () => {
const headerText = 'Test Header';
render(<ExpandableGroup renderHeader={<div>{headerText}</div>} />);
const headerElement = screen.getByText(headerText);
expect(headerElement).toBeInTheDocument();
});

it('renders the children when expanded', () => {
const childrenText = 'Test Children';
render(
<ExpandableGroup renderHeader={<div>Header</div>}>
<div>{childrenText}</div>
</ExpandableGroup>
);
const childrenElement = screen.getByText(childrenText);
expect(childrenElement).toBeInTheDocument();
});

it('expands and collapses when clicked', async () => {
const user = userEvent.setup();
const headerText = 'Test Header';
const childrenText = 'Test Children';
render(
<ExpandableGroup renderHeader={<div>{headerText}</div>}>
<div>{childrenText}</div>
</ExpandableGroup>
);
const accordionSummary = screen.getByText(headerText);
const childrenTextDiv = screen.getByText(childrenText);
expect(childrenTextDiv).not.toBeVisible();

await user.click(accordionSummary);
expect(childrenTextDiv).toBeVisible();
});
});

0 comments on commit 9ffb6d4

Please sign in to comment.