@@ -10,6 +10,8 @@ import {CommonModule, isPlatformServer} from '@angular/common';
10
10
import { TestBed , ComponentFixture , async , inject } from '@angular/core/testing' ;
11
11
import { DIR_DOCUMENT } from '@angular/cdk/bidi' ;
12
12
import {
13
+ MatchMedia ,
14
+ MockMatchMedia ,
13
15
MockMatchMediaProvider ,
14
16
SERVER_TOKEN ,
15
17
StyleBuilder ,
@@ -32,9 +34,12 @@ describe('layout-gap directive', () => {
32
34
let fakeDocument : { body : { dir ?: string } , documentElement : { dir ?: string } } ;
33
35
let styler : StyleUtils ;
34
36
let platformId : Object ;
37
+ let matchMedia : MockMatchMedia ;
35
38
let createTestComponent = ( template : string , styles ?: any ) => {
36
39
fixture = makeCreateTestComponent ( ( ) => TestLayoutGapComponent ) ( template , styles ) ;
37
- inject ( [ StyleUtils , PLATFORM_ID ] , ( _styler : StyleUtils , _platformId : Object ) => {
40
+ inject ( [ MatchMedia , StyleUtils , PLATFORM_ID ] ,
41
+ ( _matchMedia : MockMatchMedia , _styler : StyleUtils , _platformId : Object ) => {
42
+ matchMedia = _matchMedia ;
38
43
styler = _styler ;
39
44
platformId = _platformId ;
40
45
} ) ( ) ;
@@ -49,6 +54,7 @@ describe('layout-gap directive', () => {
49
54
imports : [ CommonModule , FlexLayoutModule ] ,
50
55
declarations : [ TestLayoutGapComponent ] ,
51
56
providers : [
57
+ MockMatchMediaProvider ,
52
58
{ provide : DIR_DOCUMENT , useValue : fakeDocument } ,
53
59
{ provide : SERVER_TOKEN , useValue : true }
54
60
]
@@ -332,7 +338,80 @@ describe('layout-gap directive', () => {
332
338
} ) ;
333
339
334
340
describe ( 'with responsive features' , ( ) => {
335
- // TODO(ThomasBurleson): add tests here
341
+ it ( 'should set gap on breakpoint change' , ( ) => {
342
+ let template = `
343
+ <div fxLayoutAlign='center center' fxLayoutGap='13px' fxLayoutGap.md="24px">
344
+ <div fxFlex></div>
345
+ <div fxFlex></div>
346
+ <div fxFlex></div>
347
+ </div>
348
+ ` ;
349
+ createTestComponent ( template ) ;
350
+ fixture . detectChanges ( ) ;
351
+
352
+ let nodes = queryFor ( fixture , '[fxFlex]' ) ;
353
+ expect ( nodes . length ) . toEqual ( 3 ) ;
354
+ expectEl ( nodes [ 0 ] ) . toHaveStyle ( { 'margin-right' : '13px' } , styler ) ;
355
+ expectEl ( nodes [ 1 ] ) . toHaveStyle ( { 'margin-right' : '13px' } , styler ) ;
356
+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '13px' } , styler ) ;
357
+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '0px' } , styler ) ;
358
+
359
+ matchMedia . activate ( 'md' ) ;
360
+ fixture . detectChanges ( ) ;
361
+ expectEl ( nodes [ 0 ] ) . toHaveStyle ( { 'margin-right' : '24px' } , styler ) ;
362
+ expectEl ( nodes [ 1 ] ) . toHaveStyle ( { 'margin-right' : '24px' } , styler ) ;
363
+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '24px' } , styler ) ;
364
+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '0px' } , styler ) ;
365
+ } ) ;
366
+
367
+ it ( 'should set gap without fallback' , ( ) => {
368
+ let template = `
369
+ <div fxLayoutAlign='center center' fxLayoutGap.md="24px">
370
+ <div fxFlex></div>
371
+ <div fxFlex></div>
372
+ <div fxFlex></div>
373
+ </div>
374
+ ` ;
375
+ createTestComponent ( template ) ;
376
+ fixture . detectChanges ( ) ;
377
+
378
+ let nodes = queryFor ( fixture , '[fxFlex]' ) ;
379
+ expect ( nodes . length ) . toEqual ( 3 ) ;
380
+ expectEl ( nodes [ 0 ] ) . not . toHaveStyle ( { 'margin-right' : '*' } , styler ) ;
381
+ expectEl ( nodes [ 1 ] ) . not . toHaveStyle ( { 'margin-right' : '*' } , styler ) ;
382
+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '*' } , styler ) ;
383
+
384
+ matchMedia . activate ( 'md' ) ;
385
+ fixture . detectChanges ( ) ;
386
+ expectEl ( nodes [ 0 ] ) . toHaveStyle ( { 'margin-right' : '24px' } , styler ) ;
387
+ expectEl ( nodes [ 1 ] ) . toHaveStyle ( { 'margin-right' : '24px' } , styler ) ;
388
+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '24px' } , styler ) ;
389
+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '0px' } , styler ) ;
390
+ } ) ;
391
+
392
+ it ( 'should set gap with responsive layout change' , ( ) => {
393
+ let template = `
394
+ <div fxLayout="row" fxLayout.xs="column" fxLayoutGap="24px">
395
+ <div fxFlex></div>
396
+ <div fxFlex></div>
397
+ <div fxFlex></div>
398
+ </div>
399
+ ` ;
400
+ createTestComponent ( template ) ;
401
+ fixture . detectChanges ( ) ;
402
+
403
+ let nodes = queryFor ( fixture , '[fxFlex]' ) ;
404
+ expect ( nodes . length ) . toEqual ( 3 ) ;
405
+ expectEl ( nodes [ 0 ] ) . toHaveStyle ( { 'margin-right' : '24px' } , styler ) ;
406
+ expectEl ( nodes [ 1 ] ) . toHaveStyle ( { 'margin-right' : '24px' } , styler ) ;
407
+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '*' } , styler ) ;
408
+
409
+ matchMedia . activate ( 'xs' ) ;
410
+ fixture . detectChanges ( ) ;
411
+ expectEl ( nodes [ 0 ] ) . toHaveStyle ( { 'margin-bottom' : '24px' } , styler ) ;
412
+ expectEl ( nodes [ 1 ] ) . toHaveStyle ( { 'margin-bottom' : '24px' } , styler ) ;
413
+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-bottom' : '*' } , styler ) ;
414
+ } ) ;
336
415
} ) ;
337
416
338
417
describe ( 'rtl support' , ( ) => {
@@ -412,7 +491,6 @@ describe('layout-gap directive', () => {
412
491
] ,
413
492
declarations : [ ] ,
414
493
providers : [
415
- MockMatchMediaProvider ,
416
494
{
417
495
provide : LayoutGapStyleBuilder ,
418
496
useClass : MockLayoutGapStyleBuilder ,
0 commit comments