Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit b70cbbc

Browse files
doom777msenosiain
authored andcommitted
fix(AgmMap): respect disableDefaultUI (#1709)
correctly disables streetViewControl and zoomControl when disableDefaultUi is set to true fixes: #933
1 parent 44061e8 commit b70cbbc

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

packages/core/directives/map.spec.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
});

packages/core/directives/map.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
156156
/**
157157
* The enabled/disabled state of the Zoom control.
158158
*/
159-
@Input() zoomControl: boolean = true;
159+
@Input() zoomControl: boolean;
160160

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

186186
/**
187187
* Options for the Street View control.

0 commit comments

Comments
 (0)