Skip to content

test(cypress): add card installments E2E tests#1432

Open
akash-c-k wants to merge 1 commit intomainfrom
feat/cypress-card-installments
Open

test(cypress): add card installments E2E tests#1432
akash-c-k wants to merge 1 commit intomainfrom
feat/cypress-card-installments

Conversation

@akash-c-k
Copy link
Copy Markdown
Collaborator

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Adds E2E test coverage for the card installments feature shipped in PR #1412. Uses cy.intercept to inject installment plan responses, making tests connector-agnostic and runnable without installment-capable connector configuration.

Key Changes

Existing PR (UI + Billing)

  • payment-method-selection-ui-e2e-test.cy.ts

    • 15 tests across 3 describe blocks:
      • Rendering
      • Multi-method switching
      • Mobile viewports
  • billing-address-validation-e2e-test.cy.ts

    • Covers:
      • Billing address field presence
      • Country-specific field adaptation
      • Validation error states

New PR (Installments)

  • card-installments-e2e-test.cy.ts
    • 6 tests covering:
      • Installment plan rendering
      • Plan selection
      • Payment submission with installments

Regression Covered


Test Scenarios

Payment Method Selection UI — Rendering

  • Checkout title renders correctly
  • Payment element iframe loads
  • No uncaught JS exceptions crash the iframe
  • Card number, expiry, CVV inputs visible inside iframe
  • Submit/Pay button visible

Payment Method Selection UI — Multi-Method State

  • addNewCard tab renders to access full payment method list
  • Payment method list shown when addNewCard is clicked
  • Card form shown by default or after selecting card
  • iDEAL selection hides card number input

Payment Method Selection UI — Loading & Mobile Viewport

  • Loader/shimmer visible while payment_methods is loading (3s delayed intercept)

iPhone X (375×812)

  • No horizontal overflow
  • Card input accessible

iPhone 14 (390×844)

  • Submit button fully visible

Billing Address Validation

  • Billing address fields present when required
  • Country-specific fields adapt correctly
  • Validation errors shown for invalid input

Card Installments

  • Payment element renders correctly with installments-enabled profile
  • Installment plan options are visible when available
  • Selecting an installment plan updates the UI state
  • Submit button enabled after selecting a plan
  • Payment submission proceeds with selected installment plan
  • Graceful skip via cy.log when installment plans are not returned

How did you test it?

Run headlessly: cypress run --spec "cypress/e2e/card-installments-e2e-test.cy.ts". Installment plan injection via cy.intercept ensures tests are not blocked by connector availability.

Checklist

  • I ran npm run re:build
  • I reviewed submitted code
  • I added unit tests for my changes where possible

Adds E2E test coverage for the card installments feature shipped in
PR #1412. Uses cy.intercept to inject installment plan responses,
making tests connector-agnostic and runnable without installment-capable
connector configuration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@semanticdiff-com
Copy link
Copy Markdown

semanticdiff-com bot commented Mar 23, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  cypress-tests/cypress/e2e/card-installments-e2e-test.cy.ts  0% smaller

@aritro2002
Copy link
Copy Markdown
Contributor

🔍 Code Review by opencode

Status: ⚠️ Changes Requested


🚨 Critical Issue: Missing data-testid Attributes

The tests reference data-testid attributes that don't exist in the UI components:

Test Selector Component Status
[data-testid=installment-options] InstallmentOptions.res ❌ Missing
[data-testid=installment-option] InstallmentOptionItem.res ❌ Missing

Test file references (lines 94, 147, 181, 226, 261):

$body.find("[data-testid=installment-options]")
$body.find("[data-testid=installment-option]")

Fix required - Add data-testid props:

InstallmentOptions.res:71-79:

<div
  data-testid="installment-options"
  className={`flex flex-col border !py-0 ${needsScroll ? "max-h-64 overflow-y-auto" : ""}`}>

InstallmentOptionItem.res:31-37:

<div
  data-testid="installment-option"
  onClick={_ => onSelect()}
  className={`flex gap-3 w-full ${isLastItem ? "" : "border-b"} !px-0 cursor-pointer text-left`}>

⚠️ Other Issues

1. Test Reliability (Lines 76, 150)

cy.wait(2000);  // Arbitrary delays

Suggestion: Use explicit waits on network intercepts instead:

cy.wait("@paymentMethods");

2. Expiry Input Typing (Lines 80-85, 154-159)

.type(card_exp_month);
.type(card_exp_year);  // Should be concatenated

Issue: Typing month then year separately may not work correctly. Should be:

.type(`${card_exp_month}${card_exp_year}`);

3. Missing Test for Selection State
The test checks for .selected class or aria-selected, but verify these are actually set by the component.


✅ What's Good

Aspect Status
Proper use of cy.intercept
Good test coverage (6 scenarios)
Handles missing installments gracefully
Tests both with and without installments
Clean separation of concerns

Verification Steps

# 1. Add data-testid attributes to components
# 2. Run tests
npm run re:build
cd cypress-tests && npx cypress run --spec "cypress/e2e/card-installments-e2e-test.cy.ts"

Next Steps

  1. Add data-testid attributes to InstallmentOptions.res and InstallmentOptionItem.res
  2. Verify test selectors match actual rendered HTML
  3. Fix expiry input concatenation
  4. Re-run tests to confirm they pass

Once data-testid attributes are added, this PR is ready.


Reviewed by opencode AI using hyperswitch-web skill guidelines

Copy link
Copy Markdown
Contributor

@aritro2002 aritro2002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: Card Installments E2E Tests

Critical Issues

1. Missing TestIDs in Components

The test looks for [data-testid=installment-options] and [data-testid=installment-option], but these don't exist in InstallmentOptions.res and InstallmentOptionItem.res. The components have no data-testid attributes.

Fix Required: Add testIds to the components:

// InstallmentOptions.res
<div data-testid="installment-options" className="w-full flex flex-col">

// InstallmentOptionItem.res  
<div data-testid="installment-option" onClick={_ => onSelect()} ...>

2. Wrong Mock Data Structure

The intercept modifies payment_methods array items with installment_details, but based on PaymentMethodsRecord.res, the installment_options lives in intent_data, not on payment method items:

type intentData = {
  installment_options: option<array<installmentOption>>,
  currency: string,
}

Fix Required: Update the intercept to modify the correct location:

cy.intercept("GET", "**/account/payment_methods*", (req) => {
  req.continue((res) => {
    if (res.body) {
      res.body.intent_data = res.body.intent_data || {};
      res.body.intent_data.installment_options = [
        {
          payment_method: "card",
          available_plans: [
            { interest_rate: 0.0, number_of_installments: 3, billing_frequency: "monthly", amount_details: { amount_per_installment: 1000, total_amount: 3000 } },
            { interest_rate: 5.0, number_of_installments: 6, billing_frequency: "monthly", amount_details: { amount_per_installment: 525, total_amount: 3150 } },
          ]
        }
      ];
    }
  });
}).as("paymentMethods");

Code Quality Issues

3. Brittle cy.wait() Calls

Multiple hardcoded waits (cy.wait(2000), cy.wait(1000), cy.wait(3000)). Should use alias-based waiting:

cy.wait('@paymentMethods');

4. Conditional Test Logic

Tests like should allow selecting an installment plan use if/else with cy.log() fallback, which can mask failures. Consider asserting directly:

cy.wrap($body).find("[data-testid=installment-option]").should('exist').first().click();

Checklist

  • Add data-testid attributes to installment components
  • Fix mock data structure to target intent_data.installment_options
  • Replace hardcoded cy.wait() with alias-based waiting
  • Complete the PR checklist items
  • Run tests locally to verify

Verdict: Changes Requested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Cypress test coverage enhancement for Card Installments

2 participants