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

[deps] upgrade visx-xychart to react 17 #1

Merged
merged 9 commits into from
Aug 5, 2021

Conversation

gazcn007
Copy link
Owner

@gazcn007 gazcn007 commented Jul 25, 2021

Overview

  • upgrade visx-xychart to use react 17
  • rewrite unit tests that use mount
  • rewrite unit tests that uses find(Component) pattern in enzyme to testing-library:
    • testing-library avoids checking implementation details -> reference issue

describe('<BaseAxis />', () => {
it('should be defined', () => {
expect(BaseAxis).toBeDefined();
});
it('should use scale=xScale for orientation=top/bottom', () => {
Copy link
Owner Author

Choose a reason for hiding this comment

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

hi @williaster, this is tricky to do within RTL because it is checking on function xScale being passed down through props and this counts as a checking on implementation detail. After consideration, I am thinking of removing this test for now... Do you think this test is necessary?

Choose a reason for hiding this comment

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

yeah I think that's a totally fair critique. I don't think it's essential to have the tests, tho I wonder if there's a more RTL / functional type of test. My only thought is to create actual scales say

const xScale = scaleLinear({ domain: [0, 1, 2], range: [0, 10] });
const yScale = scaleLinear({ domain: ['a', 'b', 'c'], range: [0, 10] });

and then look for tick values that match those. that's a decent amount of work to do tho and don't want to add more and more to this migration so I'm fine skipping it!

Copy link
Owner Author

Choose a reason for hiding this comment

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

ill give that a shot.
I did const xScale ={ domain: jest.fn(()=>[0, 1, 2]), range: jest.fn(() => [0, 10]) };
it complains about missing tickPosition function, i don't know where that one is being passed from

Copy link
Owner Author

Choose a reason for hiding this comment

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

That actually works! please check my changes at L56

🚀

Copy link

@williaster williaster left a comment

Choose a reason for hiding this comment

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

Wowow! thanks for such a gnarly refactor 🙏

I left a couple super minor comments, but looks great to me overall! 🙌 👏

@@ -36,7 +36,7 @@
"access": "public"
},
"peerDependencies": {
"react": "^16.4.0-0",
"react": "^17.0.0",

Choose a reason for hiding this comment

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

should this be ^16.4.0 || ^17.0.0-0 or should we go all in on 17?

Copy link
Owner Author

Choose a reason for hiding this comment

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

i'd say 17.0.0 because visx-xychart uses react-spring@v9 correct?

Copy link

@williaster williaster Aug 4, 2021

Choose a reason for hiding this comment

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

ah good point. looks like that supports ^16.8.0 || ^17.0.0 so maybe we should match that? then people can still use xychart without updating to 17.

Copy link
Owner Author

Choose a reason for hiding this comment

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

sure!

describe('<BaseAxis />', () => {
it('should be defined', () => {
expect(BaseAxis).toBeDefined();
});
it('should use scale=xScale for orientation=top/bottom', () => {

Choose a reason for hiding this comment

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

yeah I think that's a totally fair critique. I don't think it's essential to have the tests, tho I wonder if there's a more RTL / functional type of test. My only thought is to create actual scales say

const xScale = scaleLinear({ domain: [0, 1, 2], range: [0, 10] });
const yScale = scaleLinear({ domain: ['a', 'b', 'c'], range: [0, 10] });

and then look for tick values that match those. that's a decent amount of work to do tho and don't want to add more and more to this migration so I'm fine skipping it!

expect(rects.at(1).prop('fill')).not.toBe('banana');
expect(rects.at(2).prop('fill')).toBe('banana');
expect(rects.at(3).prop('fill')).not.toBe('banana');
const rects = container.querySelectorAll('rect');

Choose a reason for hiding this comment

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

glad some of these were more straight forward to refactor 😅

expect(circles.at(0).prop('fill')).toBe('banana');
expect(circles.at(1).prop('fill')).not.toBe('banana');
const circles = container.querySelectorAll('circle');
expect(circles[0]).toHaveAttribute('fill', 'banana');

Choose a reason for hiding this comment

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

so much more DOM/vanilla javascript like versus enzyme 💯

packages/visx-xychart/test/components/LineSeries.test.tsx Outdated Show resolved Hide resolved
expect(wrapper.find(TooltipProvider)).toHaveLength(1);
// the XYChart should auto-resize to it's parent size
const Wrapper = getByTestId('wrapper');
expect(Wrapper.firstChild).toHaveStyle('width: 100%; height: 100%');

Choose a reason for hiding this comment

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

nice way to do this one

<rect />
</XYChart>,
);
expect(wrapper.find(DataProvider)).toHaveLength(1);

Choose a reason for hiding this comment

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

not sure how best to test this one since context is an implementation detail kind of by definition.

Copy link
Owner Author

Choose a reason for hiding this comment

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

yea, because when this component gets rendered, you don't really see a DataProvider, EventEmitterProvider or TooltipProvider in your DOM anyways.

@gazcn007 gazcn007 merged commit 0611d48 into carl--react-17 Aug 5, 2021
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.

2 participants