Skip to content

Commit

Permalink
fix(TreeView): Fix undefined problem (#1587)
Browse files Browse the repository at this point in the history
  • Loading branch information
silvalaura committed Dec 20, 2024
1 parent 6aa5317 commit a65472a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/treeview-undefined4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-magma-dom': patch
---

fix(TreeView): Fix undefined problem
51 changes: 51 additions & 0 deletions packages/react-magma-dom/src/components/TreeView/TreeView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3434,6 +3434,29 @@ describe('TreeView', () => {
expect(getByTestId('item-child2-expand')).toBeInTheDocument();
});

it('when multiple TreeViews are passed as a child and at least one is valid and the other is undefined, the tree item is expandable', () => {
const { getByTestId } = render(
<TreeView>
<TreeItem label="Node 1" itemId="item1" testId="item1">
<TreeItem label="Child 1" itemId="item-child1" testId="item-child1">
{undefined}
</TreeItem>
{undefined}
<TreeItem label="Child 2" itemId="item-child2" testId="item-child2">
<TreeItem
label="Child 2.1"
itemId="item-child2.1"
testId="item-child2.1"
/>
</TreeItem>
</TreeItem>
</TreeView>
);

expect(getByTestId('item1-expand')).toBeInTheDocument();
userEvent.click(getByTestId('item1-expand'));
expect(getByTestId('item-child2-expand')).toBeInTheDocument();
});

it('when a fragment is passed as a child, the tree item is not expandable', () => {
const { queryByTestId } = render(
Expand Down Expand Up @@ -3477,6 +3500,34 @@ describe('TreeView', () => {
expect(queryByTestId('item1-expand')).not.toBeInTheDocument();
});

it('when undefined is passed as a child, the tree item is not expandable', () => {
const { queryByTestId } = render(
<TreeView>
<TreeItem label="Node 1" itemId="item1" testId="item1">
{undefined}
</TreeItem>
<TreeItem label="Node 2" itemId="item2" testId="item2"></TreeItem>
</TreeView>
);

expect(queryByTestId('item1-expand')).not.toBeInTheDocument();
expect(queryByTestId('item2-expand')).not.toBeInTheDocument();
});

it('when null is passed as a child, the tree item is not expandable', () => {
const { queryByTestId } = render(
<TreeView>
<TreeItem label="Node 1" itemId="item1" testId="item1">
{null}
</TreeItem>
<TreeItem label="Node 2" itemId="item2" testId="item2"></TreeItem>
</TreeView>
);

expect(queryByTestId('item1-expand')).not.toBeInTheDocument();
expect(queryByTestId('item2-expand')).not.toBeInTheDocument();
});

it('when a TreeView does not have a child, the tree item is not expandable', () => {
const { queryByTestId } = render(
<TreeView>
Expand Down

0 comments on commit a65472a

Please sign in to comment.