-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: get flatten routes which nested level more than 3 (#6555)
* fix: get flatten routes which nested level more than 3 * fix: lint
- Loading branch information
Showing
3 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ice/app': patch | ||
--- | ||
|
||
fix: get flatten routes which nested level more than 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { expect, it, describe } from 'vitest'; | ||
import getRoutePaths from '../src/utils/getRoutePaths.js'; | ||
|
||
describe('getRoutePaths', () => { | ||
it('index route with layout', () => { | ||
const routeManifest = [ | ||
{ | ||
children: [ | ||
{}, | ||
], | ||
}, | ||
]; | ||
// @ts-ignore for mock routeManifest. | ||
const routePaths = getRoutePaths(routeManifest); | ||
expect(routePaths).toEqual(['/']); | ||
}); | ||
it('nested level 1', () => { | ||
const routeManifest = [ | ||
{ | ||
children: [ | ||
{ | ||
path: 'a', | ||
}, | ||
{ | ||
path: 'b', | ||
}, | ||
], | ||
}, | ||
]; | ||
// @ts-ignore for mock routeManifest. | ||
const routePaths = getRoutePaths(routeManifest); | ||
expect(routePaths).toEqual(['/a', '/b']); | ||
}); | ||
|
||
it('nested level 2', () => { | ||
const routeManifest = [ | ||
{ | ||
children: [ | ||
{ | ||
path: 'a', | ||
children: [ | ||
{ | ||
path: 'a1', | ||
}, | ||
{ | ||
path: 'a2', | ||
}, | ||
], | ||
}, | ||
{ | ||
path: 'b', | ||
}, | ||
], | ||
}, | ||
]; | ||
// @ts-ignore for mock routeManifest. | ||
const routePaths = getRoutePaths(routeManifest, '/'); | ||
expect(routePaths).toEqual(['/a/a1', '/a/a2', '/b']); | ||
}); | ||
|
||
it('nested level 3', () => { | ||
const routeManifest = [ | ||
{ | ||
children: [ | ||
{ | ||
path: 'a', | ||
children: [ | ||
{ | ||
path: 'a1', | ||
children: [ | ||
{ | ||
path: 'a11', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
path: 'b', | ||
}, | ||
], | ||
}, | ||
]; | ||
// @ts-ignore for mock routeManifest. | ||
const routePaths = getRoutePaths(routeManifest); | ||
expect(routePaths).toEqual(['/a/a1/a11', '/b']); | ||
}); | ||
}); |