Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Create mock lib for react-leaflet
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb-sti1 committed Sep 14, 2023
1 parent 2b49369 commit 94356b8
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 10 deletions.
7 changes: 6 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"scripts": {
"start": "react-scripts start",
"build": "CI=false react-scripts build",
"test": "react-scripts test",
"test": "CI=true react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
Expand Down Expand Up @@ -62,5 +62,10 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "3.0.3"
},
"jest": {
"moduleNameMapper": {
"react-leaflet": "<rootDir>/src/mocks/reactLeafletMock.tsx"
}
}
}
9 changes: 0 additions & 9 deletions frontend/src/App.test.tsx

This file was deleted.

14 changes: 14 additions & 0 deletions frontend/src/Components/Map/MapWrapper.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import MapWrapper from './MapWrapper';

test('Check subcomponent of mapwrapper', () => {
render(<MapWrapper />);

const names = ['MapContainer', 'TileLayer', 'ScaleControl', 'ZoomControl'];

for (let idx in names) {
const element = screen.getByText(names[idx]);
expect(element).toBeInTheDocument();
}
});
26 changes: 26 additions & 0 deletions frontend/src/Components/Navbar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import Navbar from './Navbar';
import { BrowserRouter as Router } from 'react-router-dom';

function TestRouter() {
return (
<Router>
<Navbar />
</Router>
);
}
test('Check links in navbar', () => {
render(<TestRouter />);
const linkConditionsML = screen.getByText(/Conditions \(ML\)/i);
expect(linkConditionsML).toBeInTheDocument();
expect(
screen.getByRole('link', { name: /Conditions \(ML\)/i }),
).toHaveAttribute('href', '/conditions');

const linkConditionsGP = screen.getByText(/Conditions \(GP\)/i);
expect(linkConditionsGP).toBeInTheDocument();
expect(
screen.getByRole('link', { name: /Conditions \(GP\)/i }),
).toHaveAttribute('href', '/road_conditions');
});
50 changes: 50 additions & 0 deletions frontend/src/mocks/reactLeafletMock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';

function MapContainer(props: any) {
const { children } = props;

return (
<div className={'react-leaflet'}>
<span>MapContainer</span>
<br />
{children}
</div>
);
}

function TileLayer() {
return (
<div className={'react-leaflet'}>
<span>TileLayer</span>
</div>
);
}

function ScaleControl() {
return (
<div className={'react-leaflet'}>
<span>ScaleControl</span>
</div>
);
}
function ZoomControl() {
return (
<div className={'react-leaflet'}>
<span>ZoomControl</span>
</div>
);
}

function useMapEvents() {
return {
getZoom: () => {},
};
}

module.exports = {
MapContainer,
TileLayer,
ScaleControl,
ZoomControl,
useMapEvents,
};

0 comments on commit 94356b8

Please sign in to comment.