11import { inject , async } from '@angular/core/testing' ;
22import { TestComponentBuilder } from '@angular/compiler/testing' ;
3- import { Component } from '@angular/core' ;
3+ import { Component , DebugElement } from '@angular/core' ;
44import { By } from '@angular/platform-browser' ;
55
66import { MD_GRID_LIST_DIRECTIVES , MdGridList } from './grid-list' ;
@@ -160,7 +160,7 @@ describe('MdGridList', () => {
160160
161161 // check horizontal gutter
162162 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 ) ;
164164
165165 // check vertical gutter
166166 expect ( getProp ( tiles [ 0 ] , 'height' ) ) . toBe ( '100px' ) ;
@@ -186,7 +186,7 @@ describe('MdGridList', () => {
186186
187187 // check horizontal gutter
188188 expect ( getProp ( tiles [ 0 ] , 'width' ) ) . toBe ( '99px' ) ;
189- expect ( getProp ( tiles [ 1 ] , 'left' ) ) . toBe ( '101px' ) ;
189+ expect ( getComputedLeft ( tiles [ 1 ] ) ) . toBe ( 101 ) ;
190190
191191 // check vertical gutter
192192 expect ( getProp ( tiles [ 0 ] , 'height' ) ) . toBe ( '100px' ) ;
@@ -212,7 +212,7 @@ describe('MdGridList', () => {
212212
213213 // check horizontal gutter
214214 expect ( getProp ( tiles [ 0 ] , 'width' ) ) . toBe ( '99px' ) ;
215- expect ( getProp ( tiles [ 1 ] , 'left' ) ) . toBe ( '101px' ) ;
215+ expect ( getComputedLeft ( tiles [ 1 ] ) ) . toBe ( 101 ) ;
216216
217217 // check vertical gutter
218218 expect ( getProp ( tiles [ 0 ] , 'height' ) ) . toBe ( '100px' ) ;
@@ -317,22 +317,22 @@ describe('MdGridList', () => {
317317
318318 expect ( getProp ( tiles [ 0 ] , 'width' ) ) . toBe ( '299.75px' ) ;
319319 expect ( getProp ( tiles [ 0 ] , 'height' ) ) . toBe ( '100px' ) ;
320- expect ( getProp ( tiles [ 0 ] , 'left' ) ) . toBe ( '0px' ) ;
320+ expect ( getComputedLeft ( tiles [ 0 ] ) ) . toBe ( 0 ) ;
321321 expect ( getProp ( tiles [ 0 ] , 'top' ) ) . toBe ( '0px' ) ;
322322
323323 expect ( getProp ( tiles [ 1 ] , 'width' ) ) . toBe ( '99.25px' ) ;
324324 expect ( getProp ( tiles [ 1 ] , 'height' ) ) . toBe ( '201px' ) ;
325- expect ( getProp ( tiles [ 1 ] , 'left' ) ) . toBe ( ' 300.75px' ) ;
325+ expect ( getComputedLeft ( tiles [ 1 ] ) ) . toBe ( 300.75 ) ;
326326 expect ( getProp ( tiles [ 1 ] , 'top' ) ) . toBe ( '0px' ) ;
327327
328328 expect ( getProp ( tiles [ 2 ] , 'width' ) ) . toBe ( '99.25px' ) ;
329329 expect ( getProp ( tiles [ 2 ] , 'height' ) ) . toBe ( '100px' ) ;
330- expect ( getProp ( tiles [ 2 ] , 'left' ) ) . toBe ( '0px' ) ;
330+ expect ( getComputedLeft ( tiles [ 2 ] ) ) . toBe ( 0 ) ;
331331 expect ( getProp ( tiles [ 2 ] , 'top' ) ) . toBe ( '101px' ) ;
332332
333333 expect ( getProp ( tiles [ 3 ] , 'width' ) ) . toBe ( '199.5px' ) ;
334334 expect ( getProp ( tiles [ 3 ] , 'height' ) ) . toBe ( '100px' ) ;
335- expect ( getProp ( tiles [ 3 ] , 'left' ) ) . toBe ( ' 100.25px' ) ;
335+ expect ( getComputedLeft ( tiles [ 3 ] ) ) . toBe ( 100.25 ) ;
336336 expect ( getProp ( tiles [ 3 ] , 'top' ) ) . toBe ( '101px' ) ;
337337 } ) ;
338338 } ) ;
@@ -389,6 +389,18 @@ class TestGridList {
389389 rowspan : number ;
390390}
391391
392- function getProp ( el : any , prop : string ) : string {
392+ function getProp ( el : DebugElement , prop : string ) : string {
393393 return getComputedStyle ( el . nativeElement ) . getPropertyValue ( prop ) ;
394394}
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