Skip to content

Commit

Permalink
Add test for isNavigatingToNewRootLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Jan 26, 2023
1 parent f58267d commit d2e5709
Showing 1 changed file with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import type { FlightRouterState } from '../../../server/app-render'
import { isNavigatingToNewRootLayout } from './is-navigating-to-new-root-layout'

describe('shouldHardNavigate', () => {
it('should return false if there is no new root layout', () => {
const getInitialRouterStateTree = (): FlightRouterState => [
'',
{
children: [
'linking',
{
children: ['', {}],
},
],
},
undefined,
undefined,
true,
]
const initialRouterStateTree = getInitialRouterStateTree()
const getNewRouterStateTree = (): FlightRouterState => {
return [
'',
{
children: [
'link-hard-push',
{
children: [
['id', '456', 'd'],
{
children: ['', {}],
},
],
},
],
},
null,
null,
true,
]
}
const newRouterState = getNewRouterStateTree()

const result = isNavigatingToNewRootLayout(
newRouterState,
initialRouterStateTree
)

expect(result).toBe(false)
})

it('should return true if there is a mismatch between the root layouts', () => {
const getInitialRouterStateTree = (): FlightRouterState => [
'',
{
children: [
'linking',
{
children: ['', {}],
},
undefined,
undefined,
// Root layout at `linking` level.
true,
],
},
]
const initialRouterStateTree = getInitialRouterStateTree()
const getNewRouterStateTree = (): FlightRouterState => {
return [
'',
{
children: [
'link-hard-push',
{
children: [
['id', '456', 'd'],
{
children: ['', {}],
},
],
},
null,
null,
// Root layout at `link-hard-push` level.
true,
],
},
]
}
const newRouterState = getNewRouterStateTree()

const result = isNavigatingToNewRootLayout(
newRouterState,
initialRouterStateTree
)

expect(result).toBe(true)
})
})

0 comments on commit d2e5709

Please sign in to comment.