Skip to content

Commit

Permalink
Revert "Fix infinite loops on nested private routes with roles (#9204)"
Browse files Browse the repository at this point in the history
This reverts commit ee28ac0.
  • Loading branch information
jtoar committed Sep 20, 2023
1 parent a677fec commit 0362870
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 348 deletions.
109 changes: 18 additions & 91 deletions packages/router/src/__tests__/analyzeRoutes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,10 @@ describe('AnalyzeRoutes: with homePage and Children', () => {
whileLoadingPage: undefined,
wrappers: [WrapperX],
// Props passed through from set
setProps: [
{
id: 'set-one',
passThruProp: 'bazinga',
},
],
setProps: {
id: 'set-one',
passThruProp: 'bazinga',
},
})
)

Expand All @@ -160,16 +158,11 @@ describe('AnalyzeRoutes: with homePage and Children', () => {
path: '/b',
whileLoadingPage: undefined,
wrappers: [WrapperX, WrapperY], // both wrappers
setProps: [
{
id: 'set-one',
passThruProp: 'bazinga',
},
{
id: 'set-two',
theme: 'blue',
},
],
setProps: {
id: 'set-two', // the id gets overwritten by the second Set
theme: 'blue',
passThruProp: 'bazinga', // from the first set
},
})
)

Expand All @@ -180,16 +173,11 @@ describe('AnalyzeRoutes: with homePage and Children', () => {
path: '/c',
whileLoadingPage: undefined,
wrappers: [WrapperX, WrapperY], // both wrappers
setProps: [
{
id: 'set-one',
passThruProp: 'bazinga',
},
{
id: 'set-two',
theme: 'blue',
},
],
setProps: {
id: 'set-two',
theme: 'blue',
passThruProp: 'bazinga', // from the first set
},
})
)
})
Expand Down Expand Up @@ -288,12 +276,10 @@ describe('AnalyzeRoutes: with homePage and Children', () => {
page: FakePage,
wrappers: [],
setId: 1,
setProps: [
{
private: true,
unauthenticated: 'home',
},
],
setProps: {
private: true,
unauthenticated: 'home',
},
})
})

Expand Down Expand Up @@ -324,63 +310,4 @@ describe('AnalyzeRoutes: with homePage and Children', () => {
expect(namedRoutesMap.simple()).toBe('/simple')
expect(namedRoutesMap.rdSimple()).toBe('/rdSimple')
})

test('Redirect routes analysis', () => {
const HomePage = () => <h1>Home Page</h1>
const PrivateAdminPage = () => <h1>Private Admin Page</h1>
const PrivateEmployeePage = () => <h1>Private Employee Page</h1>
const PrivateNoRolesAssigned = () => <h1>Private Employee Page</h1>

const RedirectedRoutes = (
<Router>
<Route path="/" page={HomePage} name="home" />
<Private unauthenticated="home">
<Route
path="/no-roles-assigned"
page={PrivateNoRolesAssigned}
name="noRolesAssigned"
/>
<Set
private
unauthenticated="noRolesAssigned"
roles={['ADMIN', 'EMPLOYEE']}
someProp="propFromNoRolesSet"
>
<Private unauthenticated="admin" roles={'EMPLOYEE'}>
<Route
path="/employee"
page={PrivateEmployeePage}
name="privateEmployee"
/>
</Private>

<Private unauthenticated="employee" roles={'ADMIN'}>
<Route
path="/admin"
page={PrivateAdminPage}
name="privateAdmin"
/>
</Private>
</Set>
</Private>
</Router>
)

const { pathRouteMap, namedRoutesMap } = analyzeRoutes(
RedirectedRoutes.props.children,
{
currentPathName: '/simple',
}
)

console.log(JSON.stringify({ pathRouteMap, namedRoutesMap }, null, 3))

// expect(pathRouteMap['/simple'].redirect).toBe('/rdSimple')
// expect(pathRouteMap['/rdSimple'].redirect).toBeFalsy()

// // @TODO true for now, but we may not allow names on a redirect route
// expect(Object.keys(namedRoutesMap).length).toBe(2)
// expect(namedRoutesMap.simple()).toBe('/simple')
// expect(namedRoutesMap.rdSimple()).toBe('/rdSimple')
})
})
Loading

0 comments on commit 0362870

Please sign in to comment.