woocommerce/plugins/woocommerce-admin/client/analytics/settings/historical-data/test/utils.js

145 lines
3.2 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import moment from 'moment';
/**
* Internal dependencies
*/
import { formatParams, getStatus } from '../utils';
describe( 'formatParams', () => {
it( 'returns empty object when skipChecked is false and period is all', () => {
expect( formatParams( 'YYYY-MM-DD', { label: 'all' }, false ) ).toEqual(
{}
);
} );
it( 'returns skip_existing param', () => {
expect( formatParams( 'YYYY-MM-DD', { label: 'all' }, true ) ).toEqual(
{
skip_existing: true,
}
);
} );
it( 'returns correct days param based on period label', () => {
expect( formatParams( 'YYYY-MM-DD', { label: '30' }, false ) ).toEqual(
{ days: 30 }
);
} );
it( 'returns correct days param based on period date', () => {
const date = '2018-01-01';
const days = Math.floor(
moment().diff( moment( date, 'YYYY-MM-DD' ), 'days', true )
);
expect(
formatParams( 'YYYY-MM-DD', { label: 'custom', date }, false )
).toEqual( { days } );
} );
it( 'returns both params', () => {
expect( formatParams( 'YYYY-MM-DD', { label: '30' }, true ) ).toEqual( {
skip_existing: true,
days: 30,
} );
} );
} );
describe( 'getStatus', () => {
it( 'returns `initializing` when no progress numbers are defined', () => {
expect(
getStatus( {
customersTotal: 1,
inProgress: true,
ordersTotal: 1,
} )
).toEqual( 'initializing' );
} );
Migrated "import" store to "wp.data" (https://github.com/woocommerce/woocommerce-admin/pull/4982) * Migrated the "import" store to "wp.data" This commit migrates the "import" store to "wp.data" # Conflicts: # client/analytics/settings/historical-data/layout.js # packages/data/src/index.js # Conflicts: # packages/data/src/index.js # Conflicts: # packages/data/src/index.js * Added error handling This commit adds error handling to the apiFetch * Fixred reducer.js * Added reducer.js tests * Removed "endpoint" references * Tests fixed * Removed old import store files and wc-api-spec import references This commit removes old import store files and "wc-api-spec" import references # Conflicts: # client/wc-api/wc-api-spec.js # Conflicts: # client/wc-api/wc-api-spec.js * Added interval to invalidate resolution of getImportStatus * Fixed timestamp * Store dependency removed * Fixed reimport functionality # Conflicts: # client/analytics/settings/historical-data/index.js * Refactored layout.js * Refactored clearCache method * inProgress check refactored * Using activeImport from store # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed console warning # Conflicts: # client/analytics/settings/historical-data/index.js * Migration done! # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed hasImportFinished * Test fixed * Removed "setImportFinished" from actions.js and index.js * Added style to disabled button * Fixed incorrect "Finalizing" status * Fixed tests * Fixed notes update on importation start * Removed local constants * Removed css for disabled button * Typo corrected * Fixed param for getImportError method Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2020-09-01 13:21:31 +00:00
it( 'returns `initializing` when the process is "inProgress" and the cache is not clear', () => {
expect(
getStatus( {
cacheNeedsClearing: true,
customersProgress: 1,
customersTotal: 1,
inProgress: true,
ordersProgress: 1,
ordersTotal: 1,
} )
).toEqual( 'initializing' );
} );
it( 'returns `customers` when importing customers', () => {
expect(
getStatus( {
customersProgress: 0,
customersTotal: 1,
inProgress: true,
ordersProgress: 0,
ordersTotal: 1,
} )
).toEqual( 'customers' );
} );
it( 'returns `orders` when importing orders', () => {
expect(
getStatus( {
customersProgress: 1,
customersTotal: 1,
inProgress: true,
ordersProgress: 0,
ordersTotal: 1,
} )
).toEqual( 'orders' );
} );
it( 'returns `finalizing` when customers and orders are already imported', () => {
expect(
getStatus( {
customersProgress: 1,
customersTotal: 1,
inProgress: true,
ordersProgress: 1,
ordersTotal: 1,
} )
).toEqual( 'finalizing' );
} );
it( 'returns `finished` when customers and orders are already imported and inProgress is false', () => {
expect(
getStatus( {
customersProgress: 1,
customersTotal: 1,
inProgress: false,
ordersProgress: 1,
ordersTotal: 1,
} )
).toEqual( 'finished' );
} );
it( 'returns `ready` when there are customers or orders to import', () => {
expect(
getStatus( {
customersProgress: 0,
customersTotal: 1,
inProgress: false,
ordersProgress: 0,
ordersTotal: 1,
} )
).toEqual( 'ready' );
} );
it( 'returns `nothing` when there are no customers or orders to import', () => {
expect(
getStatus( {
customersProgress: 0,
customersTotal: 0,
inProgress: false,
ordersProgress: 0,
ordersTotal: 0,
} )
).toEqual( 'nothing' );
} );
} );