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(top-app-bar): Move scroll target initialization; improve test #4106

Merged
merged 3 commits into from
Nov 21, 2018

Conversation

kfranqueiro
Copy link
Contributor

This resolves the test failure discovered in #4046.

The getViewportScrollY adapter unit test was coincidentally passing because the page's scroll offset and the scroll offset of the content element were typically both 0. This only ended up not being the case when I tried running our unit tests via headless Firefox on Travis.

The test as written actually should never have passed, because getDefaultFoundation in the Top App Bar component had the side effect of resetting the scroll target, effectively undoing the test's setup.

This fixes the component to initialize the scroll target in initialize rather than getDefaultFoundation, and fixes the test to use a mock object to guarantee a distinguishable expected value.

@codecov-io
Copy link

codecov-io commented Nov 21, 2018

Codecov Report

Merging #4106 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4106   +/-   ##
=======================================
  Coverage   98.67%   98.67%           
=======================================
  Files         126      126           
  Lines        5603     5603           
  Branches      747      747           
=======================================
  Hits         5529     5529           
  Misses         74       74
Impacted Files Coverage Δ
packages/mdc-top-app-bar/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7abfd5d...abe86fc. Read the comment docs.

@@ -292,8 +291,8 @@ test('adapter#getViewportScrollY returns scroll distance', () => {

test('adapter#getViewportScrollY returns scroll distance when scrollTarget_ is not window', () => {
const {component, fixture} = setupTest();
const content = fixture.querySelector('.content');
component.scrollTarget_ = content;
const content = {addEventListener: () => {}, scrollTop: 20};
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: mockContent*

@@ -292,8 +291,8 @@ test('adapter#getViewportScrollY returns scroll distance', () => {

test('adapter#getViewportScrollY returns scroll distance when scrollTarget_ is not window', () => {
const {component, fixture} = setupTest();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove unused variable fixture.

@mdc-web-bot
Copy link
Collaborator

All 663 screenshot tests passed for commit abe86fc vs. master! 💯🎉

@kfranqueiro kfranqueiro merged commit f799659 into master Nov 21, 2018
@kfranqueiro kfranqueiro deleted the fix/top-app-bar-scroll-test branch November 21, 2018 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants