Skip to content
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

fix: #29093 for elements with length in rem #29224

Open
wants to merge 85 commits into
base: develop
Choose a base branch
from

Conversation

senpl
Copy link

@senpl senpl commented Mar 29, 2024

Additional details

Change was necessary because previous visibility check version works only with integer values for visibility. Current fix provide it with getting real width.
In theory it now fixes issue when visible element throws error as hidden/invisible or without width/height.
Still how visibility should behave when grid is used is not really clear, so there might be cases that this check is not perfect. Still I guess it's better than it was before.

Steps to test

e2e or component test

describe('Repro', () => {
    it('Skeleton Fail without changes', () => {
        cy.viewport('macbook-16');
        cy.visit('https://www.skeleton.dev/docs/get-started');
        cy.get('#sidebar-left > div > section').click();
      });
  })

How has the user experience changed?

User no longer has to use {force: true} fix.

PR Tasks

@CLAassistant
Copy link

CLAassistant commented Mar 29, 2024

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link
Collaborator

@senpl senpl marked this pull request as ready for review March 29, 2024 13:13
@jennifer-shehane
Copy link
Member

@senpl Thanks! Can you add a test around this new behavior?

There is a Contributing Guide that covers how to contribute and get Cypress running locally in generally here: https://github.com/cypress-io/cypress/blob/develop/.github/CONTRIBUTING.md

Here's an example of another issue's test code:

To run the tests:

  • within cypress root, run yarn
  • run yarn workspace @packages/driver cypress:open
  • click on the test you're writing to run it within Cypress

Instructions for running the driver tests can always be found here: https://github.com/cypress-io/cypress/blob/develop/packages/driver/README.md

Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I manually tested the change against the 3 examples this is expected to fix. It does fix them.

There are some other tests failing however, so it looks like this logic has broken some other visibility checks:
Screenshot 2024-04-11 at 4 01 24 PM

I had some concern around performance of this, and whether this would mean slower performance. Running benchmarks against offsetWidth vs getBoundingClientRect seem to indicate that getBoundingClientRect is actually faster.

Before

Screenshot 2024-04-11 at 3 18 51 PM

After

Screenshot 2024-04-11 at 3 18 51 PM

@jennifer-shehane jennifer-shehane self-requested a review May 10, 2024 14:48
@@ -117,10 +117,10 @@ describe('FileRow', () => {
cy.contains(changesRequiredDescription).should('be.visible')
cy.get('pre').should('have.length', 2)

cy.get('.shiki').should('be.visible')
cy.get('div.rounded > div.text-left.cursor-text').should('be.visible')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@senpl Could you explain the need for this change? If users are required to update their tests based on this change, this would be considered a breaking change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.shiki is not precise selector. In moment of search in this test there are two elements with this locator. One berly visible but still possible to locate.
This selector better explain what test intended to search.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be breaking change for poorly created locators. Still it's closer to what user can actually see in browser. So it's probably good change. If I could locate element in browser then it's visible, but there should be some rules to determine if something is visible or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @senpl ,

There are two .shiki elements in this component. One of them is always hidden, and one of them that should show/hide on click. The hidden state for this element is caused by a parent element with maxHeight of 0, and overflow:hidden.

I do agree that the .shiki selector here should be more specific. I edited it to assert the expected visibility state of both elements:

    // A FileRow with status=valid should not be initially open 
    cy.get('[data-cy=valid] .shiki').should('not.be.visible')
    // A FileRow with status=changes should be initially open
    cy.get('[data-cy=changes] .shiki').should('be.visible')

    // Clicking the header should collapse the shiki code view in the FileRow 
    cy.contains('cypress/integration/command.js').click()

    cy.get('[data-cy=valid] .shiki').should('not.be.visible')
    cy.get('[data-cy=changes] .shiki').should('not.be.visible')

Unfortunately, while this test passes on the develop, it does not pass with the visibility changes in this branch. Can you look into why?

Thank you!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already did.
But this second locator is still visible. I could click it in browser and get it's locator. It's not big. It could to be very hard to click on it. Still it is visible. I do not see reason for Cypress to mark something as invisible when it is visible. It might produce warning that something is hardly visible, still if it's partly visible it should not expect that element to be not visible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in pictures below .shrik width is bigger then element code below in moment of checking. This is why something that is really invisible or not exist should be checked, not something that is visible in moment of click. Alternatively we could wait for this moment to become invisible, but this would make test slower and not as practical.
chrome_rufv04rfEp
chrome_tFds2UDHKr

@jennifer-shehane jennifer-shehane dismissed their stale review May 20, 2024 13:45

Dismissing previous review

@jennifer-shehane jennifer-shehane removed their request for review May 20, 2024 13:45
@mschile mschile requested a review from cacieprins May 21, 2024 15:51
@@ -117,10 +117,10 @@ describe('FileRow', () => {
cy.contains(changesRequiredDescription).should('be.visible')
cy.get('pre').should('have.length', 2)

cy.get('.shiki').should('be.visible')
cy.get('div.rounded > div.text-left.cursor-text').should('be.visible')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @senpl ,

There are two .shiki elements in this component. One of them is always hidden, and one of them that should show/hide on click. The hidden state for this element is caused by a parent element with maxHeight of 0, and overflow:hidden.

I do agree that the .shiki selector here should be more specific. I edited it to assert the expected visibility state of both elements:

    // A FileRow with status=valid should not be initially open 
    cy.get('[data-cy=valid] .shiki').should('not.be.visible')
    // A FileRow with status=changes should be initially open
    cy.get('[data-cy=changes] .shiki').should('be.visible')

    // Clicking the header should collapse the shiki code view in the FileRow 
    cy.contains('cypress/integration/command.js').click()

    cy.get('[data-cy=valid] .shiki').should('not.be.visible')
    cy.get('[data-cy=changes] .shiki').should('not.be.visible')

Unfortunately, while this test passes on the develop, it does not pass with the visibility changes in this branch. Can you look into why?

Thank you!

@senpl senpl requested a review from cacieprins May 29, 2024 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants