@@ -23,7 +23,6 @@ describe('$anchorScroll', function() {
23
23
} ;
24
24
}
25
25
26
-
27
26
function addElements ( ) {
28
27
var elements = sliceArgs ( arguments ) ;
29
28
@@ -137,12 +136,12 @@ describe('$anchorScroll', function() {
137
136
} ) ) ;
138
137
139
138
140
- describe ( 'when implicitly using `$location.hash()` ' , function ( ) {
139
+ describe ( 'when explicitly called ' , function ( ) {
141
140
142
141
beforeEach ( createMockWindow ( ) ) ;
143
142
144
143
145
- describe ( 'and no hash is specified ' , function ( ) {
144
+ describe ( 'and implicitly using `$location.hash()` ' , function ( ) {
146
145
147
146
it ( 'should scroll to top of the window if empty hash' , inject (
148
147
changeHashAndScroll ( '' ) ,
@@ -189,6 +188,73 @@ describe('$anchorScroll', function() {
189
188
changeHashAndScroll ( 'top' ) ,
190
189
expectScrollingTo ( 'id=top' ) ) ) ;
191
190
} ) ;
191
+
192
+
193
+ describe ( 'and specifying a hash' , function ( ) {
194
+
195
+ it ( 'should ignore the `hash` argument if not a string' , inject (
196
+ spyOnJQLiteDocumentLoaded ( ) ,
197
+ addElements ( 'id=one' , 'id=two' ) ,
198
+ changeHashTo ( 'one' ) , // won't scroll since `jqLiteDocumentLoaded()` is spied upon
199
+ callAnchorScroll ( { } ) ,
200
+ expectScrollingTo ( 'id=one' ) ,
201
+ unspyOnJQLiteDocumentLoaded ( ) ) ) ;
202
+
203
+
204
+ it ( 'should ignore `$location.hash()` if `hash` is passed as argument' , inject (
205
+ spyOnJQLiteDocumentLoaded ( ) ,
206
+ addElements ( 'id=one' , 'id=two' ) ,
207
+ changeHashTo ( 'one' ) , // won't scroll since `jqLiteDocumentLoaded()` is spied upon
208
+ callAnchorScroll ( 'two' ) ,
209
+ expectScrollingTo ( 'id=two' ) ,
210
+ unspyOnJQLiteDocumentLoaded ( ) ) ) ;
211
+
212
+
213
+ it ( 'should scroll to top of the window if empty hash' , inject (
214
+ callAnchorScroll ( '' ) ,
215
+ expectScrollingToTop ) ) ;
216
+
217
+
218
+ it ( 'should not scroll if hash does not match any element' , inject (
219
+ addElements ( 'id=one' , 'id=two' ) ,
220
+ callAnchorScroll ( 'non-existing' ) ,
221
+ expectNoScrolling ( ) ) ) ;
222
+
223
+
224
+ it ( 'should scroll to anchor element with name' , inject (
225
+ addElements ( 'a name=abc' ) ,
226
+ callAnchorScroll ( 'abc' ) ,
227
+ expectScrollingTo ( 'a name=abc' ) ) ) ;
228
+
229
+
230
+ it ( 'should not scroll to other than anchor element with name' , inject (
231
+ addElements ( 'input name=xxl' , 'select name=xxl' , 'form name=xxl' ) ,
232
+ callAnchorScroll ( 'xxl' ) ,
233
+ expectNoScrolling ( ) ) ) ;
234
+
235
+
236
+ it ( 'should scroll to anchor even if other element with given name exist' , inject (
237
+ addElements ( 'input name=some' , 'a name=some' ) ,
238
+ callAnchorScroll ( 'some' ) ,
239
+ expectScrollingTo ( 'a name=some' ) ) ) ;
240
+
241
+
242
+ it ( 'should scroll to element with id with precedence over name' , inject (
243
+ addElements ( 'name=abc' , 'id=abc' ) ,
244
+ callAnchorScroll ( 'abc' ) ,
245
+ expectScrollingTo ( 'id=abc' ) ) ) ;
246
+
247
+
248
+ it ( 'should scroll to top if hash == "top" and no matching element' , inject (
249
+ callAnchorScroll ( 'top' ) ,
250
+ expectScrollingToTop ) ) ;
251
+
252
+
253
+ it ( 'should scroll to element with id "top" if present' , inject (
254
+ addElements ( 'id=top' ) ,
255
+ callAnchorScroll ( 'top' ) ,
256
+ expectScrollingTo ( 'id=top' ) ) ) ;
257
+ } ) ;
192
258
} ) ;
193
259
194
260
0 commit comments