-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ui tests for add / update / remove card (#1843)
- Loading branch information
Showing
19 changed files
with
266 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
"retries": { | ||
"runMode": 2, | ||
"openMode": 0 | ||
} | ||
}, | ||
"chromeWebSecurity": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const visaNumber = "4242424242424242" | ||
export const visaCvc = "123" | ||
export const visaExpiry = "12/30" | ||
export const mastercardNumber = "5555555555554444" | ||
export const mastercardCvc = "456" | ||
export const mastercardExpiry = "01/31" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/files-ui/cypress/support/page-objects/modals/addCardModal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const addOrUpdateCardModal = { | ||
body: () => cy.get("[data-testid=modal-container-add-or-update-card]", { timeout: 10000 }), | ||
addCardButton: () => cy.get("[data-testid=button-add-card]", { timeout: 10000 }), | ||
cancelButton: () => cy.get("[data-cy=button-cancel-add-card]"), | ||
cardErrorLabel: () => cy.get("[data-cy=label-add-card-error]"), | ||
cardNumberInput: () => cy.getWithinIframe("[data-elements-stable-field-name=cardNumber]", "#iframe-card-number iframe"), | ||
cvcNumberInput: () => cy.getWithinIframe("[data-elements-stable-field-name=cardCvc]", "#iframe-card-cvc iframe"), | ||
expiryDateInput: () => cy.getWithinIframe("[data-elements-stable-field-name=cardExpiry]", "#iframe-card-expiry iframe"), | ||
addCardHeader: () => cy.get("[data-cy=header-add-card]"), | ||
updateCardHeader: () => cy.get("[data-cy=header-update-card]"), | ||
updateCardButton: () => cy.get("[data-testid=button-update-card]", { timeout: 10000 }), | ||
|
||
awaitStripeElementReady() { | ||
// this waits for all of the posts from stripe to ensure the element is ready event is received | ||
// by waiting for these to complete we can ensure the elements will be ready for interaction | ||
cy.intercept("POST", "**/r.stripe.com/*").as("stripeElementActivation") | ||
cy.wait("@stripeElementActivation") | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/files-ui/cypress/support/page-objects/modals/removeCardModal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const removeCardModal = { | ||
body: () => cy.get("[data-testid=modal-container-remove-card-confirmation]"), | ||
cancelButton: () => cy.get("[data-testid=button-cancel-remove]"), | ||
confirmButton: () => cy.get("[data-testid=button-confirm-remove]", { timeout: 10000 }) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/files-ui/cypress/support/page-objects/toasts/cardAddedToast.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const cardAddedToast = { | ||
body: () => cy.get("[data-testid=toast-card-added]", { timeout: 10000 }), | ||
closeButton: () => cy.get("[data-testid=button-close-toast-card-added]") | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/files-ui/cypress/support/page-objects/toasts/cardUpdatedToast.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const cardUpdatedToast = { | ||
body: () => cy.get("[data-testid=toast-card-updated]", { timeout: 10000 }), | ||
closeButton: () => cy.get("[data-testid=button-close-toast-card-updated]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { navigationMenu } from "../support/page-objects/navigationMenu" | ||
import { settingsPage } from "../support/page-objects/settingsPage" | ||
import { addOrUpdateCardModal } from "../support/page-objects/modals/addCardModal" | ||
import { visaNumber, visaExpiry, visaCvc } from "../fixtures/cardData" | ||
import { mastercardNumber, mastercardExpiry, mastercardCvc } from "../fixtures/cardData" | ||
import { cardAddedToast } from "../support/page-objects/toasts/cardAddedToast" | ||
import { cardUpdatedToast } from "../support/page-objects/toasts/cardUpdatedToast" | ||
import { removeCardModal } from "../support/page-objects/modals/removeCardModal" | ||
|
||
describe("Subscription Plan", () => { | ||
|
||
context("desktop", () => { | ||
|
||
it("can add, update and remove a credit card for billing", () => { | ||
cy.web3Login({ deleteCreditCard: true }) | ||
|
||
// navigate to settings | ||
navigationMenu.settingsNavButton().click() | ||
settingsPage.subscriptionTabButton().click() | ||
|
||
// add a card | ||
settingsPage.addCardButton() | ||
.should("be.visible") | ||
.click() | ||
addOrUpdateCardModal.body().should("be.visible") | ||
addOrUpdateCardModal.addCardHeader().should("be.visible") | ||
addOrUpdateCardModal.awaitStripeElementReady() | ||
addOrUpdateCardModal.cardNumberInput().type(visaNumber) | ||
addOrUpdateCardModal.expiryDateInput().type(visaExpiry) | ||
addOrUpdateCardModal.cvcNumberInput().type(visaCvc) | ||
addOrUpdateCardModal.addCardButton().click() | ||
|
||
// for reliability wait for stripe and default card responses / requests | ||
settingsPage.awaitStripeConfirmation() | ||
settingsPage.awaitDefaultCardRequest() | ||
|
||
// close toast and ensure a card is now shown on profile | ||
cardAddedToast.body().should("be.visible") | ||
cardAddedToast.closeButton().click() | ||
settingsPage.updateCardButton().should("be.visible") | ||
settingsPage.defaultCardLabel().should("be.visible") | ||
|
||
// store the displayed visa details as cypress alias | ||
settingsPage.defaultCardLabel().invoke("text").as("partialMaskedVisa") | ||
|
||
// update the card | ||
settingsPage.updateCardButton().click() | ||
addOrUpdateCardModal.body().should("be.visible") | ||
addOrUpdateCardModal.updateCardHeader().should("be.visible") | ||
addOrUpdateCardModal.awaitStripeElementReady() | ||
addOrUpdateCardModal.cardNumberInput().type(mastercardNumber) | ||
addOrUpdateCardModal.expiryDateInput().type(mastercardExpiry) | ||
addOrUpdateCardModal.cvcNumberInput().type(mastercardCvc) | ||
addOrUpdateCardModal.updateCardButton().click() | ||
|
||
// for reliability wait for stripe and default card responses / requests | ||
settingsPage.awaitStripeConfirmation() | ||
settingsPage.awaitDefaultCardRequest() | ||
|
||
// close toast and ensure a card is shown on profile | ||
cardUpdatedToast.body().should("be.visible") | ||
cardUpdatedToast.closeButton().click() | ||
settingsPage.defaultCardLabel().should("be.visible") | ||
|
||
// store the displayed mastercard details as cypress alias | ||
settingsPage.defaultCardLabel().invoke("text").as("partialMaskedMastercard") | ||
|
||
// ensure the card number was updated by comparing cypress aliases | ||
cy.get("@partialMaskedVisa").then(($partialMaskedVisa) => { | ||
cy.get("@partialMaskedMastercard").should("not.equal", $partialMaskedVisa) | ||
}) | ||
|
||
// remove the card | ||
settingsPage.removeCardLink().click() | ||
removeCardModal.body().should("be.visible") | ||
removeCardModal.confirmButton().safeClick() | ||
settingsPage.noCardLabel().should("be.visible") | ||
settingsPage.addCardButton().should("be.visible") | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.