Files
tuono/packages/tuono-fs-router-vite-plugin/src/sort-route-nodes.spec.ts
T

116 lines
3.4 KiB
TypeScript
Raw Normal View History

2024-07-23 19:13:18 +02:00
import { describe, it, expect } from 'vitest'
2024-12-01 10:07:35 +01:00
2024-07-23 19:13:18 +02:00
import { sortRouteNodes } from './sort-route-nodes'
const routes = [
{
filePath: 'index.tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/index.tsx',
2024-07-23 19:13:18 +02:00
routePath: '/',
variableName: 'Index',
path: '/',
cleanedPath: '/',
},
{
filePath: 'about.tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/about.tsx',
2024-07-23 19:13:18 +02:00
routePath: '/about',
variableName: 'About',
path: '/about',
cleanedPath: '/about',
},
{
filePath: '__layout.tsx',
2024-07-23 19:13:18 +02:00
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/__layout.tsx',
routePath: '/__layout',
2024-07-23 19:13:18 +02:00
variableName: 'root',
},
{
filePath: 'posts/[post].tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/posts/[post].tsx',
2024-07-23 19:13:18 +02:00
routePath: '/posts/[post]',
variableName: 'Postspost',
},
{
filePath: 'posts/my-post.tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/posts/my-post.tsx',
2024-07-23 19:13:18 +02:00
routePath: '/posts/my-post',
variableName: 'PostsMyPost',
},
{
filePath: 'posts/index.tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/posts/index.tsx',
2024-07-23 19:13:18 +02:00
routePath: '/posts/',
variableName: 'PostsIndex',
},
{
filePath: 'posts/__layout.tsx',
2024-07-23 19:13:18 +02:00
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/posts/__layout.tsx',
routePath: '/posts/__layout',
2024-07-23 19:13:18 +02:00
variableName: 'Postsroot',
},
]
const expectedSorting = [
{
filePath: 'index.tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/index.tsx',
2024-07-23 19:13:18 +02:00
routePath: '/',
variableName: 'Index',
path: '/',
cleanedPath: '/',
},
{
filePath: 'about.tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/about.tsx',
2024-07-23 19:13:18 +02:00
routePath: '/about',
variableName: 'About',
path: '/about',
cleanedPath: '/about',
},
{
filePath: 'posts/__layout.tsx',
2024-07-23 19:13:18 +02:00
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/posts/__layout.tsx',
routePath: '/posts/__layout',
2024-07-23 19:13:18 +02:00
variableName: 'Postsroot',
},
{
filePath: 'posts/my-post.tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/posts/my-post.tsx',
2024-07-23 19:13:18 +02:00
routePath: '/posts/my-post',
variableName: 'PostsMyPost',
},
{
filePath: 'posts/index.tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/posts/index.tsx',
2024-07-23 19:13:18 +02:00
routePath: '/posts/',
variableName: 'PostsIndex',
},
{
filePath: 'posts/[post].tsx',
fullPath:
'/tuono/packages/tuono-fs-router-vite-plugin/tests/generator/multi-level-root-dynamic/routes/posts/[post].tsx',
2024-07-23 19:13:18 +02:00
routePath: '/posts/[post]',
variableName: 'Postspost',
},
]
2024-12-01 10:07:35 +01:00
describe('sortRouteNodes works', () => {
2024-07-23 19:13:18 +02:00
it('Should correctly sort the nodes', () => {
const sorted = sortRouteNodes(routes)
expect(sorted).toStrictEqual(expectedSorting)
})
})