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

Reset scroll state on render #732

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

danDanV1
Copy link

@danDanV1 danDanV1 commented Nov 6, 2019

Ensuresdiv#ember-testing-container scrollTop and scrollLeft are zero on render.

Fixes #729, where scrolling during testA will persist container scroll position to testB and thus make the tests brittle.

+Adds ember-qunit CSS so we can properly test the container.

Feedback/Changes welcome!

@danDanV1
Copy link
Author

danDanV1 commented Nov 6, 2019

is it possible to rerun the test? yarn is throwing Segmentation fault for some reason.

@rwjblue
Copy link
Member

rwjblue commented Nov 6, 2019

restarted

@@ -144,6 +144,8 @@ export function render(template: TemplateFactory): Promise<void> {
};
toplevelView.setOutletState(outletState);

resetScrollState();
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is the correct place to call this. It would still have the same issue if a rendering test scrolls somewhere and then an application test follows that relies on the scroll position. Should we call this in "afterEach()" instead? 🤔

Copy link
Author

Choose a reason for hiding this comment

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

I think I understand that issue. Please help me understand your thoughts on the recommendation for afterEach().

Are you suggestion that perhaps resetScrollState() should be a helper and then it'd be at the discretion of the user to call it in the afterEach hook whenever scroll state needs to be guaranteed? That way it will work regardless if it is an acceptance test or an integration test.

  setupRenderingTest(hooks);
 //OR
 //setupApplicationTest(hooks);

  hooks.afterEach(async function() {
    await resetScrollState()
  });

  test('it renders', async function(assert) {
    await render(hbs`<MyComponent />`);
});

Copy link
Author

Choose a reason for hiding this comment

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

hmmm. But even that wouldn't solve the issue is there were two renders in a single component test.

    await render(hbs`
      await render(hbs`<MyComponent />`);
    `);

    clearRender();

    await render(hbs`
      <div>SomethingElse</div>
    `);

So maybe it has to be in either render() or clearRender() for integration tests as well as used in afterEach for acceptance tests?

Copy link
Member

Choose a reason for hiding this comment

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

But even that wouldn't solve the issue is there were two renders in a single component test.

FWIW, I think this is pretty rare.


We can add logic to teardownContext and clearRender to reset the scroll state, that would work for both rendering and application tests as well as using render twice...

@amk221
Copy link
Contributor

amk221 commented Nov 25, 2020

👋🏻 Is this likely to get in?

It's just started to affect me...

Scenario: Testing dragging and dropping something. The test that is run before the drag and drop test (depending on test order with Ember Exam) may have scrolled #ember-testing-container, subsequently some third party drag/drop code that uses elementFromPoint fails.

@NullVoxPopuli
Copy link
Sponsor Collaborator

hello! sorry for not looking at this PR sooner -- would you be willing to rebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add reseting ember-testing-container scroll position during render()
5 participants