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

111 lines
2.8 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { Button } from '@wordpress/components';
import CustomizeIcon from 'gridicons/dist/customize';
2018-12-18 22:58:05 +00:00
import moment from 'moment';
2020-10-15 12:41:39 +00:00
import { render } from '@testing-library/react';
/**
* Internal dependencies
*/
import { ActivityCard } from '../';
describe( 'ActivityCard', () => {
test( 'should have correct title', () => {
2020-10-15 12:41:39 +00:00
const { getByRole } = render(
<ActivityCard title="Inbox message">
This card has some content
</ActivityCard>
);
2020-10-15 12:41:39 +00:00
expect(
getByRole( 'heading', { name: 'Inbox message' } )
).toBeInTheDocument();
} );
test( 'should render a basic card', () => {
2020-10-15 12:41:39 +00:00
const { container } = render(
<ActivityCard title="Inbox message">
This card has some content
</ActivityCard>
);
2020-10-15 12:41:39 +00:00
expect( container ).toMatchSnapshot();
} );
test( 'should render an unread bubble on a card', () => {
2020-10-15 12:41:39 +00:00
const { container } = render(
<ActivityCard title="Inbox message" unread>
This card has some content
</ActivityCard>
);
2020-10-15 12:41:39 +00:00
expect( container ).toMatchSnapshot();
} );
test( 'should render a custom icon on a card', () => {
2020-10-15 12:41:39 +00:00
const { container } = render(
<ActivityCard title="Inbox message" icon={ <CustomizeIcon /> }>
This card has some content
</ActivityCard>
);
2020-10-15 12:41:39 +00:00
expect( container ).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 = moment().subtract( 3, 'days' ).format();
2020-10-15 12:41:39 +00:00
const { container } = render(
<ActivityCard title="Inbox message" date={ threeDaysAgo }>
This card has some content
</ActivityCard>
);
2020-10-15 12:41:39 +00:00
expect( container ).toMatchSnapshot();
} );
Migrate Stock Panel to Homescreen (https://github.com/woocommerce/woocommerce-admin/pull/5729) * Refactor low stock variable to be the count instead of a boolean. * Add initial render of the Stock panel on the homescreen. * Move existing Stock panel to homescreen accordion. * Ensure int value for low stock product count. * Update ProductImage styling. * Update stock activity car styles. * Only show 5 low stock products. * Add "undo" action to the stock updated snackbar. * Fix check for explicit notice dismissal when taking actions. * Hide now-in-stock products after updating. By cllearing "edited" flag on successful update. * Fetch more products after updating stock. * Fix the number of product placeholders shown. * Only show products placeholders on the initial fetch. * Fix placeholder style. * Fetch low stock count dynamically. * Let initialOpen prop toggle Accordion panels if they haven't been toggled by the user. * Refactor item total count state. Allows for auto-updating item totals whenever identical queries (from a totals perspective) are issued. * Add last order date to low stock products API response. * Allow non-date strings in ActivityCard date prop. * Add last order date to stock panel cards. * Remove empty stock panel view. * Add test file for StockPanel. * Only request necessary fields from products endpoint. * Add test for products fetch after stock update. * Fix field name. * Add test for last order date in low stock products API response. * Stock panel should be initially closed. * Skip updating a product if the quantity is unchanged.
2020-11-25 18:51:15 +00:00
test( 'supports a non-date "date" prop on a card', () => {
// We should be able to provide any string to the date prop.
const { container } = render(
<ActivityCard title="Inbox message" date="A long, long time ago">
This card has some content
</ActivityCard>
);
expect( container ).toMatchSnapshot();
} );
test( 'should render an action on a card', () => {
const noop = () => {};
2020-10-15 12:41:39 +00:00
const { container } = render(
<ActivityCard
title="Inbox message"
actions={
<Button isSecondary onClick={ noop }>
Action
</Button>
}
>
This card has some content
</ActivityCard>
);
2020-10-15 12:41:39 +00:00
expect( container ).toMatchSnapshot();
} );
test( 'should render multiple actions on a card', () => {
const noop = () => {};
2020-10-15 12:41:39 +00:00
const { container } = render(
<ActivityCard
title="Inbox message"
actions={ [
<Button key="action1" isPrimary onClick={ noop }>
Action 1
</Button>,
<Button key="action2" isSecondary onClick={ noop }>
Action 2
</Button>,
] }
>
This card has some content
</ActivityCard>
);
2020-10-15 12:41:39 +00:00
expect( container ).toMatchSnapshot();
} );
} );