diff --git a/packages/manager/.changeset/pr-10761-tests-1723056815829.md b/packages/manager/.changeset/pr-10761-tests-1723056815829.md new file mode 100644 index 00000000000..31314c0aa7b --- /dev/null +++ b/packages/manager/.changeset/pr-10761-tests-1723056815829.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tests +--- + +Add test for Linode create error flows ([#10761](https://github.com/linode/manager/pull/10761)) diff --git a/packages/manager/cypress/e2e/core/linodes/create-linode.spec.ts b/packages/manager/cypress/e2e/core/linodes/create-linode.spec.ts index 34d33345230..bf86857ff8c 100644 --- a/packages/manager/cypress/e2e/core/linodes/create-linode.spec.ts +++ b/packages/manager/cypress/e2e/core/linodes/create-linode.spec.ts @@ -13,7 +13,10 @@ import { mockAppendFeatureFlags, mockGetFeatureFlagClientstream, } from 'support/intercepts/feature-flags'; -import { interceptCreateLinode } from 'support/intercepts/linodes'; +import { + interceptCreateLinode, + mockCreateLinodeError, +} from 'support/intercepts/linodes'; import { makeFeatureFlagData } from 'support/util/feature-flags'; import { interceptGetProfile } from 'support/intercepts/profile'; import { Region, VLAN, Config, Disk } from '@linode/api-v4'; @@ -159,7 +162,10 @@ describe('Create Linode', () => { username = xhr.response?.body.username; }); - // TODO Confirm whether or not toast notification should appear here. + // Confirm toast notification should appear on Linode create. + ui.toast.assertMessage( + `Your Linode ${linodeLabel} is being created.` + ); cy.findByText('RUNNING', { timeout: LINODE_CREATE_TIMEOUT }).should( 'be.visible' ); @@ -341,4 +347,56 @@ describe('Create Linode', () => { fbtVisible(linodeLabel); cy.contains('RUNNING', { timeout: 300000 }).should('be.visible'); }); + + /* + * - Confirms error message can show up during Linode create flow. + * - Confirms Linode can be created after retry. + */ + it('shows unexpected error during Linode create flow', () => { + const linodeRegion = chooseRegion({ + capabilities: ['Linodes'], + }); + const linodeLabel = randomLabel(); + const mockLinode = linodeFactory.build({ + id: randomNumber(), + label: linodeLabel, + region: linodeRegion.id, + }); + const createLinodeErrorMessage = + 'An error has occurred during Linode creation flow'; + + mockCreateLinodeError(createLinodeErrorMessage).as('createLinodeError'); + cy.visitWithLogin('/linodes/create'); + + // Set Linode label, OS, plan type, password, etc. + linodeCreatePage.setLabel(linodeLabel); + linodeCreatePage.selectImage('Debian 11'); + linodeCreatePage.selectRegionById(linodeRegion.id); + linodeCreatePage.selectPlan('Shared CPU', 'Nanode 1 GB'); + linodeCreatePage.setRootPassword(randomString(32)); + + // Create Linode by clicking the button. + ui.button + .findByTitle('Create Linode') + .should('be.visible') + .should('be.enabled') + .click(); + cy.wait('@createLinodeError'); + + // Confirm the createLinodeErrorMessage show up on the web page. + cy.findByText(`${createLinodeErrorMessage}`).should('be.visible'); + + // Retry to create a Linode. + mockCreateLinode(mockLinode).as('createLinode'); + ui.button + .findByTitle('Create Linode') + .should('be.visible') + .should('be.enabled') + .click(); + cy.wait('@createLinode'); + // Confirm toast notification should appear on Linode create. + ui.toast.assertMessage(`Your Linode ${linodeLabel} is being created.`); + // Confirm the createLinodeErrorMessage disappears. + cy.findByText(`${createLinodeErrorMessage}`).should('not.exist'); + }); }); diff --git a/packages/manager/cypress/support/intercepts/linodes.ts b/packages/manager/cypress/support/intercepts/linodes.ts index d01b88a7964..e3dd41d140a 100644 --- a/packages/manager/cypress/support/intercepts/linodes.ts +++ b/packages/manager/cypress/support/intercepts/linodes.ts @@ -60,6 +60,24 @@ export const mockCreateLinode = (linode: Linode): Cypress.Chainable => { ); }; +/** Intercepts POST request to create a Linode and mocks an error response. + * + * @param errorMessage - Error message to be included in the mocked HTTP response. + * @param statusCode - HTTP status code for mocked error response. Default is `400`. + * + * @returns Cypress chainable. + */ +export const mockCreateLinodeError = ( + errorMessage: string, + statusCode: number = 500 +): Cypress.Chainable => { + return cy.intercept( + 'POST', + apiMatcher('linode/instances'), + makeErrorResponse(errorMessage, statusCode) + ); +}; + /* Intercepts GET request to get a Linode. * * @param linodeId - ID of Linode to fetch.