From 9466fb3ec9d6dccc29da260506f98ecf29f36600 Mon Sep 17 00:00:00 2001 From: Philipp Giese Date: Fri, 13 Dec 2024 09:56:35 +0100 Subject: [PATCH] add specs for default redirects on new route view --- .../src/panel/pages/_index/NoRoutes.spec.ts | 48 +++++++++++++++++-- extension/src/panel/pages/_index/NoRoutes.tsx | 2 +- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/extension/src/panel/pages/_index/NoRoutes.spec.ts b/extension/src/panel/pages/_index/NoRoutes.spec.ts index f6b5565f4..d25272aa6 100644 --- a/extension/src/panel/pages/_index/NoRoutes.spec.ts +++ b/extension/src/panel/pages/_index/NoRoutes.spec.ts @@ -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', () => { @@ -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) + }) }) }) diff --git a/extension/src/panel/pages/_index/NoRoutes.tsx b/extension/src/panel/pages/_index/NoRoutes.tsx index c00f36a0b..8a3c11c1d 100644 --- a/extension/src/panel/pages/_index/NoRoutes.tsx +++ b/extension/src/panel/pages/_index/NoRoutes.tsx @@ -47,7 +47,7 @@ export const NoRoutes = () => {
- Add Route + Add route