Commit 56de2455 authored by csillag's avatar csillag Committed by Gergely Ujvari

Adding tests for applyUpdate

parent 5b488a77
...@@ -3,6 +3,7 @@ sinon.assert.expose assert, prefix: null ...@@ -3,6 +3,7 @@ sinon.assert.expose assert, prefix: null
describe 'h', -> describe 'h', ->
$scope = null $scope = null
fakeAnnotationMapper = null
fakeIdentity = null fakeIdentity = null
fakeLocation = null fakeLocation = null
fakeParams = null fakeParams = null
...@@ -10,6 +11,7 @@ describe 'h', -> ...@@ -10,6 +11,7 @@ describe 'h', ->
fakeStore = fakeStore =
SearchResource: SearchResource:
get: sinon.spy() get: sinon.spy()
fakeThreading = null
sandbox = null sandbox = null
...@@ -35,10 +37,18 @@ describe 'h', -> ...@@ -35,10 +37,18 @@ describe 'h', ->
send: sandbox.spy() send: sandbox.spy()
} }
fakeAnnotationMapper =
loadAnnotations: sandbox.spy()
fakeThreading =
idTable: {}
$provide.value 'identity', fakeIdentity $provide.value 'identity', fakeIdentity
$provide.value 'streamer', fakeStreamer $provide.value 'streamer', fakeStreamer
$provide.value '$location', fakeLocation $provide.value '$location', fakeLocation
$provide.value '$routeParams', fakeParams $provide.value '$routeParams', fakeParams
$provide.value 'annotationMapper', fakeAnnotationMapper
$provide.value 'threading', fakeThreading
return return
afterEach -> afterEach ->
...@@ -49,6 +59,7 @@ describe 'h', -> ...@@ -49,6 +59,7 @@ describe 'h', ->
beforeEach inject ($controller, $rootScope) -> beforeEach inject ($controller, $rootScope) ->
$scope = $rootScope.$new() $scope = $rootScope.$new()
$scope.$digest = sinon.spy()
createController = -> createController = ->
$controller('AppController', {$scope: $scope}) $controller('AppController', {$scope: $scope})
...@@ -57,6 +68,61 @@ describe 'h', -> ...@@ -57,6 +68,61 @@ describe 'h', ->
createController() createController()
assert.isFalse($scope.dialog.visible) assert.isFalse($scope.dialog.visible)
describe 'applyUpdate', ->
it 'calls annotationMapper.loadAnnotations() upon "create" action', ->
createController()
anns = ["my", "annotations"]
fakeStreamer.onmessage
type: "annotation-notification"
options: action: "create"
payload: anns
assert.calledWith fakeAnnotationMapper.loadAnnotations, anns
it 'calls annotationMapper.loadAnnotations() upon "update" action', ->
createController()
anns = ["my", "annotations"]
fakeStreamer.onmessage
type: "annotation-notification"
options: action: "update"
payload: anns
assert.calledWith fakeAnnotationMapper.loadAnnotations, anns
it 'calls annotationMapper.loadAnnotations() upon "past" action', ->
createController()
anns = ["my", "annotations"]
fakeStreamer.onmessage
type: "annotation-notification"
options: action: "past"
payload: anns
assert.calledWith fakeAnnotationMapper.loadAnnotations, anns
it 'looks up annotations at threading upon "delete" action', ->
createController()
$scope.$emit = sinon.spy()
# Prepare the annotation that will come "from the wire"
anns = [
id: "fakeId"
data: "remote data"
]
# Prepare the annotation that we have locally
localAnnotation =
id: "fake it"
data: "local data"
# Put our annotation into the threading id table
fakeThreading.idTable.fakeId = message: localAnnotation
# Simulate a delete action
fakeStreamer.onmessage
type: "annotation-notification"
options: action: "delete"
payload: anns
assert.calledWith $scope.$emit, "annotationDeleted", localAnnotation
describe 'AnnotationViewerController', -> describe 'AnnotationViewerController', ->
annotationViewer = null annotationViewer = 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