-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for isNavigatingToNewRootLayout
- Loading branch information
1 parent
f58267d
commit d2e5709
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
...ges/next/src/client/components/router-reducer/is-navigating-to-new-root-layout.ts.test.ts
This file contains 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,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) | ||
}) | ||
}) |