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
b2ad6fb3
Unverified
Commit
b2ad6fb3
authored
May 01, 2019
by
Hannah Stepanek
Committed by
GitHub
May 01, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1086 from hypothesis/mockable-imports-part-3
Convert mocking to mockable imports (3/4)
parents
67ecd180
6e2fc70d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
40 deletions
+51
-40
guest.coffee
src/annotator/guest.coffee
+5
-2
cross-frame-test.coffee
src/annotator/plugin/test/cross-frame-test.coffee
+3
-5
guest-test.coffee
src/annotator/test/guest-test.coffee
+29
-23
host-test.coffee
src/annotator/test/host-test.coffee
+1
-2
multi-frame-test.js
src/annotator/test/integration/multi-frame-test.js
+4
-2
sidebar-test.coffee
src/annotator/test/sidebar-test.coffee
+9
-6
No files found.
src/annotator/guest.coffee
View file @
b2ad6fb3
...
@@ -7,6 +7,7 @@ Delegator = require('./delegator')
...
@@ -7,6 +7,7 @@ Delegator = require('./delegator')
$
=
require
(
'jquery'
)
$
=
require
(
'jquery'
)
adder
=
require
(
'./adder'
)
adder
=
require
(
'./adder'
)
htmlAnchoring
=
require
(
'./anchoring/html'
)
highlighter
=
require
(
'./highlighter'
)
highlighter
=
require
(
'./highlighter'
)
rangeUtil
=
require
(
'./range-util'
)
rangeUtil
=
require
(
'./range-util'
)
selections
=
require
(
'./selections'
)
selections
=
require
(
'./selections'
)
...
@@ -37,7 +38,7 @@ module.exports = class Guest extends Delegator
...
@@ -37,7 +38,7 @@ module.exports = class Guest extends Delegator
TextSelection
:
{}
TextSelection
:
{}
# Anchoring module
# Anchoring module
anchoring
:
require
(
'./anchoring/html'
)
anchoring
:
null
# Internal state
# Internal state
plugins
:
null
plugins
:
null
...
@@ -48,7 +49,7 @@ module.exports = class Guest extends Delegator
...
@@ -48,7 +49,7 @@ module.exports = class Guest extends Delegator
html
:
html
:
adder
:
'<hypothesis-adder></hypothesis-adder>'
adder
:
'<hypothesis-adder></hypothesis-adder>'
constructor
:
(
element
,
config
)
->
constructor
:
(
element
,
config
,
anchoring
=
htmlAnchoring
)
->
super
super
this
.
adder
=
$
(
this
.
html
.
adder
).
appendTo
(
@
element
).
hide
()
this
.
adder
=
$
(
this
.
html
.
adder
).
appendTo
(
@
element
).
hide
()
...
@@ -77,6 +78,8 @@ module.exports = class Guest extends Delegator
...
@@ -77,6 +78,8 @@ module.exports = class Guest extends Delegator
# The "top" guest instance will have this as null since it's in a top frame not a sub frame
# The "top" guest instance will have this as null since it's in a top frame not a sub frame
this
.
frameIdentifier
=
config
.
subFrameIdentifier
||
null
this
.
frameIdentifier
=
config
.
subFrameIdentifier
||
null
this
.
anchoring
=
anchoring
cfOptions
=
cfOptions
=
config
:
config
config
:
config
on
:
(
event
,
handler
)
=>
on
:
(
event
,
handler
)
=>
...
...
src/annotator/plugin/test/cross-frame-test.coffee
View file @
b2ad6fb3
proxyquire
=
require
(
'proxyquire'
)
Plugin
=
require
(
'../../plugin'
)
Plugin
=
require
(
'../../plugin'
)
CrossFrame
=
null
CrossFrame
=
require
(
'../cross-frame'
)
describe
'CrossFrame'
,
->
describe
'CrossFrame'
,
->
fakeDiscovery
=
null
fakeDiscovery
=
null
...
@@ -41,16 +39,16 @@ describe 'CrossFrame', ->
...
@@ -41,16 +39,16 @@ describe 'CrossFrame', ->
proxyDiscovery
=
sandbox
.
stub
().
returns
(
fakeDiscovery
)
proxyDiscovery
=
sandbox
.
stub
().
returns
(
fakeDiscovery
)
proxyBridge
=
sandbox
.
stub
().
returns
(
fakeBridge
)
proxyBridge
=
sandbox
.
stub
().
returns
(
fakeBridge
)
CrossFrame
=
proxyquire
(
'../cross-frame'
,
{
CrossFrame
.
$imports
.
$mock
(
{
'../plugin'
:
Plugin
,
'../plugin'
:
Plugin
,
'../annotation-sync'
:
proxyAnnotationSync
,
'../annotation-sync'
:
proxyAnnotationSync
,
'../../shared/bridge'
:
proxyBridge
,
'../../shared/bridge'
:
proxyBridge
,
'../../shared/discovery'
:
proxyDiscovery
'../../shared/discovery'
:
proxyDiscovery
})
})
afterEach
->
afterEach
->
sandbox
.
restore
()
sandbox
.
restore
()
CrossFrame
.
$imports
.
$restore
()
describe
'CrossFrame constructor'
,
->
describe
'CrossFrame constructor'
,
->
it
'instantiates the Discovery component'
,
->
it
'instantiates the Discovery component'
,
->
...
...
src/annotator/test/guest-test.coffee
View file @
b2ad6fb3
proxyquire
=
require
(
'proxyquire'
)
adder
=
require
(
'../adder'
)
adder
=
require
(
'../adder'
)
Observable
=
require
(
'../util/observable'
).
Observable
Observable
=
require
(
'../util/observable'
).
Observable
Plugin
=
require
(
'../plugin'
)
Plugin
=
require
(
'../plugin'
)
...
@@ -8,9 +6,7 @@ Delegator = require('../delegator')
...
@@ -8,9 +6,7 @@ Delegator = require('../delegator')
$
=
require
(
'jquery'
)
$
=
require
(
'jquery'
)
Delegator
[
'@noCallThru'
]
=
true
Delegator
[
'@noCallThru'
]
=
true
Guest
=
null
Guest
=
require
(
'../guest'
)
anchoring
=
{}
highlighter
=
{}
rangeUtil
=
null
rangeUtil
=
null
selections
=
null
selections
=
null
...
@@ -50,12 +46,15 @@ describe 'Guest', ->
...
@@ -50,12 +46,15 @@ describe 'Guest', ->
sandbox
=
sinon
.
sandbox
.
create
()
sandbox
=
sinon
.
sandbox
.
create
()
CrossFrame
=
null
CrossFrame
=
null
fakeCrossFrame
=
null
fakeCrossFrame
=
null
highlighter
=
null
guestConfig
=
null
guestConfig
=
null
htmlAnchoring
=
null
createGuest
=
(
config
=
{})
->
createGuest
=
(
config
=
{})
->
config
=
Object
.
assign
({},
guestConfig
,
config
)
config
=
Object
.
assign
({},
guestConfig
,
config
)
element
=
document
.
createElement
(
'div'
)
element
=
document
.
createElement
(
'div'
)
return
new
Guest
(
element
,
config
)
guest
=
new
Guest
(
element
,
config
)
return
guest
beforeEach
->
beforeEach
->
sinon
.
stub
(
console
,
'warn'
)
sinon
.
stub
(
console
,
'warn'
)
...
@@ -67,10 +66,17 @@ describe 'Guest', ->
...
@@ -67,10 +66,17 @@ describe 'Guest', ->
}
}
selections
=
null
selections
=
null
guestConfig
=
{
pluginClasses
:
{}}
guestConfig
=
{
pluginClasses
:
{}}
highlighter
=
{
highlightRange
:
sinon
.
stub
()
removeHighlights
:
sinon
.
stub
()
}
htmlAnchoring
=
{
anchor
:
sinon
.
stub
()
}
Guest
=
proxyquire
(
'../guest'
,
{
Guest
.
$imports
.
$mock
(
{
'./adder'
:
{
Adder
:
FakeAdder
},
'./adder'
:
{
Adder
:
FakeAdder
},
'./anchoring/html'
:
a
nchoring
,
'./anchoring/html'
:
htmlA
nchoring
,
'./highlighter'
:
highlighter
,
'./highlighter'
:
highlighter
,
'./range-util'
:
rangeUtil
,
'./range-util'
:
rangeUtil
,
'./selections'
:
(
document
)
->
'./selections'
:
(
document
)
->
...
@@ -97,6 +103,7 @@ describe 'Guest', ->
...
@@ -97,6 +103,7 @@ describe 'Guest', ->
afterEach
->
afterEach
->
sandbox
.
restore
()
sandbox
.
restore
()
console
.
warn
.
restore
()
console
.
warn
.
restore
()
Guest
.
$imports
.
$restore
()
describe
'plugins'
,
->
describe
'plugins'
,
->
fakePlugin
=
null
fakePlugin
=
null
...
@@ -478,7 +485,7 @@ describe 'Guest', ->
...
@@ -478,7 +485,7 @@ describe 'Guest', ->
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]},
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]},
]
]
}
}
sandbox
.
stub
(
anchoring
,
'anchor'
)
.
returns
(
Promise
.
resolve
(
range
))
htmlAnchoring
.
anchor
.
returns
(
Promise
.
resolve
(
range
))
guest
.
anchor
(
annotation
).
then
->
guest
.
anchor
(
annotation
).
then
->
assert
.
isFalse
(
annotation
.
$orphan
)
assert
.
isFalse
(
annotation
.
$orphan
)
...
@@ -491,7 +498,7 @@ describe 'Guest', ->
...
@@ -491,7 +498,7 @@ describe 'Guest', ->
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]},
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]},
]
]
}
}
sandbox
.
stub
(
anchoring
,
'anchor'
)
htmlAnchoring
.
anchor
.
onFirstCall
().
returns
(
Promise
.
reject
())
.
onFirstCall
().
returns
(
Promise
.
reject
())
.
onSecondCall
().
returns
(
Promise
.
resolve
(
range
))
.
onSecondCall
().
returns
(
Promise
.
resolve
(
range
))
...
@@ -505,7 +512,7 @@ describe 'Guest', ->
...
@@ -505,7 +512,7 @@ describe 'Guest', ->
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'notinhere'
}]},
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'notinhere'
}]},
]
]
}
}
sandbox
.
stub
(
anchoring
,
'anchor'
)
.
returns
(
Promise
.
reject
())
htmlAnchoring
.
anchor
.
returns
(
Promise
.
reject
())
guest
.
anchor
(
annotation
).
then
->
guest
.
anchor
(
annotation
).
then
->
assert
.
isTrue
(
annotation
.
$orphan
)
assert
.
isTrue
(
annotation
.
$orphan
)
...
@@ -518,7 +525,7 @@ describe 'Guest', ->
...
@@ -518,7 +525,7 @@ describe 'Guest', ->
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'neitherami'
}]},
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'neitherami'
}]},
]
]
}
}
sandbox
.
stub
(
anchoring
,
'anchor'
)
.
returns
(
Promise
.
reject
())
htmlAnchoring
.
anchor
.
returns
(
Promise
.
reject
())
guest
.
anchor
(
annotation
).
then
->
guest
.
anchor
(
annotation
).
then
->
assert
.
isTrue
(
annotation
.
$orphan
)
assert
.
isTrue
(
annotation
.
$orphan
)
...
@@ -532,7 +539,7 @@ describe 'Guest', ->
...
@@ -532,7 +539,7 @@ describe 'Guest', ->
}
}
# This shouldn't be called, but if it is, we successfully anchor so that
# This shouldn't be called, but if it is, we successfully anchor so that
# this test is guaranteed to fail.
# this test is guaranteed to fail.
sandbox
.
stub
(
anchoring
,
'anchor'
)
.
returns
(
Promise
.
resolve
(
range
))
htmlAnchoring
.
anchor
.
returns
(
Promise
.
resolve
(
range
))
guest
.
anchor
(
annotation
).
then
->
guest
.
anchor
(
annotation
).
then
->
assert
.
isTrue
(
annotation
.
$orphan
)
assert
.
isTrue
(
annotation
.
$orphan
)
...
@@ -544,10 +551,9 @@ describe 'Guest', ->
...
@@ -544,10 +551,9 @@ describe 'Guest', ->
{
selector
:
[{
type
:
'TextPositionSelector'
,
start
:
0
,
end
:
5
}]},
{
selector
:
[{
type
:
'TextPositionSelector'
,
start
:
0
,
end
:
5
}]},
]
]
}
}
sandbox
.
spy
(
anchoring
,
'anchor'
)
guest
.
anchor
(
annotation
).
then
->
guest
.
anchor
(
annotation
).
then
->
assert
.
notCalled
(
a
nchoring
.
anchor
)
assert
.
notCalled
(
htmlA
nchoring
.
anchor
)
it
'updates the cross frame and bucket bar plugins'
,
()
->
it
'updates the cross frame and bucket bar plugins'
,
()
->
guest
=
createGuest
()
guest
=
createGuest
()
...
@@ -563,8 +569,8 @@ describe 'Guest', ->
...
@@ -563,8 +569,8 @@ describe 'Guest', ->
it
'returns a promise of the anchors for the annotation'
,
()
->
it
'returns a promise of the anchors for the annotation'
,
()
->
guest
=
createGuest
()
guest
=
createGuest
()
highlights
=
[
document
.
createElement
(
'span'
)]
highlights
=
[
document
.
createElement
(
'span'
)]
sandbox
.
stub
(
anchoring
,
'anchor'
)
.
returns
(
Promise
.
resolve
(
range
))
htmlAnchoring
.
anchor
.
returns
(
Promise
.
resolve
(
range
))
sandbox
.
stub
(
highlighter
,
'highlightRange'
)
.
returns
(
highlights
)
highlighter
.
highlightRange
.
returns
(
highlights
)
target
=
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]}
target
=
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]}
return
guest
.
anchor
({
target
:
[
target
]}).
then
(
anchors
)
->
return
guest
.
anchor
({
target
:
[
target
]}).
then
(
anchors
)
->
assert
.
equal
(
anchors
.
length
,
1
)
assert
.
equal
(
anchors
.
length
,
1
)
...
@@ -572,8 +578,8 @@ describe 'Guest', ->
...
@@ -572,8 +578,8 @@ describe 'Guest', ->
it
'adds the anchor to the "anchors" instance property"'
,
()
->
it
'adds the anchor to the "anchors" instance property"'
,
()
->
guest
=
createGuest
()
guest
=
createGuest
()
highlights
=
[
document
.
createElement
(
'span'
)]
highlights
=
[
document
.
createElement
(
'span'
)]
sandbox
.
stub
(
anchoring
,
'anchor'
)
.
returns
(
Promise
.
resolve
(
range
))
htmlAnchoring
.
anchor
.
returns
(
Promise
.
resolve
(
range
))
sandbox
.
stub
(
highlighter
,
'highlightRange'
)
.
returns
(
highlights
)
highlighter
.
highlightRange
.
returns
(
highlights
)
target
=
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]}
target
=
{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]}
annotation
=
{
target
:
[
target
]}
annotation
=
{
target
:
[
target
]}
return
guest
.
anchor
(
annotation
).
then
->
return
guest
.
anchor
(
annotation
).
then
->
...
@@ -589,7 +595,7 @@ describe 'Guest', ->
...
@@ -589,7 +595,7 @@ describe 'Guest', ->
highlights
=
[]
highlights
=
[]
guest
=
createGuest
()
guest
=
createGuest
()
guest
.
anchors
=
[{
annotation
,
target
,
highlights
}]
guest
.
anchors
=
[{
annotation
,
target
,
highlights
}]
removeHighlights
=
sandbox
.
stub
(
highlighter
,
'removeHighlights'
)
removeHighlights
=
highlighter
.
removeHighlights
return
guest
.
anchor
(
annotation
).
then
->
return
guest
.
anchor
(
annotation
).
then
->
assert
.
equal
(
guest
.
anchors
.
length
,
0
)
assert
.
equal
(
guest
.
anchors
.
length
,
0
)
...
@@ -599,11 +605,11 @@ describe 'Guest', ->
...
@@ -599,11 +605,11 @@ describe 'Guest', ->
it
'does not reanchor targets that are already anchored'
,
()
->
it
'does not reanchor targets that are already anchored'
,
()
->
guest
=
createGuest
()
guest
=
createGuest
()
annotation
=
target
:
[{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]}]
annotation
=
target
:
[{
selector
:
[{
type
:
'TextQuoteSelector'
,
exact
:
'hello'
}]}]
stub
=
sandbox
.
stub
(
anchoring
,
'anchor'
)
.
returns
(
Promise
.
resolve
(
range
))
htmlAnchoring
.
anchor
.
returns
(
Promise
.
resolve
(
range
))
return
guest
.
anchor
(
annotation
).
then
->
return
guest
.
anchor
(
annotation
).
then
->
guest
.
anchor
(
annotation
).
then
->
guest
.
anchor
(
annotation
).
then
->
assert
.
equal
(
guest
.
anchors
.
length
,
1
)
assert
.
equal
(
guest
.
anchors
.
length
,
1
)
assert
.
calledOnce
(
stub
)
assert
.
calledOnce
(
htmlAnchoring
.
anchor
)
describe
'#detach()'
,
->
describe
'#detach()'
,
->
it
'removes the anchors from the "anchors" instance variable'
,
->
it
'removes the anchors from the "anchors" instance variable'
,
->
...
@@ -636,7 +642,7 @@ describe 'Guest', ->
...
@@ -636,7 +642,7 @@ describe 'Guest', ->
guest
=
createGuest
()
guest
=
createGuest
()
annotation
=
{}
annotation
=
{}
highlights
=
[
document
.
createElement
(
'span'
)]
highlights
=
[
document
.
createElement
(
'span'
)]
removeHighlights
=
sandbox
.
stub
(
highlighter
,
'removeHighlights'
)
removeHighlights
=
highlighter
.
removeHighlights
guest
.
anchors
.
push
({
annotation
,
highlights
})
guest
.
anchors
.
push
({
annotation
,
highlights
})
guest
.
deleteAnnotation
(
annotation
)
guest
.
deleteAnnotation
(
annotation
)
...
...
src/annotator/test/host-test.coffee
View file @
b2ad6fb3
proxyquire
=
require
(
'proxyquire'
)
Host
=
require
(
'../host'
)
Host
=
proxyquire
(
'../host'
,
{})
describe
'Host'
,
->
describe
'Host'
,
->
sandbox
=
sinon
.
sandbox
.
create
()
sandbox
=
sinon
.
sandbox
.
create
()
...
...
src/annotator/test/integration/multi-frame-test.js
View file @
b2ad6fb3
'use strict'
;
'use strict'
;
const
proxyquire
=
require
(
'proxyquire'
);
const
isLoaded
=
require
(
'../../util/frame-util'
).
isLoaded
;
const
isLoaded
=
require
(
'../../util/frame-util'
).
isLoaded
;
const
FRAME_DEBOUNCE_WAIT
=
require
(
'../../frame-observer'
).
DEBOUNCE_WAIT
+
10
;
const
FRAME_DEBOUNCE_WAIT
=
require
(
'../../frame-observer'
).
DEBOUNCE_WAIT
+
10
;
const
CrossFrame
=
require
(
'../../plugin/cross-frame'
);
describe
(
'CrossFrame multi-frame scenario'
,
function
()
{
describe
(
'CrossFrame multi-frame scenario'
,
function
()
{
let
fakeAnnotationSync
;
let
fakeAnnotationSync
;
...
@@ -30,7 +30,7 @@ describe('CrossFrame multi-frame scenario', function() {
...
@@ -30,7 +30,7 @@ describe('CrossFrame multi-frame scenario', function() {
proxyAnnotationSync
=
sandbox
.
stub
().
returns
(
fakeAnnotationSync
);
proxyAnnotationSync
=
sandbox
.
stub
().
returns
(
fakeAnnotationSync
);
proxyBridge
=
sandbox
.
stub
().
returns
(
fakeBridge
);
proxyBridge
=
sandbox
.
stub
().
returns
(
fakeBridge
);
const
CrossFrame
=
proxyquire
(
'../../plugin/cross-frame'
,
{
CrossFrame
.
$imports
.
$mock
(
{
'../annotation-sync'
:
proxyAnnotationSync
,
'../annotation-sync'
:
proxyAnnotationSync
,
'../../shared/bridge'
:
proxyBridge
,
'../../shared/bridge'
:
proxyBridge
,
});
});
...
@@ -53,6 +53,8 @@ describe('CrossFrame multi-frame scenario', function() {
...
@@ -53,6 +53,8 @@ describe('CrossFrame multi-frame scenario', function() {
sandbox
.
restore
();
sandbox
.
restore
();
crossFrame
.
destroy
();
crossFrame
.
destroy
();
container
.
parentNode
.
removeChild
(
container
);
container
.
parentNode
.
removeChild
(
container
);
CrossFrame
.
$imports
.
$restore
();
});
});
it
(
'detects frames on page'
,
function
()
{
it
(
'detects frames on page'
,
function
()
{
...
...
src/annotator/test/sidebar-test.coffee
View file @
b2ad6fb3
events
=
require
(
'../../shared/bridge-events'
)
events
=
require
(
'../../shared/bridge-events'
)
proxyquire
=
require
(
'proxyquire'
)
Sidebar
=
require
(
'../sidebar'
)
rafStub
=
(
fn
)
->
fn
()
Sidebar
=
proxyquire
(
'../sidebar'
,
{
raf
:
rafStub
})
DEFAULT_WIDTH
=
350
DEFAULT_WIDTH
=
350
DEFAULT_HEIGHT
=
600
DEFAULT_HEIGHT
=
600
...
@@ -17,6 +12,14 @@ describe 'Sidebar', ->
...
@@ -17,6 +12,14 @@ describe 'Sidebar', ->
fakeCrossFrame
=
null
fakeCrossFrame
=
null
sidebarConfig
=
{
pluginClasses
:
{}}
sidebarConfig
=
{
pluginClasses
:
{}}
before
->
rafStub
=
(
fn
)
->
fn
()
Sidebar
.
$imports
.
$mock
({
raf
:
rafStub
})
after
->
Sidebar
.
$imports
.
$restore
()
createSidebar
=
(
config
=
{})
->
createSidebar
=
(
config
=
{})
->
config
=
Object
.
assign
({},
sidebarConfig
,
config
)
config
=
Object
.
assign
({},
sidebarConfig
,
config
)
element
=
document
.
createElement
(
'div'
)
element
=
document
.
createElement
(
'div'
)
...
...
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