Commit 888b7bb1 authored by Aron Carroll's avatar Aron Carroll

Update the annotation directive tests

parent 5bfca64c
...@@ -300,8 +300,8 @@ AnnotationController = [ ...@@ -300,8 +300,8 @@ AnnotationController = [
# an embedded widget. # an embedded widget.
### ###
annotationDirective = [ annotationDirective = [
'$document', 'annotationMapper', '$document',
($document, annotationMapper) -> ($document) ->
linkFn = (scope, elem, attrs, [ctrl, thread, threadFilter, counter]) -> linkFn = (scope, elem, attrs, [ctrl, thread, threadFilter, counter]) ->
# Observe the embedded attribute # Observe the embedded attribute
attrs.$observe 'annotationEmbedded', (value) -> attrs.$observe 'annotationEmbedded', (value) ->
......
...@@ -48,7 +48,6 @@ describe 'h', -> ...@@ -48,7 +48,6 @@ describe 'h', ->
send: sandbox.spy() send: sandbox.spy()
} }
$provide.value 'annotator', fakeAnnotator
$provide.value 'identity', fakeIdentity $provide.value 'identity', fakeIdentity
$provide.value 'streamer', fakeStreamer $provide.value 'streamer', fakeStreamer
$provide.value '$location', fakeLocation $provide.value '$location', fakeLocation
...@@ -69,7 +68,6 @@ describe 'h', -> ...@@ -69,7 +68,6 @@ describe 'h', ->
it 'does not show login form for logged in users', -> it 'does not show login form for logged in users', ->
createController() createController()
$scope.$digest()
assert.isFalse($scope.dialog.visible) assert.isFalse($scope.dialog.visible)
describe 'AnnotationViewerController', -> describe 'AnnotationViewerController', ->
......
...@@ -6,13 +6,14 @@ describe 'h.directives.annotation', -> ...@@ -6,13 +6,14 @@ describe 'h.directives.annotation', ->
$document = null $document = null
$scope = null $scope = null
$timeout = null $timeout = null
annotator = null
annotation = null annotation = null
createController = null createController = null
flash = null flash = null
fakeAuth = null fakeAuth = null
fakeStore = null fakeStore = null
fakeUser = null fakeUser = null
fakeAnnotationMapper = null
fakeAnnotationUI = null
beforeEach module('h') beforeEach module('h')
beforeEach module('h.templates') beforeEach module('h.templates')
...@@ -20,9 +21,20 @@ describe 'h.directives.annotation', -> ...@@ -20,9 +21,20 @@ describe 'h.directives.annotation', ->
beforeEach module ($provide) -> beforeEach module ($provide) ->
fakeAuth = fakeAuth =
user: 'acct:bill@localhost' user: 'acct:bill@localhost'
fakeAnnotationMapper =
createAnnotation: sandbox.stub().returns
permissions:
read: ['acct:bill@localhost']
update: ['acct:bill@localhost']
destroy: ['acct:bill@localhost']
admin: ['acct:bill@localhost']
deleteAnnotation: sandbox.stub()
fakeAnnotationUI = {}
$provide.value 'auth', fakeAuth $provide.value 'auth', fakeAuth
$provide.value 'store', fakeStore $provide.value 'store', fakeStore
$provide.value 'annotationMapper', fakeAnnotationMapper
$provide.value 'annotationUI', fakeAnnotationUI
return return
beforeEach inject (_$compile_, $controller, _$document_, $rootScope, _$timeout_) -> beforeEach inject (_$compile_, $controller, _$document_, $rootScope, _$timeout_) ->
...@@ -31,11 +43,6 @@ describe 'h.directives.annotation', -> ...@@ -31,11 +43,6 @@ describe 'h.directives.annotation', ->
$timeout = _$timeout_ $timeout = _$timeout_
$scope = $rootScope.$new() $scope = $rootScope.$new()
$scope.annotationGet = (locals) -> annotation $scope.annotationGet = (locals) -> annotation
annotator = {
createAnnotation: sandbox.spy (data) -> data
plugins: {},
publish: sandbox.spy()
}
annotation = annotation =
id: 'deadbeef' id: 'deadbeef'
document: document:
...@@ -48,7 +55,6 @@ describe 'h.directives.annotation', -> ...@@ -48,7 +55,6 @@ describe 'h.directives.annotation', ->
createController = -> createController = ->
$controller 'AnnotationController', $controller 'AnnotationController',
$scope: $scope $scope: $scope
annotator: annotator
flash: flash flash: flash
afterEach -> afterEach ->
...@@ -56,7 +62,7 @@ describe 'h.directives.annotation', -> ...@@ -56,7 +62,7 @@ describe 'h.directives.annotation', ->
describe 'when the annotation is a highlight', -> describe 'when the annotation is a highlight', ->
beforeEach -> beforeEach ->
annotator.tool = 'highlight' fakeAnnotationUI.tool = 'highlight'
annotation.$create = sinon.stub().returns annotation.$create = sinon.stub().returns
then: angular.noop then: angular.noop
catch: angular.noop catch: angular.noop
...@@ -91,36 +97,31 @@ describe 'h.directives.annotation', -> ...@@ -91,36 +97,31 @@ describe 'h.directives.annotation', ->
destroy: ['acct:joe@localhost'] destroy: ['acct:joe@localhost']
admin: ['acct:joe@localhost'] admin: ['acct:joe@localhost']
annotator.publish = sinon.spy (event, ann) ->
return unless event == 'beforeAnnotationCreated'
ann.permissions =
read: ['acct:bill@localhost']
update: ['acct:bill@localhost']
destroy: ['acct:bill@localhost']
admin: ['acct:bill@localhost']
it 'creates a new reply with the proper uri and references', -> it 'creates a new reply with the proper uri and references', ->
controller.reply() controller.reply()
match = sinon.match {references: [annotation.id], uri: annotation.uri} match = sinon.match {references: [annotation.id], uri: annotation.uri}
assert.calledWith(annotator.createAnnotation, match) assert.calledWith(fakeAnnotationMapper.createAnnotation, match)
it 'adds the world readable principal if the parent is public', -> it 'adds the world readable principal if the parent is public', ->
reply = {}
fakeAnnotationMapper.createAnnotation.returns(reply)
annotation.permissions.read.push('group:__world__') annotation.permissions.read.push('group:__world__')
controller.reply() controller.reply()
newAnnotation = annotator.createAnnotation.lastCall.args[0] assert.include(reply.permissions.read, 'group:__world__')
assert.include(newAnnotation.permissions.read, 'group:__world__')
it 'does not add the world readable principal if the parent is private', -> it 'does not add the world readable principal if the parent is private', ->
reply = {}
fakeAnnotationMapper.createAnnotation.returns(reply)
controller.reply() controller.reply()
newAnnotation = annotator.createAnnotation.lastCall.args[0] assert.notInclude(reply.permissions.read, 'group:__world__')
assert.notInclude(newAnnotation.permissions.read, 'group:__world__')
it 'fills the other permissions too', -> it 'fills the other permissions too', ->
reply = {}
fakeAnnotationMapper.createAnnotation.returns(reply)
controller.reply() controller.reply()
newAnnotation = annotator.createAnnotation.lastCall.args[0] assert.equal(reply.permissions.update[0], 'acct:bill@localhost')
assert.equal(newAnnotation.permissions.update[0], 'acct:bill@localhost') assert.equal(reply.permissions.delete[0], 'acct:bill@localhost')
assert.equal(newAnnotation.permissions.delete[0], 'acct:bill@localhost') assert.equal(reply.permissions.admin[0], 'acct:bill@localhost')
assert.equal(newAnnotation.permissions.admin[0], 'acct:bill@localhost')
describe '#render', -> describe '#render', ->
controller = null controller = null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment