Skip to content

Commit

Permalink
add specs for default redirects on new route view
Browse files Browse the repository at this point in the history
  • Loading branch information
frontendphil committed Dec 13, 2024
1 parent d1472e4 commit 9466fb3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
48 changes: 45 additions & 3 deletions extension/src/panel/pages/_index/NoRoutes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { saveLastUsedRouteId } from '@/execution-routes'
import { expectRouteToBe, render } from '@/test-utils'
import { describe, it } from 'vitest'
import {
getLastUsedRouteId,
getRoutes,
saveLastUsedRouteId,
} from '@/execution-routes'
import { expectRouteToBe, mockRoutes, render } from '@/test-utils'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, it } from 'vitest'
import { action, loader, NoRoutes } from './NoRoutes'

describe('No routes', () => {
Expand All @@ -14,5 +20,41 @@ describe('No routes', () => {

await expectRouteToBe('/test-route')
})

it('redirects to the first route if no route was last used', async () => {
await mockRoutes({ id: 'first-route' }, { id: 'second-route' })

await render('/', [{ path: '/', Component: NoRoutes, loader, action }], {
inspectRoutes: ['/:activeRouteId'],
})

await expectRouteToBe('/first-route')
})
})

describe('No routes available', () => {
it('allows to create a new route', async () => {
await render('/', [{ path: '/', Component: NoRoutes, loader, action }], {
inspectRoutes: ['/routes/edit/:routeId'],
})

await userEvent.click(screen.getByRole('button', { name: 'Add route' }))

const [newRoute] = await getRoutes()

await expectRouteToBe(`/routes/edit/${newRoute.id}`)
})

it('marks the new route as the last used one', async () => {
await render('/', [{ path: '/', Component: NoRoutes, loader, action }], {
inspectRoutes: ['/routes/edit/:routeId'],
})

await userEvent.click(screen.getByRole('button', { name: 'Add route' }))

const [newRoute] = await getRoutes()

await expect(getLastUsedRouteId()).resolves.toEqual(newRoute.id)
})
})
})
2 changes: 1 addition & 1 deletion extension/src/panel/pages/_index/NoRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const NoRoutes = () => {
<Page.Footer>
<Form method="post" className="flex flex-col">
<PrimaryButton submit icon={Plus}>
Add Route
Add route
</PrimaryButton>
</Form>
</Page.Footer>
Expand Down

0 comments on commit 9466fb3

Please sign in to comment.