Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

Commit a464cbc

Browse files
committed
fixed tests to succeed
1 parent c207ab2 commit a464cbc

4 files changed

Lines changed: 173 additions & 2 deletions

File tree

frontend/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
"react-app/jest"
3636
]
3737
},
38+
"jest": {
39+
"moduleNameMapper": {
40+
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
41+
}
42+
},
3843
"browserslist": {
3944
"production": [
4045
">0.2%",

frontend/src/_test_/DisclaimerImpressumPrivacy.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import '@testing-library/jest-dom';
44
import { MemoryRouter } from 'react-router-dom';
5-
import { LandingPageLight } from '../pages/light_mode/landing_light';
5+
import { LandingPageLight } from '../pages/home';
66

77
describe('LandingPageLight', () => {
88
test('renders the DisclaimerBox, PrivacyPolicyBox, and ImpressumBox', () => {

frontend/src/_test_/SearchPage.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
33
import { MemoryRouter } from 'react-router-dom';
44
import '@testing-library/jest-dom';
5-
import SearchPageLight from '../pages/light_mode/search_light';
5+
import SearchPageLight from '../pages/search';
66

77
// Mock the global fetch function
88
global.fetch = jest.fn();

frontend/src/setupTests.js

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2+
// allows you to do things like:
3+
// expect(element).toHaveTextContent(/react/i)
4+
// learn more: https://github.com/testing-library/jest-dom
5+
import '@testing-library/jest-dom';
6+
7+
// Mock the ogl library to prevent ES6 module parsing issues
8+
jest.mock('ogl', () => {
9+
const mockGl = {
10+
canvas: { width: 800, height: 600 },
11+
clearColor: jest.fn(),
12+
viewport: jest.fn(),
13+
enable: jest.fn(),
14+
blendFunc: jest.fn(),
15+
POINTS: 0,
16+
createProgram: jest.fn(() => ({
17+
use: jest.fn(),
18+
setUniform: jest.fn(),
19+
})),
20+
createBuffer: jest.fn(() => ({
21+
bind: jest.fn(),
22+
update: jest.fn(),
23+
})),
24+
createVertexArray: jest.fn(() => ({
25+
bind: jest.fn(),
26+
setAttribute: jest.fn(),
27+
})),
28+
};
29+
30+
const mockRenderer = jest.fn().mockImplementation(() => ({
31+
setSize: jest.fn(),
32+
render: jest.fn(),
33+
dispose: jest.fn(),
34+
gl: mockGl,
35+
}));
36+
37+
const mockCamera = jest.fn().mockImplementation(() => ({
38+
position: { set: jest.fn() },
39+
lookAt: jest.fn(),
40+
matrix: { elements: new Array(16).fill(0) },
41+
perspective: jest.fn(),
42+
}));
43+
44+
const mockGeometry = jest.fn().mockImplementation(() => ({
45+
setAttribute: jest.fn(),
46+
setIndex: jest.fn(),
47+
}));
48+
49+
const mockProgram = jest.fn().mockImplementation(() => ({
50+
bind: jest.fn(),
51+
setUniform: jest.fn(),
52+
uniforms: {
53+
uTime: { value: 0 },
54+
uSpread: { value: 1 },
55+
uBaseSize: { value: 1 },
56+
uSizeRandomness: { value: 1 },
57+
uAlphaParticles: { value: 0 },
58+
},
59+
}));
60+
61+
const mockMesh = jest.fn().mockImplementation(() => ({
62+
setParent: jest.fn(),
63+
setProgram: jest.fn(),
64+
setGeometry: jest.fn(),
65+
position: { x: 0, y: 0, z: 0 },
66+
rotation: { x: 0, y: 0, z: 0 },
67+
}));
68+
69+
return {
70+
Renderer: mockRenderer,
71+
Camera: mockCamera,
72+
Geometry: mockGeometry,
73+
Program: mockProgram,
74+
Mesh: mockMesh,
75+
};
76+
});
77+
78+
// Mock window.requestAnimationFrame
79+
global.requestAnimationFrame = jest.fn((callback) => {
80+
setTimeout(callback, 0);
81+
return 1;
82+
});
83+
84+
// Mock window.cancelAnimationFrame
85+
global.cancelAnimationFrame = jest.fn();
86+
87+
// Mock performance.now
88+
global.performance = {
89+
...global.performance,
90+
now: jest.fn(() => Date.now()),
91+
};
92+
93+
// Mock CSS modules - using moduleNameMapper approach instead of jest.mock
94+
95+
// Mock framer-motion to prevent animation-related issues in tests
96+
jest.mock('framer-motion', () => ({
97+
motion: {
98+
div: ({ children, ...props }) => <div {...props}>{children}</div>,
99+
span: ({ children, ...props }) => <span {...props}>{children}</span>,
100+
button: ({ children, ...props }) => <button {...props}>{children}</button>,
101+
},
102+
animate: jest.fn(),
103+
useMotionValue: jest.fn(() => ({ get: jest.fn(), set: jest.fn(), jump: jest.fn() })),
104+
useMotionValueEvent: jest.fn(),
105+
useTransform: jest.fn(() => ({ get: jest.fn() })),
106+
}));
107+
108+
// Mock react-simple-maps
109+
jest.mock('react-simple-maps', () => ({
110+
ComposableMap: ({ children }) => <div data-testid="composable-map">{children}</div>,
111+
Geographies: ({ children }) => <div data-testid="geographies">{children}</div>,
112+
Geography: ({ children }) => <div data-testid="geography">{children}</div>,
113+
ZoomableGroup: ({ children }) => <div data-testid="zoomable-group">{children}</div>,
114+
Marker: ({ children }) => <div data-testid="marker">{children}</div>,
115+
}));
116+
117+
// Mock react-force-graph
118+
jest.mock('react-force-graph', () => {
119+
return function MockForceGraph() {
120+
return <div data-testid="force-graph" />;
121+
};
122+
});
123+
124+
jest.mock('react-force-graph-2d', () => {
125+
return function MockForceGraph2D() {
126+
return <div data-testid="force-graph-2d" />;
127+
};
128+
});
129+
130+
// Mock recharts
131+
jest.mock('recharts', () => ({
132+
LineChart: ({ children }) => <div data-testid="line-chart">{children}</div>,
133+
Line: ({ children }) => <div data-testid="line">{children}</div>,
134+
XAxis: ({ children }) => <div data-testid="x-axis">{children}</div>,
135+
YAxis: ({ children }) => <div data-testid="y-axis">{children}</div>,
136+
CartesianGrid: ({ children }) => <div data-testid="cartesian-grid">{children}</div>,
137+
Tooltip: ({ children }) => <div data-testid="tooltip">{children}</div>,
138+
ResponsiveContainer: ({ children }) => <div data-testid="responsive-container">{children}</div>,
139+
BarChart: ({ children }) => <div data-testid="bar-chart">{children}</div>,
140+
Bar: ({ children }) => <div data-testid="bar">{children}</div>,
141+
PieChart: ({ children }) => <div data-testid="pie-chart">{children}</div>,
142+
Pie: ({ children }) => <div data-testid="pie">{children}</div>,
143+
Cell: ({ children }) => <div data-testid="cell">{children}</div>,
144+
}));
145+
146+
// Mock tsparticles
147+
jest.mock('tsparticles', () => ({
148+
loadFull: jest.fn(),
149+
}));
150+
151+
// Mock react-datepicker
152+
jest.mock('react-datepicker', () => {
153+
return function MockDatePicker(props) {
154+
return <input data-testid="datepicker" {...props} />;
155+
};
156+
});
157+
158+
// Mock the Particles component specifically to avoid WebGL issues
159+
jest.mock('./components/animated/SearchBackground/Particles', () => {
160+
return function MockParticles(props) {
161+
return <div data-testid="particles" {...props} />;
162+
};
163+
});
164+
165+
// Mock Float32Array and other WebGL-related constructors
166+
global.Float32Array = Float32Array;

0 commit comments

Comments
 (0)