5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { Component , OnInit , Inject } from '@angular/core' ;
8
+ import {
9
+ Component , OnInit , Inject
10
+ } from '@angular/core' ;
9
11
import { CommonModule } from '@angular/common' ;
10
12
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
11
13
12
14
import { MockMatchMedia } from '../../media-query/mock/mock-match-media' ;
13
15
import { MatchMedia , MatchMediaObservable } from '../../media-query/match-media' ;
14
16
import { BreakPointsProvider } from '../../media-query/providers/break-points-provider' ;
15
17
import { BreakPointRegistry } from '../../media-query/breakpoints/break-point-registry' ;
16
- import { FlexLayoutModule } from '../_module' ;
17
18
18
19
import { customMatchers } from '../../utils/testing/custom-matchers' ;
19
- import { makeCreateTestComponent , expectNativeEl } from '../../utils/testing/helpers' ;
20
+ import {
21
+ makeCreateTestComponent , expectNativeEl ,
22
+ } from '../../utils/testing/helpers' ;
23
+ import { HideDirective } from './hide' ;
24
+ import { MediaQueriesModule } from '../../media-query/_module' ;
20
25
21
- describe ( 'show directive' , ( ) => {
26
+ describe ( 'hide directive' , ( ) => {
22
27
let fixture : ComponentFixture < any > ;
23
28
let createTestComponent = makeCreateTestComponent ( ( ) => TestHideComponent ) ;
24
29
let activateMediaQuery = ( alias ) => {
@@ -29,10 +34,11 @@ describe('show directive', () => {
29
34
beforeEach ( ( ) => {
30
35
jasmine . addMatchers ( customMatchers ) ;
31
36
37
+
32
38
// Configure testbed to prepare services
33
39
TestBed . configureTestingModule ( {
34
- imports : [ CommonModule , FlexLayoutModule . forRoot ( ) ] ,
35
- declarations : [ TestHideComponent ] ,
40
+ imports : [ CommonModule , MediaQueriesModule . forRoot ( ) ] ,
41
+ declarations : [ TestHideComponent , HideDirective ] ,
36
42
providers : [
37
43
BreakPointRegistry , BreakPointsProvider ,
38
44
{ provide : MatchMedia , useClass : MockMatchMedia }
@@ -77,7 +83,7 @@ describe('show directive', () => {
77
83
78
84
it ( 'should update styles with binding changes' , ( ) => {
79
85
fixture = createTestComponent ( `
80
- <div [fxHide]="menuHidden" >
86
+ <div [fxHide]="menuHidden">
81
87
...content
82
88
</div>
83
89
` ) ;
@@ -92,7 +98,7 @@ describe('show directive', () => {
92
98
93
99
describe ( 'with responsive features' , ( ) => {
94
100
95
- it ( 'should show on `xs` viewports only' , ( ) => {
101
+ it ( 'should show on `xs` viewports only when the default is included ' , ( ) => {
96
102
fixture = createTestComponent ( `
97
103
<div fxHide="" fxHide.xs="false" >
98
104
...content
@@ -108,6 +114,52 @@ describe('show directive', () => {
108
114
109
115
} ) ;
110
116
117
+ it ( 'should preserve display and update only on activated mediaQuery' , ( ) => {
118
+ fixture = createTestComponent ( `
119
+ <div [fxHide.xs]="isHidden" style="display:inline-block"></div>
120
+ ` ) ;
121
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'inline-block' } ) ;
122
+
123
+ // should hide with this activation
124
+ activateMediaQuery ( 'xs' ) ;
125
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'none' } ) ;
126
+
127
+ // should reset to original display style
128
+ activateMediaQuery ( 'md' ) ;
129
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'inline-block' } ) ;
130
+ } ) ;
131
+
132
+ it ( 'should restore original display when disabled' , ( ) => {
133
+ fixture = createTestComponent ( `
134
+ <div [fxHide.xs]="isHidden" style="display:inline-block"></div>
135
+ ` ) ;
136
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'inline-block' } ) ;
137
+
138
+ // should hide with this activation
139
+ activateMediaQuery ( 'xs' ) ;
140
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'none' } ) ;
141
+
142
+ // should reset to original display style
143
+ fixture . componentInstance . isHidden = false ;
144
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'inline-block' } ) ;
145
+ } ) ;
146
+
147
+ it ( 'should restore original display when the mediaQuery deactivates' , ( ) => {
148
+ let originalDisplay = { 'display' : 'table' } ;
149
+ fixture = createTestComponent ( `
150
+ <div [fxHide.xs]="isHidden" style="display:table"></div>
151
+ ` ) ;
152
+ expectNativeEl ( fixture ) . toHaveCssStyle ( originalDisplay ) ;
153
+
154
+ // should hide with this activation
155
+ activateMediaQuery ( 'xs' ) ;
156
+ expectNativeEl ( fixture ) . toHaveCssStyle ( { 'display' : 'none' } ) ;
157
+
158
+ // should reset to original display style
159
+ activateMediaQuery ( 'md' ) ;
160
+ expectNativeEl ( fixture ) . toHaveCssStyle ( originalDisplay ) ;
161
+ } ) ;
162
+
111
163
it ( 'should support use of the `media` observable in templates ' , ( ) => {
112
164
fixture = createTestComponent ( `
113
165
<div [fxHide]="media.isActive('xs')" >
@@ -150,7 +202,8 @@ describe('show directive', () => {
150
202
} )
151
203
export class TestHideComponent implements OnInit {
152
204
isVisible = 0 ;
153
- menuHidden : boolean = true ;
205
+ isHidden = true ;
206
+ menuHidden = true ;
154
207
155
208
constructor ( @Inject ( MatchMediaObservable ) private media ) {
156
209
}
0 commit comments