Skip to content
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
25 changes: 24 additions & 1 deletion packages/module/src/MultiContentCard/MultiContentCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Ref } from 'react';
import { screen, render } from '@testing-library/react';
import { screen, render, act } from '@testing-library/react';
import { Button, Card, CardHeader, CardBody, Content, ContentVariants, Icon, List, ListItem, CardFooter, Dropdown, MenuToggle, DropdownList, DropdownItem, MenuToggleElement } from '@patternfly/react-core';
import { ArrowRightIcon, BellIcon, CogIcon, EllipsisVIcon, LockIcon } from '@patternfly/react-icons';
import MultiContentCard, { MultiContentCardDividerVariant } from './MultiContentCard';
Expand Down Expand Up @@ -126,6 +126,29 @@ describe('MultiContentCard component', () => {
expect(container.firstChild).toMatchSnapshot();
});

it('should call onExpand when expanding the multi-content card', () => {
const onExpand = jest.fn();

render(
<MultiContentCard
isExpandable
defaultExpanded={false}
toggleText='Expandable card toggle text'
cards={cards}
onExpand={onExpand}
/>
);
expect(screen.queryByText('Getting Started')).toBe(null);

act(() => {
screen.getByRole('button', { name: 'Details' }).click();
});

expect(onExpand).toHaveBeenCalled();

expect(screen.getByText('Getting Started')).toBeInTheDocument();
});

it('should render expandable multi-content card - with actions', () => {
const { container } = render(
<MultiContentCard
Expand Down
8 changes: 6 additions & 2 deletions packages/module/src/MultiContentCard/MultiContentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface MultiContentCardProps extends Omit<CardProps, 'children' | 'tit
withDividers?: boolean;
/** Indicates whether the card is expandable */
isExpandable?: boolean;
/** Callback expandable card */
onExpand?: () => void;
/** Indicates whether the card is expanded by default */
defaultExpanded?: boolean;
/** Indicates whether the actions toggle is right aligned */
Expand Down Expand Up @@ -67,13 +69,15 @@ const MultiContentCard: FunctionComponent<MultiContentCardProps> = ({
withDividers = false,
isExpandable = false,
defaultExpanded = true,
onExpand,
ouiaId = 'MultiContentCard',
...props
}: MultiContentCardProps) => {
const [ isExpanded, setIsExpanded ] = useState(defaultExpanded);
const classes = useStyles();
const onExpand = () => {
const onExpandChange = () => {
setIsExpanded(!isExpanded);
onExpand && onExpand();
};

const renderCards = (cards: (ReactElement | MutliContentCardProps)[], withDividers?: boolean) => (
Expand Down Expand Up @@ -105,7 +109,7 @@ const MultiContentCard: FunctionComponent<MultiContentCardProps> = ({
{isExpandable && (
<CardHeader
data-ouia-component-id={`${ouiaId}-header`}
onExpand={onExpand}
onExpand={onExpandChange}
isToggleRightAligned={isToggleRightAligned}
toggleButtonProps={{
'aria-label': 'Details',
Expand Down
Loading
Loading