Skip to content

Commit

Permalink
scaffold test
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSin committed Dec 11, 2024
1 parent dbda710 commit 04ca16e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 39 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"types:preload": "tsc -p src/preload/tsconfig.json",
"types:renderer": "tsc -p src/renderer/tsconfig.json",
"types": "npm-run-all --print-label --parallel --continue-on-error types:*",
"test": "npm-run-all --print-label --parallel lint types",
"test": "npm-run-all --print-label --parallel --continue-on-error lint types vitest ",
"vitest": "vitest --config ./src/renderer/vite.config.js",
"vite:dev": "vite dev src/renderer",
"vite:build": "vite build src/renderer"
},
Expand Down Expand Up @@ -90,6 +91,7 @@
"@tanstack/router-plugin": "^1.81.9",
"@testing-library/dom": "10.4.0",
"@testing-library/react": "16.1.0",
"@testing-library/user-event": "14.5.2",
"@types/eslint__js": "^8.42.3",
"@types/lint-staged": "^13.3.0",
"@types/node": "^20.17.6",
Expand Down
29 changes: 1 addition & 28 deletions src/renderer/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { Route as OnboardingDeviceNamingScreenImport } from './routes/Onboarding
import { Route as OnboardingDataPrivacyImport } from './routes/Onboarding/DataPrivacy'
import { Route as OnboardingCreateJoinProjectScreenImport } from './routes/Onboarding/CreateJoinProjectScreen'
import { Route as MapTabsMapImport } from './routes/(MapTabs)/_Map'
import { Route as MapTabsMapTestImport } from './routes/(MapTabs)/_Map.test'
import { Route as MapTabsMapTab2Import } from './routes/(MapTabs)/_Map.tab2'
import { Route as MapTabsMapTab1Import } from './routes/(MapTabs)/_Map.tab1'

Expand Down Expand Up @@ -86,12 +85,6 @@ const MapTabsMapRoute = MapTabsMapImport.update({
getParentRoute: () => MapTabsRoute,
} as any)

const MapTabsMapTestRoute = MapTabsMapTestImport.update({
id: '/test',
path: '/test',
getParentRoute: () => MapTabsMapRoute,
} as any)

const MapTabsMapTab2Route = MapTabsMapTab2Import.update({
id: '/tab2',
path: '/tab2',
Expand Down Expand Up @@ -185,13 +178,6 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof MapTabsMapTab2Import
parentRoute: typeof MapTabsMapImport
}
'/(MapTabs)/_Map/test': {
id: '/(MapTabs)/_Map/test'
path: '/test'
fullPath: '/test'
preLoaderRoute: typeof MapTabsMapTestImport
parentRoute: typeof MapTabsMapImport
}
}
}

Expand All @@ -200,13 +186,11 @@ declare module '@tanstack/react-router' {
interface MapTabsMapRouteChildren {
MapTabsMapTab1Route: typeof MapTabsMapTab1Route
MapTabsMapTab2Route: typeof MapTabsMapTab2Route
MapTabsMapTestRoute: typeof MapTabsMapTestRoute
}

const MapTabsMapRouteChildren: MapTabsMapRouteChildren = {
MapTabsMapTab1Route: MapTabsMapTab1Route,
MapTabsMapTab2Route: MapTabsMapTab2Route,
MapTabsMapTestRoute: MapTabsMapTestRoute,
}

const MapTabsMapRouteWithChildren = MapTabsMapRoute._addFileChildren(
Expand Down Expand Up @@ -234,7 +218,6 @@ export interface FileRoutesByFullPath {
'/Onboarding': typeof OnboardingIndexRoute
'/tab1': typeof MapTabsMapTab1Route
'/tab2': typeof MapTabsMapTab2Route
'/test': typeof MapTabsMapTestRoute
}

export interface FileRoutesByTo {
Expand All @@ -247,7 +230,6 @@ export interface FileRoutesByTo {
'/Onboarding': typeof OnboardingIndexRoute
'/tab1': typeof MapTabsMapTab1Route
'/tab2': typeof MapTabsMapTab2Route
'/test': typeof MapTabsMapTestRoute
}

export interface FileRoutesById {
Expand All @@ -263,7 +245,6 @@ export interface FileRoutesById {
'/Onboarding/': typeof OnboardingIndexRoute
'/(MapTabs)/_Map/tab1': typeof MapTabsMapTab1Route
'/(MapTabs)/_Map/tab2': typeof MapTabsMapTab2Route
'/(MapTabs)/_Map/test': typeof MapTabsMapTestRoute
}

export interface FileRouteTypes {
Expand All @@ -278,7 +259,6 @@ export interface FileRouteTypes {
| '/Onboarding'
| '/tab1'
| '/tab2'
| '/test'
fileRoutesByTo: FileRoutesByTo
to:
| '/'
Expand All @@ -290,7 +270,6 @@ export interface FileRouteTypes {
| '/Onboarding'
| '/tab1'
| '/tab2'
| '/test'
id:
| '__root__'
| '/'
Expand All @@ -304,7 +283,6 @@ export interface FileRouteTypes {
| '/Onboarding/'
| '/(MapTabs)/_Map/tab1'
| '/(MapTabs)/_Map/tab2'
| '/(MapTabs)/_Map/test'
fileRoutesById: FileRoutesById
}

Expand Down Expand Up @@ -368,8 +346,7 @@ export const routeTree = rootRoute
"parent": "/(MapTabs)",
"children": [
"/(MapTabs)/_Map/tab1",
"/(MapTabs)/_Map/tab2",
"/(MapTabs)/_Map/test"
"/(MapTabs)/_Map/tab2"
]
},
"/Onboarding/CreateJoinProjectScreen": {
Expand All @@ -394,10 +371,6 @@ export const routeTree = rootRoute
"/(MapTabs)/_Map/tab2": {
"filePath": "(MapTabs)/_Map.tab2.tsx",
"parent": "/(MapTabs)/_Map"
},
"/(MapTabs)/_Map/test": {
"filePath": "(MapTabs)/_Map.test.tsx",
"parent": "/(MapTabs)/_Map"
}
}
}
Expand Down
45 changes: 36 additions & 9 deletions src/renderer/src/routes/(MapTabs)/_Map.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
/**
* @vitest-environment jsdom
*/

import { RouterProvider, createRouter } from '@tanstack/react-router'
import type { ReactNode } from 'react'
import {
RouterProvider,
createRootRoute,
createRoute,
createRouter,
} from '@tanstack/react-router'
import { render, screen } from '@testing-library/react'
import { expect, test } from 'vitest'

import { routeTree } from '../../routeTree.gen'
import { IntlProvider } from '../../contexts/IntlContext'
import { Map } from './_Map'

const rootRoute = createRootRoute({})

const Wrapper = ({ children }: { children: ReactNode }) => (
<IntlProvider>{children}</IntlProvider>
)

const mapRoute = createRoute({
getParentRoute: () => rootRoute,
id: 'map',
component: Map,
})

const catchAllRoute = createRoute({
getParentRoute: () => mapRoute,
path: '$',
component: () => null,
})

const routeTree = rootRoute.addChildren([mapRoute.addChildren([catchAllRoute])])

const router = createRouter({ routeTree })

test('renders something', () => {
render(<RouterProvider router={router} />)
const text = screen.getByText('Tab 1')
expect(text).toBeDefined()
router.navigate({ to: '/tab1' })
// @ts-expect-error - typings
render(<RouterProvider router={router} />, { wrapper: Wrapper })
const settingsButton = screen.getByText('Settings')
expect(settingsButton).toBeDefined()
settingsButton.click()
console.log(router.state.location)
})
2 changes: 1 addition & 1 deletion src/renderer/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig((configEnv) => {
emptyOutDir: true,
},
plugins: [
TanStackRouterVite({ routeFileIgnorePattern: '*.test.tsx' }),
TanStackRouterVite({ routeFileIgnorePattern: '\\.test\\.tsx?$' }),
react(),
svgr({
include: '**/*.svg',
Expand Down

0 comments on commit 04ca16e

Please sign in to comment.