Skip to content

Commit 84741ed

Browse files
committed
feat(google-maps): Add google-map-marker component
Add tests for the google-map-marker component.
1 parent fcc6269 commit 84741ed

File tree

11 files changed

+271
-29
lines changed

11 files changed

+271
-29
lines changed

src/dev-app/google-map/google-map-demo-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {CommonModule} from '@angular/common';
1010
import {HttpClientJsonpModule, HttpClientModule} from '@angular/common/http';
1111
import {NgModule} from '@angular/core';
1212
import {GoogleMapModule} from '@angular/google-maps/google-map';
13+
import {GoogleMapMarkerModule} from '@angular/google-maps/google-map-marker';
1314
import {RouterModule} from '@angular/router';
1415

1516
import {GoogleMapDemo} from './google-map-demo';
@@ -18,6 +19,7 @@ import {GoogleMapDemo} from './google-map-demo';
1819
imports: [
1920
CommonModule,
2021
GoogleMapModule,
22+
GoogleMapMarkerModule,
2123
HttpClientJsonpModule,
2224
HttpClientModule,
2325
RouterModule.forChild([{path: '', component: GoogleMapDemo}]),

src/dev-app/google-map/google-map-demo.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
[center]="center"
55
[zoom]="zoom"
66
(mapClick)="handleClick($event)"
7-
(mapMousemove)="handleMove($event)"></google-map>
7+
(mapMousemove)="handleMove($event)">
8+
<google-map-marker [position]="gettysburg"
9+
[options]="markerOptions"
10+
(mapClick)="clickMarker($event)"></google-map-marker>
11+
</google-map>
812

913
<div>Latitude: {{display?.lat}}</div>
1014
<div>Longitude: {{display?.lng}}</div>

src/dev-app/google-map/google-map-demo.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export class GoogleMapDemo {
1919
isReady = false;
2020

2121
center = {lat: 24, lng: 12};
22+
markerOptions = {draggable: false};
23+
gettysburg = {lat: 39.830205, lng:-77.232949};
2224
zoom = 4;
2325
display?: google.maps.LatLngLiteral;
2426

@@ -36,4 +38,9 @@ export class GoogleMapDemo {
3638
handleMove(event: google.maps.MouseEvent) {
3739
this.display = event.latLng.toJSON();
3840
}
41+
42+
clickMarker(event: google.maps.MouseEvent) {
43+
console.log(this.markerOptions);
44+
this.markerOptions = {draggable: true};
45+
}
3946
}

src/google-maps/google-map-marker/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ng_test_library(
3030
),
3131
deps = [
3232
":google-map-marker",
33+
"//src/google-maps/testing",
3334
"@npm//@angular/platform-browser",
3435
],
3536
)
Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,69 @@
1-
descript('GoogleMapMarker', () => {});
1+
import { Component } from '@angular/core';
2+
import { async, TestBed } from '@angular/core/testing';
3+
import { By } from '@angular/platform-browser';
4+
5+
import {DEFAULT_OPTIONS, GoogleMapMarkerModule} from './index';
6+
7+
import {createMarkerSpy, createMarkerConstructorSpy, TestingWindow} from '../testing/fake-google-map-utils';
8+
9+
describe('GoogleMapMarker', () => {
10+
beforeEach(async(() => {
11+
TestBed.configureTestingModule({
12+
imports: [GoogleMapMarkerModule],
13+
declarations: [TestApp],
14+
});
15+
}));
16+
17+
beforeEach(() => {
18+
TestBed.compileComponents();
19+
});
20+
21+
afterEach(() => {
22+
const testingWindow: TestingWindow = window;
23+
delete testingWindow.google;
24+
});
25+
26+
it('initializes a Google Map marker', () => {
27+
let markerSpy = createMarkerSpy(DEFAULT_OPTIONS);
28+
let markerConstructorSpy = createMarkerConstructorSpy(markerSpy);
29+
30+
const fixture = TestBed.createComponent(TestApp);
31+
fixture.detectChanges();
32+
33+
expect(markerConstructorSpy).toHaveBeenCalledWith(DEFAULT_OPTIONS);
34+
});
35+
36+
it('sets marker inputs', () => {});
37+
38+
it('sets marker options, ignoring map', () => {});
39+
40+
it('gives precedence to specific inputs over options', () => {});
41+
42+
it('sets the map on the marker only once', () => {});
43+
44+
it('exposes methods that provide information about the marker', () => {});
45+
46+
it('initializes marker event handlers', () => {});
47+
});
48+
49+
@Component({
50+
selector: 'test-app',
51+
template: `<google-map-marker [title]="title"
52+
[position]="position"
53+
[label]="label"
54+
[clickable]="clickable"
55+
[options]="options"
56+
(mapClick)="handleClick()"
57+
(positionChanged)="handlePositionChanged()"></google-map-marker>`,
58+
})
59+
class TestApp {
60+
title?: string;
61+
position?: google.maps.LatLngLiteral;
62+
label?: string;
63+
clickable?: boolean;
64+
options?: google.maps.MarkerOptions;
65+
66+
handleClick() {}
67+
68+
handlePositionChanged() {}
69+
}

0 commit comments

Comments
 (0)