Skip to content

Commit

Permalink
fix(AgmMap): respect disableDefaultUI (#1709)
Browse files Browse the repository at this point in the history
correctly disables streetViewControl and zoomControl when
disableDefaultUi is set to true

fixes: #933
  • Loading branch information
doom777 authored and msenosiain committed Aug 23, 2019
1 parent 44061e8 commit b70cbbc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
66 changes: 66 additions & 0 deletions packages/core/directives/map.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// tslint:disable
import { async, ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
import { Injectable, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { By } from '@angular/platform-browser';
// tslint:enable

import {Component, Directive, ElementRef, NgZone} from '@angular/core';
import {AgmMap} from './map';
import {GoogleMapsAPIWrapper} from '../services/google-maps-api-wrapper';
import {FitBoundsService} from '../services/fit-bounds';
import { Subject } from 'rxjs';

@Injectable()
class MockElementRef {
// constructor() { super(undefined); }
nativeElement = {};
}
@Injectable()
class MockGoogleMapsAPIWrapper {
createMap = jest.fn().mockReturnValue(Promise.resolve());
clearInstanceListeners = jest.fn();
subscribeToMapEvent = jest.fn().mockReturnValue(new Subject());
getNativeMap = jest.fn().mockReturnValue(Promise.resolve({}));
}

@Injectable()
class MockFitBoundsService { }

describe('AgmMap', () => {
let fixture: ComponentFixture<AgmMap>;
let component: AgmMap;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AgmMap
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]});
TestBed.overrideComponent(AgmMap, {
set: {
providers: [
{provide: ElementRef, useClass: MockElementRef},
{provide: GoogleMapsAPIWrapper, useClass: MockGoogleMapsAPIWrapper},
{provide: FitBoundsService, useClass: MockFitBoundsService},
// NgZone,
],
}
}).compileComponents();
fixture = TestBed.createComponent(AgmMap);
component = fixture.debugElement.componentInstance;
}));

it('should create a component', () => {
expect(component).toBeTruthy();
});

it('should not enable controls when disableViewControls is true', () => {
component.disableDefaultUI = true;
fixture.detectChanges();
const mockApiWrapper: MockGoogleMapsAPIWrapper = fixture.debugElement.injector.get(GoogleMapsAPIWrapper) as any;
expect(mockApiWrapper.createMap.mock.calls[0][1].streetViewControl).not.toBe(true);
expect(mockApiWrapper.createMap.mock.calls[0][1].zoomControl).not.toBe(true);
});

});
4 changes: 2 additions & 2 deletions packages/core/directives/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
/**
* The enabled/disabled state of the Zoom control.
*/
@Input() zoomControl: boolean = true;
@Input() zoomControl: boolean;

/**
* Options for the Zoom control.
Expand All @@ -181,7 +181,7 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
* This control is part of the default UI, and should be set to false when displaying a map type
* on which the Street View road overlay should not appear (e.g. a non-Earth map type).
*/
@Input() streetViewControl: boolean = true;
@Input() streetViewControl: boolean;

/**
* Options for the Street View control.
Expand Down

0 comments on commit b70cbbc

Please sign in to comment.