woocommerce/plugins/woocommerce-admin/client/analytics/components/leaderboard/test/index.js

86 lines
2.3 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*
* @format
*/
import { mount, shallow } from 'enzyme';
/**
* WooCommerce dependencies
*/
import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency-format';
import { numberFormat } from 'lib/number-format';
/**
* Internal dependencies
*/
import { Leaderboard } from '../';
import mockData from '../__mocks__/top-selling-products-mock-data';
const rows = mockData.map( row => {
const { name, items_sold, net_revenue, orders_count } = row;
return [
{
display: '<a href="#">' + name + '</a>',
value: name,
},
{
display: numberFormat( items_sold ),
value: items_sold,
},
{
display: numberFormat( orders_count ),
value: orders_count,
},
{
display: formatCurrency( net_revenue ),
value: getCurrencyFormatDecimal( net_revenue ),
},
];
} );
const headers = [
{
label: 'Name',
},
{
label: 'Items Sold',
},
{
label: 'Orders',
},
{
Correcting and clarifying analytics terms and calculations (https://github.com/woocommerce/woocommerce-admin/pull/3104) * Relabel Net Revenue to Net Sales, revert previous refund work on Gross revenue and rename to total sales. Update the orer of all the things * Add gross sales calculation to revenue stats endpoint. * Restore coupon_total when updating order stats. * Wire up gross sales to revenue report. * Fix revenue report refunds calculation when there are no refunds. * update net sales labels and cases in order, product and category tables * Subtract refunded shipping and taxes from gross sales. * pluses to minuses to fix the gross revenue and refund totals when refunding * Add gross_sales to revenue stats orderby enum. * Change refund labels to Returns * Remove usage of defunct coupon_total column. * Store refunded amount in stats table. * Rename "gross_total" column to "total_sales". * Net total for refund orders can be used instead of a new column. * Rename gross_revenue to total_sales. * Coalesce coupons total in order stats query. SUM()ing all nulls gives null, not zero. * Use segmentation selections to backfill missing data. Fo when report columns and segmentation columns don't match. * Remove errant gross_sales from expected interval test data. * Fix gross sales tests for revenue/stats. * Move missing segment fills back to their original locations. * Fix remaining tests failing because of gross sales. * Fix db upgrade function rename of gross_total column. * Fix linter errors.
2019-11-22 15:06:14 +00:00
label: 'Net Sales',
},
];
describe( 'Leaderboard', () => {
test( 'should render empty message when there are no rows', () => {
const leaderboard = shallow(
<Leaderboard id="products" title={ '' } headers={ [] } rows={ [] } totalRows={ 5 } />
);
expect( leaderboard.find( 'EmptyTable' ).length ).toBe( 1 );
} );
test( 'should render correct data in the table', () => {
const leaderboard = mount(
<Leaderboard id="products" title={ '' } headers={ headers } rows={ rows } totalRows={ 5 } />
);
const table = leaderboard.find( 'TableCard' );
const firstRow = table.props().rows[ 0 ];
const tableItems = leaderboard.find( '.woocommerce-table__item' );
expect( firstRow[ 0 ].value ).toBe( mockData[ 0 ].name );
expect( firstRow[ 1 ].value ).toBe( mockData[ 0 ].items_sold );
expect( firstRow[ 2 ].value ).toBe( mockData[ 0 ].orders_count );
expect( firstRow[ 3 ].value ).toBe( getCurrencyFormatDecimal( mockData[ 0 ].net_revenue ) );
expect( leaderboard.render().find( '.woocommerce-table__item a' ).length ).toBe( 5 );
expect( tableItems.at( 0 ).text() ).toBe( mockData[ 0 ].name );
expect( tableItems.at( 1 ).text() ).toBe( numberFormat( mockData[ 0 ].items_sold ) );
expect( tableItems.at( 2 ).text() ).toBe( numberFormat( mockData[ 0 ].orders_count ) );
expect( tableItems.at( 3 ).text() ).toBe( formatCurrency( mockData[ 0 ].net_revenue ) );
} );
} );