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-8996] - Add test for LKE cluster rename flow #11444

Closed
wants to merge 2 commits into from
Closed
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-11444-tests-1734632019649.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Add test for LKE cluster rename flow ([#11444](https://github.com/linode/manager/pull/11444))
69 changes: 69 additions & 0 deletions packages/manager/cypress/e2e/core/kubernetes/lke-update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
mockGetControlPlaneACL,
mockUpdateControlPlaneACLError,
mockGetControlPlaneACLError,
mockUpdateClusterError,
} from 'support/intercepts/lke';
import {
mockGetLinodeType,
Expand Down Expand Up @@ -858,6 +859,74 @@ describe('LKE cluster updates', () => {
.should('be.visible')
.should('be.disabled');
});

/*
* - Confirms LKE summary page updates to reflect new cluster name.
*/
it('can rename cluster', () => {
const mockCluster = kubernetesClusterFactory.build({
k8s_version: latestKubernetesVersion,
});
const mockNewCluster = kubernetesClusterFactory.build({
label: 'newClusterName',
});

mockGetCluster(mockCluster).as('getCluster');
mockGetKubernetesVersions().as('getVersions');
mockGetClusterPools(mockCluster.id, mockNodePools).as('getNodePools');
mockUpdateCluster(mockCluster.id, mockNewCluster).as('updateCluster');

cy.visitWithLogin(`/kubernetes/clusters/${mockCluster.id}/summary`);
cy.wait(['@getCluster', '@getNodePools', '@getVersions']);

// LKE clusters can be renamed by clicking on the cluster's name in the breadcrumbs towards the top of the page.
cy.get('[data-testid="editable-text"] > [data-testid="button"]').click();
cy.findByTestId('textfield-input')
.should('be.visible')
.should('have.value', mockCluster.label)
.clear()
.type(`${mockNewCluster.label}{enter}`);

cy.wait('@updateCluster');

cy.findAllByText(mockNewCluster.label).should('be.visible');
cy.findAllByText(mockCluster.label).should('not.exist');
});

/*
* - Confirms error message shows when the API request fails.
*/
it('can handle API errors when rename cluster', () => {
const mockCluster = kubernetesClusterFactory.build({
k8s_version: latestKubernetesVersion,
});
const mockErrorCluster = kubernetesClusterFactory.build({
label: 'errorClusterName',
});
const mockErrorMessage = 'API request fails';

mockGetCluster(mockCluster).as('getCluster');
mockGetKubernetesVersions().as('getVersions');
mockGetClusterPools(mockCluster.id, mockNodePools).as('getNodePools');
mockUpdateClusterError(mockCluster.id, mockErrorMessage).as(
'updateClusterError'
);

cy.visitWithLogin(`/kubernetes/clusters/${mockCluster.id}/summary`);
cy.wait(['@getCluster', '@getNodePools', '@getVersions']);

// LKE cluster can be renamed by clicking on the cluster's name in the breadcrumbs towards the top of the page.
cy.get('[data-testid="editable-text"] > [data-testid="button"]').click();
cy.findByTestId('textfield-input')
.should('be.visible')
.should('have.value', mockCluster.label)
.clear()
.type(`${mockErrorCluster.label}{enter}`);

// Error message shows when API request fails.
cy.wait('@updateClusterError');
cy.findAllByText(mockErrorMessage).should('be.visible');
});
});

describe('LKE cluster updates for DC-specific prices', () => {
Expand Down
21 changes: 21 additions & 0 deletions packages/manager/cypress/support/intercepts/lke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,24 @@ export const mockGetLKEClusterTypes = (
): Cypress.Chainable<null> => {
return cy.intercept('GET', apiMatcher('lke/types*'), paginateResponse(types));
};

/**
* Intercepts PUT request to update an LKE cluster and mocks an error response.
*
* @param clusterId - ID of cluster for which to intercept PUT request.
* @param errorMessage - Optional error message with which to mock response.
* @param statusCode - HTTP status code with which to mock response.
*
* @returns Cypress chainable.
*/
export const mockUpdateClusterError = (
clusterId: number,
errorMessage: string = 'An unknown error occurred.',
statusCode: number = 500
): Cypress.Chainable<null> => {
return cy.intercept(
'PUT',
apiMatcher(`lke/clusters/${clusterId}`),
makeErrorResponse(errorMessage, statusCode)
);
};