@@ -2,25 +2,36 @@ import {Component} from '@angular/core';
2
2
import { async , TestBed } from '@angular/core/testing' ;
3
3
import { By } from '@angular/platform-browser' ;
4
4
5
+ import { DEFAULT_OPTIONS , GoogleMapModule , UpdatedGoogleMap } from '../google-map/index' ;
5
6
import { MapMarker } from '../map-marker/index' ;
6
7
import {
7
8
createInfoWindowConstructorSpy ,
8
9
createInfoWindowSpy ,
10
+ createMapConstructorSpy ,
11
+ createMapSpy ,
9
12
TestingWindow
10
13
} from '../testing/fake-google-map-utils' ;
11
14
12
15
import { MapInfoWindow , MapInfoWindowModule } from './index' ;
13
16
14
17
describe ( 'MapInfoWindow' , ( ) => {
18
+ let mapSpy : jasmine . SpyObj < UpdatedGoogleMap > ;
19
+
15
20
beforeEach ( async ( ( ) => {
16
21
TestBed . configureTestingModule ( {
17
- imports : [ MapInfoWindowModule ] ,
22
+ imports : [
23
+ GoogleMapModule ,
24
+ MapInfoWindowModule ,
25
+ ] ,
18
26
declarations : [ TestApp ] ,
19
27
} ) ;
20
28
} ) ) ;
21
29
22
30
beforeEach ( ( ) => {
23
31
TestBed . compileComponents ( ) ;
32
+
33
+ mapSpy = createMapSpy ( DEFAULT_OPTIONS ) ;
34
+ createMapConstructorSpy ( mapSpy ) . and . callThrough ( ) ;
24
35
} ) ;
25
36
26
37
afterEach ( ( ) => {
@@ -34,10 +45,6 @@ describe('MapInfoWindow', () => {
34
45
createInfoWindowConstructorSpy ( infoWindowSpy ) . and . callThrough ( ) ;
35
46
36
47
const fixture = TestBed . createComponent ( TestApp ) ;
37
- const fakeMap = { } as unknown as google . maps . Map ;
38
- const infoWindowComponent =
39
- fixture . debugElement . query ( By . directive ( MapInfoWindow ) ) . componentInstance ;
40
- infoWindowComponent . _setMap ( fakeMap ) ;
41
48
fixture . detectChanges ( ) ;
42
49
43
50
expect ( infoWindowConstructorSpy ) . toHaveBeenCalledWith ( {
@@ -47,17 +54,13 @@ describe('MapInfoWindow', () => {
47
54
} ) ;
48
55
49
56
it ( 'sets position' , ( ) => {
50
- const fakeMap = { } as unknown as google . maps . Map ;
51
57
const position : google . maps . LatLngLiteral = { lat : 5 , lng : 7 } ;
52
58
const infoWindowSpy = createInfoWindowSpy ( { position} ) ;
53
59
const infoWindowConstructorSpy =
54
60
createInfoWindowConstructorSpy ( infoWindowSpy ) . and . callThrough ( ) ;
55
61
56
62
const fixture = TestBed . createComponent ( TestApp ) ;
57
63
fixture . componentInstance . position = position ;
58
- const infoWindowComponent =
59
- fixture . debugElement . query ( By . directive ( MapInfoWindow ) ) . componentInstance ;
60
- infoWindowComponent . _setMap ( fakeMap ) ;
61
64
fixture . detectChanges ( ) ;
62
65
63
66
expect ( infoWindowConstructorSpy ) . toHaveBeenCalledWith ( {
@@ -67,7 +70,6 @@ describe('MapInfoWindow', () => {
67
70
} ) ;
68
71
69
72
it ( 'sets options' , ( ) => {
70
- const fakeMap = { } as unknown as google . maps . Map ;
71
73
const options : google . maps . InfoWindowOptions = {
72
74
position : { lat : 3 , lng : 5 } ,
73
75
maxWidth : 50 ,
@@ -79,9 +81,6 @@ describe('MapInfoWindow', () => {
79
81
80
82
const fixture = TestBed . createComponent ( TestApp ) ;
81
83
fixture . componentInstance . options = options ;
82
- const infoWindowComponent =
83
- fixture . debugElement . query ( By . directive ( MapInfoWindow ) ) . componentInstance ;
84
- infoWindowComponent . _setMap ( fakeMap ) ;
85
84
fixture . detectChanges ( ) ;
86
85
87
86
expect ( infoWindowConstructorSpy ) . toHaveBeenCalledWith ( {
@@ -91,7 +90,6 @@ describe('MapInfoWindow', () => {
91
90
} ) ;
92
91
93
92
it ( 'gives preference to position over options' , ( ) => {
94
- const fakeMap = { } as unknown as google . maps . Map ;
95
93
const position : google . maps . LatLngLiteral = { lat : 5 , lng : 7 } ;
96
94
const options : google . maps . InfoWindowOptions = {
97
95
position : { lat : 3 , lng : 5 } ,
@@ -105,9 +103,6 @@ describe('MapInfoWindow', () => {
105
103
const fixture = TestBed . createComponent ( TestApp ) ;
106
104
fixture . componentInstance . options = options ;
107
105
fixture . componentInstance . position = position ;
108
- const infoWindowComponent =
109
- fixture . debugElement . query ( By . directive ( MapInfoWindow ) ) . componentInstance ;
110
- infoWindowComponent . _setMap ( fakeMap ) ;
111
106
fixture . detectChanges ( ) ;
112
107
113
108
expect ( infoWindowConstructorSpy ) . toHaveBeenCalledWith ( {
@@ -117,8 +112,7 @@ describe('MapInfoWindow', () => {
117
112
} ) ;
118
113
} ) ;
119
114
120
- it ( 'exposes meethods that change the configuration of the info window' , ( ) => {
121
- const fakeMap = { } as unknown as google . maps . Map ;
115
+ it ( 'exposes methods that change the configuration of the info window' , ( ) => {
122
116
const fakeMarker = { } as unknown as google . maps . Marker ;
123
117
const fakeMarkerComponent = { _marker : fakeMarker } as unknown as MapMarker ;
124
118
const infoWindowSpy = createInfoWindowSpy ( { } ) ;
@@ -127,25 +121,22 @@ describe('MapInfoWindow', () => {
127
121
const fixture = TestBed . createComponent ( TestApp ) ;
128
122
const infoWindowComponent =
129
123
fixture . debugElement . query ( By . directive ( MapInfoWindow ) ) . componentInstance ;
130
- infoWindowComponent . _setMap ( fakeMap ) ;
131
124
fixture . detectChanges ( ) ;
132
125
133
126
infoWindowComponent . close ( ) ;
134
127
expect ( infoWindowSpy . close ) . toHaveBeenCalled ( ) ;
135
128
136
129
infoWindowComponent . open ( fakeMarkerComponent ) ;
137
- expect ( infoWindowSpy . open ) . toHaveBeenCalledWith ( fakeMap , fakeMarker ) ;
130
+ expect ( infoWindowSpy . open ) . toHaveBeenCalledWith ( mapSpy , fakeMarker ) ;
138
131
} ) ;
139
132
140
133
it ( 'exposes methods that provide information about the info window' , ( ) => {
141
- const fakeMap = { } as unknown as google . maps . Map ;
142
134
const infoWindowSpy = createInfoWindowSpy ( { } ) ;
143
135
createInfoWindowConstructorSpy ( infoWindowSpy ) . and . callThrough ( ) ;
144
136
145
137
const fixture = TestBed . createComponent ( TestApp ) ;
146
138
const infoWindowComponent =
147
139
fixture . debugElement . query ( By . directive ( MapInfoWindow ) ) . componentInstance ;
148
- infoWindowComponent . _setMap ( fakeMap ) ;
149
140
fixture . detectChanges ( ) ;
150
141
151
142
infoWindowSpy . getContent . and . returnValue ( 'test content' ) ;
@@ -159,14 +150,10 @@ describe('MapInfoWindow', () => {
159
150
} ) ;
160
151
161
152
it ( 'initializes info window event handlers' , ( ) => {
162
- const fakeMap = { } as unknown as google . maps . Map ;
163
153
const infoWindowSpy = createInfoWindowSpy ( { } ) ;
164
154
createInfoWindowConstructorSpy ( infoWindowSpy ) . and . callThrough ( ) ;
165
155
166
156
const fixture = TestBed . createComponent ( TestApp ) ;
167
- const infoWindowComponent =
168
- fixture . debugElement . query ( By . directive ( MapInfoWindow ) ) . componentInstance ;
169
- infoWindowComponent . _setMap ( fakeMap ) ;
170
157
fixture . detectChanges ( ) ;
171
158
172
159
expect ( infoWindowSpy . addListener ) . toHaveBeenCalledWith ( 'closeclick' , jasmine . any ( Function ) ) ;
@@ -182,9 +169,13 @@ describe('MapInfoWindow', () => {
182
169
183
170
@Component ( {
184
171
selector : 'test-app' ,
185
- template : `<map-info-window [position]="position"
186
- [options]="options"
187
- (closeclick)="handleClose()">test content</map-info-window>` ,
172
+ template : `<google-map>
173
+ <map-info-window [position]="position"
174
+ [options]="options"
175
+ (closeclick)="handleClose()">
176
+ test content
177
+ </map-info-window>
178
+ </google-map>` ,
188
179
} )
189
180
class TestApp {
190
181
position ?: google . maps . LatLngLiteral ;
0 commit comments