1import { createNavigationContainerRef } from '@react-navigation/native'; 2 3import { RouterStore, store } from '../global-state/router-store'; 4import { inMemoryContext } from '../testing-library/context-stubs'; 5 6describe(RouterStore, () => { 7 it(`creates mock context with empty routes`, () => { 8 store.initialize(inMemoryContext({}), createNavigationContainerRef()); 9 10 expect(store).toMatchObject({ 11 routeNode: null, 12 rootState: undefined, 13 initialState: undefined, 14 linking: undefined, 15 routeInfo: { 16 unstable_globalHref: '', 17 pathname: '', 18 params: {}, 19 segments: [], 20 }, 21 }); 22 }); 23 it(`creates qualified context with routes`, () => { 24 store.initialize( 25 inMemoryContext({ 26 index: () => null, 27 }), 28 createNavigationContainerRef() 29 ); 30 31 expect(store).toMatchObject({ 32 routeNode: expect.objectContaining({ 33 children: [ 34 expect.objectContaining({ 35 children: [], 36 contextKey: './index.js', 37 dynamic: null, 38 route: 'index', 39 }), 40 expect.objectContaining({ 41 children: [], 42 contextKey: './_sitemap.tsx', 43 dynamic: null, 44 generated: true, 45 internal: true, 46 route: '_sitemap', 47 }), 48 expect.objectContaining({ 49 children: [], 50 contextKey: './[...404].tsx', 51 dynamic: [ 52 { 53 deep: true, 54 name: '404', 55 }, 56 ], 57 generated: true, 58 internal: true, 59 route: '[...404]', 60 }), 61 ], 62 contextKey: './_layout.tsx', 63 dynamic: null, 64 generated: true, 65 route: '', 66 }), 67 linking: expect.objectContaining({ 68 config: { 69 initialRouteName: undefined, 70 screens: { 71 '[...404]': '*404', 72 _sitemap: '_sitemap', 73 index: '', 74 }, 75 }, 76 }), 77 rootState: undefined, 78 initialState: undefined, 79 routeInfo: { 80 unstable_globalHref: '', 81 pathname: '', 82 params: {}, 83 segments: [], 84 }, 85 }); 86 }); 87 88 it(`creates qualified context with routes and initial state`, () => { 89 store.initialize( 90 inMemoryContext({ 91 index: () => null, 92 }), 93 createNavigationContainerRef(), 94 new URL('/', 'http://acme.com') 95 ); 96 97 // Should be the same as`creates qualified context with routes`, but with these 98 // additional properties 99 expect(store).toMatchObject({ 100 rootState: { 101 routes: [ 102 { 103 name: 'index', 104 path: '/', 105 }, 106 ], 107 }, 108 initialState: { 109 routes: [ 110 { 111 name: 'index', 112 path: '/', 113 }, 114 ], 115 }, 116 routeInfo: { 117 unstable_globalHref: '/', 118 pathname: '/', 119 params: {}, 120 segments: [], 121 }, 122 }); 123 }); 124}); 125