({
throwAtIndex,
parentFailures,
beforeLoadNotFoundFactory,
withDefaultNotFoundComponent,
}: {
throwAtIndex: ThrowAtIndex
parentFailures: ParentFailureMap
beforeLoadNotFoundFactory?: Scenario['beforeLoadNotFoundFactory']
withDefaultNotFoundComponent?: boolean
})
| 1172 | } |
| 1173 | |
| 1174 | const setupScenario = ({ |
| 1175 | throwAtIndex, |
| 1176 | parentFailures, |
| 1177 | beforeLoadNotFoundFactory, |
| 1178 | withDefaultNotFoundComponent, |
| 1179 | }: { |
| 1180 | throwAtIndex: ThrowAtIndex |
| 1181 | parentFailures: ParentFailureMap |
| 1182 | beforeLoadNotFoundFactory?: Scenario['beforeLoadNotFoundFactory'] |
| 1183 | withDefaultNotFoundComponent?: boolean |
| 1184 | }) => { |
| 1185 | const makeHead = (label: string) => |
| 1186 | vi.fn(() => ({ meta: [{ title: label }] })) |
| 1187 | |
| 1188 | const makeLoader = (index: number) => |
| 1189 | vi.fn(() => { |
| 1190 | const failure = parentFailures[index as 0 | 1 | 2] |
| 1191 | if (failure === 'notFound') { |
| 1192 | throw notFound({ data: { source: `loader-${index}` } }) |
| 1193 | } |
| 1194 | if (failure === 'redirect') { |
| 1195 | throw redirect({ to: '/redirect-target' }) |
| 1196 | } |
| 1197 | return { level: index } |
| 1198 | }) |
| 1199 | |
| 1200 | const rootRoute = new BaseRootRoute({ |
| 1201 | loader: makeLoader(0), |
| 1202 | head: makeHead('Root'), |
| 1203 | }) |
| 1204 | |
| 1205 | const level1Route = new BaseRoute({ |
| 1206 | getParentRoute: () => rootRoute, |
| 1207 | path: '/level-1', |
| 1208 | loader: makeLoader(1), |
| 1209 | head: makeHead('Level 1'), |
| 1210 | }) |
| 1211 | |
| 1212 | const level2Route = new BaseRoute({ |
| 1213 | getParentRoute: () => level1Route, |
| 1214 | path: '/level-2', |
| 1215 | loader: makeLoader(2), |
| 1216 | head: makeHead('Level 2'), |
| 1217 | }) |
| 1218 | |
| 1219 | const level3Route = new BaseRoute({ |
| 1220 | getParentRoute: () => level2Route, |
| 1221 | path: '/level-3', |
| 1222 | loader: makeLoader(3), |
| 1223 | head: makeHead('Level 3'), |
| 1224 | }) |
| 1225 | |
| 1226 | const redirectTargetRoute = new BaseRoute({ |
| 1227 | getParentRoute: () => rootRoute, |
| 1228 | path: '/redirect-target', |
| 1229 | }) |
| 1230 | |
| 1231 | const routeTree = rootRoute.addChildren([ |
no test coverage detected