-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: clear transactions on special route (#392)
* list routes redirects to clear-transactions route instead of doing the work * add failing test * redirect from edit route to new clear transactions route * implement clear transactions route
- Loading branch information
1 parent
500e50a
commit 93bfb6f
Showing
15 changed files
with
200 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...panel/pages/$activeRouteId/clear-transactions.$newActiveRouteId/ClearTransactions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { expectRouteToBe, render } from '@/test-utils' | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
import { action, ClearTransactions } from './ClearTransactions' | ||
|
||
const { mockClearTransactions } = vi.hoisted(() => ({ | ||
mockClearTransactions: vi.fn(), | ||
})) | ||
|
||
vi.mock('./useClearTransactions', () => ({ | ||
useClearTransactions: () => mockClearTransactions, | ||
})) | ||
|
||
describe('Clear transactions', () => { | ||
beforeEach(() => { | ||
mockClearTransactions.mockResolvedValue(undefined) | ||
}) | ||
|
||
it('clears all transactions', async () => { | ||
await render('/test-route/clear-transactions/new-route', [ | ||
{ | ||
path: '/:activeRouteId/clear-transactions/:newActiveRouteId', | ||
Component: ClearTransactions, | ||
action, | ||
}, | ||
]) | ||
|
||
expect(mockClearTransactions).toHaveBeenCalled() | ||
}) | ||
|
||
it('redirects to the new active route', async () => { | ||
await render( | ||
'/test-route/clear-transactions/new-route', | ||
[ | ||
{ | ||
path: '/:activeRouteId/clear-transactions/:newActiveRouteId', | ||
Component: ClearTransactions, | ||
action, | ||
}, | ||
], | ||
{ inspectRoutes: ['/:activeRouteId'] }, | ||
) | ||
|
||
await expectRouteToBe('/new-route') | ||
}) | ||
}) |
20 changes: 20 additions & 0 deletions
20
...src/panel/pages/$activeRouteId/clear-transactions.$newActiveRouteId/ClearTransactions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useEffect } from 'react' | ||
import { redirect, useSubmit, type ActionFunctionArgs } from 'react-router' | ||
import { useClearTransactions } from './useClearTransactions' | ||
|
||
export const action = async ({ params }: ActionFunctionArgs) => { | ||
const { newActiveRouteId } = params | ||
|
||
return redirect(`/${newActiveRouteId}`) | ||
} | ||
|
||
export const ClearTransactions = () => { | ||
const clearTransactions = useClearTransactions() | ||
const submit = useSubmit() | ||
|
||
useEffect(() => { | ||
clearTransactions().then(() => submit(null, { method: 'post' })) | ||
}, [clearTransactions, submit]) | ||
|
||
return null | ||
} |
7 changes: 7 additions & 0 deletions
7
extension/src/panel/pages/$activeRouteId/clear-transactions.$newActiveRouteId/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { action, ClearTransactions as Component } from './ClearTransactions' | ||
|
||
export const ClearTransactions = { | ||
path: 'clear-transactions/:newActiveRouteId', | ||
element: <Component />, | ||
action, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import { redirect, type RouteObject } from 'react-router' | ||
import { ActiveRoute as Component, loader } from './ActiveRoute' | ||
import { ClearTransactions } from './clear-transactions.$newActiveRouteId' | ||
import { Transactions } from './transactions' | ||
|
||
export const ActiveRoute: RouteObject = { | ||
path: '/:activeRouteId', | ||
element: <Component />, | ||
loader, | ||
children: [ | ||
{ path: '', loader: () => redirect('transactions') }, | ||
{ index: true, loader: () => redirect('transactions') }, | ||
Transactions, | ||
ClearTransactions, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum Intent { | ||
saveRoute = 'saveRoute', | ||
removeRoute = 'removeRoute', | ||
clearTransactions = 'clearTransactions', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum Intent { | ||
addRoute = 'addRoute', | ||
launchRoute = 'launchRoute', | ||
clearTransactions = 'clearTransactions', | ||
} |