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-8149] - Add test for Linode create error flows #10761

Merged
merged 5 commits into from
Aug 20, 2024
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-10761-tests-1723056815829.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Add test for Linode create error flows ([#10761](https://github.com/linode/manager/pull/10761))
62 changes: 60 additions & 2 deletions packages/manager/cypress/e2e/core/linodes/create-linode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'
);
Expand Down Expand Up @@ -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');
});
});
18 changes: 18 additions & 0 deletions packages/manager/cypress/support/intercepts/linodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ export const mockCreateLinode = (linode: Linode): Cypress.Chainable<null> => {
);
};

/** 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<null> => {
return cy.intercept(
'POST',
apiMatcher('linode/instances'),
makeErrorResponse(errorMessage, statusCode)
);
};

/* Intercepts GET request to get a Linode.
*
* @param linodeId - ID of Linode to fetch.
Expand Down
Loading