2018-08-29 15:55:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-10-15 12:41:39 +00:00
|
|
|
import { render } from '@testing-library/react';
|
2020-04-02 21:54:38 +00:00
|
|
|
import { numberFormat } from '@woocommerce/number';
|
2020-06-17 23:33:40 +00:00
|
|
|
import CurrencyFactory from '@woocommerce/currency';
|
2020-08-13 02:05:22 +00:00
|
|
|
import { CURRENCY } from '@woocommerce/wc-admin-settings';
|
2018-10-30 18:57:48 +00:00
|
|
|
|
2018-08-29 15:55:56 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-04-11 02:53:05 +00:00
|
|
|
import { Leaderboard } from '../';
|
2020-02-14 02:23:21 +00:00
|
|
|
import mockData from '../data/top-selling-products-mock-data';
|
2020-04-02 21:54:38 +00:00
|
|
|
|
2020-06-17 23:33:40 +00:00
|
|
|
const { formatAmount, formatDecimal } = CurrencyFactory( CURRENCY );
|
2018-08-29 15:55:56 +00:00
|
|
|
|
2018-12-31 06:42:46 +00:00
|
|
|
describe( 'Leaderboard', () => {
|
2018-09-12 12:09:53 +00:00
|
|
|
test( 'should render empty message when there are no rows', () => {
|
2020-10-15 12:41:39 +00:00
|
|
|
const { container } = render(
|
2020-02-14 02:23:21 +00:00
|
|
|
<Leaderboard
|
|
|
|
id="products"
|
|
|
|
title={ '' }
|
|
|
|
headers={ [] }
|
|
|
|
rows={ [] }
|
|
|
|
totalRows={ 5 }
|
|
|
|
/>
|
2018-12-31 06:42:46 +00:00
|
|
|
);
|
2018-09-12 12:09:53 +00:00
|
|
|
|
2020-10-15 12:41:39 +00:00
|
|
|
expect( container ).toMatchSnapshot();
|
2018-09-12 12:09:53 +00:00
|
|
|
} );
|
|
|
|
|
2018-08-29 15:55:56 +00:00
|
|
|
test( 'should render correct data in the table', () => {
|
2020-10-15 12:41:39 +00:00
|
|
|
const rows = mockData.map( ( row ) => {
|
|
|
|
const {
|
|
|
|
name,
|
|
|
|
items_sold: itemsSold,
|
|
|
|
net_revenue: netRevenue,
|
|
|
|
orders_count: ordersCount,
|
|
|
|
} = row;
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
display: '<a href="#">' + name + '</a>',
|
|
|
|
value: name,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: numberFormat( CURRENCY, itemsSold ),
|
|
|
|
value: itemsSold,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: numberFormat( CURRENCY, ordersCount ),
|
|
|
|
value: ordersCount,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: formatAmount( netRevenue ),
|
|
|
|
value: formatDecimal( netRevenue ),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
} );
|
|
|
|
|
|
|
|
const headers = [
|
|
|
|
{
|
|
|
|
label: 'Name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Items Sold',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Orders',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Net Sales',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const { container } = render(
|
2020-02-14 02:23:21 +00:00
|
|
|
<Leaderboard
|
|
|
|
id="products"
|
|
|
|
title={ '' }
|
|
|
|
headers={ headers }
|
|
|
|
rows={ rows }
|
|
|
|
totalRows={ 5 }
|
|
|
|
/>
|
2018-12-31 06:42:46 +00:00
|
|
|
);
|
2018-08-29 15:55:56 +00:00
|
|
|
|
2020-10-15 12:41:39 +00:00
|
|
|
expect( container ).toMatchSnapshot();
|
2018-08-29 15:55:56 +00:00
|
|
|
} );
|
|
|
|
} );
|