1
- import { TestBed , ComponentFixture } from '@angular/core/testing' ;
1
+ import { TestBed , ComponentFixture , inject } from '@angular/core/testing' ;
2
2
import { Component , DebugElement , Type , ViewChild } from '@angular/core' ;
3
3
import { By } from '@angular/platform-browser' ;
4
4
import { MatGridList , MatGridListModule } from './index' ;
5
5
import { MatGridTile , MatGridTileText } from './grid-tile' ;
6
6
import { Directionality } from '@angular/cdk/bidi' ;
7
+ import { Platform } from '@angular/cdk/platform' ;
7
8
8
9
9
10
describe ( 'MatGridList' , ( ) => {
11
+ let disableComputedStyleTests = false ;
12
+
10
13
function createComponent < T > ( componentType : Type < T > ) : ComponentFixture < T > {
11
14
TestBed . configureTestingModule ( {
12
15
imports : [ MatGridListModule ] ,
13
16
declarations : [ componentType ] ,
14
17
} ) . compileComponents ( ) ;
15
18
16
- return TestBed . createComponent < T > ( componentType ) ;
19
+ const fixture = TestBed . createComponent < T > ( componentType ) ;
20
+
21
+ inject ( [ Platform ] , ( platform : Platform ) => {
22
+ // IE and Edge aren't consistent in the values that they return from `getComputedStyle`.
23
+ // In some cases they return the computed values, and in others the passed-in ones. We use
24
+ // this flag to disable the tests that depend on `getComputedStyle` in order to avoid flakes.
25
+ // TODO: we can re-enable them when we start testing against the Chromium-based Edge.
26
+ disableComputedStyleTests = platform . EDGE || platform . TRIDENT ;
27
+ } ) ( ) ;
28
+
29
+ return fixture ;
17
30
}
18
31
32
+ afterEach ( ( ) => disableComputedStyleTests = false ) ;
33
+
19
34
it ( 'should throw error if cols is not defined' , ( ) => {
20
35
const fixture = createComponent ( GridListWithoutCols ) ;
21
36
@@ -71,6 +86,11 @@ describe('MatGridList', () => {
71
86
72
87
it ( 'should default to 1:1 row height if undefined ' , ( ) => {
73
88
const fixture = createComponent ( GridListWithUnspecifiedRowHeight ) ;
89
+
90
+ if ( disableComputedStyleTests ) {
91
+ return ;
92
+ }
93
+
74
94
fixture . detectChanges ( ) ;
75
95
const tile = fixture . debugElement . query ( By . directive ( MatGridTile ) ) ;
76
96
const inlineStyles = tile . nativeElement . style ;
@@ -84,6 +104,10 @@ describe('MatGridList', () => {
84
104
it ( 'should use a ratio row height if passed in' , ( ) => {
85
105
const fixture = createComponent ( GirdListWithRowHeightRatio ) ;
86
106
107
+ if ( disableComputedStyleTests ) {
108
+ return ;
109
+ }
110
+
87
111
fixture . componentInstance . rowHeight = '4:1' ;
88
112
fixture . detectChanges ( ) ;
89
113
@@ -105,6 +129,10 @@ describe('MatGridList', () => {
105
129
it ( 'should divide row height evenly in "fit" mode' , ( ) => {
106
130
const fixture = createComponent ( GridListWithFitRowHeightMode ) ;
107
131
132
+ if ( disableComputedStyleTests ) {
133
+ return ;
134
+ }
135
+
108
136
fixture . componentInstance . totalHeight = '300px' ;
109
137
fixture . detectChanges ( ) ;
110
138
const tile = fixture . debugElement . query ( By . directive ( MatGridTile ) ) ;
@@ -122,6 +150,10 @@ describe('MatGridList', () => {
122
150
it ( 'should use the fixed row height if passed in' , ( ) => {
123
151
const fixture = createComponent ( GridListWithFixedRowHeightMode ) ;
124
152
153
+ if ( disableComputedStyleTests ) {
154
+ return ;
155
+ }
156
+
125
157
fixture . componentInstance . rowHeight = '100px' ;
126
158
fixture . detectChanges ( ) ;
127
159
@@ -136,16 +168,24 @@ describe('MatGridList', () => {
136
168
137
169
it ( 'should default to pixels if row height units are missing' , ( ) => {
138
170
const fixture = createComponent ( GridListWithUnitlessFixedRowHeight ) ;
139
- fixture . detectChanges ( ) ;
140
171
172
+ if ( disableComputedStyleTests ) {
173
+ return ;
174
+ }
175
+
176
+ fixture . detectChanges ( ) ;
141
177
const tile = fixture . debugElement . query ( By . directive ( MatGridTile ) ) ;
142
178
expect ( getDimension ( tile , 'height' ) ) . toBe ( 100 ) ;
143
179
} ) ;
144
180
145
181
it ( 'should default gutter size to 1px' , ( ) => {
146
182
const fixture = createComponent ( GridListWithUnspecifiedGutterSize ) ;
147
- fixture . detectChanges ( ) ;
148
183
184
+ if ( disableComputedStyleTests ) {
185
+ return ;
186
+ }
187
+
188
+ fixture . detectChanges ( ) ;
149
189
const tiles = fixture . debugElement . queryAll ( By . css ( 'mat-grid-tile' ) ) ;
150
190
151
191
// check horizontal gutter
@@ -161,6 +201,10 @@ describe('MatGridList', () => {
161
201
const fixture = createComponent ( GridListWithUnspecifiedGutterSize ) ;
162
202
const gridList = fixture . debugElement . query ( By . directive ( MatGridList ) ) ;
163
203
204
+ if ( disableComputedStyleTests ) {
205
+ return ;
206
+ }
207
+
164
208
gridList . componentInstance . gutterSize = 0 ;
165
209
fixture . detectChanges ( ) ;
166
210
@@ -177,8 +221,12 @@ describe('MatGridList', () => {
177
221
178
222
it ( 'should lay out the tiles correctly for a nested grid list' , ( ) => {
179
223
const fixture = createComponent ( NestedGridList ) ;
180
- fixture . detectChanges ( ) ;
181
224
225
+ if ( disableComputedStyleTests ) {
226
+ return ;
227
+ }
228
+
229
+ fixture . detectChanges ( ) ;
182
230
const innerTiles = fixture . debugElement . queryAll (
183
231
By . css ( 'mat-grid-tile mat-grid-list mat-grid-tile' ) ) ;
184
232
@@ -189,8 +237,12 @@ describe('MatGridList', () => {
189
237
190
238
it ( 'should set the gutter size if passed' , ( ) => {
191
239
const fixture = createComponent ( GridListWithGutterSize ) ;
192
- fixture . detectChanges ( ) ;
193
240
241
+ if ( disableComputedStyleTests ) {
242
+ return ;
243
+ }
244
+
245
+ fixture . detectChanges ( ) ;
194
246
const tiles = fixture . debugElement . queryAll ( By . css ( 'mat-grid-tile' ) ) ;
195
247
196
248
// check horizontal gutter
@@ -204,8 +256,12 @@ describe('MatGridList', () => {
204
256
205
257
it ( 'should use pixels if gutter units are missing' , ( ) => {
206
258
const fixture = createComponent ( GridListWithUnitlessGutterSize ) ;
207
- fixture . detectChanges ( ) ;
208
259
260
+ if ( disableComputedStyleTests ) {
261
+ return ;
262
+ }
263
+
264
+ fixture . detectChanges ( ) ;
209
265
const tiles = fixture . debugElement . queryAll ( By . css ( 'mat-grid-tile' ) ) ;
210
266
211
267
// check horizontal gutter
@@ -221,6 +277,10 @@ describe('MatGridList', () => {
221
277
const fixture = createComponent ( GridListWithUnspecifiedGutterSize ) ;
222
278
const gridList = fixture . debugElement . query ( By . directive ( MatGridList ) ) ;
223
279
280
+ if ( disableComputedStyleTests ) {
281
+ return ;
282
+ }
283
+
224
284
gridList . componentInstance . gutterSize = '10%' ;
225
285
fixture . detectChanges ( ) ;
226
286
@@ -232,8 +292,12 @@ describe('MatGridList', () => {
232
292
233
293
it ( 'should set the correct list height in ratio mode' , ( ) => {
234
294
const fixture = createComponent ( GridListWithRatioHeightAndMulipleRows ) ;
235
- fixture . detectChanges ( ) ;
236
295
296
+ if ( disableComputedStyleTests ) {
297
+ return ;
298
+ }
299
+
300
+ fixture . detectChanges ( ) ;
237
301
const list = fixture . debugElement . query ( By . directive ( MatGridList ) ) ;
238
302
const inlineStyles = list . nativeElement . style ;
239
303
@@ -244,14 +308,23 @@ describe('MatGridList', () => {
244
308
245
309
it ( 'should set the correct list height in fixed mode' , ( ) => {
246
310
const fixture = createComponent ( GridListWithFixRowHeightAndMultipleRows ) ;
247
- fixture . detectChanges ( ) ;
248
311
312
+ if ( disableComputedStyleTests ) {
313
+ return ;
314
+ }
315
+
316
+ fixture . detectChanges ( ) ;
249
317
const list = fixture . debugElement . query ( By . directive ( MatGridList ) ) ;
250
318
expect ( getDimension ( list , 'height' ) ) . toBe ( 201 ) ;
251
319
} ) ;
252
320
253
321
it ( 'should allow adjustment of tile colspan' , ( ) => {
254
322
const fixture = createComponent ( GridListWithColspanBinding ) ;
323
+
324
+ if ( disableComputedStyleTests ) {
325
+ return ;
326
+ }
327
+
255
328
fixture . componentInstance . colspan = 2 ;
256
329
fixture . detectChanges ( ) ;
257
330
@@ -266,6 +339,10 @@ describe('MatGridList', () => {
266
339
it ( 'should allow adjustment of tile rowspan' , ( ) => {
267
340
const fixture = createComponent ( GridListWithRowspanBinding ) ;
268
341
342
+ if ( disableComputedStyleTests ) {
343
+ return ;
344
+ }
345
+
269
346
fixture . componentInstance . rowspan = 2 ;
270
347
fixture . detectChanges ( ) ;
271
348
@@ -280,6 +357,10 @@ describe('MatGridList', () => {
280
357
it ( 'should lay out tiles correctly for a complex layout' , ( ) => {
281
358
const fixture = createComponent ( GridListWithComplexLayout ) ;
282
359
360
+ if ( disableComputedStyleTests ) {
361
+ return ;
362
+ }
363
+
283
364
fixture . componentInstance . tiles = [
284
365
{ cols : 3 , rows : 1 } ,
285
366
{ cols : 1 , rows : 2 } ,
@@ -314,6 +395,10 @@ describe('MatGridList', () => {
314
395
it ( 'should lay out tiles correctly' , ( ) => {
315
396
const fixture = createComponent ( GridListWithLayout ) ;
316
397
398
+ if ( disableComputedStyleTests ) {
399
+ return ;
400
+ }
401
+
317
402
fixture . detectChanges ( ) ;
318
403
const tiles = fixture . debugElement . queryAll ( By . css ( 'mat-grid-tile' ) ) ;
319
404
@@ -347,6 +432,10 @@ describe('MatGridList', () => {
347
432
( ) => {
348
433
const fixture = createComponent ( GridListWithSingleCellAtBeginning ) ;
349
434
435
+ if ( disableComputedStyleTests ) {
436
+ return ;
437
+ }
438
+
350
439
fixture . detectChanges ( ) ;
351
440
const tiles = fixture . debugElement . queryAll ( By . css ( 'mat-grid-tile' ) ) ;
352
441
@@ -401,6 +490,10 @@ describe('MatGridList', () => {
401
490
it ( 'should reset the old styles when switching to a new tile styler' , ( ) => {
402
491
const fixture = createComponent ( GirdListWithRowHeightRatio ) ;
403
492
493
+ if ( disableComputedStyleTests ) {
494
+ return ;
495
+ }
496
+
404
497
fixture . componentInstance . rowHeight = '4:1' ;
405
498
fixture . detectChanges ( ) ;
406
499
@@ -456,8 +549,12 @@ describe('MatGridList', () => {
456
549
457
550
it ( 'should lay out the tiles if they are not direct descendants of the list' , ( ) => {
458
551
const fixture = createComponent ( GridListWithIndirectTileDescendants ) ;
459
- fixture . detectChanges ( ) ;
460
552
553
+ if ( disableComputedStyleTests ) {
554
+ return ;
555
+ }
556
+
557
+ fixture . detectChanges ( ) ;
461
558
const tile = fixture . debugElement . query ( By . directive ( MatGridTile ) ) ;
462
559
const inlineStyles = tile . nativeElement . style ;
463
560
0 commit comments