From d0fb9149a0bf06f311e29a39d94cbd7d3ce7bbb6 Mon Sep 17 00:00:00 2001 From: Hussain Khalil <122488130+hkhalil-akamai@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:38:46 -0500 Subject: [PATCH] test: [M3-8693] - Cypress tests for Credit Card Expired banner (#11383) * Add e2e test for CC expired banner * Added changeset: Add cypress test for Credit Card Expired banner --- .../pr-11383-tests-1733523460107.md | 5 +++ .../credit-card-expired-banner.spec.ts | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 packages/manager/.changeset/pr-11383-tests-1733523460107.md create mode 100644 packages/manager/cypress/e2e/core/billing/credit-card-expired-banner.spec.ts diff --git a/packages/manager/.changeset/pr-11383-tests-1733523460107.md b/packages/manager/.changeset/pr-11383-tests-1733523460107.md new file mode 100644 index 00000000000..21a12a0b923 --- /dev/null +++ b/packages/manager/.changeset/pr-11383-tests-1733523460107.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tests +--- + +Add cypress test for Credit Card Expired banner ([#11383](https://github.com/linode/manager/pull/11383)) diff --git a/packages/manager/cypress/e2e/core/billing/credit-card-expired-banner.spec.ts b/packages/manager/cypress/e2e/core/billing/credit-card-expired-banner.spec.ts new file mode 100644 index 00000000000..148d8c270bd --- /dev/null +++ b/packages/manager/cypress/e2e/core/billing/credit-card-expired-banner.spec.ts @@ -0,0 +1,36 @@ +import { accountFactory } from 'src/factories'; +import { mockGetAccount } from 'support/intercepts/account'; +import { mockGetUserPreferences } from 'support/intercepts/profile'; +import { ui } from 'support/ui'; + +const creditCardExpiredBannerNotice = + 'Your credit card has expired! Please update your payment details.'; + +describe('Credit Card Expired Banner', () => { + beforeEach(() => { + mockGetUserPreferences({ dismissed_notifications: {} }); + }); + + it('appears when the expiration date is in the past', () => { + mockGetAccount( + accountFactory.build({ credit_card: { expiry: '01/2000' } }) + ).as('getAccount'); + cy.visitWithLogin('/'); + cy.wait('@getAccount'); + cy.findByText(creditCardExpiredBannerNotice).should('be.visible'); + ui.button.findByTitle('Update Card').should('be.visible').click(); + + // clicking on the link navigates to /account/billing + cy.url().should('endWith', '/account/billing'); + }); + + it('does not appear when the expiration date is in the future', () => { + mockGetAccount( + accountFactory.build({ credit_card: { expiry: '01/2999' } }) + ).as('getAccount'); + cy.visitWithLogin('/account/billing'); + cy.wait('@getAccount'); + cy.findByText('Payment Methods').should('be.visible'); + cy.findByText(creditCardExpiredBannerNotice).should('not.exist'); + }); +});