Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ui tests for notifications #2019

Merged
merged 15 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/files-ui/cypress/fixtures/cardData.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import dayjs from "dayjs"

export const visaNumber = "4242424242424242"
export const visaCvc = "123"
export const visaExpiry = "12/30"
Expand All @@ -6,4 +8,5 @@ export const mastercardCvc = "456"
export const mastercardExpiry = "01/31"
export const invalidCardNumber = "6242424242424255"
export const invalidCvc = "11"
export const invalidExpiry = "02/21"
export const invalidExpiry = "02/21"
export const currentDateExpiry = dayjs().format("MM/YY")
8 changes: 6 additions & 2 deletions packages/files-ui/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface Web3LoginOptions {
clearCSFBucket?: boolean
clearTrashBucket?: boolean
deleteShareBucket?: boolean
withNewSession?: boolean
withNewUser?: boolean
deleteCreditCard? : boolean
resetToFreePlan?: boolean
Expand All @@ -60,6 +61,7 @@ Cypress.Commands.add(
clearTrashBucket = false,
deleteShareBucket = false,
withNewUser = true,
withNewSession = false,
deleteCreditCard = false,
resetToFreePlan = false
}: Web3LoginOptions = {}) => {
Expand All @@ -78,8 +80,9 @@ Cypress.Commands.add(
})
})

if (withNewUser){
cy.session("web3loginNewUser", () => {
if (withNewUser || withNewSession){
const sessionName = `web3loginNewUser-${withNewSession ? new Date().toString() : "0"}`
cy.session(sessionName, () => {
cy.visit(url)
authenticationPage.web3Button().click()
authenticationPage.showMoreButton().click()
Expand Down Expand Up @@ -213,6 +216,7 @@ declare global {
* @param {Boolean} options.clearTrashBucket - (default: false) - whether any file in the trash bucket should be deleted.
* @param {Boolean} options.deleteShareBucket - (default: false) - whether any shared bucket should be deleted.
* @param {Boolean} options.withNewUser - (default: true) - whether to create a new user for this session.
* @param {Boolean} options.withNewSession - (default: false) - whether to create a new session.
* @param {Boolean} options.deleteCreditCard - (default: false) - whether to delete the default credit card associate to the account.
* @param {Boolean} options.resetToFreePlan - (default false) - whether to cancel any plan to make sure the user is on the free one.
* @example cy.web3Login({saveBrowser: true, url: 'http://localhost:8080'})
Expand Down
8 changes: 8 additions & 0 deletions packages/files-ui/cypress/support/page-objects/basePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ export const basePage = {
searchInput: () => cy.get("[data-testid=input-search-bar]"),
signOutDropdown: () => cy.get("[data-testid=dropdown-title-sign-out-dropdown]"),
signOutMenuOption: () => cy.get("[data-cy=menu-sign-out]"),
notificationButton: () => cy.get("[data-testid=dropdown-title-notifications]"),
notificationsHeader: () => cy.get("[data-cy=label-notifications-header]"),
notificationsThisWeekHeader: () => cy.get("[data-cy=label-notifications-this-week]"),
notificationsOlderHeader: () => cy.get("[data-cy=label-notifications-older]"),
notificationContainer: () => cy.get("[data-cy=container-notification]"),
notificationTitle: () => cy.get("[data-cy=label-notification-title]"),
notificationTime: () => cy.get("[data-cy=label-notification-time]"),

// Mobile view only element
hamburgerMenuButton: () => cy.get("[data-testid=icon-hamburger-menu]"),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { basePage } from "./basePage"
import { visaNumber, visaExpiry, visaCvc } from "../../fixtures/cardData"
import { visaNumber, visaExpiry, visaCvc, currentDateExpiry } from "../../fixtures/cardData"
import { cardAddedToast } from "../../support/page-objects/toasts/cardAddedToast"
import { selectPlanModal } from "../../support/page-objects/modals/billing/selectPlanModal"
import { planDetailsModal } from "../../support/page-objects/modals/billing/planDetailsModal"
Expand Down Expand Up @@ -40,8 +40,9 @@ export const settingsPage = {
payNowButton: () => cy.get("[data-testid=button-pay-invoice]"),

// use this convenience function when an upgraded account is required as a test requisite
upgradeSubscription(plan: "pro" | "max") {
const planContainer = plan === "pro" ? "@filesProBox" : "@filesMaxBox"
upgradeSubscription(subDetails: {plan: "pro"|"max"; isCardExpiring?: boolean}) {
const planContainer = subDetails.plan === "pro" ? "@filesProBox" : "@filesMaxBox"
const cardExpiry = subDetails.isCardExpiring === true ? currentDateExpiry : visaExpiry

this.subscriptionTabButton().click()
this.changePlanButton().click()
Expand All @@ -57,7 +58,7 @@ export const settingsPage = {
.click()
cy.awaitStripeElementReady()
selectPaymentMethodModal.cardNumberInput().type(visaNumber)
selectPaymentMethodModal.expiryDateInput().type(visaExpiry)
selectPaymentMethodModal.expiryDateInput().type(cardExpiry)
selectPaymentMethodModal.cvcNumberInput().type(visaCvc)
selectPaymentMethodModal.useThisCardButton().click()
cy.awaitStripeConfirmation()
Expand Down
7 changes: 4 additions & 3 deletions packages/files-ui/cypress/support/utils/apiTestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export const apiTestHelper = {
}

resolve()
} catch (e){
cy.log("Something wrong happened during the subscription cancelation")
console.log(e)
} catch (e: any){
console.error(e)
reject(e)
throw new Error("Something wrong happened during the subscription cancelation")
}
})
})
Expand Down Expand Up @@ -132,6 +132,7 @@ export const apiTestHelper = {
} catch(e){
console.error(e)
reject(e)
throw new Error("Something wrong happened when creating a folder")
}

navigationMenu.binNavButton().click()
Expand Down
88 changes: 88 additions & 0 deletions packages/files-ui/cypress/tests/notifications-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { homePage } from "../support/page-objects/homePage"
import { navigationMenu } from "../support/page-objects/navigationMenu"
import { settingsPage } from "../support/page-objects/settingsPage"
import { selectPlanModal } from "../support/page-objects/modals/billing/selectPlanModal"
import { planDetailsModal } from "../support/page-objects/modals/billing/planDetailsModal"
import { selectPaymentMethodModal } from "../support/page-objects/modals/billing/selectPaymentMethodModal"
import { planChangeConfirmationModal } from "../support/page-objects/modals/billing/planChangeConfirmationModal"
import { cryptoPaymentModal } from "../support/page-objects/modals/billing/cryptoPaymentModal"

describe("Notifications", () => {
beforeEach(() => {
cy.intercept("GET", "**/billing/eligibilities", {
body: { is_eligible: true }
})
})
context("desktop", () => {

it("can see and interact with a notification when a card is expiring soon", () => {
cy.web3Login({ deleteCreditCard: true, resetToFreePlan: true })

// upgrade subscription with a card expiring this month
navigationMenu.settingsNavButton().click()
settingsPage.upgradeSubscription({ plan: "max", isCardExpiring: true })

// access and inspect notification menu
settingsPage.notificationButton().click()
settingsPage.notificationsHeader().should("be.visible")
settingsPage.notificationsThisWeekHeader().should("be.visible")
settingsPage.notificationsOlderHeader().should("not.exist")
settingsPage.notificationContainer().should("have.length", 1)

// ensure individual notification has title and date
settingsPage.notificationContainer().within(() => {
settingsPage.notificationTitle().should("be.visible")
settingsPage.notificationTime().should("be.visible")
})

// click notification button to dismiss
settingsPage.notificationButton().click()
settingsPage.notificationContainer().should("not.be.visible")

// navigate away and return to plan page from notification
navigationMenu.homeNavButton().click()
cy.url().should("include", "/drive")
homePage.notificationButton().click()
homePage.notificationContainer().click()
cy.url().should("include", "/settings/plan")
})

it("can see and interact with a notification when crypto invoice is open", () => {
cy.web3Login({ withNewSession: true })
navigationMenu.settingsNavButton().click()

// initiate crypto payment then exit upgrade flow
settingsPage.subscriptionTabButton().click()
settingsPage.changePlanButton().click()
selectPlanModal.createPlanCypressAliases()
cy.get("@filesProBox").parent().within(() => {
selectPlanModal.selectPlanButton().click()
})
planDetailsModal.durationToggleSwitch().click()
planDetailsModal.selectThisPlanButton().click()
selectPaymentMethodModal.cryptoRadioInput()
.should("be.visible")
.click()
selectPaymentMethodModal.selectPaymentButton().click()
planChangeConfirmationModal.confirmPlanChangeButton().click()
cryptoPaymentModal.closeButton().click()

// access and inspect notification menu
settingsPage.notificationButton().click()
settingsPage.notificationContainer().should("have.length", 1)

// ensure individual notification has title and date
settingsPage.notificationContainer().within(() => {
settingsPage.notificationTitle().should("be.visible")
settingsPage.notificationTime().should("be.visible")
})

// navigate away and return to the plan page from notification
navigationMenu.homeNavButton().click()
cy.url().should("include", "/drive")
homePage.notificationButton().click()
homePage.notificationContainer().click()
cy.url().should("include", "/settings/plan")
})
})
})
8 changes: 4 additions & 4 deletions packages/files-ui/cypress/tests/subscription-plan-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe("Subscription Plan", () => {

// upgrade to a Max plan first
navigationMenu.settingsNavButton().click()
settingsPage.upgradeSubscription("max")
settingsPage.upgradeSubscription({ plan: "max" })

// setup intercepter, stub the used products response to disallow update
cy.intercept("GET", "**/billing/products", (req) => {
Expand Down Expand Up @@ -401,7 +401,7 @@ describe("Subscription Plan", () => {

// upgrade to a max plan first using convenience function
navigationMenu.settingsNavButton().click()
settingsPage.upgradeSubscription("max")
settingsPage.upgradeSubscription({ plan: "max" })

// store the upgraded plan name for later comparison
settingsPage.planNameLabel()
Expand Down Expand Up @@ -452,7 +452,7 @@ describe("Subscription Plan", () => {

// upgrade to a Pro plan first
navigationMenu.settingsNavButton().click()
settingsPage.upgradeSubscription("pro")
settingsPage.upgradeSubscription({ plan: "pro" })

// store the Pro plan name for later comparison
settingsPage.planNameLabel()
Expand Down Expand Up @@ -492,7 +492,7 @@ describe("Subscription Plan", () => {
})

it("can initiate and return to a crypto payment flow within 60 minutes", () => {
cy.web3Login({ deleteCreditCard: true, resetToFreePlan: true })
cy.web3Login({ deleteCreditCard: true, withNewSession: true })
navigationMenu.settingsNavButton().click()
settingsPage.subscriptionTabButton().click()
settingsPage.changePlanButton().click()
Expand Down
3 changes: 2 additions & 1 deletion packages/files-ui/cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"target": "es5",
"jsx": "react",
"lib": ["es5", "dom"],
"types": ["cypress", "cypress-file-upload"]
"types": ["cypress", "cypress-file-upload"],
"esModuleInterop": true,
},
"include": ["**/*.ts"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ const NotificationLine = ({ notification }: Props) => {
return <div
className={classes.notificationBody}
onClick={notification.onClick}
data-cy="container-notification"
>
<Typography
variant="body2"
className={classes.notificationTitle}
component="p"
data-cy="label-notification-title"
>
{notification.title}
</Typography>
<Typography
variant="body2"
className={classes.notificationTime}
component="p"
data-cy="label-notification-time"
>
{dayjs.unix(notification.createdAt).fromNow()}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const NotificationList = ({ notifications }: INotificationListProps) => {
<Typography
variant="h3"
component="p"
data-cy="label-notifications-header"
>
<Trans>Notifications</Trans>
</Typography>
Expand All @@ -88,6 +89,7 @@ const NotificationList = ({ notifications }: INotificationListProps) => {
variant="h5"
component="p"
className={classes.timeHeader}
data-cy="label-notifications-this-week"
>
<Trans>This week</Trans>
</Typography>
Expand All @@ -102,6 +104,7 @@ const NotificationList = ({ notifications }: INotificationListProps) => {
variant="h5"
component="p"
className={classes.timeHeader}
data-cy="label-notifications-older"
>
<Trans>Older notifications</Trans>
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const NotificationsDropdown = () => {
autoclose
classNames={{ options: classes.optionsOpen }}
onClose={() => setIsActive(false)}
testId="notifications"
>
<div
className={clsx(classes.notificationsButton, isActive && "active")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const DowngradeDetails = ({
const { currentSubscription, cancelCurrentSubscription, invoices } = useBilling()
const currentStorage = formatBytes(Number(currentSubscription?.product?.price.metadata?.storage_size_bytes), 2)
const [isCancelingPlan, setIsCancellingPlan] = useState(false)
const lastInvoicePaymentMethod = invoices && invoices[invoices.length - 1].payment_method
const lastInvoicePaymentMethod = invoices?.length && invoices[invoices.length - 1].payment_method

const onCancelPlan = useCallback(() => {
setIsCancellingPlan(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const DowngradeDetails = ({
const { currentSubscription, cancelCurrentSubscription, invoices } = useBilling()
const currentStorage = formatBytes(Number(currentSubscription?.product?.price.metadata?.storage_size_bytes), 2)
const [isCancelingPlan, setIsCancellingPlan] = useState(false)
const lastInvoicePaymentMethod = invoices && invoices[invoices.length - 1].payment_method
const lastInvoicePaymentMethod = invoices?.length && invoices[invoices.length - 1].payment_method

const onCancelPlan = useCallback(() => {
setIsCancellingPlan(true)
Expand Down