-
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.
- Loading branch information
1 parent
29dba9b
commit 49fcfb7
Showing
5 changed files
with
64 additions
and
11 deletions.
There are no files selected for viewing
42 changes: 39 additions & 3 deletions
42
...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 |
---|---|---|
@@ -1,9 +1,45 @@ | ||
import { describe, it, vi } from 'vitest' | ||
import { expectRouteToBe, render } from '@/test-utils' | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
import { action, ClearTransactions } from './ClearTransactions' | ||
|
||
vi.mock('') | ||
const { mockClearTransactions } = vi.hoisted(() => ({ | ||
mockClearTransactions: vi.fn(), | ||
})) | ||
|
||
vi.mock('./useClearTransactions', () => ({ | ||
useClearTransactions: () => mockClearTransactions, | ||
})) | ||
|
||
describe('Clear transactions', () => { | ||
beforeEach(() => { | ||
mockClearTransactions.mockResolvedValue(undefined) | ||
}) | ||
|
||
it('clears all transactions', async () => { | ||
throw new Error('Fail') | ||
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') | ||
}) | ||
}) |
21 changes: 20 additions & 1 deletion
21
...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 |
---|---|---|
@@ -1 +1,20 @@ | ||
export const ClearTransactions = () => null | ||
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 | ||
} |
3 changes: 2 additions & 1 deletion
3
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { ClearTransactions as Component } from './ClearTransactions' | ||
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