-
Notifications
You must be signed in to change notification settings - Fork 16
fix(deposits): stop support-chat clicks from cancelling deposits + confirm-before-cancel + uniform reference #2416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d550911
fix(deposits): confirm before cancelling + uniform shortened reference
abalinda 6347c3b
fix(support): make SupportDrawer intercept clicks when opened inside β¦
abalinda 3e1f71e
fix(deposits): guard confirm CTA against double-tap firing the cancelβ¦
abalinda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
155 changes: 155 additions & 0 deletions
155
src/components/TransactionDetails/provider-actions/__tests__/CancelDepositActions.test.tsx
This file contains hidden or 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,155 @@ | ||
| /** | ||
| * CancelDepositActions β cancel buttons for pending bank-deposit flows. | ||
| * | ||
| * Regression tests for the instant-cancel bug: the cancel button fired | ||
| * cancelOnramp straight from onClick with no confirmation, sitting right next | ||
| * to the support link β a real user cancelled a funded deposit while trying to | ||
| * report a problem, making the wire unmatchable. Every cancel must go through | ||
| * an explicit confirmation first. Nested primitives are stubbed so only this | ||
| * component's own logic is under test. | ||
| */ | ||
| import React from 'react' | ||
| import { render, screen, fireEvent, waitFor } from '@testing-library/react' | ||
|
|
||
| const mockCancelOnramp = jest.fn() | ||
| jest.mock('@/app/actions/onramp', () => ({ | ||
| cancelOnramp: (...args: unknown[]) => mockCancelOnramp(...args), | ||
| })) | ||
| const mockMantecaCancel = jest.fn() | ||
| jest.mock('@/services/manteca', () => ({ | ||
| mantecaApi: { cancelDeposit: (...args: unknown[]) => mockMantecaCancel(...args) }, | ||
| })) | ||
| jest.mock('@/services/charges', () => ({ | ||
| chargesApi: { cancel: jest.fn() }, | ||
| })) | ||
| const mockInvalidateQueries = jest.fn() | ||
| jest.mock('@tanstack/react-query', () => ({ | ||
| useQueryClient: () => ({ invalidateQueries: mockInvalidateQueries }), | ||
| })) | ||
| jest.mock('@sentry/nextjs', () => ({ captureException: jest.fn() })) | ||
| jest.mock('@/components/TransactionDetails/transaction-predicates', () => ({ | ||
| isMantecaOnrampEntry: () => false, | ||
| isRequestEntry: () => false, | ||
| })) | ||
| jest.mock('@/hooks/useTransactionHistory', () => ({ | ||
| EHistoryUserRole: { SENDER: 'SENDER' }, | ||
| })) | ||
| jest.mock('@/components/0_Bruddle/Button', () => ({ | ||
| Button: ({ | ||
| children, | ||
| onClick, | ||
| disabled, | ||
| }: { | ||
| children: React.ReactNode | ||
| onClick?: () => void | ||
| disabled?: boolean | ||
| }) => ( | ||
| <button onClick={onClick} disabled={disabled}> | ||
| {children} | ||
| </button> | ||
| ), | ||
| })) | ||
| jest.mock('@/components/Global/ErrorAlert', () => ({ | ||
| __esModule: true, | ||
| default: ({ description }: { description: string }) => <div data-testid="error">{description}</div>, | ||
| })) | ||
| jest.mock('@/components/Global/Icons/Icon', () => ({ Icon: () => <span /> })) | ||
| jest.mock('@/components/Global/ActionModal', () => ({ | ||
| __esModule: true, | ||
| default: ({ | ||
| visible, | ||
| title, | ||
| ctas, | ||
| onClose, | ||
| }: { | ||
| visible: boolean | ||
| title: React.ReactNode | ||
| ctas?: Array<{ text: string; onClick?: () => void }> | ||
| onClose: () => void | ||
| }) => | ||
| visible ? ( | ||
| <div data-testid="confirm-modal"> | ||
| <p>{title}</p> | ||
| {ctas?.map((cta) => ( | ||
| <button key={cta.text} onClick={cta.onClick}> | ||
| {cta.text} | ||
| </button> | ||
| ))} | ||
| <button onClick={onClose}>Dismiss</button> | ||
| </div> | ||
| ) : null, | ||
| })) | ||
|
|
||
| // import must come after jest.mock | ||
| import { CancelDepositActions } from '../CancelDepositActions' | ||
|
|
||
| const pendingBridgeOnramp = { | ||
| id: 'tx-1', | ||
| direction: 'bank_deposit', | ||
| status: 'pending', | ||
| extraDataForDrawer: { depositInstructions: { deposit_message: 'BRGTESTREF1234567890' } }, | ||
| } as unknown as import('@/components/TransactionDetails/transactionTransformer').TransactionDetails | ||
|
|
||
| const renderCancel = () => | ||
| render( | ||
| <CancelDepositActions | ||
| transaction={pendingBridgeOnramp} | ||
| isPendingBankRequest={false} | ||
| isLoading={false} | ||
| setIsLoading={jest.fn()} | ||
| onClose={jest.fn()} | ||
| /> | ||
| ) | ||
|
|
||
| beforeEach(() => { | ||
| mockCancelOnramp.mockReset().mockResolvedValue({}) | ||
| mockMantecaCancel.mockReset() | ||
| mockInvalidateQueries.mockReset().mockResolvedValue(undefined) | ||
| }) | ||
|
|
||
| describe('CancelDepositActions confirmation gate', () => { | ||
| it('does NOT cancel on the first click β it asks for confirmation instead', () => { | ||
| renderCancel() | ||
|
|
||
| expect(screen.queryByTestId('confirm-modal')).not.toBeInTheDocument() | ||
| fireEvent.click(screen.getByText('Cancel deposit')) | ||
|
|
||
| expect(mockCancelOnramp).not.toHaveBeenCalled() | ||
| expect(screen.getByTestId('confirm-modal')).toBeInTheDocument() | ||
| expect(screen.getByText('Cancel this deposit?')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('cancels only after the user confirms', async () => { | ||
| renderCancel() | ||
|
|
||
| fireEvent.click(screen.getByText('Cancel deposit')) | ||
| fireEvent.click(screen.getByText('Yes, cancel deposit')) | ||
|
|
||
| await waitFor(() => expect(mockCancelOnramp).toHaveBeenCalledWith('tx-1')) | ||
| }) | ||
|
|
||
| it('double-tapping the confirm button fires the cancel exactly once', async () => { | ||
| // keep the cancel in-flight so the second tap lands while the first runs | ||
| let resolveCancel: (v: unknown) => void | ||
| mockCancelOnramp.mockReturnValue(new Promise((resolve) => (resolveCancel = resolve))) | ||
| renderCancel() | ||
|
|
||
| fireEvent.click(screen.getByText('Cancel deposit')) | ||
| const confirmButton = screen.getByText('Yes, cancel deposit') | ||
| fireEvent.click(confirmButton) | ||
| fireEvent.click(confirmButton) | ||
|
|
||
| resolveCancel!({}) | ||
| await waitFor(() => expect(mockCancelOnramp).toHaveBeenCalledTimes(1)) | ||
| }) | ||
|
|
||
| it('dismissing the confirmation leaves the deposit untouched', () => { | ||
| renderCancel() | ||
|
|
||
| fireEvent.click(screen.getByText('Cancel deposit')) | ||
| fireEvent.click(screen.getByText('Dismiss')) | ||
|
|
||
| expect(mockCancelOnramp).not.toHaveBeenCalled() | ||
| expect(screen.queryByTestId('confirm-modal')).not.toBeInTheDocument() | ||
| }) | ||
| }) |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.