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

Update url.app.apps.{get|upgrade} with required cluster arg. #1833

Merged
merged 5 commits into from
Jul 1, 2020

Conversation

absoludity
Copy link
Contributor

Continues url updates for cluster requirement. Ref #1762 .

Starting to get some duplication of test setup, as the function components which use state need providers etc. I looked at options for creating the shared code, but react-scripts doesn't support the jest setupFiles option, so it might just be a separate src/helpers.test.tsx exporting some functions like getWrapper(state, component, props)? What do you think? (not for this PR, but I will cleanup the dups once decided).

The other thing that I had to wrangle here is that once wrapped in a provider, it seems that even our class-based components are no longer classes after wrapping - at least, I had to remove calls to wrapper.state() (also tried wrapper.find(ComponentName).state()) as jest kept failing saying that state() is only available on class-based components.

@andresmgot
Copy link
Contributor

Continues url updates for cluster requirement. Ref #1762 .

Starting to get some duplication of test setup, as the function components which use state need providers etc. I looked at options for creating the shared code, but react-scripts doesn't support the jest setupFiles option, so it might just be a separate src/helpers.test.tsx exporting some functions like getWrapper(state, component, props)? What do you think? (not for this PR, but I will cleanup the dups once decided).

That's fine. I would use the shared folder instead though (to avoid polluting the root folder). Something like shared/test-helpers.ts.

The other thing that I had to wrangle here is that once wrapped in a provider, it seems that even our class-based components are no longer classes after wrapping - at least, I had to remove calls to wrapper.state() (also tried wrapper.find(ComponentName).state()) as jest kept failing saying that state() is only available on class-based components.

I guess there should be an analogue way of getting the state?

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

I'd be wary of merging this until we find a way of accessing the state from the test but maybe you already have something in mind.

import AppControls, { IAppControlsProps } from "./AppControls";
import UpgradeButton from "./UpgradeButton";

const mockStore = configureMockStore([thunk]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a bit confused, the AppControls component is still a class, why all these changes are needed? Is it because of the change in react-redux?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, you commented it in the PR:

it seems that even our class-based components are no longer classes after wrapping - at least, I had to remove calls to wrapper.state()

that's weird...

expect(confirm.exists()).toBe(true);
confirm.props().onConfirm(); // Simulate confirmation

expect(wrapper.state("deleting")).toBe(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

we should block this until we find a way to get the state? We are using the state in several tests, we would lose coverage. What's your plan here?

Copy link
Contributor Author

@absoludity absoludity Jul 1, 2020

Choose a reason for hiding this comment

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

Sorry, I forgot to include the info I found: Most people (myself included) recommend not testing state (ie. not testing implementation details) but instead validating what's rendered (the effect of the state. See this answer: https://stackoverflow.com/a/58432424 which I'd mostly agree with).

The quick and dirty solution on the same answer can actually be used by us (small tweak because we can't use shallow here, so don't have dive(). I had tried wrapper.find(".appControls").state() above which didn't work (same error), but what I didn't try, which does work, is explicitly wrapper.find(AppControls).state(). So I'm updating to that so we have a record of how we can do a quick-n-dirty change, but ultimately we should not be testing implementation details IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally I agree but sometimes is much faster to just test the state, is a trade-off.

@absoludity absoludity merged commit f810c08 into master Jul 1, 2020
@absoludity absoludity deleted the 1762-pass-cluster-3 branch July 1, 2020 04:30
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.

None yet

2 participants