Skip to content

Commit c2e2ad0

Browse files
BiniCodesamuramoto
andauthored
feat: add mock elevation service (#408)
* feat: add mock elevation service * fix(elevation-service): fix typo --------- Co-authored-by: Alex Muramoto <[email protected]>
1 parent 1c770ce commit c2e2ad0

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Autocomplete } from "./places/autocomplete";
2525
import { MaxZoomService } from "./drawing/max-zoom/max-zoom";
2626
import { AutocompleteService } from "./places/autocomplete-service/autocomplete-service";
2727
import { DistanceMatrixService } from "./routes/distance-matrix-service/distance-matrix-service";
28+
import { ElevationService } from "./routes/elevation-service/elevation-service";
2829
import { Circle } from "./drawing/polygons/circle";
2930
import { Data } from "./drawing/data/data";
3031
import { DataPolygon } from "./drawing/data/data.polygon";
@@ -105,6 +106,7 @@ const initialize = function (): void {
105106
MaxZoomService,
106107
DirectionsService,
107108
DistanceMatrixService,
109+
ElevationService,
108110
marker: {
109111
PinView,
110112
AdvancedMarkerView,
@@ -149,6 +151,7 @@ export {
149151
MaxZoomService,
150152
DirectionsService,
151153
DistanceMatrixService,
154+
ElevationService,
152155
AdvancedMarkerView,
153156
PinView,
154157
FeatureLayer,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright 2022 Google LLC. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { ElevationService, initialize, mockInstances } from "../../index";
18+
19+
beforeEach(() => {
20+
initialize();
21+
});
22+
23+
test("elevation service is mocked", async () => {
24+
const service = new google.maps.ElevationService();
25+
26+
expect(await service.getElevationForLocations(null)).toBeTruthy();
27+
expect(await service.getElevationAlongPath(null)).toBeTruthy();
28+
});
29+
30+
test("registers mocks", () => {
31+
const service = new google.maps.ElevationService();
32+
service.getElevationAlongPath(null);
33+
service.getElevationForLocations(null);
34+
35+
const mocks = mockInstances.get(ElevationService);
36+
37+
expect(mocks).toHaveLength(1);
38+
expect(
39+
mockInstances.get(ElevationService)[0].getElevationAlongPath
40+
).toHaveBeenCalledWith(null);
41+
expect(
42+
mockInstances.get(ElevationService)[0].getElevationForLocations
43+
).toHaveBeenCalledWith(null);
44+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright 2022 Google LLC. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/* eslint-disable @typescript-eslint/no-unused-vars */
18+
19+
import { __registerMockInstance } from "../../registry";
20+
21+
export class ElevationService implements google.maps.ElevationService {
22+
public getElevationAlongPath = jest.fn().mockImplementation(
23+
(
24+
request: google.maps.PathElevationRequest,
25+
callback?: (
26+
elevationResults?: Array<google.maps.ElevationResult>,
27+
// @ts-expect-error
28+
elevationStatus: google.maps.ElevationStatus
29+
) => void
30+
): Promise<google.maps.PathElevationResponse> =>
31+
Promise.resolve({
32+
results: [] satisfies Array<google.maps.ElevationResult>,
33+
})
34+
);
35+
36+
public getElevationForLocations = jest.fn().mockImplementation(
37+
(
38+
request: google.maps.LocationElevationRequest,
39+
callback?: (
40+
elevationResults?: Array<google.maps.ElevationResult>,
41+
// @ts-expect-error
42+
elevationStatus: google.maps.ElevationStatus
43+
) => void
44+
): Promise<google.maps.LocationElevationResponse> =>
45+
Promise.resolve({
46+
results: [] satisfies Array<google.maps.ElevationResult>,
47+
})
48+
);
49+
50+
constructor() {
51+
__registerMockInstance(this.constructor, this);
52+
}
53+
}

0 commit comments

Comments
 (0)