"use strict";
var _async_to_generator = require("@swc/helpers/lib/_async_to_generator.js").default;
var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default;
var _react = _interop_require_default(require("react"));
var _appRouterContext = require("../../../../shared/lib/app-router-context");
var _createInitialRouterState = require("../create-initial-router-state");
var _routerReducerTypes = require("../router-reducer-types");
var _navigateReducer = require("./navigate-reducer");
var _prefetchReducer = require("./prefetch-reducer");
var _fetchServerResponse = require("../fetch-server-response");
const flightData = [
    [
        'children',
        'linking',
        'children',
        'about',
        [
            'about',
            {
                children: [
                    '',
                    {}
                ]
            }, 
        ],
        /*#__PURE__*/ _react.default.createElement("h1", null, "About Page!"),
        /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement("title", null, "About page!")), 
    ], 
];
jest.mock('../fetch-server-response', ()=>{
    return {
        fetchServerResponse: (url)=>{
            if (url.pathname === '/linking/about') {
                return Promise.resolve([
                    flightData,
                    undefined
                ]);
            }
            throw new Error('unknown url in mock');
        }
    };
});
const getInitialRouterStateTree = ()=>[
        '',
        {
            children: [
                'linking',
                {
                    children: [
                        '',
                        {}
                    ]
                }, 
            ]
        },
        undefined,
        undefined,
        true, 
    ];
function runPromiseThrowChain(fn) {
    return _runPromiseThrowChain.apply(this, arguments);
}
function _runPromiseThrowChain() {
    _runPromiseThrowChain = _async_to_generator(function*(fn) {
        try {
            return yield fn();
        } catch (err) {
            if (err instanceof Promise) {
                yield err;
                return yield runPromiseThrowChain(fn);
            }
            throw err;
        }
    });
    return _runPromiseThrowChain.apply(this, arguments);
}
describe('navigateReducer', ()=>{
    it('should apply navigation', _async_to_generator(function*() {
        const initialTree = getInitialRouterStateTree();
        const initialCanonicalUrl = '/linking';
        const children = /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout"));
        const initialParallelRoutes = new Map([
            [
                'children',
                new Map([
                    [
                        'linking',
                        {
                            status: _appRouterContext.CacheStates.READY,
                            parallelRoutes: new Map([
                                [
                                    'children',
                                    new Map([
                                        [
                                            '',
                                            {
                                                status: _appRouterContext.CacheStates.READY,
                                                data: null,
                                                subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                parallelRoutes: new Map()
                                            }, 
                                        ], 
                                    ]), 
                                ], 
                            ]),
                            data: null,
                            subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                        }, 
                    ], 
                ]), 
            ], 
        ]);
        const state = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        const action = {
            type: _routerReducerTypes.ACTION_NAVIGATE,
            url: new URL('/linking/about', 'https://localhost'),
            isExternalUrl: false,
            locationSearch: '',
            navigateType: 'push',
            forceOptimisticNavigation: false,
            cache: {
                status: _appRouterContext.CacheStates.LAZY_INITIALIZED,
                data: null,
                subTreeData: null,
                parallelRoutes: new Map()
            },
            mutable: {}
        };
        const newState = yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state, action));
        const expectedState = {
            prefetchCache: new Map(),
            pushRef: {
                mpaNavigation: false,
                pendingPush: true
            },
            focusAndScrollRef: {
                apply: true
            },
            canonicalUrl: '/linking/about',
            cache: {
                status: _appRouterContext.CacheStates.READY,
                data: null,
                subTreeData: /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout")),
                parallelRoutes: new Map([
                    [
                        'children',
                        new Map([
                            [
                                'linking',
                                {
                                    status: _appRouterContext.CacheStates.READY,
                                    parallelRoutes: new Map([
                                        [
                                            'children',
                                            new Map([
                                                [
                                                    '',
                                                    {
                                                        status: _appRouterContext.CacheStates.READY,
                                                        data: null,
                                                        subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                        parallelRoutes: new Map()
                                                    }, 
                                                ],
                                                [
                                                    'about',
                                                    {
                                                        status: _appRouterContext.CacheStates.READY,
                                                        data: null,
                                                        subTreeData: /*#__PURE__*/ _react.default.createElement("h1", null, "About Page!"),
                                                        parallelRoutes: new Map([
                                                            [
                                                                'children',
                                                                new Map([
                                                                    [
                                                                        '',
                                                                        {
                                                                            status: _appRouterContext.CacheStates.LAZY_INITIALIZED,
                                                                            data: null,
                                                                            head: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement("title", null, "About page!")),
                                                                            parallelRoutes: new Map(),
                                                                            subTreeData: null
                                                                        }, 
                                                                    ], 
                                                                ]), 
                                                            ], 
                                                        ])
                                                    }, 
                                                ], 
                                            ]), 
                                        ], 
                                    ]),
                                    data: null,
                                    subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                                }, 
                            ], 
                        ]), 
                    ], 
                ])
            },
            tree: [
                '',
                {
                    children: [
                        'linking',
                        {
                            children: [
                                'about',
                                {
                                    children: [
                                        '',
                                        {}
                                    ]
                                }
                            ]
                        }, 
                    ]
                },
                undefined,
                undefined,
                true, 
            ]
        };
        expect(newState).toMatchObject(expectedState);
    }));
    it('should apply navigation when called twice (concurrent)', _async_to_generator(function*() {
        const initialTree = getInitialRouterStateTree();
        const initialCanonicalUrl = '/linking';
        const children = /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout"));
        const initialParallelRoutes = new Map([
            [
                'children',
                new Map([
                    [
                        'linking',
                        {
                            status: _appRouterContext.CacheStates.READY,
                            parallelRoutes: new Map([
                                [
                                    'children',
                                    new Map([
                                        [
                                            '',
                                            {
                                                status: _appRouterContext.CacheStates.READY,
                                                data: null,
                                                subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                parallelRoutes: new Map()
                                            }, 
                                        ], 
                                    ]), 
                                ], 
                            ]),
                            data: null,
                            subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                        }, 
                    ], 
                ]), 
            ], 
        ]);
        const state = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        const state2 = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        const action = {
            type: _routerReducerTypes.ACTION_NAVIGATE,
            url: new URL('/linking/about', 'https://localhost'),
            isExternalUrl: false,
            locationSearch: '',
            navigateType: 'push',
            forceOptimisticNavigation: false,
            cache: {
                status: _appRouterContext.CacheStates.LAZY_INITIALIZED,
                data: null,
                subTreeData: null,
                parallelRoutes: new Map()
            },
            mutable: {}
        };
        yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state, action));
        const newState = yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state2, action));
        const expectedState = {
            prefetchCache: new Map(),
            pushRef: {
                mpaNavigation: false,
                pendingPush: true
            },
            focusAndScrollRef: {
                apply: true
            },
            canonicalUrl: '/linking/about',
            cache: {
                status: _appRouterContext.CacheStates.READY,
                data: null,
                subTreeData: /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout")),
                parallelRoutes: new Map([
                    [
                        'children',
                        new Map([
                            [
                                'linking',
                                {
                                    status: _appRouterContext.CacheStates.READY,
                                    parallelRoutes: new Map([
                                        [
                                            'children',
                                            new Map([
                                                [
                                                    '',
                                                    {
                                                        status: _appRouterContext.CacheStates.READY,
                                                        data: null,
                                                        subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                        parallelRoutes: new Map()
                                                    }, 
                                                ],
                                                [
                                                    'about',
                                                    {
                                                        status: _appRouterContext.CacheStates.READY,
                                                        data: null,
                                                        subTreeData: /*#__PURE__*/ _react.default.createElement("h1", null, "About Page!"),
                                                        parallelRoutes: new Map([
                                                            [
                                                                'children',
                                                                new Map([
                                                                    [
                                                                        '',
                                                                        {
                                                                            status: _appRouterContext.CacheStates.LAZY_INITIALIZED,
                                                                            data: null,
                                                                            head: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement("title", null, "About page!")),
                                                                            parallelRoutes: new Map(),
                                                                            subTreeData: null
                                                                        }, 
                                                                    ], 
                                                                ]), 
                                                            ], 
                                                        ])
                                                    }, 
                                                ], 
                                            ]), 
                                        ], 
                                    ]),
                                    data: null,
                                    subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                                }, 
                            ], 
                        ]), 
                    ], 
                ])
            },
            tree: [
                '',
                {
                    children: [
                        'linking',
                        {
                            children: [
                                'about',
                                {
                                    children: [
                                        '',
                                        {}
                                    ]
                                }
                            ]
                        }, 
                    ]
                },
                undefined,
                undefined,
                true, 
            ]
        };
        expect(newState).toMatchObject(expectedState);
    }));
    it('should apply navigation for external url (push)', _async_to_generator(function*() {
        const initialTree = getInitialRouterStateTree();
        const initialCanonicalUrl = '/linking';
        const children = /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout"));
        const initialParallelRoutes = new Map([
            [
                'children',
                new Map([
                    [
                        'linking',
                        {
                            status: _appRouterContext.CacheStates.READY,
                            parallelRoutes: new Map([
                                [
                                    'children',
                                    new Map([
                                        [
                                            '',
                                            {
                                                status: _appRouterContext.CacheStates.READY,
                                                data: null,
                                                subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                parallelRoutes: new Map()
                                            }, 
                                        ], 
                                    ]), 
                                ], 
                            ]),
                            data: null,
                            subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                        }, 
                    ], 
                ]), 
            ], 
        ]);
        const state = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        const state2 = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        const url = new URL('https://example.vercel.sh', 'https://localhost');
        const isExternalUrl = url.origin !== 'localhost';
        const action = {
            type: _routerReducerTypes.ACTION_NAVIGATE,
            url,
            isExternalUrl,
            locationSearch: '',
            navigateType: 'push',
            forceOptimisticNavigation: false,
            cache: {
                status: _appRouterContext.CacheStates.LAZY_INITIALIZED,
                data: null,
                subTreeData: null,
                parallelRoutes: new Map()
            },
            mutable: {}
        };
        yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state, action));
        const newState = yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state2, action));
        const expectedState = {
            prefetchCache: new Map(),
            pushRef: {
                mpaNavigation: true,
                pendingPush: true
            },
            focusAndScrollRef: {
                apply: false
            },
            canonicalUrl: 'https://example.vercel.sh/',
            cache: {
                status: _appRouterContext.CacheStates.READY,
                data: null,
                subTreeData: /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout")),
                parallelRoutes: new Map([
                    [
                        'children',
                        new Map([
                            [
                                'linking',
                                {
                                    status: _appRouterContext.CacheStates.READY,
                                    parallelRoutes: new Map([
                                        [
                                            'children',
                                            new Map([
                                                [
                                                    '',
                                                    {
                                                        status: _appRouterContext.CacheStates.READY,
                                                        data: null,
                                                        subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                        parallelRoutes: new Map()
                                                    }, 
                                                ], 
                                            ]), 
                                        ], 
                                    ]),
                                    data: null,
                                    subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                                }, 
                            ], 
                        ]), 
                    ], 
                ])
            },
            tree: [
                '',
                {
                    children: [
                        'linking',
                        {
                            children: [
                                '',
                                {}
                            ]
                        }, 
                    ]
                },
                undefined,
                undefined,
                true, 
            ]
        };
        expect(newState).toMatchObject(expectedState);
    }));
    it('should apply navigation for external url (replace)', _async_to_generator(function*() {
        const initialTree = getInitialRouterStateTree();
        const initialCanonicalUrl = '/linking';
        const children = /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout"));
        const initialParallelRoutes = new Map([
            [
                'children',
                new Map([
                    [
                        'linking',
                        {
                            status: _appRouterContext.CacheStates.READY,
                            parallelRoutes: new Map([
                                [
                                    'children',
                                    new Map([
                                        [
                                            '',
                                            {
                                                status: _appRouterContext.CacheStates.READY,
                                                data: null,
                                                subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                parallelRoutes: new Map()
                                            }, 
                                        ], 
                                    ]), 
                                ], 
                            ]),
                            data: null,
                            subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                        }, 
                    ], 
                ]), 
            ], 
        ]);
        const state = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        const state2 = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        const url = new URL('https://example.vercel.sh', 'https://localhost');
        const isExternalUrl = url.origin !== 'localhost';
        const action = {
            type: _routerReducerTypes.ACTION_NAVIGATE,
            url,
            isExternalUrl,
            locationSearch: '',
            navigateType: 'replace',
            forceOptimisticNavigation: false,
            cache: {
                status: _appRouterContext.CacheStates.LAZY_INITIALIZED,
                data: null,
                subTreeData: null,
                parallelRoutes: new Map()
            },
            mutable: {}
        };
        yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state, action));
        const newState = yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state2, action));
        const expectedState = {
            prefetchCache: new Map(),
            pushRef: {
                mpaNavigation: true,
                pendingPush: false
            },
            focusAndScrollRef: {
                apply: false
            },
            canonicalUrl: 'https://example.vercel.sh/',
            cache: {
                status: _appRouterContext.CacheStates.READY,
                data: null,
                subTreeData: /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout")),
                parallelRoutes: new Map([
                    [
                        'children',
                        new Map([
                            [
                                'linking',
                                {
                                    status: _appRouterContext.CacheStates.READY,
                                    parallelRoutes: new Map([
                                        [
                                            'children',
                                            new Map([
                                                [
                                                    '',
                                                    {
                                                        status: _appRouterContext.CacheStates.READY,
                                                        data: null,
                                                        subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                        parallelRoutes: new Map()
                                                    }, 
                                                ], 
                                            ]), 
                                        ], 
                                    ]),
                                    data: null,
                                    subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                                }, 
                            ], 
                        ]), 
                    ], 
                ])
            },
            tree: [
                '',
                {
                    children: [
                        'linking',
                        {
                            children: [
                                '',
                                {}
                            ]
                        }, 
                    ]
                },
                undefined,
                undefined,
                true, 
            ]
        };
        expect(newState).toMatchObject(expectedState);
    }));
    it('should apply navigation for forceOptimisticNavigation', _async_to_generator(function*() {
        const initialTree = getInitialRouterStateTree();
        const initialCanonicalUrl = '/linking';
        const children = /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout"));
        const initialParallelRoutes = new Map([
            [
                'children',
                new Map([
                    [
                        'linking',
                        {
                            status: _appRouterContext.CacheStates.READY,
                            parallelRoutes: new Map([
                                [
                                    'children',
                                    new Map([
                                        [
                                            '',
                                            {
                                                status: _appRouterContext.CacheStates.READY,
                                                data: null,
                                                subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                parallelRoutes: new Map()
                                            }, 
                                        ], 
                                    ]), 
                                ], 
                            ]),
                            data: null,
                            subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                        }, 
                    ], 
                ]), 
            ], 
        ]);
        const state = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        const state2 = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        const action = {
            type: _routerReducerTypes.ACTION_NAVIGATE,
            url: new URL('/linking/about', 'https://localhost'),
            isExternalUrl: false,
            locationSearch: '',
            navigateType: 'push',
            forceOptimisticNavigation: true,
            cache: {
                status: _appRouterContext.CacheStates.LAZY_INITIALIZED,
                data: null,
                subTreeData: null,
                parallelRoutes: new Map()
            },
            mutable: {}
        };
        yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state, action));
        const newState = yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state2, action));
        const expectedState = {
            prefetchCache: new Map(),
            pushRef: {
                mpaNavigation: false,
                pendingPush: true
            },
            focusAndScrollRef: {
                apply: true
            },
            canonicalUrl: '/linking/about',
            cache: {
                status: _appRouterContext.CacheStates.READY,
                data: null,
                subTreeData: /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout")),
                parallelRoutes: new Map([
                    [
                        'children',
                        new Map([
                            [
                                'linking',
                                {
                                    status: _appRouterContext.CacheStates.READY,
                                    parallelRoutes: new Map([
                                        [
                                            'children',
                                            new Map([
                                                [
                                                    '',
                                                    {
                                                        status: _appRouterContext.CacheStates.READY,
                                                        data: null,
                                                        subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                        parallelRoutes: new Map()
                                                    }, 
                                                ],
                                                [
                                                    'about',
                                                    {
                                                        status: _appRouterContext.CacheStates.DATA_FETCH,
                                                        // Real promise is not needed here.
                                                        data: Promise.resolve(),
                                                        parallelRoutes: new Map(),
                                                        subTreeData: null
                                                    }, 
                                                ], 
                                            ]), 
                                        ], 
                                    ]),
                                    data: null,
                                    subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                                }, 
                            ], 
                        ]), 
                    ], 
                ])
            },
            tree: [
                '',
                {
                    children: [
                        'linking',
                        {
                            children: [
                                'about',
                                {
                                    children: [
                                        '',
                                        {}
                                    ]
                                },
                                undefined,
                                'refetch'
                            ]
                        }, 
                    ]
                }, 
            ]
        };
        expect(newState).toMatchObject(expectedState);
    }));
    it('should apply navigation with prefetched data', _async_to_generator(function*() {
        const initialTree = getInitialRouterStateTree();
        const initialCanonicalUrl = '/linking';
        const children = /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout"));
        const initialParallelRoutes = new Map([
            [
                'children',
                new Map([
                    [
                        'linking',
                        {
                            status: _appRouterContext.CacheStates.READY,
                            parallelRoutes: new Map([
                                [
                                    'children',
                                    new Map([
                                        [
                                            '',
                                            {
                                                status: _appRouterContext.CacheStates.READY,
                                                data: null,
                                                subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                parallelRoutes: new Map()
                                            }, 
                                        ], 
                                    ]), 
                                ], 
                            ]),
                            data: null,
                            subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                        }, 
                    ], 
                ]), 
            ], 
        ]);
        const url = new URL('/linking/about', 'https://localhost');
        const serverResponse = yield (0, _fetchServerResponse).fetchServerResponse(url, initialTree, true);
        const prefetchAction = {
            type: _routerReducerTypes.ACTION_PREFETCH,
            url,
            tree: initialTree,
            serverResponse
        };
        const state = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        yield runPromiseThrowChain(()=>(0, _prefetchReducer).prefetchReducer(state, prefetchAction));
        const state2 = (0, _createInitialRouterState).createInitialRouterState({
            initialTree,
            initialCanonicalUrl,
            children,
            initialParallelRoutes,
            isServer: false,
            location: new URL('/linking', 'https://localhost')
        });
        yield runPromiseThrowChain(()=>(0, _prefetchReducer).prefetchReducer(state2, prefetchAction));
        const action = {
            type: _routerReducerTypes.ACTION_NAVIGATE,
            url: new URL('/linking/about', 'https://localhost'),
            isExternalUrl: false,
            navigateType: 'push',
            locationSearch: '',
            forceOptimisticNavigation: false,
            cache: {
                status: _appRouterContext.CacheStates.LAZY_INITIALIZED,
                data: null,
                subTreeData: null,
                parallelRoutes: new Map()
            },
            mutable: {}
        };
        yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state, action));
        const newState = yield runPromiseThrowChain(()=>(0, _navigateReducer).navigateReducer(state2, action));
        const expectedState = {
            prefetchCache: new Map([
                [
                    '/linking/about',
                    {
                        canonicalUrlOverride: undefined,
                        flightData: [
                            [
                                'children',
                                'linking',
                                'children',
                                'about',
                                [
                                    'about',
                                    {
                                        children: [
                                            '',
                                            {}
                                        ]
                                    }, 
                                ],
                                /*#__PURE__*/ _react.default.createElement("h1", null, "About Page!"),
                                /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement("title", null, "About page!")), 
                            ], 
                        ],
                        tree: [
                            '',
                            {
                                children: [
                                    'linking',
                                    {
                                        children: [
                                            'about',
                                            {
                                                children: [
                                                    '',
                                                    {}
                                                ]
                                            }, 
                                        ]
                                    }, 
                                ]
                            },
                            undefined,
                            undefined,
                            true, 
                        ]
                    }, 
                ], 
            ]),
            pushRef: {
                mpaNavigation: false,
                pendingPush: true
            },
            focusAndScrollRef: {
                apply: true
            },
            canonicalUrl: '/linking/about',
            cache: {
                status: _appRouterContext.CacheStates.READY,
                data: null,
                subTreeData: /*#__PURE__*/ _react.default.createElement("html", null, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, "Root layout")),
                parallelRoutes: new Map([
                    [
                        'children',
                        new Map([
                            [
                                'linking',
                                {
                                    status: _appRouterContext.CacheStates.READY,
                                    parallelRoutes: new Map([
                                        [
                                            'children',
                                            new Map([
                                                [
                                                    '',
                                                    {
                                                        status: _appRouterContext.CacheStates.READY,
                                                        data: null,
                                                        subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking page"),
                                                        parallelRoutes: new Map()
                                                    }, 
                                                ],
                                                [
                                                    'about',
                                                    {
                                                        status: _appRouterContext.CacheStates.READY,
                                                        data: null,
                                                        parallelRoutes: new Map([
                                                            [
                                                                'children',
                                                                new Map([
                                                                    [
                                                                        '',
                                                                        {
                                                                            status: _appRouterContext.CacheStates.LAZY_INITIALIZED,
                                                                            subTreeData: null,
                                                                            data: null,
                                                                            head: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement("title", null, "About page!")),
                                                                            parallelRoutes: new Map()
                                                                        }, 
                                                                    ], 
                                                                ]), 
                                                            ], 
                                                        ]),
                                                        subTreeData: /*#__PURE__*/ _react.default.createElement("h1", null, "About Page!")
                                                    }, 
                                                ], 
                                            ]), 
                                        ], 
                                    ]),
                                    data: null,
                                    subTreeData: /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, "Linking layout level")
                                }, 
                            ], 
                        ]), 
                    ], 
                ])
            },
            tree: [
                '',
                {
                    children: [
                        'linking',
                        {
                            children: [
                                'about',
                                {
                                    children: [
                                        '',
                                        {}
                                    ]
                                }
                            ]
                        }, 
                    ]
                },
                undefined,
                undefined,
                true, 
            ]
        };
        expect(newState).toMatchObject(expectedState);
    }));
});

if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
  Object.defineProperty(exports.default, '__esModule', { value: true });
  Object.assign(exports.default, exports);
  module.exports = exports.default;
}

//# sourceMappingURL=navigate-reducer.test.js.map