Skip to content

Commit 509b96d

Browse files
committed
Fix failing map component tests
1 parent b94ed81 commit 509b96d

File tree

3 files changed

+25
-50
lines changed

3 files changed

+25
-50
lines changed

web/pretest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
echo "Running 'pretest.sh' script to download Google Maps API for testing..."
1717
rm google-maps-api.js
1818
date +"// Download time: %Y-%m-%d %H:%M" >> google-maps-api.js
19-
curl 'https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry' >> google-maps-api.js
19+
curl 'https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,marker' >> google-maps-api.js
2020
echo "'pretest.sh' finished"

web/src/app/pages/main-page-container/main-page/map/map.component.spec.ts

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,12 @@ import {MultiPolygon} from 'app/models/geometry/multi-polygon';
3232
import {Point} from 'app/models/geometry/point';
3333
import {Job} from 'app/models/job.model';
3434
import {LocationOfInterest} from 'app/models/loi.model';
35-
import {Submission} from 'app/models/submission/submission.model';
3635
import {DataSharingType, Survey} from 'app/models/survey.model';
3736
import {AuthService} from 'app/services/auth/auth.service';
3837
import {
3938
DrawingToolsService,
4039
EditMode,
4140
} from 'app/services/drawing-tools/drawing-tools.service';
42-
import {GroundPinService} from 'app/services/ground-pin/ground-pin.service';
43-
import {LoadingState} from 'app/services/loading-state.model';
4441
import {LocationOfInterestService} from 'app/services/loi/loi.service';
4542
import {NavigationService} from 'app/services/navigation/navigation.service';
4643
import {SubmissionService} from 'app/services/submission/submission.service';
@@ -56,6 +53,7 @@ describe('MapComponent', () => {
5653
let mockLois$: BehaviorSubject<List<LocationOfInterest>>;
5754
let loiServiceSpy: jasmine.SpyObj<LocationOfInterestService>;
5855
let mockLocationOfInterestId$: BehaviorSubject<string | null>;
56+
let mockTaskId$: BehaviorSubject<string | null>;
5957
let navigationServiceSpy: jasmine.SpyObj<NavigationService>;
6058
let submissionServiceSpy: jasmine.SpyObj<SubmissionService>;
6159
let mockEditMode$: BehaviorSubject<EditMode>;
@@ -179,6 +177,7 @@ describe('MapComponent', () => {
179177
'NavigationService',
180178
[
181179
'getLocationOfInterestId$',
180+
'getTaskId$',
182181
'getSubmissionId$',
183182
'selectLocationOfInterest',
184183
'clearLocationOfInterestId',
@@ -189,6 +188,10 @@ describe('MapComponent', () => {
189188
navigationServiceSpy.getLocationOfInterestId$.and.returnValue(
190189
mockLocationOfInterestId$
191190
);
191+
mockTaskId$ = new BehaviorSubject<string | null>(null);
192+
navigationServiceSpy.getTaskId$.and.returnValue(
193+
mockTaskId$
194+
);
192195
navigationServiceSpy.getSubmissionId$.and.returnValue(
193196
of<string | null>(null)
194197
);
@@ -254,16 +257,16 @@ describe('MapComponent', () => {
254257
);
255258
}));
256259

257-
it('should render markers on map', () => {
260+
fit('should render markers on map', () => {
258261
expect(component.markers.size).toEqual(2);
259262
const marker1 = component.markers.get(poiId1)!;
260263
assertMarkerLatLng(marker1, new google.maps.LatLng(4.56, 1.23));
261-
assertMarkerIcon(marker1, jobColor1, 30);
262-
expect(marker1.getMap()).toEqual(component.map.googleMap!);
264+
expect(marker1.element.innerHTML).toContain(`fill="${jobColor1}"`);
265+
expect(marker1.map).toEqual(component.map.googleMap!);
263266
const marker2 = component.markers.get(poiId2)!;
264267
assertMarkerLatLng(marker2, new google.maps.LatLng(45.6, 12.3));
265-
assertMarkerIcon(marker2, jobColor2, 30);
266-
expect(marker2.getMap()).toEqual(component.map.googleMap!);
268+
expect(marker2.element.innerHTML).toContain(`fill="${jobColor2}"`);
269+
expect(marker2.map).toEqual(component.map.googleMap!);
267270
});
268271

269272
it('should render polygons on map - polygon loi', () => {
@@ -324,8 +327,8 @@ describe('MapComponent', () => {
324327
expect(component.markers.size).toEqual(1);
325328
const marker1 = component.markers.get(poiId1)!;
326329
assertMarkerLatLng(marker1, new google.maps.LatLng(4.56, 1.23));
327-
assertMarkerIcon(marker1, jobColor1, 30);
328-
expect(marker1.getMap()).toEqual(component.map.googleMap!);
330+
expect(marker1.element.innerHTML).toContain(`fill="${jobColor1}"`);
331+
expect(marker1.map).toEqual(component.map.googleMap!);
329332
}));
330333

331334
it('should fit the map when survey changed', fakeAsync(() => {
@@ -362,12 +365,12 @@ describe('MapComponent', () => {
362365
expect(component.markers.size).toEqual(2);
363366
const marker1 = component.markers.get(poiId2)!;
364367
assertMarkerLatLng(marker1, new google.maps.LatLng(45.7, 12.3));
365-
assertMarkerIcon(marker1, jobColor2, 30);
366-
expect(marker1.getMap()).toEqual(component.map.googleMap!);
368+
expect(marker1.element.innerHTML).toContain(`fill="${jobColor2}"`);
369+
expect(marker1.map).toEqual(component.map.googleMap!);
367370
const marker2 = component.markers.get(poiId3)!;
368371
assertMarkerLatLng(marker2, new google.maps.LatLng(78.9, 78.9));
369-
assertMarkerIcon(marker2, jobColor2, 30);
370-
expect(marker2.getMap()).toEqual(component.map.googleMap!);
372+
expect(marker2.element.innerHTML).toContain(`fill="${jobColor2}"`);
373+
expect(marker2.map).toEqual(component.map.googleMap!);
371374
expect(component.polygons.size).toEqual(1);
372375
const [polygon] = component.polygons.get(polygonLoiId1)!;
373376
assertPolygonPaths(polygon, [
@@ -393,14 +396,6 @@ describe('MapComponent', () => {
393396
).toHaveBeenCalledOnceWith(poiId1);
394397
});
395398

396-
it('should enlarge the marker when loi is selected', fakeAsync(() => {
397-
mockLocationOfInterestId$.next(poiId1);
398-
tick();
399-
400-
const marker1 = component.markers.get(poiId1)!;
401-
assertMarkerIcon(marker1, jobColor1, 50);
402-
}));
403-
404399
it('should select loi when polygon is clicked', () => {
405400
const [polygon] = component.polygons.get(polygonLoiId1)!;
406401
google.maps.event.trigger(polygon, 'click', {
@@ -435,17 +430,17 @@ describe('MapComponent', () => {
435430

436431
it('markers are not draggable by default', () => {
437432
const marker1 = component.markers.get(poiId1)!;
438-
expect(marker1.getDraggable()).toBeFalse();
433+
expect(marker1.gmpDraggable).toBeFalse();
439434
const marker2 = component.markers.get(poiId2)!;
440-
expect(marker2.getDraggable()).toBeFalse();
435+
expect(marker2.gmpDraggable).toBeFalse();
441436
});
442437

443438
it('should set marker draggable when loi is selected', fakeAsync(() => {
444439
mockLocationOfInterestId$.next(poiId1);
445440
tick();
446441

447442
const marker1 = component.markers.get(poiId1)!;
448-
expect(marker1.getDraggable()).toBeTrue();
443+
expect(marker1.gmpDraggable).toBeTrue();
449444
}));
450445

451446
it('should not set marker draggable when loi is selected and drawing tools turned off', fakeAsync(() => {
@@ -454,7 +449,7 @@ describe('MapComponent', () => {
454449
tick();
455450

456451
const marker1 = component.markers.get(poiId1)!;
457-
expect(marker1.getDraggable()).toBeFalse();
452+
expect(marker1.gmpDraggable).toBeFalse();
458453
}));
459454

460455
it('reposition dialog is not displayed by default', () => {
@@ -662,24 +657,11 @@ describe('MapComponent', () => {
662657
}));
663658

664659
function assertMarkerLatLng(
665-
marker: google.maps.Marker,
660+
marker: google.maps.marker.AdvancedMarkerElement,
666661
latLng: google.maps.LatLng
667662
): void {
668-
expect(marker.getPosition()?.lat()).toEqual(latLng.lat());
669-
expect(marker.getPosition()?.lng()).toEqual(latLng.lng());
670-
}
671-
672-
function assertMarkerIcon(
673-
marker: google.maps.Marker,
674-
iconColor: string,
675-
iconSize: number
676-
): void {
677-
const icon = marker.getIcon() as google.maps.Icon;
678-
expect(atob(icon.url.slice(GroundPinService.urlPrefix.length))).toContain(
679-
iconColor
680-
);
681-
expect(icon.scaledSize?.height).toEqual(iconSize);
682-
expect(icon.scaledSize?.width).toEqual(iconSize);
663+
expect(marker.position?.lat).toEqual(latLng.lat());
664+
expect(marker.position?.lng).toEqual(latLng.lng());
683665
}
684666

685667
function assertPolygonPaths(

web/src/app/pages/main-page-container/main-page/map/map.component.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,6 @@ export class MapComponent implements AfterViewInit, OnChanges, OnDestroy {
426426
if (color === undefined) {
427427
color = this.DEFAULT_MARKER_COLOR;
428428
}
429-
const icon = {
430-
url: this.groundPinService.getPinImageSource(color),
431-
scaledSize: {
432-
width: normalIconScale,
433-
height: normalIconScale,
434-
},
435-
} as google.maps.Icon;
436429

437430
// TODO(#2108): Switch to custom HTML and CSS markers. Having a custom HTML will
438431
// improve text wrapping, allow for a more square shape, and custom styles for

0 commit comments

Comments
 (0)