woocommerce/packages/js/js-tests/src/setup-globals.js

132 lines
2.6 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { setLocaleData } from '@wordpress/i18n';
import { registerStore } from '@wordpress/data';
import 'regenerator-runtime/runtime';
// Set up `wp.*` aliases. Doing this because any tests importing wp stuff will
// likely run into this.
global.wp = {
shortcode: {
next() {},
regexp: jest.fn().mockReturnValue( new RegExp() ),
},
};
global.wc = {};
const wordPressPackages = [ 'element', 'date', 'data' ];
const wooCommercePackages = [
'components',
'csv',
'currency',
'date',
'navigation',
'number',
'data',
];
global.wcTracks = {
isEnabled: false,
};
// aliases
global.wcSettings = {
adminUrl: 'https://vagrant.local/wp/wp-admin/',
countries: [],
currency: {
code: 'USD',
precision: 2,
symbol: '$',
symbolPosition: 'left',
decimalSeparator: '.',
priceFormat: '%1$s%2$s',
thousandSeparator: ',',
},
defaultDateRange: 'period=month&compare=previous_year',
2018-07-04 01:50:12 +00:00
date: {
dow: 0,
},
locale: {
siteLocale: 'en_US',
userLocale: 'en_US',
weekdaysShort: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
},
admin: {
orderStatuses: {
pending: 'Pending payment',
processing: 'Processing',
'on-hold': 'On hold',
completed: 'Completed',
cancelled: 'Cancelled',
refunded: 'Refunded',
failed: 'Failed',
},
wcAdminSettings: {
woocommerce_actionable_order_statuses: [],
woocommerce_excluded_report_order_statuses: [],
},
dataEndpoints: {
performanceIndicators: [
{
chart: 'total_sales',
label: 'Total sales',
stat: 'revenue/total_sales',
},
{
chart: 'net_revenue',
label: 'Net sales',
stat: 'revenue/net_revenue',
},
{
chart: 'orders_count',
label: 'Orders',
stat: 'orders/orders_count',
},
{
chart: 'items_sold',
label: 'Items sold',
stat: 'products/items_sold',
},
],
},
},
};
2018-05-28 10:55:19 +00:00
wordPressPackages.forEach( ( lib ) => {
Object.defineProperty( global.wp, lib, {
get: () => require( `@wordpress/${ lib }` ),
} );
} );
wooCommercePackages.forEach( ( lib ) => {
Object.defineProperty( global.wc, lib, {
get: () => require( `@woocommerce/${ lib }` ),
} );
} );
2022-03-21 10:28:05 +00:00
const config = require( '../../../../plugins/woocommerce-admin/config/development.json' );
// Check if test is jsdom or node
if ( global.window ) {
window.wcAdminFeatures = config && config.features ? config.features : {};
}
setLocaleData(
{ '': { domain: 'woocommerce-admin', lang: 'en_US' } },
'woocommerce-admin'
);
// Mock core/notices store for components dispatching core notices
registerStore( 'core/notices', {
reducer: () => {
return {};
},
actions: {
createNotice: () => {},
},
selectors: {},
} );