From 8195dee1100733ed9460d4cb276f79f442e68074 Mon Sep 17 00:00:00 2001 From: Sabrina Jodexnis Date: Sat, 11 Mar 2023 18:46:41 +0100 Subject: [PATCH 1/3] fix: typescipt and eslint errors --- src/maps/event/event.ts | 2 +- src/maps/event/mvcobject.ts | 4 +- src/maps/maps/map.ts | 61 ++++++++++++++++++--------- src/street-view/rendering/panorama.ts | 1 + 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/maps/event/event.ts b/src/maps/event/event.ts index edd24191e..e44fcad34 100644 --- a/src/maps/event/event.ts +++ b/src/maps/event/event.ts @@ -18,7 +18,7 @@ export const MapsEventListener: google.maps.MapsEventListener = { remove: jest.fn(), }; -export const event: typeof google.maps.event = { +export const event: google.maps.event = { addDomListener: jest .fn() .mockImplementation( diff --git a/src/maps/event/mvcobject.ts b/src/maps/event/mvcobject.ts index 7c323f1ea..ee9a1ecc0 100644 --- a/src/maps/event/mvcobject.ts +++ b/src/maps/event/mvcobject.ts @@ -20,10 +20,10 @@ import { MapsEventListener } from "./event"; /* eslint-disable @typescript-eslint/no-explicit-any */ export class MVCObject implements google.maps.MVCObject { - public static _mockClasses: typeof MVCObject[] = []; + public static _mockClasses: (typeof MVCObject)[] = []; public static mockInstances: MVCObject[] = []; - public constructor() { + constructor() { const ctor = this.constructor as typeof MVCObject; __registerMockInstance(ctor, this); diff --git a/src/maps/maps/map.ts b/src/maps/maps/map.ts index c2e5ec415..a84ddace2 100644 --- a/src/maps/maps/map.ts +++ b/src/maps/maps/map.ts @@ -16,34 +16,32 @@ import { StreetViewPanorama } from "../../street-view/rendering/panorama"; import { LatLng, LatLngBounds } from "../coordinates/latlng"; +import { MapsEventListener } from "../event/event"; import { MVCObject } from "../event/mvcobject"; export class Map_ extends MVCObject implements google.maps.Map { - public controls: Array>; + public controls: Array>; public data: google.maps.Data; public mapTypes: google.maps.MapTypeRegistry; public overlayMapTypes: google.maps.MVCArray; - constructor(mapDiv: Element | null, opts?: google.maps.MapOptions) { - super(); - this.data = new google.maps.Data(); - this.controls = [ - new google.maps.MVCArray(), // BOTTOM_CENTER - new google.maps.MVCArray(), // BOTTOM_LEFT - new google.maps.MVCArray(), // BOTTOM_RIGHT - new google.maps.MVCArray(), // LEFT_BOTTOM - new google.maps.MVCArray(), // LEFT_CENTER - new google.maps.MVCArray(), // LEFT_TOP - new google.maps.MVCArray(), // RIGHT_BOTTOM - new google.maps.MVCArray(), // RIGHT_CENTER - new google.maps.MVCArray(), // RIGHT_TOP - new google.maps.MVCArray(), // TOP_CENTER - new google.maps.MVCArray(), // TOP_LEFT - new google.maps.MVCArray(), // TOP_RIGHT - ]; - this.mapTypes = new google.maps.MVCObject(); - this.overlayMapTypes = new google.maps.MVCArray(); - } + public getFeatureLayer = jest.fn().mockImplementation( + (featureType: google.maps.FeatureType): google.maps.FeatureLayer => + ({ + featureType: {} as google.maps.FeatureType, + isAvailable: true, + addListener: (eventName: string, handler: () => void) => + MapsEventListener, + } satisfies google.maps.FeatureLayer) + ); + + public getMapCapabilities = jest + .fn() + .mockImplementation( + (): google.maps.MapCapabilities => + ({} satisfies google.maps.MapCapabilities) + ); + public fitBounds = jest .fn() .mockImplementation( @@ -146,4 +144,25 @@ export class Map_ extends MVCObject implements google.maps.Map { .mockImplementation((clickable: boolean): void => { return null; }); + + constructor(mapDiv: Element | null, opts?: google.maps.MapOptions) { + super(); + this.data = new google.maps.Data(); + this.controls = [ + new google.maps.MVCArray(), // BOTTOM_CENTER + new google.maps.MVCArray(), // BOTTOM_LEFT + new google.maps.MVCArray(), // BOTTOM_RIGHT + new google.maps.MVCArray(), // LEFT_BOTTOM + new google.maps.MVCArray(), // LEFT_CENTER + new google.maps.MVCArray(), // LEFT_TOP + new google.maps.MVCArray(), // RIGHT_BOTTOM + new google.maps.MVCArray(), // RIGHT_CENTER + new google.maps.MVCArray(), // RIGHT_TOP + new google.maps.MVCArray(), // TOP_CENTER + new google.maps.MVCArray(), // TOP_LEFT + new google.maps.MVCArray(), // TOP_RIGHT + ]; + this.mapTypes = new google.maps.MVCObject(); + this.overlayMapTypes = new google.maps.MVCArray(); + } } diff --git a/src/street-view/rendering/panorama.ts b/src/street-view/rendering/panorama.ts index 2781f7353..d233887f0 100644 --- a/src/street-view/rendering/panorama.ts +++ b/src/street-view/rendering/panorama.ts @@ -22,6 +22,7 @@ export class StreetViewPanorama extends MVCObject implements google.maps.StreetViewPanorama { + public focus = jest.fn().mockImplementation((): void => {}); public controls: MVCArray[] = []; public getLinks = jest .fn() From 1a335bd929834c7d403de2b08f3a3e91962b4305 Mon Sep 17 00:00:00 2001 From: Sabrina Jodexnis Date: Thu, 23 Mar 2023 18:45:50 +0100 Subject: [PATCH 2/3] style(map): remove whitespace --- src/maps/maps/map.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/maps/maps/map.ts b/src/maps/maps/map.ts index 012a325c2..f4ddf1a6f 100644 --- a/src/maps/maps/map.ts +++ b/src/maps/maps/map.ts @@ -29,14 +29,14 @@ export class Map_ extends MVCObject implements google.maps.Map { public getFeatureLayer = jest.fn( (featureType: google.maps.FeatureType) => new FeatureLayer() ); - + public getMapCapabilities = jest.fn(() => { return { isAdvancedMarkersAvailable: false, isDataDrivenStylingAvailable: false, }; }); - + public fitBounds = jest .fn() .mockImplementation( From 061b468b40bea57f67e0e408f125baea2a4a337e Mon Sep 17 00:00:00 2001 From: Sabrina Jodexnis Date: Thu, 23 Mar 2023 18:47:38 +0100 Subject: [PATCH 3/3] fix(panorama): remove double implementation of focus --- src/street-view/rendering/panorama.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/street-view/rendering/panorama.ts b/src/street-view/rendering/panorama.ts index fd13ddbce..d233887f0 100644 --- a/src/street-view/rendering/panorama.ts +++ b/src/street-view/rendering/panorama.ts @@ -94,5 +94,4 @@ export class StreetViewPanorama .fn() .mockImplementation((flag: boolean): void => null); public setZoom = jest.fn().mockImplementation((zoom: number): void => null); - public focus = jest.fn(); }