-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Comment Template Unit Test: Cover odd/even classes #40471
Conversation
25f0e93
to
efafb72
Compare
efafb72
to
bde09d5
Compare
c3c1127
to
4b92fd6
Compare
I've tried producing a minimal test case that would fail (this PR doesn't have the fix from #40455 yet), but I'm struggling to find one. @michalczaplinski Based on your work on that PR, can you help me find one? Currently, I'm using
Which I thought would give even-even-odd-odd (since it'd start assigning classes at comment 4 -> 2 -> 3 -> 1), but it didn't. I also tried a few different other variants (see commit log), but to no avail ( You might have a better insight in how this works, can you maybe suggest a different comment hierarchy to test with? 😅 |
Hey @ockham ! I think the issue you hit is that the Instead, "odd" and "even" refers to the index of the comment, when traversing them depth-first. At least that's how the classes are applied in core so I've used the same logic in the block. 2022-04-20_19-21-07.mp4This means that your test should be passing (as it indeed is!). To be honest, I don't know if those classes are particularly useful but I didn't want to deviate from the way they're applied in core. |
Hey @michalczaplinski, thanks for the explanation! I should've been a bit clearer: The motivation for this PR was to create a unit test that would fail if #40455 wasn't applied. While we already had a test with some nested comments, the way they were nested didn't cause the unit test too fail with regards to To that end, I actually created this branch from Anyway, we can keep trying for a bit longer. What we shouldn't do is merge this PR as-is; it has no added value compared to the previous nesting layout, since the tests would pass in both cases. Instead, we need to make it fail (with regard to |
@ockham I've checked out the branch and I've ran the tests and the output is what I would expect 🤔 Am I missing something here? |
Oh wow, that's super interesting. Looks like the tests are failing exactly as they should when you run them locally @michalczaplinski 😮 Well the weirdest thing to me is that in CI, they pass: And it doesn't seem like the test is being ignored, since they did fail earlier when I had made other mistakes in the expected block markup 😕 I'm a bit stumped here -- the whole point of this exercise would be for the tests to alert us if we mess up the comment classes logic via CI -- i.e. to block a PR from merging... |
I think this is because github actions do not care that you've created this branch before merging #40455 😄 The action is run on the repository in the state that it would have after the current change in the PR were applied to You can verify this by running locally the same
If you open the Comment Template's So, I think that we can merge this PR as is, as it should indeed fail if there is a regression in the way the CSS classes are applied. |
I gotta admit, I thought that GHA worked differently than that 🤔 😅 Anyway, good point! I'd like to put it to a test before merging: I'll rebase on |
4b92fd6
to
936301f
Compare
Yes! It did! |
PR only increases unit test coverage; change has been shown to cover a previous regression, and to otherwise pass reliably (see). Going to merge. |
Backported to Core (thanks to @DAreRodz) in this PR: WordPress/wordpress-develop#2649 |
What?
Add a unit test to cover the Comment Template block's
even
/odd
behavior (i.e. add coverage for #40455).Why?
Cover against regressions of #40455.
How?
By changing our nested test comments in a way that allows us to detect if odd/even classes are applied correctly.
Testing Instructions
npm run test-unit-php
. The test should fail now. Here's proof from a previous CI run.