-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGoogleMap.test.tsx
More file actions
48 lines (40 loc) · 1.51 KB
/
GoogleMap.test.tsx
File metadata and controls
48 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { render } from '@testing-library/react';
import GoogleMap from '@/components/MapComponent/GoogleMap';
type Marker = { id: string; lat: number; lng: number; title: string; icon?: string };
const mockMarkers: Marker[] = [
{ id: '1', lat: 53.1, lng: -0.5, title: 'Test Pin 1' },
{ id: '2', lat: 53.2, lng: -0.6, title: 'Test Pin 2', icon: 'http://example.com/icon.png' },
];
const mockCenter = { lat: 53.1, lng: -0.5 };
beforeEach(() => {
(window as any).google = {
maps: {
Map: jest.fn().mockImplementation(function () {}),
Marker: jest.fn().mockImplementation(function () {
this.setMap = jest.fn();
this.addListener = jest.fn();
}),
InfoWindow: jest.fn().mockImplementation(function () {
this.open = jest.fn();
this.close = jest.fn();
}),
},
};
});
afterEach(() => {
delete (window as any).google;
});
describe('GoogleMap', () => {
it('renders map container', () => {
const { container } = render(<GoogleMap markers={mockMarkers} center={mockCenter} />);
expect(container.querySelector('div')).toBeInTheDocument();
});
it('initialises Google Maps when center provided', () => {
render(<GoogleMap markers={mockMarkers} center={mockCenter} />);
expect((window as any).google.maps.Map).toHaveBeenCalled();
});
it('creates markers using Google Maps API', () => {
render(<GoogleMap markers={mockMarkers} center={mockCenter} />);
expect((window as any).google.maps.Marker).toHaveBeenCalledTimes(mockMarkers.length);
});
});