Repository navigation
fix(clusters): Back leaves the new-cluster page after a saved-draft or Stripe redirect #1851
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
base: claude/1311-guide-region-swap
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||||||||||||||||||||||||
| /** @vitest-environment jsdom */ | ||||||||||||||||||||||||||||
| import { cleanup, render, waitFor } from '@testing-library/react'; | ||||||||||||||||||||||||||||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||||||||||||||||||||||||||||
| import { ProcessSetupIntent } from './ProcessSetupIntent'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const state = vi.hoisted(() => ({ | ||||||||||||||||||||||||||||
| navigate: vi.fn(), | ||||||||||||||||||||||||||||
| saved: null as unknown, | ||||||||||||||||||||||||||||
| setupIntent: {} as { status: string; payment_method: string | null }, | ||||||||||||||||||||||||||||
| stripe: { retrieveSetupIntent: vi.fn() }, | ||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||
| vi.mock('@stripe/react-stripe-js', () => ({ useStripe: () => state.stripe })); | ||||||||||||||||||||||||||||
| vi.mock('@tanstack/react-router', () => ({ | ||||||||||||||||||||||||||||
| useNavigate: () => state.navigate, | ||||||||||||||||||||||||||||
| useParams: () => ({ organizationId: 'org-a' }), | ||||||||||||||||||||||||||||
| useSearch: () => ({}), | ||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||
| vi.mock('@/hooks/useLocalStorage', () => ({ useLocalStorage: () => [state.saved] })); | ||||||||||||||||||||||||||||
| vi.mock('@/integrations/stripe/useProcessStripePaymentMethod', () => { | ||||||||||||||||||||||||||||
| const process = (_paymentMethod: string, onProcessed: () => void) => onProcessed(); | ||||||||||||||||||||||||||||
| return { useProcessStripePaymentMethod: () => process }; | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| afterEach(() => { | ||||||||||||||||||||||||||||
| cleanup(); | ||||||||||||||||||||||||||||
| state.navigate.mockReset(); | ||||||||||||||||||||||||||||
| state.stripe.retrieveSetupIntent.mockReset(); | ||||||||||||||||||||||||||||
| state.saved = null; | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent test pollution and ensure test isolation, reset the JSDOM window history/URL back to the root in the
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| function returnFromStripe(setupIntent: { status: string; payment_method: string | null }) { | ||||||||||||||||||||||||||||
| window.history.pushState(null, '', '/?setup_intent_client_secret=seti_secret#/org-a/billing/confirm'); | ||||||||||||||||||||||||||||
| state.stripe.retrieveSetupIntent.mockResolvedValue({ setupIntent }); | ||||||||||||||||||||||||||||
| render(<ProcessSetupIntent />); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| describe('ProcessSetupIntent', () => { | ||||||||||||||||||||||||||||
| it('replaces itself with the cluster draft, so Back from the form skips this page (#1326)', async () => { | ||||||||||||||||||||||||||||
| state.saved = { clusterName: 'Draft' }; | ||||||||||||||||||||||||||||
| returnFromStripe({ status: 'succeeded', payment_method: 'pm_card' }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| await waitFor(() => expect(state.navigate).toHaveBeenCalled()); | ||||||||||||||||||||||||||||
| expect(state.navigate).toHaveBeenCalledWith({ search: undefined, to: '../../new-cluster', replace: true }); | ||||||||||||||||||||||||||||
| expect(window.location.search).toBe(''); | ||||||||||||||||||||||||||||
| expect(window.location.hash).toBe('#/org-a/billing/confirm'); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| it('replaces itself on the way back to a cluster edit too', async () => { | ||||||||||||||||||||||||||||
| state.saved = { clusterId: 'clu-a' }; | ||||||||||||||||||||||||||||
| returnFromStripe({ status: 'processing', payment_method: null }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| await waitFor(() => expect(state.navigate).toHaveBeenCalled()); | ||||||||||||||||||||||||||||
| expect(state.navigate).toHaveBeenCalledWith({ search: undefined, to: '../../clu-a/edit', replace: true }); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
setupIntentproperty in the hoisted state is defined but never used in any of the tests. It can be safely removed to keep the test setup clean.