-
Notifications
You must be signed in to change notification settings - Fork 24
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
3210ed6
commit 9a5f94d
Showing
4 changed files
with
242 additions
and
24 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
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
79 changes: 79 additions & 0 deletions
79
src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/UpgradeFormModal.test.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,79 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
import UpgradeFormModal from './UpgradeFormModal' | ||
|
||
describe('UpgradeFormModal', () => { | ||
const mockOnClose = vi.fn() | ||
const mockOnConfirm = vi.fn() | ||
const mockUrl = 'https://verify.stripe.com' | ||
|
||
const setup = (isUpgrading = false) => { | ||
return render( | ||
<UpgradeFormModal | ||
isOpen={true} | ||
onClose={mockOnClose} | ||
onConfirm={mockOnConfirm} | ||
url={mockUrl} | ||
isUpgrading={isUpgrading} | ||
/> | ||
) | ||
} | ||
|
||
beforeEach(() => { | ||
vi.resetAllMocks() | ||
}) | ||
|
||
it('renders modal with correct content', () => { | ||
setup() | ||
|
||
expect(screen.getByText('Incomplete Plan Upgrade')).toBeInTheDocument() | ||
expect( | ||
screen.getByText( | ||
/You have a pending plan upgrade awaiting payment verification/ | ||
) | ||
).toBeInTheDocument() | ||
expect(screen.getByText('here')).toHaveAttribute('href', mockUrl) | ||
expect( | ||
screen.getByText( | ||
/Are you sure you want to abandon this upgrade and start a new one/ | ||
) | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it('calls onClose when cancel button is clicked', async () => { | ||
setup() | ||
const utils = userEvent.setup() | ||
|
||
const cancelButton = screen.getByRole('button', { name: 'Cancel' }) | ||
await utils.click(cancelButton) | ||
|
||
expect(mockOnClose).toHaveBeenCalled() | ||
}) | ||
|
||
it('calls onConfirm when confirm button is clicked', async () => { | ||
setup() | ||
const utils = userEvent.setup() | ||
|
||
const confirmButton = screen.getByRole('button', { | ||
name: 'Yes, Start New Upgrade', | ||
}) | ||
await utils.click(confirmButton) | ||
|
||
expect(mockOnConfirm).toHaveBeenCalled() | ||
}) | ||
|
||
describe('when isUpgrading is true', () => { | ||
it('disables buttons and shows processing text', () => { | ||
setup(true) | ||
|
||
const cancelButton = screen.getByRole('button', { name: 'Cancel' }) | ||
const confirmButton = screen.getByRole('button', { | ||
name: 'Processing...', | ||
}) | ||
|
||
expect(cancelButton).toBeDisabled() | ||
expect(confirmButton).toBeDisabled() | ||
}) | ||
}) | ||
}) |