1
1
import { inject , async } from '@angular/core/testing' ;
2
2
import { TestComponentBuilder } from '@angular/compiler/testing' ;
3
- import { Component } from '@angular/core' ;
3
+ import { Component , DebugElement } from '@angular/core' ;
4
4
import { By } from '@angular/platform-browser' ;
5
5
6
6
import { MD_GRID_LIST_DIRECTIVES , MdGridList } from './grid-list' ;
@@ -160,7 +160,7 @@ describe('MdGridList', () => {
160
160
161
161
// check horizontal gutter
162
162
expect ( getProp ( tiles [ 0 ] , 'width' ) ) . toBe ( '99.5px' ) ;
163
- expect ( getProp ( tiles [ 1 ] , 'left' ) ) . toBe ( ' 100.5px' ) ;
163
+ expect ( getComputedLeft ( tiles [ 1 ] ) ) . toBe ( 100.5 ) ;
164
164
165
165
// check vertical gutter
166
166
expect ( getProp ( tiles [ 0 ] , 'height' ) ) . toBe ( '100px' ) ;
@@ -186,7 +186,7 @@ describe('MdGridList', () => {
186
186
187
187
// check horizontal gutter
188
188
expect ( getProp ( tiles [ 0 ] , 'width' ) ) . toBe ( '99px' ) ;
189
- expect ( getProp ( tiles [ 1 ] , 'left' ) ) . toBe ( '101px' ) ;
189
+ expect ( getComputedLeft ( tiles [ 1 ] ) ) . toBe ( 101 ) ;
190
190
191
191
// check vertical gutter
192
192
expect ( getProp ( tiles [ 0 ] , 'height' ) ) . toBe ( '100px' ) ;
@@ -212,7 +212,7 @@ describe('MdGridList', () => {
212
212
213
213
// check horizontal gutter
214
214
expect ( getProp ( tiles [ 0 ] , 'width' ) ) . toBe ( '99px' ) ;
215
- expect ( getProp ( tiles [ 1 ] , 'left' ) ) . toBe ( '101px' ) ;
215
+ expect ( getComputedLeft ( tiles [ 1 ] ) ) . toBe ( 101 ) ;
216
216
217
217
// check vertical gutter
218
218
expect ( getProp ( tiles [ 0 ] , 'height' ) ) . toBe ( '100px' ) ;
@@ -317,22 +317,22 @@ describe('MdGridList', () => {
317
317
318
318
expect ( getProp ( tiles [ 0 ] , 'width' ) ) . toBe ( '299.75px' ) ;
319
319
expect ( getProp ( tiles [ 0 ] , 'height' ) ) . toBe ( '100px' ) ;
320
- expect ( getProp ( tiles [ 0 ] , 'left' ) ) . toBe ( '0px' ) ;
320
+ expect ( getComputedLeft ( tiles [ 0 ] ) ) . toBe ( 0 ) ;
321
321
expect ( getProp ( tiles [ 0 ] , 'top' ) ) . toBe ( '0px' ) ;
322
322
323
323
expect ( getProp ( tiles [ 1 ] , 'width' ) ) . toBe ( '99.25px' ) ;
324
324
expect ( getProp ( tiles [ 1 ] , 'height' ) ) . toBe ( '201px' ) ;
325
- expect ( getProp ( tiles [ 1 ] , 'left' ) ) . toBe ( ' 300.75px' ) ;
325
+ expect ( getComputedLeft ( tiles [ 1 ] ) ) . toBe ( 300.75 ) ;
326
326
expect ( getProp ( tiles [ 1 ] , 'top' ) ) . toBe ( '0px' ) ;
327
327
328
328
expect ( getProp ( tiles [ 2 ] , 'width' ) ) . toBe ( '99.25px' ) ;
329
329
expect ( getProp ( tiles [ 2 ] , 'height' ) ) . toBe ( '100px' ) ;
330
- expect ( getProp ( tiles [ 2 ] , 'left' ) ) . toBe ( '0px' ) ;
330
+ expect ( getComputedLeft ( tiles [ 2 ] ) ) . toBe ( 0 ) ;
331
331
expect ( getProp ( tiles [ 2 ] , 'top' ) ) . toBe ( '101px' ) ;
332
332
333
333
expect ( getProp ( tiles [ 3 ] , 'width' ) ) . toBe ( '199.5px' ) ;
334
334
expect ( getProp ( tiles [ 3 ] , 'height' ) ) . toBe ( '100px' ) ;
335
- expect ( getProp ( tiles [ 3 ] , 'left' ) ) . toBe ( ' 100.25px' ) ;
335
+ expect ( getComputedLeft ( tiles [ 3 ] ) ) . toBe ( 100.25 ) ;
336
336
expect ( getProp ( tiles [ 3 ] , 'top' ) ) . toBe ( '101px' ) ;
337
337
} ) ;
338
338
} ) ;
@@ -389,6 +389,18 @@ class TestGridList {
389
389
rowspan : number ;
390
390
}
391
391
392
- function getProp ( el : any , prop : string ) : string {
392
+ function getProp ( el : DebugElement , prop : string ) : string {
393
393
return getComputedStyle ( el . nativeElement ) . getPropertyValue ( prop ) ;
394
394
}
395
+
396
+ /** Gets the `left` position of an element. */
397
+ function getComputedLeft ( element : DebugElement ) : number {
398
+ // While the other properties in this test use `getComputedStyle`, we use `getBoundingClientRect`
399
+ // for left because iOS Safari doesn't support using `getComputedStyle` to get the calculated
400
+ // `left` balue when using CSS `calc`. We subtract the `left` of the document body because
401
+ // browsers, by default, add a margin to the body (typically 8px).
402
+ let elementRect = element . nativeElement . getBoundingClientRect ( ) ;
403
+ let bodyRect = document . body . getBoundingClientRect ( ) ;
404
+
405
+ return elementRect . left - bodyRect . left ;
406
+ }
0 commit comments