Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 committed Jun 7, 2023
1 parent ad47eea commit 545d982
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 49 deletions.
2 changes: 1 addition & 1 deletion packages/internal/src/__tests__/nestedPages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('User specified imports, with static imports', () => {
outputWithStaticImports = prebuildWebFile(routesFile, {
prerender: true,
forJest: true,
})?.code //?
})?.code

outputNoStaticImports = prebuildWebFile(routesFile, {
forJest: true,
Expand Down
3 changes: 1 addition & 2 deletions packages/router/src/__tests__/router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ describe('slow imports', () => {
timeoutForFlakeyAsyncTests
)

// TODO: Page loading delay not implemented
test(
'usePageLoadingContext',
async () => {
Expand Down Expand Up @@ -1058,7 +1057,7 @@ test('renders first matching route only', async () => {
await waitFor(() => screen.getByText(/Home Page/))

// go to about page, and make sure that's the only page rendered
act(() => navigate(routes.about())) //?
act(() => navigate(routes.about()))

await waitFor(() => screen.getByText('About Page'))
expect(screen.queryByText(/param/)).not.toBeInTheDocument()
Expand Down
104 changes: 58 additions & 46 deletions packages/router/src/__tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('validatePath', () => {
it.each([
{ path: 'invalid/route', routeName: 'isInvalid' },
{ path: '{id}/invalid/route', routeName: 'isInvalid' },
{ path: ' /invalid/route', routeName: 'isInvalid' }
{ path: ' /invalid/route', routeName: 'isInvalid' },
])(
'rejects "%s" path that does not begin with a slash',
({ path, routeName }) => {
Expand All @@ -254,72 +254,84 @@ describe('validatePath', () => {
)

it.each([
{ path: '/path/to/user profile', routeName: 'hasSpaces'},
{ path: '/path/ to/userprofile', routeName: 'hasSpaces'},
{ path: '/path/to /userprofile', routeName: 'hasSpaces'},
{ path: '/path/to/users/{id: Int}', routeName: 'hasSpaces'},
{ path: '/path/to/users/{id :Int}', routeName: 'hasSpaces'},
{ path: '/path/to/users/{id : Int}', routeName: 'hasSpaces'},
{ path: '/path/to/users/{ id:Int}', routeName: 'hasSpaces'},
{ path: '/path/to/users/{id:Int }', routeName: 'hasSpaces'},
{ path: '/path/to/users/{ id:Int }', routeName: 'hasSpaces'},
{ path: '/path/to/users/{ id : Int }', routeName: 'hasSpaces'},
{ path: '/path/to/user profile', routeName: 'hasSpaces' },
{ path: '/path/ to/userprofile', routeName: 'hasSpaces' },
{ path: '/path/to /userprofile', routeName: 'hasSpaces' },
{ path: '/path/to/users/{id: Int}', routeName: 'hasSpaces' },
{ path: '/path/to/users/{id :Int}', routeName: 'hasSpaces' },
{ path: '/path/to/users/{id : Int}', routeName: 'hasSpaces' },
{ path: '/path/to/users/{ id:Int}', routeName: 'hasSpaces' },
{ path: '/path/to/users/{id:Int }', routeName: 'hasSpaces' },
{ path: '/path/to/users/{ id:Int }', routeName: 'hasSpaces' },
{ path: '/path/to/users/{ id : Int }', routeName: 'hasSpaces' },
])('rejects paths with spaces: "%s"', ({ path, routeName }) => {
expect(() => validatePath(path, routeName)).toThrowError(
`Route path for ${routeName} contains spaces: "${path}"`
)
})

it.each([
{ path: '/users/{id}/photos/{id}', routeName: "hasDuplicateParams"},
{ path: '/users/{id}/photos/{id:Int}', routeName: "hasDuplicateParams"},
{ path: '/users/{id:Int}/photos/{id}', routeName: "hasDuplicateParams"},
{ path: '/users/{id:Int}/photos/{id:Int}', routeName: "hasDuplicateParams"},
{ path: '/users/{id}/photos/{id}', routeName: 'hasDuplicateParams' },
{ path: '/users/{id}/photos/{id:Int}', routeName: 'hasDuplicateParams' },
{ path: '/users/{id:Int}/photos/{id}', routeName: 'hasDuplicateParams' },
{
path: '/users/{id:Int}/photos/{id:Int}',
routeName: 'hasDuplicateParams',
},
])('rejects path "%s" with duplicate params', ({ path, routeName }) => {
expect(() => validatePath(path, routeName)).toThrowError(
`Route path contains duplicate parameter: "${path}"`
)
})

it.each([
{ path: '/users/{id:Int}/photos/{photo_id:Int}', routeName: "validCorrectPath" },
{ path: '/users/{id}/photos/{photo_id}', routeName: "validCorrectPath" },
{ path: '/users/{id}/photos/{photo_id}?format=jpg&w=400&h=400', routeName: "validCorrectPath" },
{ path: '/', routeName: "validCorrectPath" },
{ path: '/404', routeName: "validCorrectPath" },
{ path: '/about', routeName: "validCorrectPath" },
{ path: '/about/redwood', routeName: "validCorrectPath" },
{
path: '/users/{id:Int}/photos/{photo_id:Int}',
routeName: 'validCorrectPath',
},
{ path: '/users/{id}/photos/{photo_id}', routeName: 'validCorrectPath' },
{
path: '/users/{id}/photos/{photo_id}?format=jpg&w=400&h=400',
routeName: 'validCorrectPath',
},
{ path: '/', routeName: 'validCorrectPath' },
{ path: '/404', routeName: 'validCorrectPath' },
{ path: '/about', routeName: 'validCorrectPath' },
{ path: '/about/redwood', routeName: 'validCorrectPath' },
])('validates correct path "%s"', ({ path, routeName }) => {
expect(() => validatePath(path, routeName)).not.toThrow()
})

it.each([
{ path: '/path/{ref}', routeName: "ref" },
{ path: '/path/{ref}/bazinga', routeName: "ref" },
{ path: '/path/{ref:Int}', routeName: "ref" },
{ path: '/path/{ref:Int}/bazinga', routeName: "ref" },
{ path: '/path/{key}', routeName: "key" },
{ path: '/path/{key}/bazinga', routeName: "key" },
{ path: '/path/{key:Int}', routeName: "key" },
{ path: '/path/{key:Int}/bazinga', routeName: "key" }
])('rejects paths with ref or key as path parameters: "%s"', ({ path, routeName }) => {
expect(() => validatePath(path, routeName)).toThrowError(
[
`Route for ${routeName} contains ref or key as a path parameter: "${path}"`,
"`ref` and `key` shouldn't be used as path parameters because they're special React props.",
'You can fix this by renaming the path parameter.',
].join('\n')
)
})
{ path: '/path/{ref}', routeName: 'ref' },
{ path: '/path/{ref}/bazinga', routeName: 'ref' },
{ path: '/path/{ref:Int}', routeName: 'ref' },
{ path: '/path/{ref:Int}/bazinga', routeName: 'ref' },
{ path: '/path/{key}', routeName: 'key' },
{ path: '/path/{key}/bazinga', routeName: 'key' },
{ path: '/path/{key:Int}', routeName: 'key' },
{ path: '/path/{key:Int}/bazinga', routeName: 'key' },
])(
'rejects paths with ref or key as path parameters: "%s"',
({ path, routeName }) => {
expect(() => validatePath(path, routeName)).toThrowError(
[
`Route for ${routeName} contains ref or key as a path parameter: "${path}"`,
"`ref` and `key` shouldn't be used as path parameters because they're special React props.",
'You can fix this by renaming the path parameter.',
].join('\n')
)
}
)

it.each([
{ path: '/path/{reff}', routeName: "validRefKeyVariations" },
{ path: '/path/{reff:Int}', routeName: "validRefKeyVariations" },
{ path: '/path/{reff}/bazinga', routeName: "validRefKeyVariations" },
{ path: '/path/{keys}', routeName: "validRefKeyVariations" },
{ path: '/path/{keys:Int}', routeName: "validRefKeyVariations" },
{ path: '/path/key', routeName: "validRefKeyVariations" },
{ path: '/path/key/bazinga', routeName: "validRefKeyVariations" },
{ path: '/path/{reff}', routeName: 'validRefKeyVariations' },
{ path: '/path/{reff:Int}', routeName: 'validRefKeyVariations' },
{ path: '/path/{reff}/bazinga', routeName: 'validRefKeyVariations' },
{ path: '/path/{keys}', routeName: 'validRefKeyVariations' },
{ path: '/path/{keys:Int}', routeName: 'validRefKeyVariations' },
{ path: '/path/key', routeName: 'validRefKeyVariations' },
{ path: '/path/key/bazinga', routeName: 'validRefKeyVariations' },
])(
`doesn't reject paths with variations on ref or key as path parameters: "%s"`,
({ path, routeName }) => {
Expand Down

0 comments on commit 545d982

Please sign in to comment.