fix(payment): resume QRIS after closing dialog
Docker Image / Build and Push Docker Image (push) Successful in 2m5s

This commit is contained in:
Codex
2026-07-29 12:26:27 +08:00
parent e071f83474
commit 4cbdd0da7c
5 changed files with 130 additions and 18 deletions
@@ -4,6 +4,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
dispatch: vi.fn(),
handleQrisResume: vi.fn(),
hasHiddenQrisPayment: false,
resetLaunchState: vi.fn(),
payment: {
selectedPlanId: "vip_monthly",
@@ -25,6 +27,8 @@ vi.mock("@/stores/payment/payment-context", () => ({
vi.mock("@/app/_hooks/use-payment-launch-flow", () => ({
usePaymentLaunchFlow: () => ({
handleQrisResume: mocks.handleQrisResume,
hasHiddenQrisPayment: mocks.hasHiddenQrisPayment,
resetLaunchState: mocks.resetLaunchState,
launch: {},
}),
@@ -91,10 +95,14 @@ describe("SubscriptionCheckoutButton renewal confirmation", () => {
.IS_REACT_ACT_ENVIRONMENT = true;
localStorage.clear();
mocks.dispatch.mockClear();
mocks.handleQrisResume.mockClear();
mocks.hasHiddenQrisPayment = false;
mocks.resetLaunchState.mockClear();
mocks.payment.selectedPlanId = "vip_monthly";
mocks.payment.autoRenew = true;
mocks.payment.payChannel = "stripe";
mocks.payment.isCreatingOrder = false;
mocks.payment.isPollingOrder = false;
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
@@ -180,6 +188,30 @@ describe("SubscriptionCheckoutButton renewal confirmation", () => {
type: "PaymentCreateOrderSubmitted",
});
});
it("reopens a hidden QRIS order without creating another order", () => {
mocks.payment.payChannel = "ezpay";
mocks.payment.isPollingOrder = true;
mocks.hasHiddenQrisPayment = true;
act(() =>
root.render(
<SubscriptionCheckoutButton
disabled
subscriptionType="topup"
sourceCharacterSlug="elio"
/>,
),
);
const resumeButton = getButton(container, "Resume QRIS payment");
expect(resumeButton.disabled).toBe(false);
act(() => resumeButton.click());
expect(mocks.handleQrisResume).toHaveBeenCalledOnce();
expect(mocks.resetLaunchState).not.toHaveBeenCalled();
expect(mocks.dispatch).not.toHaveBeenCalled();
});
});
function renderButton(
@@ -200,9 +232,13 @@ function renderButton(
}
function clickButton(root: ParentNode, label: string): void {
getButton(root, label).click();
}
function getButton(root: ParentNode, label: string): HTMLButtonElement {
const button = Array.from(root.querySelectorAll("button")).find(
(item) => item.textContent?.trim() === label,
);
if (!button) throw new Error(`Expected ${label} button`);
button.click();
return button;
}