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
c0a05f89
Commit
c0a05f89
authored
Jan 17, 2015
by
Nick Stenning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1858 from hypothesis/thread-prune-fix
Threading events fix and tests
parents
889c7533
2605ac16
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
9 deletions
+73
-9
threading.coffee
h/static/scripts/annotator/plugin/threading.coffee
+14
-8
threading-test.coffee
tests/js/plugin/threading-test.coffee
+59
-1
No files found.
h/static/scripts/annotator/plugin/threading.coffee
View file @
c0a05f89
...
...
@@ -75,17 +75,23 @@ class Annotator.Plugin.Threading extends Annotator.Plugin
break
annotationDeleted
:
(
annotation
)
=>
if
id
of
this
.
idTable
container
=
this
.
idTable
[
id
]
if
this
.
idTable
[
annotation
.
id
]
container
=
this
.
idTable
[
annotation
.
id
]
container
.
message
=
null
delete
this
.
idTable
[
id
]
delete
this
.
idTable
[
annotation
.
id
]
this
.
pruneEmpties
(
@
root
)
else
for
id
,
container
of
this
.
idTable
for
child
in
container
.
children
when
child
.
message
is
annotation
child
.
message
=
null
this
.
pruneEmpties
(
@
root
)
return
if
annotation
.
references
refs
=
annotation
.
references
unless
angular
.
isArray
(
refs
)
then
refs
=
[
refs
]
parentRef
=
refs
[
refs
.
length
-
1
]
parent
=
this
.
idTable
[
parentRef
]
else
parent
=
@
root
for
child
in
parent
.
children
when
child
.
message
is
annotation
child
.
message
=
null
this
.
pruneEmpties
(
@
root
)
break
annotationsLoaded
:
(
annotations
)
=>
messages
=
(
@
root
.
flattenChildren
()
or
[]).
concat
(
annotations
)
...
...
tests/js/plugin/threading-test.coffee
View file @
c0a05f89
assert
=
chai
.
assert
sinon
.
assert
.
expose
(
assert
,
prefix
:
''
)
sinon
.
assert
.
expose
(
assert
,
prefix
:
null
)
sandbox
=
sinon
.
sandbox
.
create
()
describe
'Annotator.Threading'
,
->
createThreadingInstance
=
(
options
)
->
...
...
@@ -84,3 +85,60 @@ describe 'Annotator.Threading', ->
instance
.
pruneEmpties
(
root
)
assert
.
equal
(
root
.
children
.
length
,
0
)
describe
'handles events'
,
->
annotator
=
null
instance
=
null
beforeEach
->
instance
=
createThreadingInstance
()
instance
.
pluginInit
()
annotator
=
publish
:
(
event
,
args
)
->
unless
angular
.
isArray
(
args
)
then
args
=
[
args
]
meth
=
instance
.
events
[
event
]
instance
[
meth
].
apply
(
instance
,
args
)
afterEach
->
sandbox
.
restore
()
it
'calls the thread method on beforeAnnotationCreated'
,
->
annotation
=
{
id
:
'foo'
}
sandbox
.
spy
(
instance
,
'thread'
)
annotator
.
publish
'beforeAnnotationCreated'
,
annotation
assert
.
calledWithMatch
instance
.
thread
,
[
annotation
]
it
'calls the thread method on annotationsLoaded'
,
->
annotation
=
{
id
:
'foo'
}
sandbox
.
spy
(
instance
,
'thread'
)
annotator
.
publish
'annotationsLoaded'
,
[
annotation
]
assert
.
calledWithMatch
instance
.
thread
,
[
annotation
]
it
'removes matching top level threads when annotationDeleted is called'
,
->
annotation
=
{
id
:
'foo'
}
instance
.
thread
([
annotation
])
assert
.
equal
(
instance
.
root
.
children
.
length
,
1
)
assert
.
equal
(
instance
.
idTable
[
'foo'
].
message
,
annotation
)
sandbox
.
spy
(
instance
,
'pruneEmpties'
)
annotator
.
publish
'annotationDeleted'
,
annotation
assert
.
called
(
instance
.
pruneEmpties
)
assert
.
equal
(
instance
.
root
.
children
.
length
,
0
)
assert
.
isUndefined
(
instance
.
idTable
[
'foo'
])
it
'removes matching reply threads when annotationDeleted is called'
,
->
parent
=
{
id
:
'foo'
}
reply
=
{
id
:
'bar'
,
references
:
[
'foo'
]}
instance
.
thread
([
parent
,
reply
])
assert
.
equal
(
instance
.
idTable
[
'foo'
].
children
.
length
,
1
)
assert
.
equal
(
instance
.
idTable
[
'bar'
].
message
,
reply
)
sandbox
.
spy
(
instance
,
'pruneEmpties'
)
annotator
.
publish
'annotationDeleted'
,
reply
assert
.
called
(
instance
.
pruneEmpties
)
assert
.
equal
(
instance
.
idTable
[
'foo'
].
children
.
length
,
0
)
assert
.
isUndefined
(
instance
.
idTable
[
'bar'
])
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