Skip to content

Commit

Permalink
solve a Sonar Issue (#893)
Browse files Browse the repository at this point in the history
* fix: add missing key prop

* feat: migrate a component

* feat: add unittest
  • Loading branch information
EmmanuelDemey authored Aug 22, 2024
1 parent feec9b6 commit 486a5b4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/packages/components/tree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export const Tree = ({ treeData, canDrag, linkPath }: TreeTypes) => {
canDrop={() => false}
generateNodeProps={(rowInfo) => ({
buttons: [
<Link to={linkPath(rowInfo.node.id)}>{rowInfo.node.label}</Link>,
<Link key={rowInfo.node.id} to={linkPath(rowInfo.node.id)}>
{rowInfo.node.label}
</Link>,
],
})}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import '@testing-library/jest-dom';
import { render, fireEvent } from '@testing-library/react';
import { render, fireEvent, screen } from '@testing-library/react';

import { CollapsiblePanel } from '.';

describe('Collapsible Panel', () => {
it('should display children content', () => {
render(
<CollapsiblePanel id="id" title="title" collapsible={false}>
Children
</CollapsiblePanel>
);
const div = screen.getByText('Children');
expect(div.getAttribute('hidden')).toBeFalsy();
expect(div.getAttribute('aria-labelledby')).toBe('idbutton');
expect(div.id).toBe('idbody');
});
it('should not be collapsible', () => {
const { container } = render(
<CollapsiblePanel id="id" title="title" collapsible={false}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { useState, useCallback } from 'react';
import { useState, useCallback, PropsWithChildren } from 'react';
import { Note } from '@inseefr/wilco';

type CollapsiblePanelTypes = {
id: string;
title: any;
hidden?: boolean;
collapsible?: boolean;
};
export const CollapsiblePanel = ({
id,
title,
children,
hidden: hiddenProps,
collapsible = true,
}) => {
}: Readonly<PropsWithChildren<CollapsiblePanelTypes>>) => {
const [hidden, setHidden] = useState(hiddenProps);
const clickTitleHandler = useCallback(() => {
setHidden(!hidden);
Expand Down

0 comments on commit 486a5b4

Please sign in to comment.