Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Goldsmith <mark.goldsmith@rtspecialty.com>2020-02-19 08:51:03 -0500
committerMark Goldsmith <mark.goldsmith@rtspecialty.com>2020-02-19 08:52:53 -0500
commit1e76291ada7040a0fdd9f96979e26f782b82bf2d (patch)
tree5d91854aa95bab66e4dc5c09caee8ae8452f3d8b
parente9ded067b1f60311db97d405298a2663304a3fc0 (diff)
downloadliza-1e76291ada7040a0fdd9f96979e26f782b82bf2d.tar.gz
liza-1e76291ada7040a0fdd9f96979e26f782b82bf2d.tar.bz2
liza-1e76291ada7040a0fdd9f96979e26f782b82bf2d.zip
[DEV-7060] Set document in constructor of ElementStyler
-rw-r--r--src/ui/ElementStyler.js11
-rw-r--r--test/ui/ElementStylerTest.js16
2 files changed, 19 insertions, 8 deletions
diff --git a/src/ui/ElementStyler.js b/src/ui/ElementStyler.js
index 4ee28cc..3101a05 100644
--- a/src/ui/ElementStyler.js
+++ b/src/ui/ElementStyler.js
@@ -88,6 +88,12 @@ module.exports = Class( 'ElementStyler',
*/
'private _jquery': null,
+ /**
+ * HTML Document
+ * @type {HTMLElement}
+ */
+ 'private _document': null,
+
_answerStyles: {
'deductible': function( value, _, default_val )
@@ -193,6 +199,7 @@ module.exports = Class( 'ElementStyler',
{
this._$context = jquery;
this._jquery = jquery;
+ this._document = jquery( 'body' ).context;
},
@@ -855,10 +862,10 @@ module.exports = Class( 'ElementStyler',
if ( hasindex )
{
var id = this._getElementId( name, index );
-
+
if ( id )
{
- element = document.getElementById( id );
+ element = this._document.getElementById( id );
// let's hope for the best
if ( element !== null )
diff --git a/test/ui/ElementStylerTest.js b/test/ui/ElementStylerTest.js
index e7d16af..30812a8 100644
--- a/test/ui/ElementStylerTest.js
+++ b/test/ui/ElementStylerTest.js
@@ -115,10 +115,15 @@ describe( 'ui.ElementStyler', () =>
{
it( "determines the correct element id for " + name, () =>
{
- // Stub all objects
- $ = sinon.stub();
- jQuery = sinon.stub();
- document = sinon.stub();
+ // Stub document and jQuery calls
+ $ = sinon.stub();
+ jQuery = sinon.stub();
+
+ const document = {
+ getElementById: sinon.stub()
+ };
+
+ jQuery.withArgs( 'body' ).returns( { context: document } );
const sut = Sut( jQuery );
@@ -136,12 +141,11 @@ describe( 'ui.ElementStyler', () =>
html: html,
};
- document.getElementById = sinon.stub();
document.getElementById.returns( node );
sut.getWidgetByName( name, index, null, context );
- const actual_id = document.getElementById.getCall(0).args[0];
+ const actual_id = document.getElementById.getCall( 0 ).args[ 0 ];
expect( actual_id )
.to.equal( expected_id );