Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
a5b69f7f
Commit
a5b69f7f
authored
Jan 30, 2015
by
Aron Carroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for AnnotationMapperService
parent
d0795706
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
0 deletions
+121
-0
annotation-mapper-service-test.coffee
tests/js/annotation-mapper-service-test.coffee
+121
-0
No files found.
tests/js/annotation-mapper-service-test.coffee
0 → 100644
View file @
a5b69f7f
assert
=
chai
.
assert
sinon
.
assert
.
expose
(
assert
,
prefix
:
''
)
describe
'AnnotationMapperService'
,
->
sandbox
=
sinon
.
sandbox
.
create
()
$rootScope
=
null
fakeStore
=
null
fakeThreading
=
null
annotationMapper
=
null
beforeEach
module
(
'h'
)
beforeEach
module
(
$provide
)
->
fakeStore
=
AnnotationResource
:
sandbox
.
stub
().
returns
({})
fakeThreading
=
idTable
:
{}
$provide
.
value
(
'store'
,
fakeStore
)
$provide
.
value
(
'threading'
,
fakeThreading
)
return
beforeEach
inject
(
_annotationMapper_
,
_$rootScope_
)
->
$rootScope
=
_$rootScope_
annotationMapper
=
_annotationMapper_
afterEach
:
->
sandbox
.
restore
()
describe
'.loadAnnotations()'
,
->
it
'triggers the annotationLoaded event'
,
->
sandbox
.
stub
(
$rootScope
,
'$emit'
)
annotations
=
[{
id
:
1
},
{
id
:
2
},
{
id
:
3
}]
annotationMapper
.
loadAnnotations
(
annotations
)
assert
.
called
(
$rootScope
.
$emit
)
assert
.
calledWith
(
$rootScope
.
$emit
,
'annotationsLoaded'
,
[{},
{},
{}])
it
'triggers the annotationUpdated event for each annotation in the threading cache'
,
->
sandbox
.
stub
(
$rootScope
,
'$emit'
)
annotations
=
[{
id
:
1
},
{
id
:
2
},
{
id
:
3
}]
cached
=
{
message
:
{
id
:
1
,
$
$tag
:
'tag1'
}}
fakeThreading
.
idTable
[
1
]
=
cached
annotationMapper
.
loadAnnotations
(
annotations
)
assert
.
called
(
$rootScope
.
$emit
)
assert
.
calledWith
(
$rootScope
.
$emit
,
'annotationUpdated'
,
cached
.
message
)
it
'replaces the properties on the cached annotation with those from the loaded one'
,
->
sandbox
.
stub
(
$rootScope
,
'$emit'
)
annotations
=
[{
id
:
1
,
url
:
'http://example.com'
}]
cached
=
{
message
:
{
id
:
1
,
$
$tag
:
'tag1'
}}
fakeThreading
.
idTable
[
1
]
=
cached
annotationMapper
.
loadAnnotations
(
annotations
)
assert
.
called
(
$rootScope
.
$emit
)
assert
.
calledWith
(
$rootScope
.
$emit
,
'annotationUpdated'
,
{
id
:
1
url
:
'http://example.com'
})
it
'excludes cached annotations from the annotationLoaded event'
,
->
sandbox
.
stub
(
$rootScope
,
'$emit'
)
annotations
=
[{
id
:
1
,
url
:
'http://example.com'
}]
cached
=
{
message
:
{
id
:
1
,
$
$tag
:
'tag1'
}}
fakeThreading
.
idTable
[
1
]
=
cached
annotationMapper
.
loadAnnotations
(
annotations
)
assert
.
called
(
$rootScope
.
$emit
)
assert
.
calledWith
(
$rootScope
.
$emit
,
'annotationsLoaded'
,
[])
describe
'.createAnnotation()'
,
->
it
'creates a new annotaton resource'
,
->
ann
=
{}
fakeStore
.
AnnotationResource
.
returns
(
ann
)
ret
=
annotationMapper
.
createAnnotation
(
ann
)
assert
.
equal
(
ret
,
ann
)
it
'creates a new resource with the new keyword'
,
->
ann
=
{}
fakeStore
.
AnnotationResource
.
returns
(
ann
)
ret
=
annotationMapper
.
createAnnotation
()
assert
.
calledWithNew
(
fakeStore
.
AnnotationResource
)
it
'emits the "beforeAnnotationCreated" event'
,
->
sandbox
.
stub
(
$rootScope
,
'$emit'
)
ann
=
{}
fakeStore
.
AnnotationResource
.
returns
(
ann
)
ret
=
annotationMapper
.
createAnnotation
()
assert
.
calledWith
(
$rootScope
.
$emit
,
'beforeAnnotationCreated'
,
ann
)
describe
'.deleteAnnotation()'
,
->
it
'deletes the annotation on the server'
,
->
p
=
Promise
.
resolve
()
ann
=
{
$delete
:
sandbox
.
stub
().
returns
(
p
)}
annotationMapper
.
deleteAnnotation
(
ann
)
assert
.
called
(
ann
.
$delete
)
it
'triggers the "annotationDeleted" event on success'
,
->
sandbox
.
stub
(
$rootScope
,
'$emit'
)
p
=
Promise
.
resolve
()
ann
=
{
$delete
:
sandbox
.
stub
().
returns
(
p
)}
annotationMapper
.
deleteAnnotation
(
ann
)
p
.
then
->
assert
.
called
(
$rootScope
.
$emit
)
assert
.
calledWith
(
$rootScope
.
$emit
,
'annotationDeleted'
,
ann
)
it
'does nothing on error'
,
->
sandbox
.
stub
(
$rootScope
,
'$emit'
)
p
=
Promise
.
reject
()
ann
=
{
$delete
:
sandbox
.
stub
().
returns
(
p
)}
annotationMapper
.
deleteAnnotation
(
ann
)
p
.
catch
->
assert
.
notCalled
(
$rootScope
.
$emit
)
it
'returns the annotation'
,
->
p
=
Promise
.
resolve
()
ann
=
{
$delete
:
sandbox
.
stub
().
returns
(
p
)}
assert
.
equal
(
annotationMapper
.
deleteAnnotation
(
ann
),
ann
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment