refactor(payment): share checkout dialogs

This commit is contained in:
2026-07-14 18:23:08 +08:00
parent 0033625866
commit 5bec04a970
8 changed files with 187 additions and 148 deletions
@@ -0,0 +1,52 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";
import { PaymentLaunchDialogs } from "../payment-launch-dialogs";
const hiddenLaunch = {
handleEzpayCancel: vi.fn(),
handleEzpayConfirm: vi.fn(),
handleStripeClose: vi.fn(),
handleStripeConfirmed: vi.fn(),
isConfirmingEzpay: false,
shouldShowEzpayConfirmDialog: false,
shouldShowStripeDialog: false,
stripeClientSecret: null,
};
describe("PaymentLaunchDialogs", () => {
it("renders nothing when neither payment dialog is active", () => {
expect(
renderToStaticMarkup(
<PaymentLaunchDialogs
currentOrderId={null}
externalCheckoutAnalyticsKey="payment.external_checkout"
ezpayDescription="Continue to payment."
launch={hiddenLaunch}
/>,
),
).toBe("");
});
it("renders the shared Ezpay confirmation content", () => {
const html = renderToStaticMarkup(
<PaymentLaunchDialogs
currentOrderId="order-123"
externalCheckoutAnalyticsKey="tip.external_checkout"
ezpayDescription="Your coffee order is ready."
launch={{
...hiddenLaunch,
isConfirmingEzpay: true,
shouldShowEzpayConfirmDialog: true,
}}
/>,
);
expect(html).toContain('role="alertdialog"');
expect(html).toContain("Continue to GCash?");
expect(html).toContain("Your coffee order is ready.");
expect(html).toContain("Order No. order-123");
expect(html).toContain('data-analytics-key="tip.external_checkout"');
expect(html).toContain("Opening...");
});
});