Adding a current user service, refactoring various consequences of this change:

This commit is contained in:
Will Marshall
2014-04-25 16:59:46 +10:00
parent 8f539aca1f
commit 28230f0436
11 changed files with 68 additions and 16 deletions

View File

@@ -5,6 +5,7 @@ describe "CheckoutCtrl", ->
beforeEach ->
module("Darkswarm")
angular.module('Darkswarm').value('user', {})
Order = {
submit: ->
navigate: ->

View File

@@ -12,11 +12,3 @@ describe "SidebarCtrl", ->
scope = $rootScope
ctrl = $controller 'SidebarCtrl', {$scope: scope, $location: location}
scope.$apply()
it 'is active when a location is set', ->
expect(scope.active()).toEqual true
it 'is inactive no location is set', ->
location.path = ->
null
expect(scope.active()).toEqual false

View File

@@ -0,0 +1,37 @@
describe "Sidebar", ->
location = null
Sidebar = null
Navigation = null
beforeEach ->
module("Darkswarm")
inject (_Sidebar_, $location, _Navigation_) ->
Sidebar = _Sidebar_
Navigation = _Navigation_
location = $location
Sidebar.paths = ["/test", "/frogs"]
it 'is active when a location in paths is set', ->
spyOn(location, "path").andReturn "/test"
expect(Sidebar.active()).toEqual true
it 'is inactive if location is set', ->
spyOn(location, "path").andReturn null
expect(Sidebar.active()).toEqual false
describe "Toggling on/off", ->
it 'toggles the current sidebar path', ->
expect(Sidebar.active()).toEqual false
Navigation.path = "/frogs"
Sidebar.toggle()
expect(Sidebar.active()).toEqual true
it 'If current navigation path is not in the sidebar, it toggles the first sidebar path', ->
Navigation.path = "/donkeys"
spyOn(Navigation, 'navigate')
Sidebar.toggle()
expect(Navigation.navigate).toHaveBeenCalledWith("/test")