@@ -9,6 +9,7 @@ import {Component} from '@angular/core';
9
9
import { CommonModule } from '@angular/common' ;
10
10
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
11
11
12
+ import { DIR_DOCUMENT } from '../../bidi/directionality' ;
12
13
import { DEFAULT_BREAKPOINTS_PROVIDER } from '../../media-query/breakpoints/break-points-provider' ;
13
14
import { BreakPointRegistry } from '../../media-query/breakpoints/break-point-registry' ;
14
15
import { MockMatchMedia } from '../../media-query/mock/mock-match-media' ;
@@ -27,20 +28,23 @@ import {
27
28
describe ( 'flex directive' , ( ) => {
28
29
let fixture : ComponentFixture < any > ;
29
30
let expectDOMFrom = makeExpectDOMFrom ( ( ) => TestFlexComponent ) ;
31
+ let fakeDocument : { body : { dir ?: string } , documentElement : { dir ?: string } } ;
30
32
let componentWithTemplate = ( template : string ) => {
31
33
fixture = makeCreateTestComponent ( ( ) => TestFlexComponent ) ( template ) ;
32
34
} ;
33
35
34
36
beforeEach ( ( ) => {
35
37
jasmine . addMatchers ( customMatchers ) ;
38
+ fakeDocument = { body : { } , documentElement : { } } ;
36
39
37
40
// Configure testbed to prepare services
38
41
TestBed . configureTestingModule ( {
39
42
imports : [ CommonModule , FlexLayoutModule ] ,
40
43
declarations : [ TestFlexComponent ] ,
41
44
providers : [
42
45
BreakPointRegistry , DEFAULT_BREAKPOINTS_PROVIDER ,
43
- { provide : MatchMedia , useClass : MockMatchMedia }
46
+ { provide : MatchMedia , useClass : MockMatchMedia } ,
47
+ { provide : DIR_DOCUMENT , useValue : fakeDocument }
44
48
]
45
49
} ) ;
46
50
} ) ;
@@ -134,6 +138,44 @@ describe('flex directive', () => {
134
138
} ) ;
135
139
} ) ;
136
140
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
+
137
179
} ) ;
138
180
139
181
} ) ;
0 commit comments