-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(google-maps): add advanced marker #28525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
src/google-maps/map-advanced-marker/map-advanced-marker.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
import {Component, ViewChild} from '@angular/core'; | ||
import {TestBed, fakeAsync, flush} from '@angular/core/testing'; | ||
|
||
import {DEFAULT_OPTIONS, GoogleMap} from '../google-map/google-map'; | ||
import { | ||
createAdvancedMarkerConstructorSpy, | ||
createAdvancedMarkerSpy, | ||
createMapConstructorSpy, | ||
createMapSpy, | ||
} from '../testing/fake-google-map-utils'; | ||
import {DEFAULT_MARKER_OPTIONS, MapAdvancedMarker} from './map-advanced-marker'; | ||
|
||
describe('MapAdvancedMarker', () => { | ||
let mapSpy: jasmine.SpyObj<google.maps.Map>; | ||
|
||
beforeEach(() => { | ||
mapSpy = createMapSpy(DEFAULT_OPTIONS); | ||
createMapConstructorSpy(mapSpy); | ||
}); | ||
|
||
afterEach(() => { | ||
(window.google as any) = undefined; | ||
}); | ||
|
||
it('initializes a Google Map advanced marker', fakeAsync(() => { | ||
const advancedMarkerSpy = createAdvancedMarkerSpy(DEFAULT_MARKER_OPTIONS); | ||
const advancedMarkerConstructorSpy = createAdvancedMarkerConstructorSpy(advancedMarkerSpy); | ||
|
||
const fixture = TestBed.createComponent(TestApp); | ||
fixture.detectChanges(); | ||
flush(); | ||
expect(advancedMarkerConstructorSpy).toHaveBeenCalledWith({ | ||
...DEFAULT_MARKER_OPTIONS, | ||
title: undefined, | ||
content: undefined, | ||
gmpDraggable: undefined, | ||
zIndex: undefined, | ||
map: mapSpy, | ||
}); | ||
})); | ||
|
||
it('sets advanced marker inputs', fakeAsync(() => { | ||
const options: google.maps.marker.AdvancedMarkerElementOptions = { | ||
position: {lat: 3, lng: 5}, | ||
title: 'marker title', | ||
map: mapSpy, | ||
content: undefined, | ||
gmpDraggable: true, | ||
zIndex: 1, | ||
}; | ||
const advancedMarkerSpy = createAdvancedMarkerSpy(options); | ||
const advancedMarkerConstructorSpy = createAdvancedMarkerConstructorSpy(advancedMarkerSpy); | ||
|
||
const fixture = TestBed.createComponent(TestApp); | ||
fixture.componentInstance.position = options.position; | ||
fixture.componentInstance.title = options.title; | ||
fixture.componentInstance.content = options.content; | ||
fixture.componentInstance.gmpDraggable = options.gmpDraggable; | ||
fixture.componentInstance.zIndex = options.zIndex; | ||
|
||
fixture.detectChanges(); | ||
flush(); | ||
|
||
expect(advancedMarkerConstructorSpy).toHaveBeenCalledWith(options); | ||
})); | ||
|
||
it('sets marker options, ignoring map', fakeAsync(() => { | ||
const options: google.maps.marker.AdvancedMarkerElementOptions = { | ||
position: {lat: 3, lng: 5}, | ||
title: 'marker title', | ||
content: undefined, | ||
gmpDraggable: true, | ||
zIndex: 1, | ||
}; | ||
const advancedMarkerSpy = createAdvancedMarkerSpy(options); | ||
const advancedMarkerConstructorSpy = createAdvancedMarkerConstructorSpy(advancedMarkerSpy); | ||
|
||
const fixture = TestBed.createComponent(TestApp); | ||
fixture.componentInstance.options = options; | ||
fixture.detectChanges(); | ||
flush(); | ||
|
||
expect(advancedMarkerConstructorSpy).toHaveBeenCalledWith({...options, map: mapSpy}); | ||
})); | ||
|
||
it('gives precedence to specific inputs over options', fakeAsync(() => { | ||
const options: google.maps.marker.AdvancedMarkerElementOptions = { | ||
position: {lat: 3, lng: 5}, | ||
title: 'marker title', | ||
content: undefined, | ||
gmpDraggable: true, | ||
zIndex: 1, | ||
}; | ||
|
||
const expectedOptions: google.maps.marker.AdvancedMarkerElementOptions = { | ||
position: {lat: 4, lng: 6}, | ||
title: 'marker title 2', | ||
content: undefined, | ||
gmpDraggable: false, | ||
zIndex: 999, | ||
map: mapSpy, | ||
}; | ||
const advancedMarkerSpy = createAdvancedMarkerSpy(options); | ||
const advancedMarkerConstructorSpy = createAdvancedMarkerConstructorSpy(advancedMarkerSpy); | ||
|
||
const fixture = TestBed.createComponent(TestApp); | ||
fixture.componentInstance.position = expectedOptions.position; | ||
fixture.componentInstance.title = expectedOptions.title; | ||
fixture.componentInstance.content = expectedOptions.content; | ||
fixture.componentInstance.gmpDraggable = expectedOptions.gmpDraggable; | ||
fixture.componentInstance.zIndex = expectedOptions.zIndex; | ||
fixture.componentInstance.options = options; | ||
|
||
fixture.detectChanges(); | ||
flush(); | ||
|
||
expect(advancedMarkerConstructorSpy).toHaveBeenCalledWith(expectedOptions); | ||
})); | ||
|
||
it('initializes marker event handlers', fakeAsync(() => { | ||
const advancedMarkerSpy = createAdvancedMarkerSpy(DEFAULT_MARKER_OPTIONS); | ||
createAdvancedMarkerConstructorSpy(advancedMarkerSpy); | ||
|
||
const addSpy = advancedMarkerSpy.addListener; | ||
const fixture = TestBed.createComponent(TestApp); | ||
fixture.detectChanges(); | ||
flush(); | ||
|
||
expect(addSpy).toHaveBeenCalledWith('click', jasmine.any(Function)); | ||
expect(addSpy).not.toHaveBeenCalledWith('drag', jasmine.any(Function)); | ||
expect(addSpy).not.toHaveBeenCalledWith('dragend', jasmine.any(Function)); | ||
expect(addSpy).not.toHaveBeenCalledWith('dragstart', jasmine.any(Function)); | ||
})); | ||
|
||
it('should be able to add an event listener after init', fakeAsync(() => { | ||
const advancedMarkerSpy = createAdvancedMarkerSpy(DEFAULT_MARKER_OPTIONS); | ||
createAdvancedMarkerConstructorSpy(advancedMarkerSpy); | ||
|
||
const addSpy = advancedMarkerSpy.addListener; | ||
const fixture = TestBed.createComponent(TestApp); | ||
fixture.detectChanges(); | ||
flush(); | ||
|
||
expect(addSpy).not.toHaveBeenCalledWith('drag', jasmine.any(Function)); | ||
|
||
// Pick an event that isn't bound in the template. | ||
const subscription = fixture.componentInstance.advancedMarker.mapDrag.subscribe(); | ||
fixture.detectChanges(); | ||
|
||
expect(addSpy).toHaveBeenCalledWith('drag', jasmine.any(Function)); | ||
subscription.unsubscribe(); | ||
})); | ||
}); | ||
|
||
@Component({ | ||
selector: 'test-app', | ||
template: ` | ||
<google-map> | ||
<map-advanced-marker | ||
[title]="title" | ||
[position]="position" | ||
[content]="content" | ||
[gmpDraggable]="gmpDraggable" | ||
[zIndex]="zIndex" | ||
(mapClick)="handleClick()" | ||
[options]="options" /> | ||
</google-map> | ||
`, | ||
standalone: true, | ||
imports: [GoogleMap, MapAdvancedMarker], | ||
}) | ||
class TestApp { | ||
@ViewChild(MapAdvancedMarker) advancedMarker: MapAdvancedMarker; | ||
title?: string | null; | ||
position?: google.maps.LatLng | google.maps.LatLngLiteral | null; | ||
content?: Node | google.maps.marker.PinElement | null; | ||
gmpDraggable?: boolean | null; | ||
zIndex?: number | null; | ||
options: google.maps.marker.AdvancedMarkerElementOptions; | ||
|
||
handleClick() {} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.