woocommerce/plugins/woocommerce-admin/client/layout/activity-panel/activity-card/test/index.js

106 lines
2.6 KiB
JavaScript
Raw Normal View History

/** @format */
/**
* External dependencies
*/
import { Button } from '@wordpress/components';
import Gridicon from 'gridicons';
import { shallow } from 'enzyme';
/**
* Internal dependencies
*/
import { ActivityCard } from '../';
import { Gravatar } from '@woocommerce/components';
describe( 'ActivityCard', () => {
test( 'should have correct title', () => {
const card = <ActivityCard title="Inbox message">This card has some content</ActivityCard>;
expect( card.props.title ).toBe( 'Inbox message' );
} );
test( 'should render a basic card', () => {
const card = shallow(
<ActivityCard title="Inbox message">This card has some content</ActivityCard>
);
expect( card ).toMatchSnapshot();
} );
test( 'should render an unread bubble on a card', () => {
const card = shallow(
<ActivityCard title="Inbox message" unread>
This card has some content
</ActivityCard>
);
expect( card ).toMatchSnapshot();
} );
test( 'should render a custom icon on a card', () => {
const card = shallow(
<ActivityCard title="Inbox message" icon={ <Gridicon icon="customize" /> }>
This card has some content
</ActivityCard>
);
expect( card ).toMatchSnapshot();
} );
test( 'should render a gravatar on a card', () => {
const card = shallow(
<ActivityCard title="Inbox message" icon={ <Gravatar user="admin@local.test" /> }>
This card has some content
</ActivityCard>
);
expect( card ).toMatchSnapshot();
} );
test( 'should render a timestamp on a card', () => {
// We're generating this via moment to ensure it's always "3 days ago".
const threeDaysAgo = wp.date
.moment()
.subtract( 3, 'days' )
.format();
const card = shallow(
<ActivityCard title="Inbox message" date={ threeDaysAgo }>
This card has some content
</ActivityCard>
);
expect( card ).toMatchSnapshot();
} );
test( 'should render an action on a card', () => {
const noop = () => {};
const card = shallow(
<ActivityCard
title="Inbox message"
actions={
<Button isDefault onClick={ noop }>
Action
</Button>
}
>
This card has some content
</ActivityCard>
);
expect( card ).toMatchSnapshot();
} );
test( 'should render multiple actions on a card', () => {
const noop = () => {};
const card = shallow(
<ActivityCard
title="Inbox message"
actions={ [
<Button isPrimary onClick={ noop }>
Action 1
</Button>,
<Button isDefault onClick={ noop }>
Action 2
</Button>,
] }
>
This card has some content
</ActivityCard>
);
expect( card ).toMatchSnapshot();
} );
} );