import React from 'react' import type { FlightRouterState } from '../../../server/app-render/types' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import { createInitialRouterState } from './create-initial-router-state' import { PrefetchCacheEntryStatus, PrefetchKind } from './router-reducer-types' const getInitialRouterStateTree = (): FlightRouterState => [ '', { children: [ 'linking', { children: ['', {}], }, ], }, undefined, undefined, true, ] const navigatedAt = Date.now() describe('createInitialRouterState', () => { it('should return the correct initial router state', () => { const initialTree = getInitialRouterStateTree() const initialCanonicalUrl = '/linking' const children = (
Root layout ) const initialParallelRoutes: CacheNode['parallelRoutes'] = new Map() const state = createInitialRouterState({ navigatedAt, initialFlightData: [[initialTree, ['', children, {}, null]]], initialCanonicalUrlParts: initialCanonicalUrl.split('/'), initialParallelRoutes, location: new URL('/linking', 'https://localhost') as any, couldBeIntercepted: false, postponed: false, prerendered: false, }) const state2 = createInitialRouterState({ navigatedAt, initialFlightData: [[initialTree, ['', children, {}, null]]], initialCanonicalUrlParts: initialCanonicalUrl.split('/'), initialParallelRoutes, location: new URL('/linking', 'https://localhost') as any, couldBeIntercepted: false, postponed: false, prerendered: false, }) const expectedCache: CacheNode = { navigatedAt, lazyData: null, rsc: children, prefetchRsc: null, head: null, prefetchHead: null, loading: null, parallelRoutes: new Map([ [ 'children', new Map([ [ 'linking', { navigatedAt, parallelRoutes: new Map([ [ 'children', new Map([ [ '', { navigatedAt, lazyData: null, rsc: null, prefetchRsc: null, parallelRoutes: new Map(), loading: null, head: null, prefetchHead: null, }, ], ]), ], ]), lazyData: null, rsc: null, prefetchRsc: null, head: null, prefetchHead: null, loading: null, }, ], ]), ], ]), } const expected: ReturnType