Repository navigation
fix(challenge): account for browser zoom, add note to challenge (for width challenge) - #37688
Conversation
|
@lasjorg It's possible to format the YAML strings however you want, but you need to wrap them in single or double quotes. Here's the spec, but the main points are
For example: tests:
- text: Your code should change the <code>width</code> property of the card to 245 pixels by using the <code>fullCard</code> class selector.
testString: "assert(
Math.round(
document.querySelector('.fullCard').getBoundingClientRect().width
) -
10 ===
245 &&
/\\.fullCard{\\S*width:245px(;\\S*}|})/.test(
$('style')
.text()
.replace(/\\s/g, '')
)
);" |
|
@lasjorg You could also create a helper function and place it in the |
|
Thank you both for the info. I don't think I have ever seen a challenge where the assert code was formatted. I like the formatting but I think the escaping makes the regex harder to read and is likely to confuse some if unaware of the YAML rules. @ojeytonwilliams @RandellDawson Do you guys think I need to make it more clear what the |
|
Switched to just using regex. |
ojeytonwilliams
left a comment
There was a problem hiding this comment.
Looks good. Just need to remove the warning.
|
Are there any outstanding issues that this PR closes? If so, can we get them listed in the PR body? |
|
@RandellDawson I don't think there are any open issues for this challenge (just the one closed). At least not that I found. |
RandellDawson
left a comment
There was a problem hiding this comment.
I can pass the challenge with the following which do not actually affect the width.
.fullCard {
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
max-width: 245px;
}OR
.fullCard {
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
Width: 245px;
}OR
.fullCard {
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
mywidth: 245px;
}|
@RandellDawson Yes I know, sorry. I did see that the regex(s) was lax but I just kept it like it was. It also allows for incorrect syntax (also because of the I guess we have to rewrite them. If anyone has any good suggestions I'm all ears. Not going to lie. I'm half tempted to just put back the zoom note and leave it how it was to begin with. This zoom nonsense is apparently a "feature" of Blink and not a bug. Who knows just how many challenges are affected. Rewriting 3 or 4 challenges is not so bad, but if we have to rewrite a bunch of them just to accommodate this one problem then I'm not so sure it's worth it. Adding a note to each affected challenge might make more sense. That way we also won't inadvertently introduce new bugs. I'm just confused why we haven't seen this reported before now? These (new?) bug reports seems to oddly correspond in time with the latest major site update. But maybe it's just a coincidence. |
|
This is why I thought we'd better off without regex. It accepts both correct ways of doing it (I checked that much), but so much more besides (which I should have checked, but didn't). Apparently we have to use it. As for solving this, aren't there two types of tests that have the bug. Dimensions set inline and dimensions set by css? The first type seems to be solved by checking
Except that that is a pain for people that actually need it to be zoomed to be able to read.
Eh, I don't agree with them. Since they aren't consistent with Firefox, at least one of them has a bug. |
|
I have reverted to my initial code for now. @ojeytonwilliams Sure some fixes are pretty easy. I'm just not sure how many challenges are actually affected by this.
It seems they have decided that precision of 1/64th of a pixel is enough. I guess it might be a performance thing. Unless we can come up with a good regex, I think my initial code for the PR is the best we have so far. I don't see the rounding being a problem here because we are limiting the valid input to 245 using the regex so the user can not enter some weird value. Also, this is on a fixed sized element so the viewport dimension does not dynamically change the element dimension. These two facts combined makes me think we can get away with rounding the number. Theoretical issues aside. I think we should implement it and get it tested, at least until we have something better. It can't be worse than what we have in production now. |
|
I've used a regex like this a number of times in the past @lasjorg... not sure if you want to keep changing this around, but it's pretty robust - it could apply to the other PR as well. |
|
@moT01 @ojeytonwilliams Do you think we need to use the better regex or should we just go with the one we already have? |
There was a problem hiding this comment.
The current state of this PR doesn't address @RandellDawson's concerns, they are still a problem - although his second example should pass since capitalization still applies the style.
After playing around with this for a little bit, the rounding issue was just too much of a pain for me. I came up with this...
testString: const fullCard = code.match(/\.fullCard\s*{[\s\S]+?[^}]}/g)[0];
assert(/width\s*:\s*245px\s*(;|})/gi.test(fullCard) &&
getComputedStyle(document.querySelector('.fullCard')).maxWidth === 'none');
It's similar to what I suggested earlier, but adds a check that max-width isn't used. That's what I would go with, but I don't really care as long as it works and, right now, it isn't.
|
@moT01 Thank you for the help. There are edge cases for broken syntax with this pure regex based approach. You can break the output while still passing the test. Invalid syntax after the opening brace: Extra character before Missing semicolon on the rule that comes before: There are probably other edge cases I haven't considered. Not sure how, or if, we should test for this? |
|
@lasjorg I think any regex we come up with is likely to accept some incorrect answers. As long as it passes all the correct answers we can come up with and as long as it rejects typical mistakes, I'm okay with that. As long as @RandellDawson and @moT01 are happy, that's good enough for me. |
|
The first edge case does not bother me as bad as the 2nd and 3rd. Those two would not create the desired effect in the preview pane, yet pass the challenge. |
|
Just so I don't forget, I have push this "as is" for now.
|
moT01
left a comment
There was a problem hiding this comment.
Alright, I'm fine adding it like this, it fixes the rounding issues that were the main problem. The only edge case that I found is that using min-width: 245px will pass. But, that input is unlikely and I hate to keep asking for changes for small things like that. If any other edge cases come up, we can deal with them then. Thanks for all the work on this @lasjorg 🎉
|
Thank you for your contribution to the page! 👍 |
…width challenge) (freeCodeCamp#37688) * fix(challenge): account for browser zoom, add note to challenge * fix(challenge): use regex for width assert * fix(challenge): remove note * fix(challenge): revert to initial PR code * updated regex, add check for maxWidth
Update index.md)masterbranch of freeCodeCamp.This is the same fix as for the height challenge. I do not have any confirmation for this fix yet (forum post showing the issue). We may or may not want to wait for one.
I thought about wrapping this in a function to add a variable explaining the
- 10part, just to avoid any "magic" numbers. But that just makes the assert really long and without proper formatting it gets hard to read in my opinion.The
- 10is subtracting the padding and border of the.fullCardelement to get the "true" width.