1 | import {NgZone} from '@angular/core';
|
2 | import {TestBed, inject} from '@angular/core/testing';
|
3 |
|
4 | import {SebmGoogleMapPolygon} from '../../directives/google-map-polygon';
|
5 | import {GoogleMapsAPIWrapper} from '../google-maps-api-wrapper';
|
6 | import {Polygon} from '../google-maps-types';
|
7 | import {PolygonManager} from './polygon-manager';
|
8 |
|
9 | describe('PolygonManager', () => {
|
10 | beforeEach(() => {
|
11 | TestBed.configureTestingModule({
|
12 | providers: [
|
13 | {provide: NgZone, useFactory: () => new NgZone({enableLongStackTrace: true})},
|
14 | PolygonManager, SebmGoogleMapPolygon, {
|
15 | provide: GoogleMapsAPIWrapper,
|
16 | useValue: jasmine.createSpyObj('GoogleMapsAPIWrapper', ['createPolygon'])
|
17 | }
|
18 | ]
|
19 | });
|
20 | });
|
21 |
|
22 | describe('Create a new polygon', () => {
|
23 | it('should call the mapsApiWrapper when creating a new polygon',
|
24 | inject(
|
25 | [PolygonManager, GoogleMapsAPIWrapper],
|
26 | (polygonManager: PolygonManager, apiWrapper: GoogleMapsAPIWrapper) => {
|
27 | const newPolygon = new SebmGoogleMapPolygon(polygonManager);
|
28 | polygonManager.addPolygon(newPolygon);
|
29 |
|
30 | expect(apiWrapper.createPolygon).toHaveBeenCalledWith({
|
31 | clickable: true,
|
32 | draggable: false,
|
33 | editable: false,
|
34 | fillColor: undefined,
|
35 | fillOpacity: undefined,
|
36 | geodesic: false,
|
37 | paths: [],
|
38 | strokeColor: undefined,
|
39 | strokeOpacity: undefined,
|
40 | strokeWeight: undefined,
|
41 | visible: undefined,
|
42 | zIndex: undefined
|
43 | });
|
44 | }));
|
45 | });
|
46 |
|
47 | describe('Delete a polygon', () => {
|
48 | it('should set the map to null when deleting a existing polygon',
|
49 | inject(
|
50 | [PolygonManager, GoogleMapsAPIWrapper],
|
51 | (polygonManager: PolygonManager, apiWrapper: GoogleMapsAPIWrapper) => {
|
52 | const newPolygon = new SebmGoogleMapPolygon(polygonManager);
|
53 |
|
54 | const polygonInstance: Polygon = jasmine.createSpyObj('Polygon', ['setMap']);
|
55 | (<any>apiWrapper.createPolygon).and.returnValue(Promise.resolve(polygonInstance));
|
56 |
|
57 | polygonManager.addPolygon(newPolygon);
|
58 | polygonManager.deletePolygon(newPolygon).then(() => {
|
59 | expect(polygonInstance.setMap).toHaveBeenCalledWith(null);
|
60 | });
|
61 | }));
|
62 | });
|
63 | });
|