Skip to content

Commit

Permalink
test(structured-list): increase coverage (#17705)
Browse files Browse the repository at this point in the history
  • Loading branch information
ariellalgilmore authored Oct 10, 2024
1 parent 8ec84a4 commit 33fd9e7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
StructuredListRow,
StructuredListInput,
StructuredListCell,
} from '@carbon/react';
} from '../StructuredList';
import { CheckmarkFilled } from '@carbon/react/icons';

const prefix = 'cds';
Expand Down Expand Up @@ -71,9 +71,12 @@ const renderComponent = ({ ...rest } = {}) => {
);
};

const structuredListBodyRowGenerator = (numRows, rest) => {
const structuredListBodyRowGenerator = (numRows, rest, selection) => {
return Array.apply(null, Array(numRows)).map((n, i) => (
<StructuredListRow key={`row-${i}`} onKeyDown={onKeyDownHandlerFn}>
<StructuredListRow
key={`row-${i}`}
onKeyDown={onKeyDownHandlerFn}
selection={selection}>
<StructuredListCell>Row {i}</StructuredListCell>
<StructuredListCell>Row {i}, Col 2</StructuredListCell>
<StructuredListCell>
Expand Down Expand Up @@ -102,7 +105,7 @@ const structuredListBodyRowGenerator = (numRows, rest) => {
};

const renderSelectionVariant = ({ ...rest } = {}) => {
const { inputProps, wrapperProps } = rest;
const { inputProps, wrapperProps, rowSelection } = rest;
return render(
<StructuredListWrapper selection {...wrapperProps}>
<StructuredListHead>
Expand All @@ -114,7 +117,7 @@ const renderSelectionVariant = ({ ...rest } = {}) => {
</StructuredListRow>
</StructuredListHead>
<StructuredListBody onKeyDown={onKeyDownBodyHandlerFn}>
{structuredListBodyRowGenerator(4, inputProps)}
{structuredListBodyRowGenerator(4, inputProps, rowSelection)}
</StructuredListBody>
</StructuredListWrapper>
);
Expand Down Expand Up @@ -238,6 +241,12 @@ describe('StructuredList', () => {
await user.keyboard('[ArrowDown]');
expect(onKeyDownHandlerFn).toHaveBeenCalledTimes(3);
});

it('should be able to click on a selected row', async () => {
renderSelectionVariant({ rowSelection: true });

await userEvent.click(screen.getByText('Row 1'));
});
});

describe('StructuredListBody', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import StructuredListSkeleton from '../StructuredList.Skeleton';
import { render } from '@testing-library/react';

describe('StructuredListSkeleton', () => {
it('should support a custom `className` prop on the outermost element', () => {
const { container } = render(<StructuredListSkeleton className="test" />);
expect(container.firstChild).toHaveClass('test');
});

it('should spread additional props on the outermost element', () => {
const { container } = render(<StructuredListSkeleton data-testid="test" />);
expect(container.firstChild).toHaveAttribute('data-testid', 'test');
});
});

0 comments on commit 33fd9e7

Please sign in to comment.