-
-
Notifications
You must be signed in to change notification settings - Fork 7
refactor(lib): move info modal to dedicated /info route #657
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
Open
antontranelis
wants to merge
6
commits into
main
Choose a base branch
from
feature/info-modal-route
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ec2bce1
refactor: move info modal to dedicated /info route
antontranelis 4eb782a
refactor(lib): move info modal to dedicated /info route
antontranelis 5caec3f
refactor(lib): move Modal from Gaming to AppShell
antontranelis 844b82a
Merge branch 'main' into feature/info-modal-route
mahula 743903d
Merge branch 'main' into feature/info-modal-route
mahula 3f9fa30
feat(other): add unit and e2e tests for info modal route (#657) (#703)
mahula File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /// <reference types="cypress" /> | ||
|
|
||
| /** | ||
| * Info Modal Route E2E Tests | ||
| * | ||
| * Validates the route-based info modal introduced by PR #657: | ||
| * - Route /info renders the modal (E1) | ||
| * - NavBar ? link navigates to /info (E2) | ||
| * - Content "Close" button navigates back to / (E3) | ||
| */ | ||
|
|
||
| describe('Info Modal Route', () => { | ||
| it('E1: visiting /info renders the info modal', () => { | ||
| cy.visit('/info') | ||
|
|
||
| cy.get('.tw\\:card', { timeout: 15000 }).should('be.visible') | ||
| cy.get('.tw\\:backdrop-brightness-75').should('exist') | ||
| cy.contains('Close').should('be.visible') | ||
| cy.location('pathname').should('eq', '/info') | ||
| }) | ||
|
|
||
| it('E2: NavBar ? icon navigates to /info', () => { | ||
| cy.visit('/') | ||
| cy.waitForMapReady() | ||
|
|
||
| // Dismiss auto-opened modal if info_open is true in backend | ||
| cy.get('body').then(($body) => { | ||
| if ($body.find('.tw\\:backdrop-brightness-75').length > 0) { | ||
| cy.get('.tw\\:card button').contains('✕').click() | ||
| cy.location('pathname').should('eq', '/') | ||
| } | ||
| }) | ||
|
|
||
| cy.get('a[href="/info"]').should('be.visible').click() | ||
|
|
||
| cy.location('pathname').should('eq', '/info') | ||
| cy.get('.tw\\:card', { timeout: 10000 }).should('be.visible') | ||
| }) | ||
|
|
||
| it('E3: content "Close" button closes modal and navigates to /', () => { | ||
| cy.visit('/info') | ||
| cy.get('.tw\\:card', { timeout: 15000 }).should('be.visible') | ||
|
|
||
| cy.contains('label', 'Close').click() | ||
|
|
||
| cy.location('pathname').should('eq', '/') | ||
| cy.get('.tw\\:backdrop-brightness-75').should('not.exist') | ||
| }) | ||
| }) | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { render, cleanup } from '@testing-library/react' | ||
| import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest' | ||
|
|
||
| import { InfoRedirect } from './InfoRedirect' | ||
|
|
||
| // --- Mocks --- | ||
|
|
||
| const mockNavigate = vi.fn() | ||
|
|
||
| vi.mock('react-router-dom', async () => { | ||
| const actual = await vi.importActual('react-router-dom') | ||
| return { | ||
| ...actual, | ||
| useNavigate: () => mockNavigate, | ||
| } | ||
| }) | ||
|
|
||
| // Save original location so we can restore it after each test | ||
| const originalLocation = window.location | ||
|
|
||
| // Helper to set window.location.pathname for tests | ||
| function setPathname(pathname: string) { | ||
| Object.defineProperty(window, 'location', { | ||
| value: { pathname, search: '', hash: '', href: `http://localhost${pathname}` }, | ||
| writable: true, | ||
| configurable: true, | ||
| }) | ||
| } | ||
|
|
||
| // --- Tests --- | ||
|
|
||
| describe('<InfoRedirect />', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| setPathname('/') | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| cleanup() | ||
| // Restore original window.location to avoid leaking into other test files | ||
| Object.defineProperty(window, 'location', { | ||
| value: originalLocation, | ||
| writable: true, | ||
| configurable: true, | ||
| }) | ||
| }) | ||
|
|
||
| it('U1: navigates to /info when enabled and pathname is "/"', () => { | ||
| render(<InfoRedirect enabled={true} />) | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledTimes(1) | ||
| expect(mockNavigate).toHaveBeenCalledWith('/info') | ||
| }) | ||
|
|
||
| it('U2: does NOT navigate when enabled is false', () => { | ||
| render(<InfoRedirect enabled={false} />) | ||
|
|
||
| expect(mockNavigate).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('U3: does NOT navigate when pathname is not "/"', () => { | ||
| setPathname('/login') | ||
|
|
||
| render(<InfoRedirect enabled={true} />) | ||
|
|
||
| expect(mockNavigate).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('U4: only navigates once even if re-rendered', () => { | ||
| const { rerender } = render(<InfoRedirect enabled={true} />) | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledTimes(1) | ||
|
|
||
| rerender(<InfoRedirect enabled={true} />) | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledTimes(1) | ||
| }) | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { useEffect, useRef } from 'react' | ||
| import { useNavigate } from 'react-router-dom' | ||
|
|
||
| interface InfoRedirectProps { | ||
| /** If true, redirects to /info route on initial page load (once) */ | ||
| enabled?: boolean | ||
| } | ||
|
|
||
| /** | ||
| * Redirects to /info route on initial page load when enabled. | ||
| * Only redirects once per session to avoid redirect loops. | ||
| * Place this component inside the Router context but outside of Routes. | ||
| * @category AppShell | ||
| */ | ||
| export function InfoRedirect({ enabled }: InfoRedirectProps) { | ||
| const navigate = useNavigate() | ||
| const hasRedirected = useRef(false) | ||
|
|
||
| useEffect(() => { | ||
| if (enabled && window.location.pathname === '/' && !hasRedirected.current) { | ||
| hasRedirected.current = true | ||
| void navigate('/info') | ||
| } | ||
| }, [enabled, navigate]) | ||
|
|
||
| return null | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { MapOverlayPage } from '#components/Templates' | ||
|
|
||
| /** | ||
| * @category AppShell | ||
| */ | ||
| export function Modal({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <MapOverlayPage | ||
| backdrop | ||
| card | ||
| className='tw:h-fit tw:max-h-[calc(100%-2.5em)] tw:overflow-auto tw:w-[calc(100%-32px)] tw:min-w-80 tw:max-w-[612px] tw:transition-opacity tw:duration-500 tw:opacity-100 tw:pointer-events-auto' | ||
| > | ||
| {children} | ||
| </MapOverlayPage> | ||
mahula marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
mahula marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| export * from './AppShell' | ||
| export { SideBar } from './SideBar' | ||
| export { Content } from './Content' | ||
| export { InfoRedirect } from './InfoRedirect' | ||
| export { Modal } from './Modal' | ||
| export { default as SVG } from 'react-inlinesvg' |
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| export { Modal } from './Modal' | ||
| export { Quests } from './Quests' |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.