Skip to content

Commit

Permalink
fix: ensure active route when deleting the currently active one (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
frontendphil authored Dec 16, 2024
1 parent 5b75a0a commit 93adc0d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getRoute, getRoutes } from '@/execution-routes'
import { getLastUsedRouteId, getRoute, getRoutes } from '@/execution-routes'
import { useInjectedWallet } from '@/providers'
import {
expectRouteToBe,
Expand Down Expand Up @@ -340,6 +340,35 @@ describe('Edit Zodiac route', () => {

await expectRouteToBe('/')
})

it('sets another route as active, when the the deleted route is currently active', async () => {
await mockRoutes({ id: 'first-route' }, { id: 'second-route' })

await render(
'/routes/edit/first-route',
[
{
path: '/routes/edit/:routeId',
Component: EditRoute,
loader,
action,
},
],
{ inspectRoutes: ['/routes'] },
)

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

const { getByRole } = within(
screen.getByRole('dialog', { name: 'Remove route' }),
)

await userEvent.click(getByRole('button', { name: 'Remove' }))

await expect(getLastUsedRouteId()).resolves.toEqual('second-route')
})
})

describe('Switch chain', () => {
Expand Down
4 changes: 4 additions & 0 deletions extension/src/panel/pages/routes/edit.$routeId/EditRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export const action = async ({ params, request }: ActionFunctionArgs) => {
return redirect('/')
}

const [newActiveRoute] = routes

await saveLastUsedRouteId(newActiveRoute.id)

return redirect('/routes')
}

Expand Down

0 comments on commit 93adc0d

Please sign in to comment.