1
1
describe ( 'position elements' , function ( ) {
2
-
3
2
var TargetElMock = function ( width , height ) {
4
3
this . width = width ;
5
4
this . height = height ;
@@ -12,8 +11,8 @@ describe('position elements', function () {
12
11
var $position ;
13
12
14
13
beforeEach ( module ( 'ui.bootstrap.position' ) ) ;
15
- beforeEach ( inject ( function ( _$position_ ) {
16
- $position = _$position_ ;
14
+ beforeEach ( inject ( function ( $uibPosition ) {
15
+ $position = $uibPosition ;
17
16
} ) ) ;
18
17
beforeEach ( function ( ) {
19
18
jasmine . addMatchers ( {
@@ -39,7 +38,6 @@ describe('position elements', function () {
39
38
} ) ;
40
39
41
40
describe ( 'append-to-body: false' , function ( ) {
42
-
43
41
beforeEach ( function ( ) {
44
42
//mock position info normally queried from the DOM
45
43
$position . position = function ( ) {
@@ -106,3 +104,61 @@ describe('position elements', function () {
106
104
} ) ;
107
105
} ) ;
108
106
} ) ;
107
+
108
+ /* Deprecation tests below */
109
+
110
+ describe ( 'position deprecation' , function ( ) {
111
+ var TargetElMock = function ( width , height ) {
112
+ this . width = width ;
113
+ this . height = height ;
114
+
115
+ this . prop = function ( propName ) {
116
+ return propName === 'offsetWidth' ? width : height ;
117
+ } ;
118
+ } ;
119
+ beforeEach ( module ( 'ui.bootstrap.position' ) ) ;
120
+
121
+ it ( 'should suppress warning' , function ( ) {
122
+ module ( function ( $provide ) {
123
+ $provide . value ( '$positionSuppressWarning' , true ) ;
124
+ } ) ;
125
+
126
+ inject ( function ( $log , $position ) {
127
+ spyOn ( $log , 'warn' ) ;
128
+ //mock position info normally queried from the DOM
129
+ $position . position = function ( ) {
130
+ return {
131
+ width : 20 ,
132
+ height : 20 ,
133
+ top : 100 ,
134
+ left : 100
135
+ } ;
136
+ } ;
137
+
138
+ $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'other' ) ;
139
+
140
+ expect ( $log . warn . calls . count ( ) ) . toBe ( 0 ) ;
141
+ } ) ;
142
+ } ) ;
143
+
144
+ it ( 'should give warning by default' , inject ( function ( $log ) {
145
+ spyOn ( $log , 'warn' ) ;
146
+
147
+ inject ( function ( $position ) {
148
+ //mock position info normally queried from the DOM
149
+ $position . position = function ( ) {
150
+ return {
151
+ width : 20 ,
152
+ height : 20 ,
153
+ top : 100 ,
154
+ left : 100
155
+ } ;
156
+ } ;
157
+
158
+ $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'other' ) ;
159
+
160
+ expect ( $log . warn . calls . count ( ) ) . toBe ( 1 ) ;
161
+ expect ( $log . warn . calls . argsFor ( 0 ) ) . toEqual ( [ '$position is now deprecated. Use $uibPosition instead.' ] ) ;
162
+ } ) ;
163
+ } ) ) ;
164
+ } ) ;
0 commit comments