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): Fix JS error when navigation icon is not present. #2751

Merged
merged 4 commits into from
May 18, 2018

Conversation

abhiomkar
Copy link
Collaborator

@abhiomkar abhiomkar commented May 17, 2018

Fixes Top App Bar's initialize method to add ripple to nav icon only when it is present.

Fixes #2721

…n icon is not present.

Fixes Top App Bar's initialize method to add ripple to nav icon only when it is present.
@codecov-io
Copy link

codecov-io commented May 17, 2018

Codecov Report

Merging #2751 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2751      +/-   ##
==========================================
+ Coverage   98.48%   98.48%   +<.01%     
==========================================
  Files          98       98              
  Lines        4230     4231       +1     
  Branches      537      538       +1     
==========================================
+ Hits         4166     4167       +1     
  Misses         64       64
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 6a1792a...5d14bc2. Read the comment docs.

@kfranqueiro
Copy link
Contributor

kfranqueiro commented May 17, 2018

This is something we should be able to verify with a new unit test (make sure it fails without the fix and passes with it).

mdc-top-app-bar.test.js already has a setupTest function with an optional parameter that will remove the navigation icon, which we should be able to use to test this... I'm actually wondering how tests calling setupTest(true) weren't already failing, since theoretically the error being fixed should occur as soon as the component was constructed.

Edit: I think it wasn't failing due to the use of FakeRipple in the unit tests. The actual error occurs when Top App Bar attempts to instantiate a MDCRipple on null.

…ipple factory.

Also updated existing test case to use stubs instead of asserting private properties.
@abhiomkar
Copy link
Collaborator Author

Yes, the use of FakeRipple in unit test suppresses this bug.

I've added a new test case to cover this case also updated other test case to make use of stubs instead of asserting on private properties. PTAL.

td.verify(rippleFactory(td.matchers.anything()), {times: totalIcons});
});

test('constructor instantiates icon ripples except for nav icon', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Rephrase to 'constructor does not instantiate ripple for nav icon when not present'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. Thanks!

@abhiomkar abhiomkar merged commit 7643f3b into master May 18, 2018
@abhiomkar abhiomkar deleted the fix_topappbar_navicon_issue2721 branch May 18, 2018 20:02
const {root} = setupTest(/** removeIcon */ false, rippleFactory);

const totalIcons = getIconsCount(root);
td.verify(rippleFactory(td.matchers.anything()), {times: totalIcons});
Copy link
Contributor

@williamernest williamernest May 23, 2018

Choose a reason for hiding this comment

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

This test and the following test are causing warnings in the test runner and CI. Line 99 is mocking this object, and then it's testing that the mocked object got called.

WARN: 'Warning: testdouble.js - td.verify - test double was both stubbed and verified with arguments (anything()), which is redundant and probably unnecessary. (see: https://github.com/testdouble/testdouble.js/blob/master/docs/B-frequently-asked-questions.md#why-shouldnt-i-call-both-tdwhen-and-tdverify-for-a-single-interaction-with-a-test-double )'

Copy link
Contributor

@kfranqueiro kfranqueiro May 23, 2018

Choose a reason for hiding this comment

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

Whoops, good catch. I suppose since we're stubbing the function, inside it we can increment a variable that's local to the test function, and just assert that it has the value we expect afterwards?

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.

4 participants