@@ -16,11 +16,13 @@ import {MatchMedia} from '../../media-query/match-media';
1616import { FlexLayoutModule } from '../_module' ;
1717
1818import { __platform_browser_private__ } from '@angular/platform-browser' ;
19- import { customMatchers , expect } from '../../utils/testing/custom-matchers' ;
19+ import { customMatchers , expect } from '../../utils/testing/custom-matchers' ;
2020import {
2121 makeExpectDOMFrom ,
2222 makeExpectDOMForQuery ,
23- makeCreateTestComponent
23+ makeCreateTestComponent ,
24+ expectNativeEl ,
25+ queryFor
2426} from '../../utils/testing/helpers' ;
2527
2628const getDOM = __platform_browser_private__ . getDOM ;
@@ -31,6 +33,10 @@ describe('flex directive', () => {
3133 let expectDOMFrom = makeExpectDOMFrom ( ( ) => TestFlexComponent ) ;
3234 let expectDomForQuery = makeExpectDOMForQuery ( ( ) => TestFlexComponent ) ;
3335 let componentWithTemplate = makeCreateTestComponent ( ( ) => TestFlexComponent ) ;
36+ let activateMediaQuery = ( alias , allowOverlaps ?: boolean ) => {
37+ let matchMedia : MockMatchMedia = fixture . debugElement . injector . get ( MatchMedia ) ;
38+ matchMedia . activate ( alias , allowOverlaps ) ;
39+ } ;
3440
3541 beforeEach ( ( ) => {
3642 jasmine . addMatchers ( customMatchers ) ;
@@ -60,10 +66,10 @@ describe('flex directive', () => {
6066
6167 let dom = fRef . debugElement . children [ 0 ] . nativeElement ;
6268 let isBox = getDOM ( ) . hasStyle ( dom , 'box-sizing' , 'border-box' ) ;
63- let hasFlex = getDOM ( ) . hasStyle ( dom , 'flex' , '1 1 1e-09px' ) || // IE
64- getDOM ( ) . hasStyle ( dom , 'flex' , '1 1 1e-9px' ) || // Chrome
65- getDOM ( ) . hasStyle ( dom , 'flex' , '1 1 0.000000001px' ) || // Safari
66- getDOM ( ) . hasStyle ( dom , 'flex' , '1 1 0px' ) ;
69+ let hasFlex = getDOM ( ) . hasStyle ( dom , 'flex' , '1 1 1e-09px' ) || // IE
70+ getDOM ( ) . hasStyle ( dom , 'flex' , '1 1 1e-9px' ) || // Chrome
71+ getDOM ( ) . hasStyle ( dom , 'flex' , '1 1 0.000000001px' ) || // Safari
72+ getDOM ( ) . hasStyle ( dom , 'flex' , '1 1 0px' ) ;
6773
6874 expect ( isBox ) . toBeTruthy ( ) ;
6975 expect ( hasFlex ) . toBeTruthy ( ) ;
@@ -104,7 +110,7 @@ describe('flex directive', () => {
104110 } ) ;
105111 it ( 'should work with calc values' , ( ) => {
106112 // @see http://caniuse.com/#feat=calc for IE issues with calc()
107- if ( ! isIE ) {
113+ if ( ! isIE ) {
108114 expectDOMFrom ( `<div fxFlex="calc(30vw - 10px)"></div>` ) . toHaveCssStyle ( {
109115 'box-sizing' : 'border-box' ,
110116 'flex' : '1 1 calc(30vw - 10px)'
@@ -246,7 +252,70 @@ describe('flex directive', () => {
246252 } ) ;
247253 } ) ;
248254
255+ describe ( 'with responsive features' , ( ) => {
249256
257+ it ( 'should initialize the component with the largest matching breakpoint' , ( ) => {
258+ fixture = componentWithTemplate ( `
259+ <div fxFlex="auto"
260+ fxFlex.gt-xs="33%"
261+ fxFlex.gt-sm="50%" >
262+ </div>
263+ ` ) ;
264+
265+ activateMediaQuery ( 'xl' ) ;
266+ expectNativeEl ( fixture ) . toHaveCssStyle ( {
267+ 'flex' : '1 1 50%'
268+ } ) ;
269+
270+ activateMediaQuery ( 'sm' ) ;
271+ expectNativeEl ( fixture ) . toHaveCssStyle ( {
272+ 'flex' : '1 1 33%'
273+ } ) ;
274+ } ) ;
275+
276+ it ( 'should fallback the default layout properly' , ( ) => {
277+ fixture = componentWithTemplate ( `
278+ <div fxLayout="column">
279+ <div fxFlex="auto" fxFlex.gt-sm="50" > </div>
280+ <div fxFlex="auto" fxFlex.gt-sm="24.4"> </div>
281+ <div fxFlex="auto" fxFlex.gt-sm="25.6"> </div>
282+ </div>
283+ ` ) ;
284+
285+ activateMediaQuery ( 'sm' , true ) ;
286+ fixture . detectChanges ( ) ;
287+
288+ let nodes = queryFor ( fixture , "[fxFlex]" ) ;
289+ expect ( nodes . length ) . toEqual ( 3 ) ;
290+ expect ( nodes [ 0 ] . nativeElement ) . toHaveCssStyle ( { 'flex' : '1 1 auto' } ) ;
291+ expect ( nodes [ 1 ] . nativeElement ) . toHaveCssStyle ( { 'flex' : '1 1 auto' } ) ;
292+ expect ( nodes [ 2 ] . nativeElement ) . toHaveCssStyle ( { 'flex' : '1 1 auto' } ) ;
293+
294+ activateMediaQuery ( 'xl' , true ) ;
295+ fixture . detectChanges ( ) ;
296+
297+ nodes = queryFor ( fixture , "[fxFlex]" ) ;
298+ expect ( nodes [ 0 ] . nativeElement ) . toHaveCssStyle ( { 'flex' : '1 1 100%' , 'max-height' : '50%' } ) ;
299+ expect ( nodes [ 1 ] . nativeElement ) . toHaveCssStyle ( { 'flex' : '1 1 100%' , 'max-height' : '24.4%' } ) ;
300+ expect ( nodes [ 2 ] . nativeElement ) . toHaveCssStyle ( { 'flex' : '1 1 100%' , 'max-height' : '25.6%' } ) ;
301+
302+ activateMediaQuery ( 'sm' , true ) ;
303+ fixture . detectChanges ( ) ;
304+
305+ nodes = queryFor ( fixture , "[fxFlex]" ) ;
306+ expect ( nodes . length ) . toEqual ( 3 ) ;
307+ expect ( nodes [ 0 ] . nativeElement ) . toHaveCssStyle ( { 'flex' : '1 1 auto' } ) ;
308+ expect ( nodes [ 1 ] . nativeElement ) . toHaveCssStyle ( { 'flex' : '1 1 auto' } ) ;
309+ expect ( nodes [ 2 ] . nativeElement ) . toHaveCssStyle ( { 'flex' : '1 1 auto' } ) ;
310+
311+ expect ( nodes [ 0 ] . nativeElement ) . not . toHaveCssStyle ( { 'max-height' : '50%' } ) ;
312+ expect ( nodes [ 1 ] . nativeElement ) . not . toHaveCssStyle ( { 'max-height' : '24.4%' } ) ;
313+ expect ( nodes [ 2 ] . nativeElement ) . not . toHaveCssStyle ( { 'max-height' : '25.6%' } ) ;
314+ expect ( nodes [ 0 ] . nativeElement ) . not . toHaveCssStyle ( { 'max-height' : '*' } ) ;
315+ expect ( nodes [ 1 ] . nativeElement ) . not . toHaveCssStyle ( { 'max-height' : '*' } ) ;
316+ expect ( nodes [ 2 ] . nativeElement ) . not . toHaveCssStyle ( { 'max-height' : '*' } ) ;
317+ } ) ;
318+ } ) ;
250319} ) ;
251320
252321
0 commit comments