Skip to content

Conversation

@KaylaBrady
Copy link
Contributor

@KaylaBrady KaylaBrady commented Oct 3, 2022

ticket: https://app.asana.com/0/1152340551558956/1203058157664665/f

This PR refactors <RightPanel> so that Page component tests are no longer also testing the RightPanel component. A separate ticket will further explore possible changes to useSocket based on the findings in the discussion of this PR.

Previous WIP notes This PR currently includes some changes that resolved the console errors previously seen in the test file. I don't see this PR as it stands now as a comprehensive approach to resolving this issue, but want to document what I've found so far

Prior to these changes:

  • running "renders a selected vehicle" and "on mobile, allows you to toggle to the map view and back again" one at a time: both succeeded
  • running all SearchPage.test.tsx at once with "renders a selected vehicle" before "on mobile, allows you to toggle to the map view and back again": both tests succeed, but console errors logged
  • running all SearchPage.test.tsx at once with "renders a selected vehicle" after "on mobile, allows you to toggle to the map view and back again": both tests succeed, no console errors logged.

Isolating the issue:

  • removing the selectedVehicleOrGhost from state in "renders a selected vehicle": both tests succeed, no console errors logged
  • removing async/await from "on mobile, allows you to toggle to the map view and back again": both tests succeed, no console errors
  • Mocking out <RightPanel>: both tests succeed, no console errors logged

After performing the above tests, I wondered if something about the call to react-test-renderer.create() in "renders a selected vehicle" wasn't being cleaned up properly before running the next test.

  • Switched to use react-testing-library renderer instead to avoid errors due to inconsistent renderers within the same file
  • Mocked out additional API calls used in the VPP to resolve Error: Error: connect ECONNREFUSED 127.0.0.1:80 errors
  • most potentially concerning change : added cleanup function to useSocket to resolve Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.

While those fixes within the test file resolved the console errors, it raises a few more questions:

  • Would moving <RightPanel> up a level so it is a sibling to these pages rather than a child help to keep these tests isolated?
  • is the useSocket hook not having a cleanup function a real problem, or a symptom of something else missing in the test? I suspect it is a real problem, but have doubts since it is an older area of the code. Though this kind of issue might not have user-facing impact
  • Is there an advantage I'm overlooking to using react-test-renderer for snapshots over react-testing-library render+asFragment`?

@github-actions
Copy link

github-actions bot commented Oct 3, 2022

Coverage of commit d9edb96

Summary coverage rate:
  lines......: 94.0% (2463 of 2620 lines)
  functions..: 73.0% (1034 of 1417 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@lemald
Copy link
Member

lemald commented Oct 4, 2022

With regards to moving <RightPanel> up a level, at first I was undecided but now I'm in favor. My fear was that there could be pages where we don't want the right panel to appear, but then I remembered that currently you can access notifications from any page, and opening a notification entails being able to open the VPP. If that ever changes we'll need to make other significant changes to Skate, and independently rendering <RightPanel> in each separate existing page component is repeated code. So yeah, I'd say go for it, it will make the application code cleaner and it sounds like it will help with testing too.

@KaylaBrady
Copy link
Contributor Author

KaylaBrady commented Oct 4, 2022

👍 Thanks @lemald, I'll rework this PR to move <RightPanel>.

I suspsect that one possible user-facing added benefit of moving <RightPanel> up a level is that it the panel won't re-render when switching between modes. Right now:

  1. open the VPP from search and open the block minischedule
  2. navigate to the route ladder. VPP reset to vehicle status

I expect with this change, the VPP would stay on the block minischedule when switching between modes. Before making this change I can confirm with product in the ticket whether the existing behavior is intended.

@lemald
Copy link
Member

lemald commented Oct 4, 2022

👍 Thanks @lemald, I'll rework this PR to move <RightPanel>.

I suspsect that one possible user-facing added benefit of moving <RightPanel> up a level is that it the panel won't re-render when switching between modes. Right now:

1. open the VPP from search and open the block minischedule

2. navigate to the route ladder. VPP reset to vehicle status

I expect with this change, the VPP would stay on the block minischedule when switching between modes. Before making this change I can confirm with product in the ticket whether the existing behavior is intended.

Ah, yes, that's also a good point! I suspect you're correct about how it will work with the change, and it should be a nice (if small) UX improvement.

@github-actions
Copy link

github-actions bot commented Oct 5, 2022

Coverage of commit 9b00054

Summary coverage rate:
  lines......: 94.0% (2463 of 2620 lines)
  functions..: 73.0% (1034 of 1417 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@github-actions
Copy link

github-actions bot commented Oct 6, 2022

Coverage of commit cb2ca68

Summary coverage rate:
  lines......: 94.0% (2463 of 2620 lines)
  functions..: 73.0% (1034 of 1417 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@KaylaBrady KaylaBrady marked this pull request as ready for review October 6, 2022 17:22
@KaylaBrady KaylaBrady requested a review from lemald October 7, 2022 16:57
Copy link
Member

@lemald lemald left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@KaylaBrady KaylaBrady temporarily deployed to dev-green October 11, 2022 14:15 Inactive
@github-actions
Copy link

Coverage of commit 7c55d10

Summary coverage rate:
  lines......: 94.0% (2463 of 2620 lines)
  functions..: 73.0% (1034 of 1417 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@KaylaBrady KaylaBrady temporarily deployed to dev-green October 11, 2022 19:32 Inactive
@KaylaBrady KaylaBrady force-pushed the kb-test-interdependency branch from 7c55d10 to afa58c1 Compare October 11, 2022 20:17
@github-actions
Copy link

Coverage of commit afa58c1

Summary coverage rate:
  lines......: 94.0% (2463 of 2620 lines)
  functions..: 73.0% (1034 of 1417 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@KaylaBrady KaylaBrady temporarily deployed to dev-green October 11, 2022 20:25 Inactive
Copy link
Member

@lemald lemald left a comment

Choose a reason for hiding this comment

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

Latest changes look good!

@github-actions
Copy link

Coverage of commit 5f64db2

Summary coverage rate:
  lines......: 94.0% (2463 of 2620 lines)
  functions..: 73.0% (1034 of 1417 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@github-actions
Copy link

Coverage of commit 5f64db2

Summary coverage rate:
  lines......: 94.0% (2463 of 2620 lines)
  functions..: 73.0% (1034 of 1417 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@KaylaBrady KaylaBrady merged commit e254d03 into master Oct 12, 2022
@KaylaBrady KaylaBrady deleted the kb-test-interdependency branch October 12, 2022 13:09
@lemald lemald mentioned this pull request Oct 12, 2022
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.

3 participants