-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RED] add test for payment success page
- Loading branch information
1 parent
73d9979
commit b1333ae
Showing
4 changed files
with
104 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { render, waitFor } from '@testing-library/react' | ||
import '@testing-library/jest-dom' | ||
import PaymentSuccessPage from '@/app/payment/success/page' | ||
import { useLazyGetTransactionQuery } from '@/redux/api/paymentApi' | ||
|
||
jest.mock('next/link', () => { | ||
const MockedLink = ({ children, href }: any) => <a href={href}>{children}</a> | ||
|
||
MockedLink.displayName = 'MockedNextLink' | ||
|
||
return MockedLink | ||
}) | ||
|
||
jest.mock('next/navigation', () => ({ | ||
useSearchParams: jest.fn(() => ({ | ||
get: jest.fn(() => 'test_order_id'), | ||
})), | ||
})) | ||
|
||
jest.mock('@/redux/api/paymentApi', () => ({ | ||
useLazyGetTransactionQuery: jest.fn(), | ||
})) | ||
describe('PaymentSuccess Component', () => { | ||
it('renders the success message when data is loaded', async () => { | ||
;(useLazyGetTransactionQuery as jest.Mock).mockReturnValue([ | ||
jest.fn(), | ||
{ | ||
data: { | ||
transaction_detail: { | ||
id: 'transaction_id', | ||
package: { | ||
id: 2, | ||
name: 'Premium', | ||
}, | ||
midtrans_url: null, | ||
midtrans_transaction_id: 'midtrans_id', | ||
order_id: 'order_id', | ||
price: 10000, | ||
checkout_time: '2024-05-06T14:49:19Z', | ||
expiry_time: '2024-05-06T15:04:19Z', | ||
payment_type: 'qris', | ||
payment_merchant: 'gopay', | ||
status: 'settlement', | ||
}, | ||
}, | ||
isLoading: false, | ||
}, | ||
]) | ||
|
||
const { getByText, getByRole } = render(<PaymentSuccessPage />) | ||
|
||
await waitFor(() => { | ||
expect(getByText('Payment Success')).toBeInTheDocument() | ||
expect(getByText('Premium')).toBeInTheDocument() | ||
const button = getByRole('button', { name: 'Go to transactions' }) | ||
expect(button.closest('a')).toHaveAttribute( | ||
'href', | ||
'/payment/transactions/' | ||
) | ||
}) | ||
}) | ||
|
||
it('shows loader when data is still loading', () => { | ||
;(useLazyGetTransactionQuery as jest.Mock).mockReturnValue([ | ||
jest.fn(), | ||
{ | ||
data: null, | ||
isLoading: true, | ||
}, | ||
]) | ||
|
||
const { getByTestId } = render(<PaymentSuccessPage />) | ||
|
||
expect(getByTestId('loader')).toBeInTheDocument() | ||
}) | ||
}) |
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,3 @@ | ||
export default function PaymentSuccessPage() { | ||
return <div></div> | ||
} |