forked from biouno/uno-choice-plugin
-
Notifications
You must be signed in to change notification settings - Fork 103
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
[JENKINS-74025] Extract inline JavaScript from checkboxContent.jelly
#374
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/resources/org/biouno/unochoice/common/checkbox-content.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
window.addEventListener("DOMContentLoaded", () => { | ||
document.querySelectorAll(".checkbox-content-data-holder").forEach((dataHolder) => { | ||
const { maxCount, randomName } = dataHolder.dataset; | ||
|
||
var height = 0; | ||
var refElement = document.getElementById(`ecp_${randomName}_0`); | ||
if (maxCount > 0 && refElement && refElement.offsetHeight != 0) { | ||
for (var i = 0; i < maxCount; i++) { | ||
height += refElement.offsetHeight + 3; | ||
} | ||
} | ||
else { | ||
height = maxCount * 25.5; | ||
} | ||
|
||
height = Math.floor(height); | ||
document.getElementById(`ecp_${randomName}`).style.height = height + "px"; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thanks for the PRs to update this code pattern on this repo, @yaroslavafenkin !
I was looking at the changes on these PRs, and it occurred to me that if we moved the inline functions to this file as a function, then we could call that in these
forEach
loop, while also being able to write tests to verify those functions. WDYT?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.
Sure, I could look into that.
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.
I'm trying to figure out to approach this.
If I just extract the function like this:
I won't have access to the
setHeight
function in*.test.js
. I tried to mark it as exported so that I can access it in a unit test, but that makes Java tests fail withand with a lot of entries in the stack trace containing
htmlunit
.Another option I thought of is moving the
setHeight
function toUtil.ts
. But it's a little different that other functions there. It doesn't return anything, but just modifies the state of a DOM element depending also on some data in another DOM element. Without any further refactoring and given its reliance on DOM can this even be tested?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.
Hi @yaroslavafenkin
I think it'd be easier to use Jest with an update to its current config that only loads typescript files (or you can write it in TS if you prefer), e.g. after applying your diff (thanks for that!!!):
Then running
yarn run test
finds the extra test, and it passes successfully (although the test is not doing anything useful right now). I think we will have to use jsdom do prepare the elements forsetHeight
to be called, and then test a few scenarios 👍Let me know if that helps.
Cheers
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.
TS is fine for me to use.
I've created
checkbox-content.test.ts
insrc/test/js
. Here's its content (without imports, as those require tweaks depending on the approach taken):Now there are few paths when it comes to code arrangement:
setHeight
incheckbox-content.js
. To be able to call the function in a test I've tried adding theexport
keyword before thefunction
keyword incheckbox-content.js
. Runningnpm run test
results in log telling mesetHeight
is not defined.setHeight
toUtil.ts
. With that I was able to write a test that passed just fine. I went to test whether everything still worked in the Jenkins UI, and it didn't.Util.js
isn't included into the page asUnoChoice.js
is. I could appendUtil.js
somewhere here, then it would work. Would pollute the page with unneeded object though.setHeight
toUnoChoice.es6
as that one is exported and included into the page already. I cannot import thesetHeight
fromUnoChoice.es6
in a test though. First of all.es6
isn't a module extension recognized by jest. I was able to get past that by changing jest's config, but then I get the following error: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.
Hi @kinow, I wanted to let you know that this plugin is now in the top 3 of plugins with CSP violations and unreleased CSP fixes by popularity (along with Blue Ocean and Artifactory). Our contract with Alpha Omega lasts until the end of the year, so ideally we could get this plugin released with CSP fixes in the next few weeks while we still have staffing to work on it. While the risk of regression is low with CSP changes, releasing a few weeks before the end of the year would also give us time to address any regressions in the unlikely case that any are reported. Historically Jenkins activity slows down a lot in the month of December as well.
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.
Hi @basil, the CSP violations are fixed by these inline extraction pull requests? If so, I'd be happy to review & merge them without the extra work to refactor it and write the tests (as these would be tests for existing code, and not for new code). I'd just open a new issue to work on that later.
WDYT?
BTW, @basil, I saw some plugins are using GitHub issues... would you know if it'd be possible for a plugin with JIRA issues to migrate to GitHub issues, please?
Thanks
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.
Releasing the existing PRs and working on refactoring for test coverage in a separate issue sounds great to me. That would enable us to get some soak time for the production change while the project is still being funded.
I believe there was a thread on the developer mailing list about migrating to GitHub issues but I do not remember the current status. I believe that you can enable GitHub issues for this repository in the GitHub UI and set a flag in
jenkins-infra/repository-permissions-updater
to show a link to GitHub issues on the plugin site. Not sure about migrating existing Jira issues to GitHub issues. (Indeed, a high-fidelity migration covering all existing use cases was my main concern the last time this topic was discussed.)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.
Roger that, then I can try to release it by the end of this weekend, so that we have it ready for testing over next week (90% sure I can do that, but family/life/$work/etc comes first, as you know).
Some time ago I found a similar thread, I think I know how to enable it on a project.
Yeah, that's what I couldn't find before. I think the... GitLab plugin was the first plugin I saw using GitHub issues. But that's lower priority than releasing it. I will review & merge it, open the new issue in JIRA, do some triaging on the issues to see if there's anything else simple that could be added, and then cut the release. While others test it, then, I will see if I can work on moving this and maybe tap-plugin both to GitHub issues.
Cheers