mirror of
https://github.com/wassname/side-by-side.git
synced 2026-09-09 11:34:24 +08:00
Test route service
This commit is contained in:
@@ -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,5 +1,5 @@
|
||||
angular.module("sideBySide").service "route", ['$location', ($location) ->
|
||||
@params = $location.url()
|
||||
@params = $location.path()
|
||||
.split('/')
|
||||
.filter((item) -> item)
|
||||
.map (item) ->
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
Reference in New Issue
Block a user