Giter Site home page Giter Site logo

Comments (5)

christophherr avatar christophherr commented on September 11, 2024

@no-stack-dub-sack
What I have found so far:
Function testHorizontallyCentered expects delta to be between < 3 and > -3 to return true.
https://github.com/freeCodeCamp/testable-projects-fcc/blob/master/src/project-tests/quote-machine-tests.js#L14

When a scroll bar is visible on my 13.3" display, delta is always 8.5.
(It doesn't matter whether clientWidth, offsetWidth or scrollWidth is used in quote-machine-tests.js#L10)
I added console.logs showing the values of the test variables to my codepen.

Changing the function to return delta < 9 && delta > -3 passes the test locally and (after changing the rawgit url) in the codepen .

I don't know if the original value for delta follows a best practice or if it could just be adjusted.

from testable-projects-fcc.

no-stack-dub-sack avatar no-stack-dub-sack commented on September 11, 2024

@christophherr nice investigative work! Hmmm, the only issue I see with changing the delta to your suggestion, I guess, is that this solution covers your display, but will this also cover another display where the delta is greater that 8.5. Also, how large can we make the margin of error, before it's possible to fool the test even if the element is not horizontally centered.

I wonder if we can brainstorm another way of determining the element is centered that is more reliable across different displays...

from testable-projects-fcc.

christophherr avatar christophherr commented on September 11, 2024

@no-stack-dub-sack From testing on a few different display sizes (15.6", 19" and @Enikol 24"), it seems that as long as the aspect ratio stays the same, 8.5 is the value when a scroll bar is visible (e.g. 17px being the scrollbar width).
We could check if a scrollbar is visible and change the delta range accordingly.
There is a problem when the browser window is zoomed in or out. I´ve seen variations up to +13 for delta. It looks like checking for the zoom factor of a browser window is pretty convoluted if not impossible. We might be able to check the window.devicePixelRatio but I haven't looked at how delta would have to be adjusted for variations on that.
Is this the only challenge that checks if an element is centred?

from testable-projects-fcc.

no-stack-dub-sack avatar no-stack-dub-sack commented on September 11, 2024

@christophherr I believe it's the only test that looks for centered on the entire page - others test for centered within other elements.

Maybe we can go ahead and change the delta to 8.5, and put a note in the unit test copy that says "(be sure your browser is not zoomed in or out when running this test)" or something like that.

Thoughts?

from testable-projects-fcc.

christophherr avatar christophherr commented on September 11, 2024

@no-stack-dub-sack Sounds good to me, especially if it´s the only test of its kind.
It's probably not ideal from an a11y (accessibility) point of view.
I'll submit a PR over the weekend.

from testable-projects-fcc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.