Commit 6e2fc70d authored by Robert Knight's avatar Robert Knight

Make anchoring implementation constructor-injectable in Guest class

This enables mocking of the `anchoring/html` module in tests without having
to patch the `anchoring` property after the class is constructed.
parent 403bbda5
......@@ -38,7 +38,7 @@ module.exports = class Guest extends Delegator
TextSelection: {}
# Anchoring module
anchoring: htmlAnchoring
anchoring: null
# Internal state
plugins: null
......@@ -49,7 +49,7 @@ module.exports = class Guest extends Delegator
html:
adder: '<hypothesis-adder></hypothesis-adder>'
constructor: (element, config) ->
constructor: (element, config, anchoring = htmlAnchoring) ->
super
this.adder = $(this.html.adder).appendTo(@element).hide()
......@@ -78,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
this.frameIdentifier = config.subFrameIdentifier || null
this.anchoring = anchoring
cfOptions =
config: config
on: (event, handler) =>
......
......@@ -54,7 +54,6 @@ describe 'Guest', ->
config = Object.assign({}, guestConfig, config)
element = document.createElement('div')
guest = new Guest(element, config)
guest.anchoring = htmlAnchoring
return guest
beforeEach ->
......@@ -77,6 +76,7 @@ describe 'Guest', ->
Guest.$imports.$mock({
'./adder': {Adder: FakeAdder},
'./anchoring/html': htmlAnchoring,
'./highlighter': highlighter,
'./range-util': rangeUtil,
'./selections': (document) ->
......
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