2016-06-17 15:48:33 +02:00
|
|
|
/**
|
|
|
|
* Test stubs to mirror available global variables.
|
|
|
|
* Those variables usually come from the back-end via templates.
|
|
|
|
* See /wagtailadmin/templates/wagtailadmin/admin_base.html.
|
|
|
|
*/
|
|
|
|
|
2016-02-26 22:10:54 +01:00
|
|
|
global.wagtailConfig = {
|
2016-06-17 15:48:33 +02:00
|
|
|
ADMIN_API: {
|
2019-11-05 12:39:48 +01:00
|
|
|
DOCUMENTS: '/admin/api/main/documents/',
|
|
|
|
IMAGES: '/admin/api/main/images/',
|
|
|
|
PAGES: '/admin/api/main/pages/',
|
2017-02-12 16:29:56 +01:00
|
|
|
EXTRA_CHILDREN_PARAMETERS: '',
|
2016-06-17 15:48:33 +02:00
|
|
|
},
|
|
|
|
ADMIN_URLS: {
|
|
|
|
PAGES: '/admin/pages/',
|
|
|
|
},
|
2017-02-09 16:52:07 +01:00
|
|
|
DATE_FORMATTING: {
|
|
|
|
DATE_FORMAT: 'MMM. D, YYYY',
|
|
|
|
SHORT_DATE_FORMAT: 'DD/MM/YYYY',
|
|
|
|
},
|
2020-10-22 17:24:41 +02:00
|
|
|
WAGTAIL_I18N_ENABLED: true,
|
|
|
|
LOCALES: [
|
|
|
|
{
|
|
|
|
code: 'en',
|
|
|
|
display_name: 'English',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'fr',
|
|
|
|
display_nam: 'French',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
ACTIVE_LOCALE: 'en',
|
2016-02-26 22:10:54 +01:00
|
|
|
};
|
|
|
|
|
2023-02-14 12:17:30 +01:00
|
|
|
const script = document.createElement('script');
|
|
|
|
script.type = 'application/json';
|
|
|
|
script.id = 'wagtail-config';
|
|
|
|
script.textContent = JSON.stringify({ CSRF_TOKEN: 'potato' });
|
|
|
|
document.body.appendChild(script);
|
2023-01-12 22:55:40 +01:00
|
|
|
|
2016-02-26 22:10:54 +01:00
|
|
|
global.wagtailVersion = '1.6a1';
|
2018-02-02 23:11:21 +01:00
|
|
|
|
2018-04-17 23:27:07 +02:00
|
|
|
global.wagtail = {};
|
|
|
|
|
2018-02-02 23:11:21 +01:00
|
|
|
global.chooserUrls = {
|
|
|
|
documentChooser: '/admin/documents/chooser/',
|
|
|
|
emailLinkChooser: '/admin/choose-email-link/',
|
2019-08-13 18:24:00 +02:00
|
|
|
anchorLinkChooser: '/admin/choose-anchor-link',
|
2018-02-02 23:11:21 +01:00
|
|
|
embedsChooser: '/admin/embeds/chooser/',
|
|
|
|
externalLinkChooser: '/admin/choose-external-link/',
|
|
|
|
imageChooser: '/admin/images/chooser/',
|
|
|
|
pageChooser: '/admin/choose-page/',
|
|
|
|
};
|
|
|
|
|
2018-06-01 23:40:23 +02:00
|
|
|
/* use dummy content for onload handlers just so that we can verify that we've chosen the right one */
|
|
|
|
global.IMAGE_CHOOSER_MODAL_ONLOAD_HANDLERS = { type: 'image' };
|
|
|
|
global.PAGE_CHOOSER_MODAL_ONLOAD_HANDLERS = { type: 'page' };
|
2018-06-04 17:56:36 +02:00
|
|
|
global.EMBED_CHOOSER_MODAL_ONLOAD_HANDLERS = { type: 'embed' };
|
2018-06-04 22:37:37 +02:00
|
|
|
global.DOCUMENT_CHOOSER_MODAL_ONLOAD_HANDLERS = { type: 'document' };
|
2022-12-16 14:28:23 +01:00
|
|
|
|
|
|
|
class PageChooserModal {}
|
|
|
|
global.PageChooserModal = PageChooserModal;
|
2023-06-24 13:29:12 +02:00
|
|
|
|
|
|
|
/** Mock window.scrollTo as not provided via JSDom */
|
|
|
|
window.scrollTo = jest.fn();
|
|
|
|
|
|
|
|
/** Mock console.warn to filter out warnings from React due to Draftail legacy Component API usage.
|
|
|
|
* Draftail/Draft-js is unlikely to support these and the warnings are not useful for unit test output.
|
|
|
|
*/
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
const consoleWarnOriginal = console.warn;
|
|
|
|
console.warn = function filterWarnings(...args) {
|
|
|
|
/* eslint-enable no-console */
|
|
|
|
|
|
|
|
const [warning, component] = args;
|
|
|
|
|
|
|
|
const legacyReactWarnings = [
|
|
|
|
'Warning: componentWillMount has been renamed, and is not recommended for use.',
|
|
|
|
'Warning: componentWillReceiveProps has been renamed, and is not recommended for use.',
|
|
|
|
'Warning: componentWillUpdate has been renamed, and is not recommended for use.',
|
|
|
|
];
|
|
|
|
|
|
|
|
const ignoredComponents = ['DraftEditor', 'PluginEditor'];
|
|
|
|
|
|
|
|
if (
|
|
|
|
legacyReactWarnings.some((_) => warning.includes(_)) &&
|
|
|
|
ignoredComponents.includes(component)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
consoleWarnOriginal.apply(console, args);
|
|
|
|
};
|