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-8098] - Refactor StackScript create test to be resilient to Image deprecations #10788

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

Refactor StackScript create test to be resilient to Image deprecations ([#10788](https://github.com/linode/manager/pull/10788))
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { chooseRegion } from 'support/util/regions';
import { SimpleBackoffMethod } from 'support/util/backoff';
import { cleanUp } from 'support/util/cleanup';
import { createTestLinode } from 'support/util/linodes';
import { interceptGetAllImages } from 'support/intercepts/images';
import type { Image } from '@linode/api-v4';
import { getFilteredImagesForImageSelect } from 'src/components/ImageSelectv2/utilities';

// StackScript fixture paths.
const stackscriptBasicPath = 'stackscripts/stackscript-basic.sh';
Expand Down Expand Up @@ -289,24 +292,10 @@ describe('Create stackscripts', () => {

const linodeLabel = randomLabel();

/*
* Arbitrarily-chosen images to check in order to confirm that "Any/All"
* StackScripts allow any image to be selected.
*/
const imageSamples = [
{ label: 'AlmaLinux 9', sel: 'linode/almalinux9' },
{ label: 'Alpine 3.19', sel: 'linode/alpine3.19' },
{ label: 'Arch Linux', sel: 'linode/arch' },
{ label: 'CentOS Stream 9', sel: 'linode/centos-stream9' },
{ label: 'Debian 12', sel: 'linode/debian12' },
{ label: 'Fedora 40', sel: 'linode/fedora40' },
{ label: 'Rocky Linux 9', sel: 'linode/rocky9' },
{ label: 'Ubuntu 24.04 LTS', sel: 'linode/ubuntu24.04' },
];

interceptCreateStackScript().as('createStackScript');
interceptGetStackScripts().as('getStackScripts');
interceptCreateLinode().as('createLinode');
interceptGetAllImages().as('getAllImages');

cy.defer(createLinodeAndImage, {
label: 'creating Linode and Image',
Expand All @@ -331,31 +320,50 @@ describe('Create stackscripts', () => {
cy.wait('@createStackScript');
cy.url().should('endWith', '/stackscripts/account');

cy.wait('@getStackScripts');
cy.findByText(stackscriptLabel)
.should('be.visible')
.closest('tr')
.within(() => {
cy.findByText(stackscriptDesc).should('be.visible');
cy.findByText(stackscriptImage).should('be.visible');
});

// Navigate to StackScript details page and click deploy Linode button.
cy.findByText(stackscriptLabel).should('be.visible').click();

ui.button
.findByTitle('Deploy New Linode')
.should('be.visible')
.should('be.enabled')
.click();

// Confirm that expected images are present in "Choose an image" drop-down.
cy.findByPlaceholderText('Choose an image').should('be.visible').click();

imageSamples.forEach((imageSample) => {
const imageLabel = imageSample.label;
cy.wait('@getAllImages').then((res) => {
// Fetch Images from response data and filter out Kubernetes images.
const imageData = res.response?.body.data;
const filteredImageData = getFilteredImagesForImageSelect(
imageData,
'public'
);

cy.findByText(imageLabel).scrollIntoView().should('be.visible');
cy.wait('@getStackScripts');
cy.findByText(stackscriptLabel)
.should('be.visible')
.closest('tr')
.within(() => {
cy.findByText(stackscriptDesc).should('be.visible');
cy.findByText(stackscriptImage).should('be.visible');
});

// Navigate to StackScript details page and click deploy Linode button.
cy.findByText(stackscriptLabel).should('be.visible').click();

ui.button
.findByTitle('Deploy New Linode')
.should('be.visible')
.should('be.enabled')
.click();

// Confirm that expected images are present in "Choose an image" drop-down.
cy.findByPlaceholderText('Choose an image')
.should('be.visible')
.click();

/*
* Arbitrarily-chosen images to check in order to confirm that "Any/All"
* StackScripts allow any image to be selected.
*
*/
filteredImageData?.forEach((imageSample: Image) => {
const imageLabel = imageSample.label;
cy.findAllByText(imageLabel)
.last()
.scrollIntoView()
.should('exist')
.should('be.visible');
});
});

// Select private image.
Expand Down
9 changes: 9 additions & 0 deletions packages/manager/cypress/support/intercepts/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export const interceptUploadImage = (): Cypress.Chainable<null> => {
return cy.intercept('POST', apiMatcher('images/upload'));
};

/**
* Intercepts GET request to retrieve all images.
*
* @returns Cypress chainable.
*/
export const interceptGetAllImages = (): Cypress.Chainable<null> => {
return cy.intercept('GET', apiMatcher('images*'));
};

/**
* Intercepts GET request to retrieve all images and mocks response.
*
Expand Down
Loading