fix: correct team switch logic - #821
Open
dennisvankekem wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR corrects the team-switch navigation logic in the Header component so that switching teams reliably lands users on the appropriate team dashboard/section overview, and adds unit tests to validate the updated routing behavior.
Changes:
- Replace string-replace based team switching with pathname segment parsing to preserve (or intentionally reset to) the correct section when changing teams.
- Tighten the
handleChangeTeamevent typing by using MUI’sSelectChangeEvent. - Add a new
Header.test.tsxsuite covering common team-switching routes (dashboard, section overview, nested resource pages, and non-team routes).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/components/Header.tsx | Updates getNextPathname logic to compute the correct next route when switching teams. |
| src/components/Header.test.tsx | Adds unit tests validating team switching behavior across several route shapes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
src/components/Header.tsx:139
getNextPathnamebreaks for the/teamsroute (exact route exists) becausesegmentsbecomes['teams']and the function falls through toreturn/teams/${nextTeamId}/${segments[2]}``, producing/teams/<id>/undefined. Handle the `/teams` case explicitly (and consider adding a regression test for it).
const segments = pathname.split('/').filter(Boolean)
// Not on a team route
if (segments[0] !== 'teams') return `/teams/${nextTeamId}`
src/components/Header.test.tsx:79
useLocationis mocked without the requiredkeyfield (and without a cast), which can cause TypeScript errors depending on theLocationtype from react-router. Include akeyand cast toReturnType<typeof useLocation>like the other mocked hooks.
mockedUseLocation.mockReturnValue({
pathname,
search: '',
hash: '',
state: undefined,
src/components/Header.test.tsx:196
document.querySelector(...)can returnnull, and passing that intofireEvent.changeis both a TypeScript error and a potential runtime failure if the selector ever changes. Assert non-null (or use Testing Library queries) before firing the event.
const hiddenInput = document.querySelector('[data-cy="select-oboteam"] input')
fireEvent.change(hiddenInput, {
target: {
value: 'alpha',
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Considerations