woocommerce/plugins/woocommerce-admin/tests/js/setup-globals.js

75 lines
1.5 KiB
JavaScript
Raw Normal View History

/** @format */
/**
* External dependencies
*/
import { setLocaleData } from '@wordpress/i18n';
// 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',
];
const wooCommercePackages = [
'components',
'csv',
'currency',
'date',
'navigation',
'number',
];
wordPressPackages.forEach( lib => {
Object.defineProperty( global.wp, lib, {
get: () => require( `@wordpress/${ lib }` ),
} );
} );
wooCommercePackages.forEach( lib => {
Object.defineProperty( global.wc, lib, {
get: () => require( `@woocommerce/${ lib }` ),
} );
} );
global.wcSettings = {
adminUrl: 'https://vagrant.local/wp/wp-admin/',
locale: 'en-US',
currency: { code: 'USD', precision: 2, symbol: '$' },
2018-07-04 01:50:12 +00:00
date: {
dow: 0,
},
2018-10-18 09:34:37 +00:00
orderStatuses: {
2018-11-28 02:58:17 +00:00
pending: 'Pending payment',
processing: 'Processing',
'on-hold': 'On hold',
completed: 'Completed',
cancelled: 'Cancelled',
refunded: 'Refunded',
failed: 'Failed',
2018-10-18 09:34:37 +00:00
},
l10n: {
userLocale: 'en_US',
weekdaysShort: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
},
2019-05-22 21:43:04 +00:00
wcAdminSettings: {
woocommerce_actionable_order_statuses: [],
woocommerce_excluded_report_order_statuses: [],
},
};
2018-05-28 10:55:19 +00:00
const config = require( '../../config/development.json' );
window.wcAdminFeatures = config && config.features ? config.features : {};
setLocaleData( { '': { domain: 'woocommerce-admin', lang: 'en_US' } }, 'woocommerce-admin' );