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: render without routing when using as a React component #838

Merged
merged 8 commits into from
May 5, 2022

Conversation

tynandebold
Copy link
Member

@tynandebold tynandebold commented May 3, 2022

Signed-off-by: Tynan DeBold [email protected]

Description

The Brix team tried to render the component instance of Viz on a page with a route like this: /post/:id. That didn't work because of the exact path matching we have here. Nothing was rendered.

Development notes

Now we use the displayGlobalToolbar variable as a switch case: if we display to global toolbar, then we also want all other app elements (UpdateReminder, ExperimentTracking, etc.). If not, we only render the FlowChartWrapper component.

QA notes

You need to test locally in a dummy repo. You can use npm link to do that, but it's tedious. I can show you, as I've already done with @studioswong.

Checklist

  • Read the contributing guidelines
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added new entries to the RELEASE.md file
  • Added tests to cover my changes

@tynandebold tynandebold requested a review from yetudada as a code owner May 3, 2022 11:36
@tynandebold tynandebold removed the request for review from yetudada May 3, 2022 11:36
Copy link
Contributor

@studioswong studioswong left a comment

Choose a reason for hiding this comment

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

Thanks for setting this up - glad that we got a chance to catch up on this, it looks much better to use the displayGlobalToolbar to single out the Brix use case now :)

It would be great if we can add a test case under wrapper.test.js to test this new use case for the npm component import 😄

Signed-off-by: Tynan DeBold <[email protected]>
@tynandebold tynandebold requested a review from studioswong May 3, 2022 14:53
@tynandebold
Copy link
Member Author

Thanks for setting this up - glad that we got a chance to catch up on this, it looks much better to use the displayGlobalToolbar to single out the Brix use case now :)

It would be great if we can add a test case under wrapper.test.js to test this new use case for the npm component import 😄

Great call. I added a test checking if the SettingsModal is rendered or not. We already check if the GlobalToolbar renders, so this seems suitable. Let me know if you think there's another thing we can check for though.

Comment on lines 35 to 40
it('does not display the settings modal when displayGlobalToolbar is false', () => {
const wrapper = setup.mount(Wrapper, mockPropsNoGlobalToolbar);
const container = wrapper.find('.pipeline-settings-modal');
expect(container.length).toBe(0);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

In looking at this test, this test doesn't serve any purpose / isn't exactly testing anything as the settings modal won't be displayed even if displayGlobalToolbar is true ( .pipeline-settings-modal is only triggered when the modal is triggered and not on the existence of the globalToolbar).

This could be deleted and ideally, we should set up a test to mock the navigation to one of the routes (such as /experiment-tracking) and ensuring that the app doesn't get routed when displayGlobalToolbar is false. ( the test condition would be something like 'does not perform any routing when displayGlobalToolbar is false').

@tynandebold tynandebold self-assigned this May 4, 2022
Signed-off-by: Tynan DeBold <[email protected]>
Comment on lines 36 to 44
it('does not perform any routing when displayGlobalToolbar is false', () => {
const wrapper = setup.mount(
<MemoryRouter initialEntries={['/experiment-tracking']}>
<Wrapper />
</MemoryRouter>,
mockPropsNoGlobalToolbar
);

const container = wrapper.find('.pipeline-ui--experiment-tracking');
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this test - this is definitely structured in a much better way.

I've just had a play around with this and tried testing this using mockProps instead of mockPropsNoGlobalToolbar but unfortunately this still passes, which indicates that there is something missing from this setup.

This could either be that we are testing with the wrong css class, or something to do with the setup - worth to do a bit of digging around to find out and set up the right test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm struggling on this one. I don't see a good way to test this.

Since we'll only render the FlowChartWrapper when we use mockPropsNoGlobalToolbar, we won't have access to any routing, so actually my use of MemoryRouter doesn't make sense here.

And since we don't have access to that routing or even react-router at this stage, I don't see a way to mock navigation to one of the routes using any of the methods you normally would use when routing is present on the page or in the component.

If you have a better idea, do please share it, because I can't see it.

…x/standlone-component-routing

Signed-off-by: Tynan DeBold <[email protected]>
@tynandebold tynandebold requested a review from studioswong May 5, 2022 11:05
…x/standlone-component-routing

Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
@studioswong studioswong mentioned this pull request May 5, 2022
5 tasks
Signed-off-by: Tynan DeBold <[email protected]>
Copy link
Contributor

@studioswong studioswong left a comment

Choose a reason for hiding this comment

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

Glad that we got to pair and look into this - what weird things we are seeing with the tests!

Thanks for pushing through with this and glad we came to a test that is generic enough to capture the intent of this PR - let's get this in for the release 😄

@tynandebold tynandebold merged commit 5b20ed5 into main May 5, 2022
@tynandebold tynandebold deleted the fix/standlone-component-routing branch May 5, 2022 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants