-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move disclosures to fetch-logic #8008
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
Check warning on line 1 in cfgov/unprocessed/apps/paying-for-college/js/disclosures/utils/dollar-sign.js GitHub Actions / frontend
|
||
* | ||
* @param selector | ||
Check warning on line 3 in cfgov/unprocessed/apps/paying-for-college/js/disclosures/utils/dollar-sign.js GitHub Actions / frontend
Check warning on line 3 in cfgov/unprocessed/apps/paying-for-college/js/disclosures/utils/dollar-sign.js GitHub Actions / frontend
|
||
*/ | ||
function Query(selector) { | ||
this.elements = []; | ||
|
@@ -17,17 +17,11 @@ | |
if (typeof selector === 'string' && selector !== '') { | ||
this.elements = document.querySelectorAll(selector); | ||
} | ||
|
||
// if ( this.elements.length > 1 ) { | ||
// return this.elements; | ||
// } else { | ||
// return this.elements[0]; | ||
// } | ||
} | ||
|
||
Query.prototype.attr = function (name, value) { | ||
if (typeof value === 'undefined') { | ||
return this.elements[0].getAttribute(name); | ||
return this.elements.length ? this.elements[0].getAttribute(name) : null; | ||
} else { | ||
this.elements.forEach((elem) => { | ||
elem.setAttribute(name, value); | ||
|
@@ -36,13 +30,13 @@ | |
}; | ||
|
||
Query.prototype.cloner = function () { | ||
return this.elements[0].cloneNode(true); | ||
return this.elements.length ? this.elements[0].cloneNode(true) : null; | ||
}; | ||
|
||
Query.prototype.text = function (value) { | ||
// getter | ||
if (typeof value === 'undefined') { | ||
return this.elements[0].textContent; | ||
return this.elements.length ? this.elements[0].textContent : null; | ||
} | ||
//setter | ||
else { | ||
|
@@ -55,7 +49,7 @@ | |
Query.prototype.val = function (value) { | ||
// getter | ||
if (typeof value === 'undefined' && this.elements.length > 0) { | ||
return this.elements[0].value; | ||
return this.elements.length ? this.elements[0].value : null; | ||
} | ||
//setter | ||
else { | ||
|
@@ -146,19 +140,11 @@ | |
}; | ||
|
||
Query.prototype.height = function () { | ||
if (this.elements.length > 0) { | ||
return this.elements[0].offsetHeight; | ||
} else { | ||
return null; | ||
} | ||
return this.elements.length ? this.elements[0].offsetHeight : null; | ||
}; | ||
|
||
Query.prototype.top = function () { | ||
if (this.elements.length > 0) { | ||
return this.elements[0].offsetTop; | ||
} else { | ||
return null; | ||
} | ||
return this.elements.length ? this.elements[0].offsetTop : null; | ||
}; | ||
|
||
Query.prototype.listen = function (eventType, callback) { | ||
|
@@ -168,7 +154,7 @@ | |
}; | ||
|
||
Query.prototype.tagName = function () { | ||
return this.elements[0].tagName; | ||
return this.elements.length ? this.elements[0].tagName : null; | ||
}; | ||
|
||
Query.prototype.addClass = function (classNames) { | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this code know about Cypress? It seems like whatever the need is here should be offloaded to the test logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is kinda gross, the problem is though that the data isn't available in the test db, so this warning code will always trigger, even though the actual http requests are stubbed.
Putting this logic here allows Cypress to skip the warning code (which we want) and, in normal use of the app, allows the warning conditional to trigger when we need it.
I think maybe the best solution would be rearchitecting how the warning logic works/how the warning is propagated from the backend to the frontend, but that seemed out of scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd be happy to fast-follow that because this is pretty gross. 😁