|
| 1 | +// @vitest-environment jsdom |
| 2 | +// |
| 3 | +// Automated accessibility checks for the QR/payment flow (#766). These |
| 4 | +// components render the pay-to-receipt path exercised by |
| 5 | +// e2e/tests/pay-to-receipt.spec.ts, so an axe violation here means a real |
| 6 | +// user relying on a screen reader or keyboard could get stuck paying or |
| 7 | +// receiving a payment. |
| 8 | +import { describe, expect, it } from "vitest"; |
| 9 | +import { render } from "@testing-library/react"; |
| 10 | +import { axe, toHaveNoViolations } from "jest-axe"; |
| 11 | +import { QRPreview } from "@/components/QRPreview"; |
| 12 | +import { SigningSummary } from "@/components/SigningSummary"; |
| 13 | +import { ActivePaymentState } from "@/components/payment-states/ActivePaymentState"; |
| 14 | +import { PaidPaymentState } from "@/components/payment-states/PaidPaymentState"; |
| 15 | +import { ExpiredPaymentState } from "@/components/payment-states/ExpiredPaymentState"; |
| 16 | +import { RefundedPaymentState } from "@/components/payment-states/RefundedPaymentState"; |
| 17 | + |
| 18 | +expect.extend(toHaveNoViolations); |
| 19 | + |
| 20 | +const activeStatus = { |
| 21 | + username: "alice", |
| 22 | + amount: "100", |
| 23 | + asset: "USDC", |
| 24 | + memo: null, |
| 25 | + destinationPublicKey: "GABC1234567890", |
| 26 | + expiresAt: null, |
| 27 | + swapOptions: null, |
| 28 | + acceptsMultipleAssets: false, |
| 29 | + acceptedAssets: null, |
| 30 | + userMessage: "Complete this payment to alice.", |
| 31 | + availableActions: ["pay"], |
| 32 | +}; |
| 33 | + |
| 34 | +const paidStatus = { |
| 35 | + username: "alice", |
| 36 | + amount: "100", |
| 37 | + asset: "USDC", |
| 38 | + memo: null, |
| 39 | + transactionHash: "abc123", |
| 40 | + paidAt: new Date().toISOString(), |
| 41 | + userMessage: "Payment received.", |
| 42 | +}; |
| 43 | + |
| 44 | +const expiredStatus = { |
| 45 | + username: "alice", |
| 46 | + amount: "100", |
| 47 | + asset: "USDC", |
| 48 | + memo: null, |
| 49 | + expiresAt: new Date().toISOString(), |
| 50 | + userMessage: "This link has expired.", |
| 51 | +}; |
| 52 | + |
| 53 | +describe("QR/payment flow accessibility", () => { |
| 54 | + it("QRPreview with a value has no axe violations", async () => { |
| 55 | + const { container } = render(<QRPreview value="stellar:GABC?amount=100" />); |
| 56 | + expect(await axe(container)).toHaveNoViolations(); |
| 57 | + }); |
| 58 | + |
| 59 | + it("QRPreview placeholder (no value) has no axe violations", async () => { |
| 60 | + const { container } = render(<QRPreview />); |
| 61 | + expect(await axe(container)).toHaveNoViolations(); |
| 62 | + }); |
| 63 | + |
| 64 | + it("SigningSummary has no axe violations", async () => { |
| 65 | + const { container } = render( |
| 66 | + <SigningSummary |
| 67 | + action="purchase" |
| 68 | + amount={{ value: 100, asset: "USDC" }} |
| 69 | + details={[{ label: "Recipient", value: "alice" }]} |
| 70 | + expiry={new Date(Date.now() + 60_000)} |
| 71 | + fee={{ value: 1, asset: "USDC", percentage: 1 }} |
| 72 | + />, |
| 73 | + ); |
| 74 | + expect(await axe(container)).toHaveNoViolations(); |
| 75 | + }); |
| 76 | + |
| 77 | + it("ActivePaymentState has no axe violations", async () => { |
| 78 | + const { container } = render( |
| 79 | + <ActivePaymentState |
| 80 | + status={activeStatus} |
| 81 | + onPaymentInitiated={() => {}} |
| 82 | + onPaymentCompleted={() => {}} |
| 83 | + />, |
| 84 | + ); |
| 85 | + expect(await axe(container)).toHaveNoViolations(); |
| 86 | + }); |
| 87 | + |
| 88 | + it("PaidPaymentState has no axe violations", async () => { |
| 89 | + const { container } = render(<PaidPaymentState status={paidStatus} />); |
| 90 | + expect(await axe(container)).toHaveNoViolations(); |
| 91 | + }); |
| 92 | + |
| 93 | + it("ExpiredPaymentState has no axe violations", async () => { |
| 94 | + const { container } = render(<ExpiredPaymentState status={expiredStatus} />); |
| 95 | + expect(await axe(container)).toHaveNoViolations(); |
| 96 | + }); |
| 97 | + |
| 98 | + it("RefundedPaymentState has no axe violations", async () => { |
| 99 | + const { container } = render(<RefundedPaymentState status={paidStatus} />); |
| 100 | + expect(await axe(container)).toHaveNoViolations(); |
| 101 | + }); |
| 102 | +}); |
0 commit comments