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