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

test: [M3-9143] - Cypress test for Service Transfers fetch error #11607

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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-11607-tests-1738694493702.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Add Cypress test for Service Transfers fetch error ([#11607](https://github.com/linode/manager/pull/11607))
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
mockGetEntityTransfers,
mockReceiveEntityTransfer,
mockInitiateEntityTransferError,
mockGetEntityTransfersError,
} from 'support/intercepts/account';
import { mockGetLinodes } from 'support/intercepts/linodes';
import { ui } from 'support/ui';
Expand All @@ -27,6 +28,9 @@ import { cleanUp } from 'support/util/cleanup';

import type { EntityTransferStatus } from '@linode/api-v4';

// Service transfer error message.
export const serviceTransferErrorMessage = 'An unknown error has occurred';

// Service transfer landing page URL.
const serviceTransferLandingUrl = '/account/service-transfers';

Expand Down Expand Up @@ -107,6 +111,18 @@ const assertReceiptError = (errorMessage: string) => {
});
};

/**
* Asserts that an error message is shown upon service transfer tables.
*
* @param errorMessage - Error message which is expected to be shown.
*/
const assertServiceTransfersError = (errorMessage: string) => {
// Error Icon should shows up.
cy.findByTestId('ErrorOutlineIcon').should('be.visible');
// Error message should be visible.
cy.findByText(errorMessage, { exact: false }).should('be.visible');
};

authenticate();
describe('Account service transfers', () => {
before(() => {
Expand Down Expand Up @@ -475,4 +491,32 @@ describe('Account service transfers', () => {
initiateLinodeTransfer(mockLinodes[0].label);
cy.findByText(errorMessage).should('be.visible');
});

/*
* - Confirms that an error message is displayed in both the Received and Sent tables when the requests to fetch service transfers fail.
*/
it('can display an error message when the request fails to fetch service transfer', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('can display an error message when the request fails to fetch service transfer', () => {
it('should display an error message when the request fails to fetch service transfer', () => {

mockGetEntityTransfersError().as('getTransfersError');

cy.visitWithLogin(serviceTransferLandingUrl);
cy.wait('@getTransfersError');

cy.get('[data-qa-panel="Pending Service Transfers"]').should('not.exist');

// Confirm that an error message is displayed in "Received Service Transfers" panel.
cy.get('[data-qa-panel="Received Service Transfers"]')
.should('be.visible')
.within(() => {
cy.get('[data-testid="KeyboardArrowDownIcon"]').click();
assertServiceTransfersError(serviceTransferErrorMessage);
});

// Confirm that an error message is displayed is in "Sent Service Transfers" panel.
cy.get('[data-qa-panel="Sent Service Transfers"]')
.should('be.visible')
.within(() => {
cy.get('[data-testid="KeyboardArrowDownIcon"]').click();
assertServiceTransfersError(serviceTransferErrorMessage);
});
Comment on lines +506 to +520
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove the assertServiceTransfersError function and simplify this to something like:

['Received Service Transfers', 'Sent Service Transfers'].forEach((transfer) => {
  cy.get(`[data-qa-panel="${transfer}"]`)
  .should('be.visible')
  .within(() => {
    cy.get('[data-testid="KeyboardArrowDownIcon"]').click();
    // Error Icon should shows up.
    cy.findByTestId('ErrorOutlineIcon').should('be.visible');
    // Error message should be visible.
    cy.findByText(serviceTransferErrorMessage, { exact: false }).should('be.visible');
  });
})

});
});
19 changes: 19 additions & 0 deletions packages/manager/cypress/support/intercepts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,25 @@ export const mockGetEntityTransfers = (
});
};

/**
* Intercepts GET request to fetch service transfers and mocks an error response.
*
* @param errorMessage - API error message with which to mock response.
* @param statusCode - HTTP status code with which to mock response.
*
* @returns Cypress chainable.
*/
export const mockGetEntityTransfersError = (
errorMessage: string = 'An unknown error has occurred',
statusCode: number = 500
) => {
return cy.intercept(
'GET',
apiMatcher('account/entity-transfers*'),
makeErrorResponse(errorMessage, statusCode)
);
};

/**
* Intercepts GET request to receive entity transfer and mocks response.
*
Expand Down