@@ -16,11 +16,13 @@ import {MatchMedia} from '../../media-query/match-media';
16
16
import { FlexLayoutModule } from '../_module' ;
17
17
18
18
import { __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' ;
20
20
import {
21
21
makeExpectDOMFrom ,
22
22
makeExpectDOMForQuery ,
23
- makeCreateTestComponent
23
+ makeCreateTestComponent ,
24
+ expectNativeEl ,
25
+ queryFor
24
26
} from '../../utils/testing/helpers' ;
25
27
26
28
const getDOM = __platform_browser_private__ . getDOM ;
@@ -31,6 +33,10 @@ describe('flex directive', () => {
31
33
let expectDOMFrom = makeExpectDOMFrom ( ( ) => TestFlexComponent ) ;
32
34
let expectDomForQuery = makeExpectDOMForQuery ( ( ) => TestFlexComponent ) ;
33
35
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
+ } ;
34
40
35
41
beforeEach ( ( ) => {
36
42
jasmine . addMatchers ( customMatchers ) ;
@@ -60,10 +66,10 @@ describe('flex directive', () => {
60
66
61
67
let dom = fRef . debugElement . children [ 0 ] . nativeElement ;
62
68
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' ) ;
67
73
68
74
expect ( isBox ) . toBeTruthy ( ) ;
69
75
expect ( hasFlex ) . toBeTruthy ( ) ;
@@ -104,7 +110,7 @@ describe('flex directive', () => {
104
110
} ) ;
105
111
it ( 'should work with calc values' , ( ) => {
106
112
// @see http://caniuse.com/#feat=calc for IE issues with calc()
107
- if ( ! isIE ) {
113
+ if ( ! isIE ) {
108
114
expectDOMFrom ( `<div fxFlex="calc(30vw - 10px)"></div>` ) . toHaveCssStyle ( {
109
115
'box-sizing' : 'border-box' ,
110
116
'flex' : '1 1 calc(30vw - 10px)'
@@ -246,7 +252,70 @@ describe('flex directive', () => {
246
252
} ) ;
247
253
} ) ;
248
254
255
+ describe ( 'with responsive features' , ( ) => {
249
256
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
+ } ) ;
250
319
} ) ;
251
320
252
321
0 commit comments