react-code-dataset / next.js /packages /next /src /client /components /router-reducer /fill-lazy-items-till-leaf-with-head.test.tsx
| import React from 'react' | |
| import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head' | |
| import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' | |
| import type { FlightData } from '../../../server/app-render/types' | |
| const getFlightData = (): FlightData => { | |
| return [ | |
| [ | |
| [ | |
| '', | |
| { | |
| children: [ | |
| 'linking', | |
| { | |
| children: [ | |
| 'about', | |
| { | |
| children: ['', {}], | |
| }, | |
| ], | |
| }, | |
| ], | |
| }, | |
| null, | |
| null, | |
| true, | |
| ], | |
| ['', {}, <h1>About Page!</h1>], | |
| <> | |
| <title>About page!</title> | |
| </>, | |
| ], | |
| ] | |
| } | |
| const navigatedAt = Date.now() | |
| describe('fillLazyItemsTillLeafWithHead', () => { | |
| it('should fill lazy items till leaf with head', () => { | |
| const cache: CacheNode = { | |
| navigatedAt, | |
| lazyData: null, | |
| rsc: null, | |
| prefetchRsc: null, | |
| head: null, | |
| prefetchHead: null, | |
| parallelRoutes: new Map(), | |
| loading: null, | |
| } | |
| const existingCache: CacheNode = { | |
| navigatedAt, | |
| lazyData: null, | |
| rsc: <>Root layout</>, | |
| prefetchRsc: null, | |
| head: null, | |
| prefetchHead: null, | |
| loading: null, | |
| parallelRoutes: new Map([ | |
| [ | |
| 'children', | |
| new Map([ | |
| [ | |
| 'linking', | |
| { | |
| navigatedAt, | |
| lazyData: null, | |
| rsc: <>Linking</>, | |
| prefetchRsc: null, | |
| head: null, | |
| prefetchHead: null, | |
| loading: null, | |
| parallelRoutes: new Map([ | |
| [ | |
| 'children', | |
| new Map([ | |
| [ | |
| '', | |
| { | |
| navigatedAt, | |
| lazyData: null, | |
| rsc: <>Page</>, | |
| prefetchRsc: null, | |
| head: null, | |
| prefetchHead: null, | |
| loading: null, | |
| parallelRoutes: new Map(), | |
| }, | |
| ], | |
| ]), | |
| ], | |
| ]), | |
| }, | |
| ], | |
| ]), | |
| ], | |
| ]), | |
| } | |
| const flightData = getFlightData() | |
| if (typeof flightData === 'string') { | |
| throw new Error('invalid flight data') | |
| } | |
| // Mirrors the way router-reducer values are passed in. | |
| const flightDataPath = flightData[0] | |
| const [treePatch, cacheNodeSeedData, head /*, isHeadPartial */] = | |
| flightDataPath.slice(-4) | |
| fillLazyItemsTillLeafWithHead( | |
| navigatedAt, | |
| cache, | |
| existingCache, | |
| treePatch, | |
| cacheNodeSeedData, | |
| head, | |
| undefined | |
| ) | |
| const expectedCache: CacheNode = { | |
| navigatedAt, | |
| lazyData: null, | |
| rsc: null, | |
| prefetchRsc: null, | |
| head: null, | |
| prefetchHead: null, | |
| loading: null, | |
| parallelRoutes: new Map([ | |
| [ | |
| 'children', | |
| new Map([ | |
| [ | |
| 'linking', | |
| { | |
| navigatedAt, | |
| lazyData: null, | |
| rsc: null, | |
| prefetchRsc: null, | |
| head: null, | |
| prefetchHead: null, | |
| loading: null, | |
| parallelRoutes: new Map([ | |
| [ | |
| 'children', | |
| new Map([ | |
| [ | |
| 'about', | |
| { | |
| navigatedAt, | |
| lazyData: null, | |
| loading: null, | |
| parallelRoutes: new Map([ | |
| [ | |
| 'children', | |
| new Map([ | |
| [ | |
| '', | |
| { | |
| navigatedAt, | |
| lazyData: null, | |
| rsc: null, | |
| prefetchRsc: null, | |
| prefetchHead: null, | |
| loading: null, | |
| parallelRoutes: new Map(), | |
| head: null, | |
| }, | |
| ], | |
| ]), | |
| ], | |
| ]), | |
| rsc: null, | |
| prefetchRsc: null, | |
| head: null, | |
| prefetchHead: null, | |
| }, | |
| ], | |
| [ | |
| '', | |
| { | |
| navigatedAt, | |
| lazyData: null, | |
| rsc: <>Page</>, | |
| prefetchRsc: null, | |
| head: null, | |
| prefetchHead: null, | |
| loading: null, | |
| parallelRoutes: new Map(), | |
| }, | |
| ], | |
| ]), | |
| ], | |
| ]), | |
| }, | |
| ], | |
| ]), | |
| ], | |
| ]), | |
| } | |
| expect(cache).toMatchObject(expectedCache) | |
| }) | |
| }) | |