That function is a plain mess. Unreadable, containing features that are unused (yet) but buggy, variable duplication, missing newline at the end of file, countless unrelated variable declarations in one line, missing spaces between operators, data() stored for two elements but only used for one, blah blah blah.
It took me an unnecessary long time to figure out what's going on in here at all, and that should be fixed.
This patch features no change in behaviour, except for the solved bugs that don't show up yet. (They would show up in my upcoming "check box state preservation" patch, though.) Might not apply without previously applying #308668: Make test selection page work with non-JS, although I think it would. Anyways, this brings the especially the checkbox handling function into a state where it's not a pain to look at it. Please review and apply.
Comment | File | Size | Author |
---|---|---|---|
#17 | simpletest-sanitize-js.patch | 3.32 KB | boombatower |
#13 | simpletest-sanitize-js.patch | 3.14 KB | jpetso |
#10 | simpletest-sanitize-js.patch | 5.47 KB | jpetso |
#9 | simpletest-sanitize-js.patch | 5.67 KB | jpetso |
#8 | 308719.patch | 5.2 KB | RobLoach |
Comments
Comment #1
jpetso CreditAttribution: jpetso commentedMore accurate title, as it also touches a few lines in the expand/collapse function.
Comment #2
jpetso CreditAttribution: jpetso commentedOk, the five-liner dependency has been applied, now it's the turn of this patch. I do hope that not killing kittens pays off, especially since my other patch for #305150: Keep running tests checked depends on this clean-up.
Comment #3
boombatower CreditAttribution: boombatower commentedI agree code needs a clean-up. glad someone else worked on this. Not sure how it go that way as I never looked at the js then one day I did and I closed it quickly :) I review when I get home.
Comment #4
RobLoachI visited the SimpleTest page, expanded and collapsed some tests, checked a parent test, as well as the select all, and everything seemed functional. The actual JavaScript tests are broken until #315798: JavaScript Patch #2: Weight goes in.
Comment #5
Dries CreditAttribution: Dries commentedIt looks like we can clean it up some more. For example, you declare $self, but than you keep using $this. Maybe that means we can get rid of $self -- $this is self-explanatory to me.
Bonus points for some additional code comments.
Comment #6
webchickAlso, trs and trs_formatted are not clear variable names. I know this wasn't you're doing, but as long as you're in here anyway? ;)
Comment #7
jpetso CreditAttribution: jpetso commented@Dries:
Not that I'm experienced with JavaScript/jQuery in any way, but if I remember correctly,
$(this)
denotes the current context (for the elements that $(...) selects) whereasself
is declared in the "top context" and stays the same also inside the other functions in all the sub-contexts. Thus,$(this)
is different thanself
in all functions except the one whereself
is declared. At least, that's how I got it? Might be wrong here, tell me if I am.On the other hand, you're right that there are a few instances of
$(this)
that could safely be replaced byself
, I just don't know which way is more easily understandable.@webchick:
True, but on the other hand "trs" accurately describes what the variable holds, other variable names would be more meta than that. Suggestions for a better name? "test_rows" might be workable, maybe.
Comment #8
RobLoachThis a bit better?
Comment #9
jpetso CreditAttribution: jpetso commentedBetter, yes. Seems to me like using self consistently is the only choice here, as using $(this) where appropriate is confusing even to Dries. So let's go all the way. Reworked the comments a bit, too.
I noticed that the select-everything checkbox at the top doesn't work correctly with this patch applied (it also didn't exist when I first wrote the patch), so that should probably be fixed. Steps to reproduce:
In other words, checking or unchecking the select-all checkbox doesn't update the 'simpletest-checked-tests' counter. Which makes me wonder if we should use such a counter at all... it should totally be possible to check this stuff on the fly, shouldn't it?
Comment #10
jpetso CreditAttribution: jpetso commentedOh wow, this is just so much better. Getting rid of status tracking and
self
in the checkbox handling part, which resolves all possible bugs there might ever be. Or something. Please review and commit.Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedThe last submitted patch failed testing.
Comment #12
jpetso CreditAttribution: jpetso commentedOk, so #305150: Keep running tests checked has been committed for quite a while now, but as people love features more than janitorial stuff, this issue got ignored as soon as the other one was in. That means that the bugs in the simpletest.js checkbox code do now actually manifest, because some test checkboxes are checked initially but ignored by simpletest.js's internal "selected checkboxes per group" counter.
The group collapsing function has been cleaned up by some other patch, so there's no need for cleaning that one up anymore. Therefore, let's focus on the actual purpose of this issue and get the checkbox code a) readable, and b) bug free. Rerolled patch attached.
In case you don't believe how buggy this is, here's a few steps to reproduce:
You might also try this one (slight variation, same cause):
Please get this committed, it's just a vast improvement over the current state and I'd be disappointed if I need to reroll it again in another 3 months.
Comment #13
jpetso CreditAttribution: jpetso commenteder, the actual patch.
Comment #14
webchickBoy, nothing motivates someone to commit a patch quite like a lecture. :P~~~
Get someone to review it and mark it RTBC, then we'll see about committing it.
Comment #15
webchickThough I will say, thanks for the nice steps on how to reproduce the bugs. :)
Comment #16
jpetso CreditAttribution: jpetso commentedTrue, sorry for making it sound slightly bitter. Actually it's more like the opposite; I've been doing this patch for fun with no personal gain whatsoever - I have no need for it to be committed, do with it whatever you like. And sure, I know that someone needs to RTBC it before it gets committed, it's just that I won't run after anyone for that to happen. It's all yours!
Comment #17
boombatower CreditAttribution: boombatower commented!!
++checkedTests
instead ofcheckedTests++
? Seems like post-incramenting is standard when there is no reason for them to pre-incramenting.Comment #18
jpetso CreditAttribution: jpetso commentedMakes a boolean (true) out of a non-boolean (1 / "checked" / whatever the value was, I don't remember anymore). Makes a boolean (false) out of null, or whatever that value was. Not sure which one applied to that specific case - it's been 4 months since I wrote that stuff - but better safe than sorry.
If post-incrementing is the standard somehow then I'm totally fine with using it. I usually use the pre-increment because the post-increment is normally implemented as
x = value; ++value; return x;
which is kind of an unnecessary indirection, even if only a minor one. (Disclaimer: I haven't actually checked the ECMAScript specs or an implementation of it to make sure this is also the case here. Should apply, though.)"Still takes a long time" like in, "same as before", or like in "performance regression"? (It's just like a third second at my place, but that obviously depends a lot on the machine and JS interpreter.) Also, where is that "select all" checkbox being implemented anyways? I imagine that it probably checks all the test checkboxes which triggers some unnecessary calculation. As the version in my patch does not need to keep track of checkbox status, we could save performance if the JavaScript behavior of that function was turned off before (un)checking the boxes, and turned on after that's done.
Comment #19
boombatower CreditAttribution: boombatower commentedSounds fine...so we can use your previous patch (just note the pre-incrementing if anyone cares (supper minor)).
The long time is the same as before.
Specs:
Firefox 3.0.5
openSUSE 11.1 (KDE 4.1.3)
AMD Phenom(tm) 9950 Quad-Core Processor
I don't see any reason why it should be slow, as it was on my old machine as well (which still shouldn't have been).
Comment #20
Dries CreditAttribution: Dries commentedLooks good to me. Committed to CVS HEAD. We can worry about the 'long time' in a follow-up patch. Thanks jpestso and boombatower!