2023-10-23 07:13:17 -05:00
|
|
|
import '@testing-library/jest-dom';
|
2024-07-03 05:47:29 -05:00
|
|
|
const { TextEncoder, TextDecoder } = require('util');
|
2023-10-23 07:13:17 -05:00
|
|
|
|
|
|
|
class BroadcastChannelMock {
|
2023-10-26 01:36:28 -05:00
|
|
|
onmessage() {/* mock */}
|
2023-10-23 07:13:17 -05:00
|
|
|
postMessage(data) {
|
|
|
|
this.onmessage({ data });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
global.BroadcastChannel = BroadcastChannelMock;
|
|
|
|
|
|
|
|
global.__webpack_public_path__ = '';
|
|
|
|
|
|
|
|
global.matchMedia = (query)=>({
|
|
|
|
matches: false,
|
|
|
|
media: query,
|
|
|
|
onchange: null,
|
|
|
|
addListener: jest.fn(), // deprecated
|
|
|
|
removeListener: jest.fn(), // deprecated
|
|
|
|
addEventListener: jest.fn(),
|
|
|
|
removeEventListener: jest.fn(),
|
|
|
|
dispatchEvent: jest.fn(),
|
|
|
|
});
|
|
|
|
|
2024-05-20 00:11:55 -05:00
|
|
|
class GeneralObserver {
|
2023-10-23 07:13:17 -05:00
|
|
|
observe() {return null;}
|
|
|
|
unobserve() {return null;}
|
|
|
|
disconnect() {return null;}
|
|
|
|
}
|
|
|
|
|
2024-05-20 00:11:55 -05:00
|
|
|
global.IntersectionObserver = GeneralObserver;
|
|
|
|
global.ResizeObserver = GeneralObserver;
|
2023-10-23 07:13:17 -05:00
|
|
|
|
|
|
|
import lodash from 'lodash';
|
|
|
|
global._ = lodash;
|
|
|
|
|
|
|
|
|
|
|
|
// Console error should not be called
|
|
|
|
global.beforeAll(() => {
|
|
|
|
jest.spyOn(console, 'error');
|
|
|
|
});
|
|
|
|
|
|
|
|
global.beforeEach(() => {
|
|
|
|
console.error.mockClear();
|
|
|
|
});
|
|
|
|
|
|
|
|
global.afterEach(() => {
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
expect(console.error).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
window.HTMLElement.prototype.scrollIntoView = function() {};
|
|
|
|
|
2024-02-20 23:45:25 -06:00
|
|
|
// required for Codemirror 6 to run in jsdom
|
|
|
|
document.createRange = () => {
|
|
|
|
const range = new Range();
|
|
|
|
|
|
|
|
range.getBoundingClientRect = jest.fn();
|
|
|
|
|
|
|
|
range.getClientRects = jest.fn(() => ({
|
|
|
|
item: () => null,
|
|
|
|
length: 0,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return range;
|
|
|
|
};
|
|
|
|
|
2024-06-27 02:51:18 -05:00
|
|
|
// for virtual tables, height should exist.
|
|
|
|
Element.prototype.getBoundingClientRect = jest.fn(function () {
|
|
|
|
if (this.classList?.contains('pgrt')) {
|
|
|
|
return {
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
toJSON: () => {},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
toJSON: () => {},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2024-11-14 02:46:38 -06:00
|
|
|
Object.defineProperty(global.SVGElement.prototype, 'getBBox', {
|
|
|
|
writable: true,
|
|
|
|
value: jest.fn().mockReturnValue({
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 100,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2024-07-03 05:47:29 -05:00
|
|
|
global.TextEncoder = TextEncoder;
|
|
|
|
global.TextDecoder = TextDecoder;
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2024-04-08 21:51:14 -05:00
|
|
|
jest.setTimeout(18000); // 1 second
|