|
| 1 | +// tslint:disable |
| 2 | +import { async, ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing'; |
| 3 | +import { Injectable, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; |
| 4 | +import { isPlatformBrowser } from '@angular/common'; |
| 5 | +import { By } from '@angular/platform-browser'; |
| 6 | +// tslint:enable |
| 7 | + |
| 8 | +import {Component, Directive, ElementRef, NgZone} from '@angular/core'; |
| 9 | +import {AgmMap} from './map'; |
| 10 | +import {GoogleMapsAPIWrapper} from '../services/google-maps-api-wrapper'; |
| 11 | +import {FitBoundsService} from '../services/fit-bounds'; |
| 12 | +import { Subject } from 'rxjs'; |
| 13 | + |
| 14 | +@Injectable() |
| 15 | +class MockElementRef { |
| 16 | + // constructor() { super(undefined); } |
| 17 | + nativeElement = {}; |
| 18 | +} |
| 19 | +@Injectable() |
| 20 | +class MockGoogleMapsAPIWrapper { |
| 21 | + createMap = jest.fn().mockReturnValue(Promise.resolve()); |
| 22 | + clearInstanceListeners = jest.fn(); |
| 23 | + subscribeToMapEvent = jest.fn().mockReturnValue(new Subject()); |
| 24 | + getNativeMap = jest.fn().mockReturnValue(Promise.resolve({})); |
| 25 | +} |
| 26 | + |
| 27 | +@Injectable() |
| 28 | +class MockFitBoundsService { } |
| 29 | + |
| 30 | +describe('AgmMap', () => { |
| 31 | + let fixture: ComponentFixture<AgmMap>; |
| 32 | + let component: AgmMap; |
| 33 | + |
| 34 | + beforeEach(async(() => { |
| 35 | + TestBed.configureTestingModule({ |
| 36 | + declarations: [ |
| 37 | + AgmMap |
| 38 | + ], |
| 39 | + schemas: [ CUSTOM_ELEMENTS_SCHEMA ]}); |
| 40 | + TestBed.overrideComponent(AgmMap, { |
| 41 | + set: { |
| 42 | + providers: [ |
| 43 | + {provide: ElementRef, useClass: MockElementRef}, |
| 44 | + {provide: GoogleMapsAPIWrapper, useClass: MockGoogleMapsAPIWrapper}, |
| 45 | + {provide: FitBoundsService, useClass: MockFitBoundsService}, |
| 46 | + // NgZone, |
| 47 | + ], |
| 48 | + } |
| 49 | + }).compileComponents(); |
| 50 | + fixture = TestBed.createComponent(AgmMap); |
| 51 | + component = fixture.debugElement.componentInstance; |
| 52 | + })); |
| 53 | + |
| 54 | + it('should create a component', () => { |
| 55 | + expect(component).toBeTruthy(); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should not enable controls when disableViewControls is true', () => { |
| 59 | + component.disableDefaultUI = true; |
| 60 | + fixture.detectChanges(); |
| 61 | + const mockApiWrapper: MockGoogleMapsAPIWrapper = fixture.debugElement.injector.get(GoogleMapsAPIWrapper) as any; |
| 62 | + expect(mockApiWrapper.createMap.mock.calls[0][1].streetViewControl).not.toBe(true); |
| 63 | + expect(mockApiWrapper.createMap.mock.calls[0][1].zoomControl).not.toBe(true); |
| 64 | + }); |
| 65 | + |
| 66 | +}); |
0 commit comments