@@ -17,7 +17,7 @@ import {ObservableMediaService} from '../../media-query/observable-media-service
17
17
import { BreakPointsProvider } from '../../media-query/providers/break-points-provider' ;
18
18
import { BreakPointRegistry } from '../../media-query/breakpoints/break-point-registry' ;
19
19
20
- import { customMatchers , expect } from '../../utils/testing/custom-matchers' ;
20
+ import { customMatchers , expect , NgMatchers } from '../../utils/testing/custom-matchers' ;
21
21
import {
22
22
makeCreateTestComponent , expectNativeEl , queryFor
23
23
} from '../../utils/testing/helpers' ;
@@ -27,9 +27,22 @@ import {MediaQueriesModule} from '../../media-query/_module';
27
27
describe ( 'hide directive' , ( ) => {
28
28
let fixture : ComponentFixture < any > ;
29
29
let createTestComponent = makeCreateTestComponent ( ( ) => TestHideComponent ) ;
30
- let activateMediaQuery = ( alias ) => {
30
+ let activateMediaQuery : Function = ( alias , useOverlaps = false ) : void => {
31
31
let matchMedia : MockMatchMedia = fixture . debugElement . injector . get ( MatchMedia ) ;
32
- matchMedia . activate ( alias ) ;
32
+ matchMedia . activate ( alias , useOverlaps ) ;
33
+ } ;
34
+ let makeExpectWithActivation = ( _fixture_ : ComponentFixture < any > , selector : string ) => {
35
+ fixture = _fixture_ ;
36
+ return ( alias ?: string ) : NgMatchers => {
37
+ if ( alias ) {
38
+ activateMediaQuery ( alias ) ;
39
+ }
40
+ fixture . detectChanges ( ) ;
41
+
42
+ let nodes = queryFor ( fixture , selector ) ;
43
+ expect ( nodes . length ) . toEqual ( 1 ) ;
44
+ return expect ( nodes [ 0 ] . nativeElement ) ;
45
+ } ;
33
46
} ;
34
47
35
48
beforeEach ( ( ) => {
@@ -102,7 +115,7 @@ describe('hide directive', () => {
102
115
</button>
103
116
` ) ;
104
117
expectNativeEl ( fixture , { isHidden : true } ) . toHaveCssStyle ( { 'display' : 'none' } ) ;
105
- expectNativeEl ( fixture , { isHidden : false } ) . toHaveCssStyle ( { 'display' : 'block' } ) ;
118
+ expectNativeEl ( fixture , { isHidden : false } ) . toHaveCssStyle ( { 'display' : 'inline- block' } ) ;
106
119
} ) ;
107
120
108
121
it ( 'should use "flex" display style when the element also has an fxLayout' , ( ) => {
@@ -226,23 +239,41 @@ describe('hide directive', () => {
226
239
</div>
227
240
</div>
228
241
` ;
242
+ let expectActivation = makeExpectWithActivation ( createTestComponent ( template ) , '.hideOnMd' ) ;
229
243
230
- fixture = createTestComponent ( template ) ;
231
- fixture . detectChanges ( ) ;
232
-
233
- let nodes = queryFor ( fixture , ".hideOnMd" ) ;
234
- expect ( nodes . length ) . toEqual ( 1 ) ;
235
- expect ( nodes [ 0 ] . nativeElement ) . toHaveCssStyle ( { 'display' : 'block' } ) ;
244
+ expectActivation ( ) . toHaveCssStyle ( { 'display' : 'block' } ) ;
245
+ expectActivation ( 'md' ) . toHaveCssStyle ( { 'display' : 'none' } ) ;
246
+ } ) ;
236
247
237
- activateMediaQuery ( 'md' ) ;
238
- fixture . detectChanges ( ) ;
248
+ it ( 'should restore proper display mode when not hiding' , ( ) => {
249
+ let template = `
250
+ <div>
251
+ <span fxHide.xs class="hideOnXs">Label</span>
252
+ </div>
253
+ ` ;
254
+ let expectActivation = makeExpectWithActivation ( createTestComponent ( template ) , '.hideOnXs' ) ;
239
255
240
- nodes = queryFor ( fixture , ".hideOnMd" ) ;
241
- expect ( nodes . length ) . toEqual ( 1 ) ;
242
- expect ( nodes [ 0 ] . nativeElement ) . toHaveCssStyle ( { 'display' : 'none ' } ) ;
256
+ expectActivation ( ) . toHaveCssStyle ( { 'display' : 'inline' } ) ;
257
+ expectActivation ( 'xs' ) . toHaveCssStyle ( { 'display' : 'none' } ) ;
258
+ expectActivation ( 'md' ) . toHaveCssStyle ( { 'display' : 'inline ' } ) ;
243
259
} ) ;
244
260
} ) ;
245
261
262
+ it ( 'should support hide and show' , ( ) => {
263
+ fixture = createTestComponent ( `
264
+ <div fxShow fxHide.gt-sm style="display:inline-block;">
265
+ This content to be shown ONLY when gt-sm
266
+ </div>
267
+ ` ) ;
268
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'inline-block' } ) ;
269
+
270
+ activateMediaQuery ( 'md' , true ) ;
271
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'none' } ) ;
272
+
273
+ activateMediaQuery ( 'xs' , true ) ;
274
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'inline-block' } ) ;
275
+ } ) ;
276
+
246
277
} ) ;
247
278
248
279
0 commit comments