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 ...@@ -38,7 +38,7 @@ module.exports = class Guest extends Delegator
TextSelection: {} TextSelection: {}
# Anchoring module # Anchoring module
anchoring: htmlAnchoring anchoring: null
# Internal state # Internal state
plugins: null plugins: null
...@@ -49,7 +49,7 @@ module.exports = class Guest extends Delegator ...@@ -49,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()
...@@ -78,6 +78,8 @@ module.exports = class Guest extends Delegator ...@@ -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 # 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) =>
......
...@@ -54,7 +54,6 @@ describe 'Guest', -> ...@@ -54,7 +54,6 @@ describe 'Guest', ->
config = Object.assign({}, guestConfig, config) config = Object.assign({}, guestConfig, config)
element = document.createElement('div') element = document.createElement('div')
guest = new Guest(element, config) guest = new Guest(element, config)
guest.anchoring = htmlAnchoring
return guest return guest
beforeEach -> beforeEach ->
...@@ -77,6 +76,7 @@ describe 'Guest', -> ...@@ -77,6 +76,7 @@ describe 'Guest', ->
Guest.$imports.$mock({ Guest.$imports.$mock({
'./adder': {Adder: FakeAdder}, './adder': {Adder: FakeAdder},
'./anchoring/html': htmlAnchoring,
'./highlighter': highlighter, './highlighter': highlighter,
'./range-util': rangeUtil, './range-util': rangeUtil,
'./selections': (document) -> './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