@@ -9,6 +9,7 @@ import {Component} from '@angular/core';
99import { CommonModule } from '@angular/common' ;
1010import { ComponentFixture , TestBed } from '@angular/core/testing' ;
1111
12+ import { DIR_DOCUMENT } from '../../bidi/directionality' ;
1213import { DEFAULT_BREAKPOINTS_PROVIDER } from '../../media-query/breakpoints/break-points-provider' ;
1314import { BreakPointRegistry } from '../../media-query/breakpoints/break-point-registry' ;
1415import { MockMatchMedia } from '../../media-query/mock/mock-match-media' ;
@@ -27,20 +28,23 @@ import {
2728describe ( 'flex directive' , ( ) => {
2829 let fixture : ComponentFixture < any > ;
2930 let expectDOMFrom = makeExpectDOMFrom ( ( ) => TestFlexComponent ) ;
31+ let fakeDocument : { body : { dir ?: string } , documentElement : { dir ?: string } } ;
3032 let componentWithTemplate = ( template : string ) => {
3133 fixture = makeCreateTestComponent ( ( ) => TestFlexComponent ) ( template ) ;
3234 } ;
3335
3436 beforeEach ( ( ) => {
3537 jasmine . addMatchers ( customMatchers ) ;
38+ fakeDocument = { body : { } , documentElement : { } } ;
3639
3740 // Configure testbed to prepare services
3841 TestBed . configureTestingModule ( {
3942 imports : [ CommonModule , FlexLayoutModule ] ,
4043 declarations : [ TestFlexComponent ] ,
4144 providers : [
4245 BreakPointRegistry , DEFAULT_BREAKPOINTS_PROVIDER ,
43- { provide : MatchMedia , useClass : MockMatchMedia }
46+ { provide : MatchMedia , useClass : MockMatchMedia } ,
47+ { provide : DIR_DOCUMENT , useValue : fakeDocument }
4448 ]
4549 } ) ;
4650 } ) ;
@@ -134,6 +138,44 @@ describe('flex directive', () => {
134138 } ) ;
135139 } ) ;
136140
141+ it ( 'should set margin-right for rtl layouts on document body' , ( ) => {
142+ fakeDocument . body . dir = 'rtl' ;
143+ componentWithTemplate ( `
144+ <div fxLayout='row' class='test'>
145+ <div fxFlex='30px' fxFlexOffset='17px'> </div>
146+ </div>
147+ ` ) ;
148+ fixture . detectChanges ( ) ;
149+
150+ let element = queryFor ( fixture , '[fxFlex]' ) [ 0 ] . nativeElement ;
151+ expect ( element ) . toHaveStyle ( { 'margin-right' : '17px' } ) ;
152+ } ) ;
153+
154+ it ( 'should set margin-right for rtl layouts on documentElement' , ( ) => {
155+ fakeDocument . documentElement . dir = 'rtl' ;
156+ componentWithTemplate ( `
157+ <div fxLayout='row' class='test'>
158+ <div fxFlex='30px' fxFlexOffset='17px'> </div>
159+ </div>
160+ ` ) ;
161+ fixture . detectChanges ( ) ;
162+
163+ let element = queryFor ( fixture , '[fxFlex]' ) [ 0 ] . nativeElement ;
164+ expect ( element ) . toHaveStyle ( { 'margin-right' : '17px' } ) ;
165+ } ) ;
166+
167+ it ( 'should set margin-left for ltr layouts' , ( ) => {
168+ componentWithTemplate ( `
169+ <div fxLayout='row' class='test'>
170+ <div fxFlex='30px' fxFlexOffset='17px'> </div>
171+ </div>
172+ ` ) ;
173+ fixture . detectChanges ( ) ;
174+
175+ let element = queryFor ( fixture , '[fxFlex]' ) [ 0 ] . nativeElement ;
176+ expect ( element ) . toHaveStyle ( { 'margin-left' : '17px' } ) ;
177+ } ) ;
178+
137179 } ) ;
138180
139181} ) ;
0 commit comments