Skip to content

Commit f729d60

Browse files
authored
Add test to check that the wrapper around actions only renders when expected
1 parent d23a51d commit f729d60

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/components/MediaCard/tests/MediaCard.test.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Heading, Popover, Button, ActionList, Badge} from 'components';
33
import {mountWithApp} from 'test-utilities';
44

55
import {MediaCard} from '../MediaCard';
6+
import styles from '../MediaCard.scss';
67

78
const mockProps = {
89
children: <img alt="" />,
@@ -48,6 +49,41 @@ describe('<MediaCard>', () => {
4849
expect(videoCard).toContainReactComponent('p', {children: description});
4950
});
5051

52+
it('does not render a wrapper around actions when primaryAction and secondaryAction are empty', () => {
53+
const videoCard = mountWithApp(
54+
<MediaCard
55+
{...mockProps}
56+
primaryAction={undefined}
57+
secondaryAction={undefined}
58+
/>,
59+
);
60+
61+
expect(videoCard).not.toContainReactComponent('div', {
62+
className: expect.stringContaining(styles.ActionContainer),
63+
});
64+
});
65+
66+
it('renders a wrapper around actions when primaryAction and secondaryAction are provided', () => {
67+
const mockAction = {content: 'test'};
68+
const videoCardWithPrimaryAction = mountWithApp(
69+
<MediaCard {...mockProps} primaryAction={mockAction} />,
70+
);
71+
const videoCardWithSecondaryAction = mountWithApp(
72+
<MediaCard
73+
{...mockProps}
74+
primaryAction={undefined}
75+
secondaryAction={mockAction}
76+
/>,
77+
);
78+
79+
expect(videoCardWithPrimaryAction).toContainReactComponent('div', {
80+
className: expect.stringContaining(styles.ActionContainer),
81+
});
82+
expect(videoCardWithSecondaryAction).toContainReactComponent('div', {
83+
className: expect.stringContaining(styles.ActionContainer),
84+
});
85+
});
86+
5187
it('renders a Button with the primaryAction', () => {
5288
const primaryAction = {content: 'test primary action'};
5389
const videoCard = mountWithApp(

0 commit comments

Comments
 (0)