6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
import {
9
- Component , OnInit , Inject , ElementRef
9
+ Component , OnInit
10
10
} from '@angular/core' ;
11
- import { CommonModule } from '@angular/common' ;
12
- import { ComponentFixture , TestBed } from '@angular/core/testing' ;
11
+ import { CommonModule } from '@angular/common' ;
12
+ import { ComponentFixture , TestBed } from '@angular/core/testing' ;
13
13
14
- import { MockMatchMedia } from '../../media-query/mock/mock-match-media' ;
15
- import { MatchMedia } from '../../media-query/match-media' ;
16
- import { ObservableMedia } from '../../media-query/observable-media-service' ;
17
- import { BreakPointsProvider } from '../../media-query/breakpoints/break-points' ;
18
- import { BreakPointRegistry } from '../../media-query/breakpoints/break-point-registry' ;
19
- import { BaseFxDirectiveAdapter } from './class' ;
14
+ import { MockMatchMedia } from '../../media-query/mock/mock-match-media' ;
15
+ import { MatchMedia } from '../../media-query/match-media' ;
16
+ import { ObservableMedia } from '../../media-query/observable-media-service' ;
17
+ import { BreakPointsProvider } from '../../media-query/breakpoints/break-points' ;
18
+ import { BreakPointRegistry } from '../../media-query/breakpoints/break-point-registry' ;
20
19
21
- import { customMatchers , expect } from '../../utils/testing/custom-matchers' ;
20
+ import { customMatchers } from '../../utils/testing/custom-matchers' ;
22
21
import {
23
22
makeCreateTestComponent , expectNativeEl
24
23
} from '../../utils/testing/helpers' ;
25
- import { ClassDirective } from './class' ;
26
- import { MediaQueriesModule } from '../../media-query/_module' ;
24
+ import { ClassDirective } from './class' ;
25
+ import { MediaQueriesModule } from '../../media-query/_module' ;
27
26
28
27
describe ( 'class directive' , ( ) => {
29
28
let fixture : ComponentFixture < any > ;
@@ -42,7 +41,7 @@ describe('class directive', () => {
42
41
declarations : [ TestClassComponent , ClassDirective ] ,
43
42
providers : [
44
43
BreakPointRegistry , BreakPointsProvider ,
45
- { provide : MatchMedia , useClass : MockMatchMedia }
44
+ { provide : MatchMedia , useClass : MockMatchMedia }
46
45
]
47
46
} ) ;
48
47
} ) ;
@@ -54,17 +53,17 @@ describe('class directive', () => {
54
53
} ) ;
55
54
56
55
[ 'xs' , 'sm' , 'md' , 'lg' ]
57
- . forEach ( mq => {
58
- const selector = `class-${ mq } ` ;
59
- it ( `should apply '${ selector } ' with '${ mq } ' media query` , ( ) => {
60
- fixture = createTestComponent ( `
56
+ . forEach ( mq => {
57
+ const selector = `class-${ mq } ` ;
58
+ it ( `should apply '${ selector } ' with '${ mq } ' media query` , ( ) => {
59
+ fixture = createTestComponent ( `
61
60
<div class.${ mq } ="${ selector } ">
62
61
</div>
63
62
` ) ;
64
- activateMediaQuery ( mq , true ) ;
65
- expectNativeEl ( fixture ) . toHaveCssClass ( selector ) ;
63
+ activateMediaQuery ( mq , true ) ;
64
+ expectNativeEl ( fixture ) . toHaveCssClass ( selector ) ;
65
+ } ) ;
66
66
} ) ;
67
- } ) ;
68
67
69
68
it ( 'should keep existing class selector' , ( ) => {
70
69
fixture = createTestComponent ( `
@@ -96,11 +95,11 @@ describe('class directive', () => {
96
95
</div>
97
96
` ) ;
98
97
activateMediaQuery ( 'xs' , true ) ;
99
- expectNativeEl ( fixture , { hasXs1 : true , hasXs2 : false } ) . toHaveCssClass ( 'xs-1' ) ;
100
- expectNativeEl ( fixture , { hasXs1 : true , hasXs2 : false } ) . not . toHaveCssClass ( 'xs-2' ) ;
98
+ expectNativeEl ( fixture , { hasXs1 : true , hasXs2 : false } ) . toHaveCssClass ( 'xs-1' ) ;
99
+ expectNativeEl ( fixture , { hasXs1 : true , hasXs2 : false } ) . not . toHaveCssClass ( 'xs-2' ) ;
101
100
102
- expectNativeEl ( fixture , { hasXs1 : false , hasXs2 : true } ) . toHaveCssClass ( 'xs-2' ) ;
103
- expectNativeEl ( fixture , { hasXs1 : false , hasXs2 : true } ) . not . toHaveCssClass ( 'xs-1' ) ;
101
+ expectNativeEl ( fixture , { hasXs1 : false , hasXs2 : true } ) . toHaveCssClass ( 'xs-2' ) ;
102
+ expectNativeEl ( fixture , { hasXs1 : false , hasXs2 : true } ) . not . toHaveCssClass ( 'xs-1' ) ;
104
103
} ) ;
105
104
106
105
it ( 'should work with ngClass array notation' , ( ) => {
@@ -114,42 +113,6 @@ describe('class directive', () => {
114
113
} ) ;
115
114
} ) ;
116
115
117
- export class MockElementRef extends ElementRef {
118
- constructor ( ) {
119
- const nEl = document . createElement ( 'DIV' ) ;
120
- super ( nEl ) ;
121
- this . nativeElement = nEl ;
122
- }
123
- }
124
-
125
- describe ( 'BaseFxDirectiveAdapter class' , ( ) => {
126
- let component ;
127
- beforeEach ( ( ) => {
128
- component = new BaseFxDirectiveAdapter ( null , new MockElementRef ( ) , null ) ;
129
- } ) ;
130
- describe ( 'cacheInput' , ( ) => {
131
- it ( 'should call _cacheInputArray when source is an array' , ( ) => {
132
- spyOn ( component , '_cacheInputArray' ) ;
133
- component . cacheInput ( 'key' , [ ] ) ;
134
- expect ( component . _cacheInputArray ) . toHaveBeenCalled ( ) ;
135
- } ) ;
136
- it ( 'should call _cacheInputObject when source is an object' , ( ) => {
137
- spyOn ( component , '_cacheInputObject' ) ;
138
- component . cacheInput ( 'key' , { } ) ;
139
- expect ( component . _cacheInputObject ) . toHaveBeenCalled ( ) ;
140
- } ) ;
141
- it ( 'should call _cacheInputString when source is a string' , ( ) => {
142
- spyOn ( component , '_cacheInputString' ) ;
143
- component . cacheInput ( 'key' , '' ) ;
144
- expect ( component . _cacheInputString ) . toHaveBeenCalled ( ) ;
145
- } ) ;
146
- it ( 'should throw when source is not an object, array or string' , ( ) => {
147
- expect ( component . cacheInput . bind ( null , true ) ) . toThrow ( ) ;
148
- } ) ;
149
- } ) ;
150
-
151
- } ) ;
152
-
153
116
// *****************************************************************
154
117
// Template Component
155
118
// *****************************************************************
@@ -162,7 +125,7 @@ export class TestClassComponent implements OnInit {
162
125
hasXs1 : boolean ;
163
126
hasXs2 : boolean ;
164
127
165
- constructor ( @ Inject ( ObservableMedia ) private media ) {
128
+ constructor ( private media : ObservableMedia ) {
166
129
}
167
130
168
131
ngOnInit ( ) {
0 commit comments