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

test: Add React Router Fog of War test #885

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { testFogOfWar } from 'e2e-shared/specs/react-router/fog-of-war.cy'

testFogOfWar({
path: '/fog-of-war'
})
2 changes: 2 additions & 0 deletions packages/e2e/react-router/v6/src/react-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const router = createBrowserRouter(
<Route path="form/useQueryStates" lazy={load(import('./routes/form.useQueryStates'))} />
<Route path="referential-stability/useQueryState" lazy={load(import('./routes/referential-stability.useQueryState'))} />
<Route path="referential-stability/useQueryStates" lazy={load(import('./routes/referential-stability.useQueryStates'))} />
<Route path="fog-of-war" lazy={load(import('./routes/fog-of-war._index'))} />
<Route path="fog-of-war/result" lazy={load(import('./routes/fog-of-war.result'))} />
<Route path="conditional-rendering/useQueryState" lazy={load(import('./routes/conditional-rendering.useQueryState'))} />
<Route path="conditional-rendering/useQueryStates" lazy={load(import('./routes/conditional-rendering.useQueryStates'))} />

Expand Down
5 changes: 5 additions & 0 deletions packages/e2e/react-router/v6/src/routes/fog-of-war._index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FogOfWarStartPage } from 'e2e-shared/specs/react-router/fog-of-war'

export default function FogOfWarStart() {
return <FogOfWarStartPage resultHref="/fog-of-war/result" />
}
3 changes: 3 additions & 0 deletions packages/e2e/react-router/v6/src/routes/fog-of-war.result.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FogOfWarResultPage } from 'e2e-shared/specs/react-router/fog-of-war'

export default FogOfWarResultPage
3 changes: 3 additions & 0 deletions packages/e2e/react-router/v7/app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ export default [
route('/form/useQueryStates', './routes/form.useQueryStates.tsx'),
route('/referential-stability/useQueryState', './routes/referential-stability.useQueryState.tsx'),
route('/referential-stability/useQueryStates', './routes/referential-stability.useQueryStates.tsx'),
route('/fog-of-war', './routes/fog-of-war._index.tsx'),
route('/fog-of-war/result', './routes/fog-of-war.result.tsx'),
route('/conditional-rendering/useQueryState', './routes/conditional-rendering.useQueryState.tsx'),
route('/conditional-rendering/useQueryStates', './routes/conditional-rendering.useQueryStates.tsx'),

route('/render-count/:hook/:shallow/:history/:startTransition/no-loader', './routes/render-count.$hook.$shallow.$history.$startTransition.no-loader.tsx'),
route('/render-count/:hook/:shallow/:history/:startTransition/sync-loader', './routes/render-count.$hook.$shallow.$history.$startTransition.sync-loader.tsx'),
route('/render-count/:hook/:shallow/:history/:startTransition/async-loader', './routes/render-count.$hook.$shallow.$history.$startTransition.async-loader.tsx'),
Expand Down
5 changes: 5 additions & 0 deletions packages/e2e/react-router/v7/app/routes/fog-of-war._index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FogOfWarStartPage } from 'e2e-shared/specs/react-router/fog-of-war'

export default function FogOfWarStart() {
return <FogOfWarStartPage resultHref="/fog-of-war/result" />
}
3 changes: 3 additions & 0 deletions packages/e2e/react-router/v7/app/routes/fog-of-war.result.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FogOfWarResultPage } from 'e2e-shared/specs/react-router/fog-of-war'

export default FogOfWarResultPage
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { testFogOfWar } from 'e2e-shared/specs/react-router/fog-of-war.cy'

testFogOfWar({
path: '/fog-of-war'
})
5 changes: 5 additions & 0 deletions packages/e2e/remix/app/routes/fog-of-war._index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FogOfWarStartPage } from 'e2e-shared/specs/react-router/fog-of-war'

export default function FogOfWarStart() {
return <FogOfWarStartPage resultHref="/fog-of-war/result" />
}
3 changes: 3 additions & 0 deletions packages/e2e/remix/app/routes/fog-of-war.result.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FogOfWarResultPage } from 'e2e-shared/specs/react-router/fog-of-war'

export default FogOfWarResultPage
5 changes: 5 additions & 0 deletions packages/e2e/remix/cypress/e2e/shared/fog-of-war.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { testFogOfWar } from 'e2e-shared/specs/react-router/fog-of-war.cy'

testFogOfWar({
path: '/fog-of-war'
})
12 changes: 12 additions & 0 deletions packages/e2e/shared/specs/react-router/fog-of-war.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createTest } from '../../create-test'

export const testFogOfWar = createTest('Fog of War', ({ path }) => {
it('should navigate to the result page', () => {
cy.visit(path)
cy.contains('#hydration-marker', 'hydrated').should('be.hidden')
cy.get('#set').click()
cy.get('#navigate').click()
cy.location('pathname').should('eq', `${path}/result`)
cy.get('#result').should('have.text', 'pass')
})
})
22 changes: 22 additions & 0 deletions packages/e2e/shared/specs/react-router/fog-of-war.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useQueryState } from 'nuqs'
import { useLink } from '../../components/link'

export function FogOfWarStartPage({ resultHref }: { resultHref: string }) {
const [, setState] = useQueryState('test')
// const [, setState] = useState('init')
const Link = useLink()
return (
<>
<button id="set" onClick={() => setState('pass')}>
Set
</button>
<Link id="navigate" href={resultHref}>
Navigate
</Link>
</>
)
}

export function FogOfWarResultPage() {
return <div id="result">pass</div>
}