View
@@ -4,6 +4,7 @@ events = require('../events')
describe 'AppController', ->
$controller = null
$scope = null
$rootScope = null
fakeAnnotationUI = null
fakeAuth = null
fakeDrafts = null
@@ -14,6 +15,7 @@ describe 'AppController', ->
fakeSession = null
fakeGroups = null
fakeRoute = null
fakeWindow = null
sandbox = null
@@ -45,6 +47,8 @@ describe 'AppController', ->
remove: sandbox.spy()
all: sandbox.stub().returns([])
discard: sandbox.spy()
count: sandbox.stub().returns(0)
unsaved: sandbox.stub().returns([])
}
fakeFeatures = {
@@ -55,6 +59,7 @@ describe 'AppController', ->
fakeIdentity = {
watch: sandbox.spy()
request: sandbox.spy()
logout: sandbox.stub()
}
fakeLocation = {
@@ -69,6 +74,11 @@ describe 'AppController', ->
fakeRoute = {reload: sandbox.spy()}
fakeWindow = {
top: {}
confirm: sandbox.stub()
}
$provide.value 'annotationUI', fakeAnnotationUI
$provide.value 'auth', fakeAuth
$provide.value 'drafts', fakeDrafts
@@ -79,10 +89,12 @@ describe 'AppController', ->
$provide.value '$route', fakeRoute
$provide.value '$location', fakeLocation
$provide.value '$routeParams', fakeParams
$provide.value '$window', fakeWindow
return
beforeEach inject (_$controller_, $rootScope) ->
beforeEach inject (_$controller_, _$rootScope_) ->
$controller = _$controller_
$rootScope = _$rootScope_
$scope = $rootScope.$new()
afterEach ->
@@ -91,14 +103,13 @@ describe 'AppController', ->
describe 'isSidebar property', ->
it 'is false if the window is the top window', ->
$window = {}
$window.top = $window
createController({$window})
fakeWindow.top = fakeWindow
createController()
assert.isFalse($scope.isSidebar)
it 'is true if the window is not the top window', ->
$window = {top: {}}
createController({$window})
fakeWindow.top = {}
createController()
assert.isTrue($scope.isSidebar)
it 'watches the identity service for identity change events', ->
@@ -156,3 +167,63 @@ describe 'AppController', ->
fakeRoute.reload = sinon.spy()
$scope.$broadcast(events.USER_CHANGED, {initialLoad: false})
assert.calledOnce(fakeRoute.reload)
describe 'logout()', ->
it 'prompts the user if there are drafts', ->
fakeDrafts.count.returns(1)
createController()
$scope.logout()
assert.equal(fakeWindow.confirm.callCount, 1)
it 'emits "annotationDeleted" for each unsaved draft annotation', ->
fakeDrafts.unsaved = sandbox.stub().returns(
["draftOne", "draftTwo", "draftThree"]
)
createController()
$rootScope.$emit = sandbox.stub()
$scope.logout()
assert($rootScope.$emit.calledThrice)
assert.deepEqual(
$rootScope.$emit.firstCall.args, ["annotationDeleted", "draftOne"])
assert.deepEqual(
$rootScope.$emit.secondCall.args, ["annotationDeleted", "draftTwo"])
assert.deepEqual(
$rootScope.$emit.thirdCall.args, ["annotationDeleted", "draftThree"])
it 'discards draft annotations', ->
createController()
$scope.logout()
assert(fakeDrafts.discard.calledOnce)
it 'does not emit "annotationDeleted" if the user cancels the prompt', ->
createController()
fakeDrafts.count.returns(1)
$rootScope.$emit = sandbox.stub()
fakeWindow.confirm.returns(false)
$scope.logout()
assert($rootScope.$emit.notCalled)
it 'does not discard drafts if the user cancels the prompt', ->
createController()
fakeDrafts.count.returns(1)
fakeWindow.confirm.returns(false)
$scope.logout()
assert(fakeDrafts.discard.notCalled)
it 'does not prompt if there are no drafts', ->
createController()
fakeDrafts.count.returns(0)
$scope.logout()
assert.equal(fakeWindow.confirm.callCount, 0)
View
@@ -73,7 +73,6 @@ def run_tests(self):
DEV_EXTRAS = ['pyramid_debugtoolbar>=2.1', 'prospector[with_pyroma]', 'pep257',
'pyramid_multiauth', 'sphinxcontrib-httpdomain']
TESTING_EXTRAS = ['mock>=1.3.0', 'pytest>=2.5', 'pytest-cov', 'factory-boy']
CLAIM_EXTRAS = ['mandrill']
YAML_EXTRAS = ['PyYAML']
setup(
@@ -104,7 +103,6 @@ def run_tests(self):
extras_require={
'dev': DEV_EXTRAS + YAML_EXTRAS,
'testing': TESTING_EXTRAS,
'claim': CLAIM_EXTRAS,
'YAML': YAML_EXTRAS,
},
tests_require=DEV_EXTRAS + TESTING_EXTRAS,
@@ -125,7 +123,6 @@ def run_tests(self):
'console_scripts': [
'hypothesis=h.script:main',
'hypothesis-buildext=h.buildext:main',
'hypothesis-invite=h.claim.invite:main',
'hypothesis-worker=h.worker:main',
],
'h.worker': [