Skip to content
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: 5 additions & 0 deletions packages/manager/.changeset/pr-10349-tests-1712253815522.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Add Cypress tests for Account billing drawers ([#10349](https://github.com/linode/manager/pull/10349))
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { paymentMethodFactory, profileFactory } from '@src/factories';
import { accountUserFactory } from '@src/factories/accountUsers';
import { grantsFactory } from '@src/factories/grants';
import { ADMINISTRATOR, PARENT_USER } from 'src/features/Account/constants';
import { mockGetPaymentMethods, mockGetUser } from 'support/intercepts/account';
import {
mockAppendFeatureFlags,
Expand Down Expand Up @@ -173,6 +174,56 @@ const assertAddPaymentMethodEnabled = () => {
});
};

/**
* Asserts that the "Make a Payment" button is disabled.
*
* Additionally confirms that clicking the "Make a Payment" button reveals
* a tooltip and does not open the "Make a Payment" drawer.
*
* @param tooltipText - Expected tooltip message to be shown to the user.
*/
const assertMakeAPaymentDisabled = (tooltipText: string) => {
// Confirm "Make A Payment" button is disabled, then click it.
ui.button
.findByTitle('Make a Payment')
.should('be.visible')
.should('be.disabled')
.click();

// Assert that "Make a Payment" drawer does not open and that tooltip is revealed.
cy.get(`[data-qa-drawer-title="Make a Payment"]`).should('not.exist');
ui.tooltip.findByText(tooltipText).should('be.visible');
};

/**
* Asserts that the "Make a Payment" button is enabled.
*
* Additionally confirms that clicking the "Make a Payment" button reveals
* a tooltip and does not open the "Make a Payment" drawer.
*
* @param tooltipText - Expected tooltip message to be shown to the user.
*/
const assertMakeAPaymentEnabled = () => {
// Confirm "Make A Payment" button is enabled, then click it.
ui.button
.findByTitle('Make a Payment')
.should('be.visible')
.should('be.enabled')
.click();

cy.get(`[data-qa-drawer-title="Make a Payment"]`).should('be.visible');
ui.drawer
.findByTitle('Make a Payment')
.should('be.visible')
.within(() => {
ui.button
.findByTitle('Pay Now')
.should('be.visible')
.should('be.enabled');
ui.drawerCloseButton.find().click();
});
};

describe('restricted user billing flows', () => {
beforeEach(() => {
mockGetPaymentMethods(mockPaymentMethods);
Expand Down Expand Up @@ -215,6 +266,7 @@ describe('restricted user billing flows', () => {
cy.visitWithLogin('/account/billing');
assertEditBillingInfoEnabled();
assertAddPaymentMethodEnabled();
assertMakeAPaymentEnabled();
});
});

Expand Down Expand Up @@ -261,6 +313,10 @@ describe('restricted user billing flows', () => {

assertEditBillingInfoDisabled(restrictedUserTooltip);
assertAddPaymentMethodDisabled(restrictedUserTooltip);
assertMakeAPaymentDisabled(
restrictedUserTooltip +
` Please contact your ${ADMINISTRATOR} to request the necessary permissions.`
);
});

/*
Expand All @@ -287,6 +343,10 @@ describe('restricted user billing flows', () => {

assertEditBillingInfoDisabled(restrictedUserTooltip);
assertAddPaymentMethodDisabled(restrictedUserTooltip);
assertMakeAPaymentDisabled(
restrictedUserTooltip +
` Please contact your ${PARENT_USER} to request the necessary permissions.`
);
});

/*
Expand Down Expand Up @@ -323,6 +383,7 @@ describe('restricted user billing flows', () => {
cy.findByText(mockProfileRegular.username);
assertEditBillingInfoEnabled();
assertAddPaymentMethodEnabled();
assertMakeAPaymentEnabled();

// Confirm button behavior for parent users.
mockGetProfile(mockProfileParent);
Expand All @@ -331,6 +392,7 @@ describe('restricted user billing flows', () => {
cy.findByText(mockProfileParent.username);
assertEditBillingInfoEnabled();
assertAddPaymentMethodEnabled();
assertMakeAPaymentEnabled();
});
});
});