Skip to content

Commit 9325f8e

Browse files
committed
feat: add tests for MarkerMap component and update package.json for testing dependencies
1 parent a9c4eb7 commit 9325f8e

File tree

6 files changed

+210
-19
lines changed

6 files changed

+210
-19
lines changed

bun.lock

Lines changed: 127 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"preview": "bunx vite preview",
2525
"release": "bun run build && bun publish --access example/public",
2626
"version": "bunx standard-version",
27-
"prepare": "husky"
27+
"prepare": "husky",
28+
"test": "bun test --preload ./test/setup.ts",
29+
"test:watch": "bun test --watch --preload ./test/setup.ts"
2830
},
2931
"files": [
3032
"dist"
@@ -42,13 +44,18 @@
4244
"react-map-gl": "7.0.20"
4345
},
4446
"devDependencies": {
47+
"@testing-library/jest-dom": "^6.9.1",
48+
"@testing-library/react": "^16.3.0",
4549
"@tracktor/biome-config-react": "^1.3.0",
50+
"@types/jsdom": "^27.0.0",
4651
"@types/mapbox-gl": "^3.4.1",
4752
"@types/node": "^22.14.0",
4853
"@types/react": "^19.0.0",
4954
"@types/react-dom": "^19.0.0",
5055
"@vitejs/plugin-react": "^4.6.0",
56+
"bun-types": "^1.3.1",
5157
"husky": "^9.1.7",
58+
"jsdom": "^27.0.1",
5259
"prism-react-renderer": "^2.4.1",
5360
"react": "^19.0.0",
5461
"react-dom": "^19.0.0",

src/Features/MarkerMap/MarkerMap.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ const MarkerMap = ({
7171
});
7272

7373
return (
74-
<Box sx={{ height, position: "relative", width, ...containerStyle }}>
74+
<Box data-testid="mapbox-container" sx={{ height, position: "relative", width, ...containerStyle }}>
7575
<GlobalStyles styles={mapboxGlobalStyles} />
7676

7777
{loading && (
7878
<Skeleton
79+
data-testid="skeleton-loader"
7980
width={width}
8081
height={height}
8182
variant={square ? "rectangular" : "rounded"}

test/MarkerMap.test.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { render, screen } from "@testing-library/react";
2+
import { describe, test, expect, mock } from "bun:test";
3+
import MarkerMap from "@/Features/MarkerMap/MarkerMap";
4+
5+
mock.module("react-map-gl", () => ({
6+
__esModule: true,
7+
// @ts-ignore
8+
default: ({ children, ...props }) => (
9+
<div data-testid={props["data-testid"]}>{children}</div>
10+
),
11+
// @ts-ignore
12+
Marker: ({ children }) => <div>{children}</div>,
13+
// @ts-ignore
14+
Popup: ({ children }) => <div>{children}</div>,
15+
// @ts-ignore
16+
Source: ({ children }) => <div>{children}</div>,
17+
// @ts-ignore
18+
Layer: ({ children }) => <div>{children}</div>,
19+
}));
20+
21+
// 🧭 Mock du hook MarkerMap pour éviter la logique mapbox
22+
mock.module("@/Features/MarkerMap/useMarkerMap", () => ({
23+
default: () => ({
24+
selectedMarker: null,
25+
setSelected: mock(),
26+
handleMarkerClick: mock(),
27+
handleMarkerHover: mock(),
28+
handleMapLoad: mock(),
29+
mapRef: { current: null },
30+
dblZoom: true,
31+
initialCenter: { latitude: 48.8566, longitude: 2.3522, zoom: 5 },
32+
coreStyle: "mapbox://styles/mapbox/streets-v11",
33+
coopGestures: true,
34+
route: null,
35+
}),
36+
}));
37+
38+
describe("🗺️ MarkerMap", () => {
39+
test("rend sans crash", () => {
40+
render(<MarkerMap onMapClick={() => {}} />);
41+
// @ts-ignore
42+
expect(screen.getByTestId("mapbox-container")).toBeInTheDocument();
43+
});
44+
});

test/setup.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import "@testing-library/jest-dom";
2+
import { JSDOM } from "jsdom";
3+
4+
const dom = new JSDOM("<!doctype html><html><body></body></html>", {
5+
url: "http://localhost/",
6+
});
7+
8+
globalThis.window = dom.window as any;
9+
globalThis.document = dom.window.document;
10+
globalThis.navigator = dom.window.navigator;
11+
12+
Object.assign(globalThis, {
13+
HTMLElement: dom.window.HTMLElement,
14+
CustomEvent: dom.window.CustomEvent,
15+
});
16+
17+
globalThis.ResizeObserver = class {
18+
observe() {}
19+
unobserve() {}
20+
disconnect() {}
21+
};

tsconfig.json

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"lib": ["ESNext", "DOM", "DOM.Iterable"],
77
"module": "ESNext",
88
"skipLibCheck": true,
9-
109
"moduleResolution": "Node",
1110
"resolveJsonModule": true,
1211
"isolatedModules": true,
@@ -15,33 +14,27 @@
1514
"noEmit": true,
1615
"jsx": "react-jsx",
1716
"esModuleInterop": true,
18-
19-
/* Linting */
2017
"strict": true,
2118
"noUnusedLocals": true,
2219
"noUnusedParameters": true,
2320
"noFallthroughCasesInSwitch": true,
2421
"noUncheckedSideEffectImports": true,
25-
22+
"types": ["bun-types", "@testing-library/jest-dom"],
2623
"paths": {
27-
"@/*": [
28-
"src/*"
29-
],
30-
"example/*": [
31-
"example/*"
32-
],
33-
"~/*": [
34-
"./*"
35-
]
24+
"@/*": ["src/*"],
25+
"example/*": ["example/*"],
26+
"~/*": ["./*"]
3627
},
3728
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.tsbuildinfo"
3829
},
3930
"files": [],
4031
"include": [
4132
"src",
42-
"example"
33+
"example",
34+
"test",
35+
"test/setup.ts"
4336
],
4437
"references": [
4538
{ "path": "./tsconfig.node.json" }
4639
]
47-
}
40+
}

0 commit comments

Comments
 (0)