Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(structured-list): increase coverage #17705

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});
Loading