@wandelbots/wandelbots-js-react-components
Version:
React UI toolkit for building applications on top of the Wandelbots platform
112 lines (105 loc) • 2.61 kB
text/typescript
import "@testing-library/jest-dom"
import { beforeAll, vi } from "vitest"
// Mock ResizeObserver
global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}))
// Mock IntersectionObserver
global.IntersectionObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}))
// Mock matchMedia
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
})
// Mock WebGL context for Three.js
const mockWebGLContext = {
getExtension: vi.fn(),
getParameter: vi.fn(),
createShader: vi.fn(),
shaderSource: vi.fn(),
compileShader: vi.fn(),
createProgram: vi.fn(),
attachShader: vi.fn(),
linkProgram: vi.fn(),
useProgram: vi.fn(),
createBuffer: vi.fn(),
bindBuffer: vi.fn(),
bufferData: vi.fn(),
createTexture: vi.fn(),
bindTexture: vi.fn(),
texImage2D: vi.fn(),
texParameteri: vi.fn(),
generateMipmap: vi.fn(),
viewport: vi.fn(),
clearColor: vi.fn(),
clear: vi.fn(),
drawArrays: vi.fn(),
drawElements: vi.fn(),
enableVertexAttribArray: vi.fn(),
vertexAttribPointer: vi.fn(),
uniform1f: vi.fn(),
uniform2f: vi.fn(),
uniform3f: vi.fn(),
uniform4f: vi.fn(),
uniformMatrix4fv: vi.fn(),
getUniformLocation: vi.fn(),
getAttribLocation: vi.fn(),
enable: vi.fn(),
disable: vi.fn(),
depthFunc: vi.fn(),
blendFunc: vi.fn(),
cullFace: vi.fn(),
frontFace: vi.fn(),
VERTEX_SHADER: 35633,
FRAGMENT_SHADER: 35632,
ARRAY_BUFFER: 34962,
ELEMENT_ARRAY_BUFFER: 34963,
STATIC_DRAW: 35044,
DYNAMIC_DRAW: 35048,
TEXTURE_2D: 3553,
RGBA: 6408,
UNSIGNED_BYTE: 5121,
TEXTURE_MAG_FILTER: 10240,
TEXTURE_MIN_FILTER: 10241,
LINEAR: 9729,
COLOR_BUFFER_BIT: 16384,
DEPTH_BUFFER_BIT: 256,
DEPTH_TEST: 2929,
BLEND: 3042,
SRC_ALPHA: 770,
ONE_MINUS_SRC_ALPHA: 771,
CULL_FACE: 2884,
BACK: 1029,
CCW: 2305,
FLOAT: 5126,
FALSE: 0,
TRUE: 1,
}
HTMLCanvasElement.prototype.getContext = vi
.fn()
.mockImplementation((contextType) => {
if (contextType === "webgl" || contextType === "experimental-webgl") {
return mockWebGLContext
}
return null
})
beforeAll(() => {
// Suppress console errors in tests
vi.spyOn(console, "error").mockImplementation(() => {})
vi.spyOn(console, "warn").mockImplementation(() => {})
})