| /******************************************************************************** |
| * Copyright (c) 2020 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0 |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ********************************************************************************/ |
| |
| import {Component, ViewChild} from "@angular/core"; |
| import {async, ComponentFixture, TestBed} from "@angular/core/testing"; |
| import {LatLng, LatLngLiteral} from "leaflet"; |
| import {Subject} from "rxjs"; |
| import {LeafletModule} from "../../leaflet.module"; |
| import {LeafletCenterMarkerDirective} from "./leaflet-center-marker.directive"; |
| |
| describe("LeafletCenterMarkerDirective", () => { |
| |
| const latLng: LatLngLiteral = { |
| lat: 52.520008, |
| lng: 13.404954 |
| }; |
| |
| let component: LeafletCenterMarkerSpecComponent; |
| let fixture: ComponentFixture<LeafletCenterMarkerSpecComponent>; |
| let directive: LeafletCenterMarkerDirective; |
| |
| beforeEach(async(() => { |
| TestBed.configureTestingModule({ |
| imports: [LeafletModule], |
| declarations: [LeafletCenterMarkerSpecComponent] |
| }).compileComponents(); |
| })); |
| |
| beforeEach(() => { |
| fixture = TestBed.createComponent(LeafletCenterMarkerSpecComponent); |
| component = fixture.componentInstance; |
| fixture.detectChanges(); |
| directive = component.directive; |
| }); |
| |
| it("should update marker coordinates on move events", () => { |
| const center = new LatLng(latLng.lat, latLng.lng); |
| const move$ = new Subject<any>(); |
| const setLatLngSpy = spyOn(directive.marker, "setLatLng").and.callThrough(); |
| spyOn(directive.leafletDirective.leaflet, "getCenter").and.returnValue(center); |
| spyOn(directive, "on").and.returnValue(move$.asObservable()); |
| directive.ngOnInit(); |
| move$.next(); |
| expect(setLatLngSpy).toHaveBeenCalledWith(center); |
| }); |
| |
| }); |
| |
| @Component({ |
| selector: "app-leaflet-center-marker-spec", |
| template: ` |
| <div appLeaflet> |
| <ng-container appLeafletCenterMarker> |
| </ng-container> |
| </div> |
| ` |
| }) |
| class LeafletCenterMarkerSpecComponent { |
| |
| @ViewChild(LeafletCenterMarkerDirective, {static: true}) |
| public directive: LeafletCenterMarkerDirective; |
| |
| } |