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 , PLATFORM_ID } from '@angular/core' ;
9
- import { CommonModule , isPlatformServer } from '@angular/common' ;
8
+ import { Component , OnInit } from '@angular/core' ;
9
+ import { CommonModule } from '@angular/common' ;
10
10
import { ComponentFixture , TestBed , inject } from '@angular/core/testing' ;
11
11
import {
12
12
MatchMedia ,
@@ -29,15 +29,12 @@ describe('hide directive', () => {
29
29
let fixture : ComponentFixture < any > ;
30
30
let matchMedia : MockMatchMedia ;
31
31
let styler : StyleUtils ;
32
- let platformId : Object ;
33
32
let createTestComponent = ( template : string ) => {
34
33
fixture = makeCreateTestComponent ( ( ) => TestHideComponent ) ( template ) ;
35
34
36
- inject ( [ MatchMedia , StyleUtils , PLATFORM_ID ] ,
37
- ( _matchMedia : MockMatchMedia , _styler : StyleUtils , _platformId : Object ) => {
35
+ inject ( [ MatchMedia , StyleUtils ] , ( _matchMedia : MockMatchMedia , _styler : StyleUtils ) => {
38
36
matchMedia = _matchMedia ;
39
37
styler = _styler ;
40
- platformId = _platformId ;
41
38
} ) ( ) ;
42
39
43
40
return fixture ;
@@ -80,19 +77,19 @@ describe('hide directive', () => {
80
77
81
78
it ( 'should initial with component visible when set to `false`' , ( ) => {
82
79
createTestComponent ( `<div fxHide="false"></div>` ) ;
83
- expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
80
+ expectNativeEl ( fixture ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
84
81
} ) ;
85
82
86
83
it ( 'should initial with component visible when set to `0`' , ( ) => {
87
84
createTestComponent ( `<div [fxHide]="isVisible"></div>` ) ;
88
- expectNativeEl ( fixture , { isVisible : 0 } ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
85
+ expectNativeEl ( fixture , { isVisible : 0 } ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
89
86
} ) ;
90
87
91
88
it ( 'should update styles with binding changes' , ( ) => {
92
89
createTestComponent ( `<div [fxHide]="menuHidden"></div>` ) ;
93
90
expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'none' } , styler ) ;
94
91
fixture . componentInstance . toggleMenu ( ) ;
95
- expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
92
+ expectNativeEl ( fixture ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
96
93
fixture . componentInstance . toggleMenu ( ) ;
97
94
expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'none' } , styler ) ;
98
95
} ) ;
@@ -103,16 +100,15 @@ describe('hide directive', () => {
103
100
'display' : 'none'
104
101
} , styler ) ;
105
102
106
- // TODO(CaerusKaru): Domino doesn't calculate the right styles here
107
- expectNativeEl ( fixture , { isHidden : false } ) . toHaveStyle ( {
108
- 'display' : isPlatformServer ( platformId ) ? 'block' : 'inline-block'
103
+ expectNativeEl ( fixture , { isHidden : false } ) . not . toHaveStyle ( {
104
+ 'display' : 'none'
109
105
} , styler ) ;
110
106
} ) ;
111
107
112
108
it ( 'should use "flex" display style when the element also has an fxLayout' , ( ) => {
113
109
createTestComponent ( `<div fxLayout [fxHide]="isHidden"></div>` ) ;
114
110
expectNativeEl ( fixture , { isHidden : true } ) . toHaveStyle ( { 'display' : 'none' } , styler ) ;
115
- expectNativeEl ( fixture , { isHidden : false } ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
111
+ expectNativeEl ( fixture , { isHidden : false } ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
116
112
} ) ;
117
113
118
114
@@ -125,7 +121,7 @@ describe('hide directive', () => {
125
121
126
122
expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'none' } , styler ) ;
127
123
matchMedia . activate ( 'xs' ) ;
128
- expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
124
+ expectNativeEl ( fixture ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
129
125
matchMedia . activate ( 'md' ) ;
130
126
expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'none' } , styler ) ;
131
127
} ) ;
@@ -172,24 +168,24 @@ describe('hide directive', () => {
172
168
173
169
it ( 'should support use of the `media` observable in templates ' , ( ) => {
174
170
createTestComponent ( `<div [fxHide]="media.isActive('xs')"></div>` ) ;
175
- expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
171
+ expectNativeEl ( fixture ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
176
172
177
173
matchMedia . activate ( 'xs' ) ;
178
174
expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'none' } , styler ) ;
179
175
180
176
matchMedia . activate ( 'lg' ) ;
181
- expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
177
+ expectNativeEl ( fixture ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
182
178
} ) ;
183
179
184
180
it ( 'should support use of the `media` observable in adaptive templates ' , ( ) => {
185
181
createTestComponent ( `<div fxHide="false" [fxHide.md]="media.isActive('xs')"></div>` ) ;
186
- expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
182
+ expectNativeEl ( fixture ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
187
183
188
184
matchMedia . activate ( 'xs' ) ;
189
- expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
185
+ expectNativeEl ( fixture ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
190
186
191
187
matchMedia . activate ( 'md' ) ;
192
- expectNativeEl ( fixture ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
188
+ expectNativeEl ( fixture ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
193
189
} ) ;
194
190
195
191
it ( 'should hide when used with fxLayout and the ".md" breakpoint activates' , ( ) => {
@@ -211,7 +207,7 @@ describe('hide directive', () => {
211
207
let expectActivation : any =
212
208
makeExpectWithActivation ( createTestComponent ( template ) , '.hideOnMd' ) ;
213
209
214
- expectActivation ( ) . toHaveStyle ( { 'display' : 'block ' } , styler ) ;
210
+ expectActivation ( ) . not . toHaveStyle ( { 'display' : 'none ' } , styler ) ;
215
211
expectActivation ( 'md' ) . toHaveStyle ( { 'display' : 'none' } , styler ) ;
216
212
} ) ;
217
213
@@ -224,14 +220,9 @@ describe('hide directive', () => {
224
220
let expectActivation : any =
225
221
makeExpectWithActivation ( createTestComponent ( template ) , '.hideOnXs' ) ;
226
222
227
- // TODO(CaerusKaru): the Domino server impl. does not process inline display correctly
228
- expectActivation ( ) . toHaveStyle ( {
229
- 'display' : isPlatformServer ( platformId ) ? 'block' : 'inline'
230
- } , styler ) ;
223
+ expectActivation ( ) . not . toHaveStyle ( { 'display' : 'none' } , styler ) ;
231
224
expectActivation ( 'xs' ) . toHaveStyle ( { 'display' : 'none' } , styler ) ;
232
- expectActivation ( 'md' ) . toHaveStyle ( {
233
- 'display' : isPlatformServer ( platformId ) ? 'block' : 'inline'
234
- } , styler ) ;
225
+ expectActivation ( 'md' ) . not . toHaveStyle ( { 'display' : 'none' } , styler ) ;
235
226
} ) ;
236
227
} ) ;
237
228
0 commit comments