Test route service

This commit is contained in:
Vit Brunner
2014-12-18 22:27:01 +01:00
parent 1939e73a43
commit a092857dea
3 changed files with 45 additions and 1 deletions
+1
View File
@@ -59,6 +59,7 @@ module.exports = (grunt) ->
test_scripts: [
'bower_components/qunit/qunit/qunit.js'
'tests/_setup.js'
'tests/services/route.js'
'tests/services/reader/_factory.js'
'tests/services/reader/markdown.js'
'tests/services/reader/json.js'
+1 -1
View File
@@ -1,5 +1,5 @@
angular.module("sideBySide").service "route", ['$location', ($location) ->
@params = $location.url()
@params = $location.path()
.split('/')
.filter((item) -> item)
.map (item) ->
+43
View File
@@ -0,0 +1,43 @@
route = {}
module "route", {
setup: () ->
angular.module("sideBySide").service("$location", () ->
@path = () ->
'/asdf:zxcv/qwerty:asdf'
@url = () ->
'/asdf:zxcv/qwerty:asdf#test'
@absUrl = () ->
'http://example.com/asdf:zxcv/qwerty:asdf#test'
@
)
route = angular.injector(['ng', 'sideBySide']).get('route')
}
test "has app url", () ->
equal route.appUrl, 'http://example.com'
test "gets parameters", () ->
deepEqual route.params, {
'asdf': 'zxcv'
'qwerty': 'asdf'
'base': ''
}
test "updates parameters", () ->
route.update('asdf', 'hjkl')
deepEqual route.params, {
'asdf': 'hjkl'
'qwerty': 'asdf'
'base': ''
}
test "adds parameter", () ->
route.update('new', 'one')
deepEqual route.params, {
'asdf': 'zxcv'
'qwerty': 'asdf'
'base': ''
'new': 'one'
}