From 8cd1c77fd1512cd99a7a1065a9ace63e9c646e53 Mon Sep 17 00:00:00 2001 From: Joe D'Amore Date: Thu, 22 Aug 2024 10:17:30 -0400 Subject: [PATCH 1/3] Filter StackScripts response data similarly to Cloud to fix content assertion failure --- .../smoke-community-stackscrips.spec.ts | 112 ++++++++++++------ 1 file changed, 75 insertions(+), 37 deletions(-) diff --git a/packages/manager/cypress/e2e/core/stackscripts/smoke-community-stackscrips.spec.ts b/packages/manager/cypress/e2e/core/stackscripts/smoke-community-stackscrips.spec.ts index d30c17acd52..43ae5fa6dc0 100644 --- a/packages/manager/cypress/e2e/core/stackscripts/smoke-community-stackscrips.spec.ts +++ b/packages/manager/cypress/e2e/core/stackscripts/smoke-community-stackscrips.spec.ts @@ -1,21 +1,25 @@ -import { authenticate } from 'support/api/authentication'; +import type { StackScript } from '@linode/api-v4'; +import { Profile, getImages, getProfile } from '@linode/api-v4'; + import { stackScriptFactory } from 'src/factories'; +import { isLinodeKubeImageId } from 'src/store/image/image.helpers'; +import { formatDate } from 'src/utilities/formatDate'; + +import { authenticate } from 'support/api/authentication'; +import { interceptCreateLinode } from 'support/intercepts/linodes'; +import { mockGetUserPreferences } from 'support/intercepts/profile'; import { interceptGetStackScripts, - mockGetStackScripts, mockGetStackScript, + mockGetStackScripts, } from 'support/intercepts/stackscripts'; import { ui } from 'support/ui'; +import { cleanUp } from 'support/util/cleanup'; +import { depaginate } from 'support/util/paginate'; import { randomLabel, randomString } from 'support/util/random'; import { chooseRegion } from 'support/util/regions'; -import { cleanUp } from 'support/util/cleanup'; -import { interceptCreateLinode } from 'support/intercepts/linodes'; -import { getProfile } from '@linode/api-v4'; -import { Profile } from '@linode/api-v4'; -import { formatDate } from '@src/utilities/formatDate'; -import type { StackScript } from '@linode/api-v4'; -import { mockGetUserPreferences } from 'support/intercepts/profile'; +import type { Image } from '@linode/api-v4'; const mockStackScripts: StackScript[] = [ stackScriptFactory.build({ @@ -187,37 +191,71 @@ describe('Community Stackscripts integration tests', () => { */ it('pagination works with infinite scrolling', () => { interceptGetStackScripts().as('getStackScripts'); - cy.visitWithLogin('/stackscripts/community'); - cy.wait('@getStackScripts'); - // Confirm that empty state is not shown. - cy.get('[data-qa-stackscript-empty-msg="true"]').should('not.exist'); - cy.findByText('Automate deployment scripts').should('not.exist'); - - // Confirm that scrolling to the bottom of the StackScripts list causes - // pagination to occur automatically. Perform this check 3 times. - for (let i = 0; i < 3; i += 1) { - cy.findByLabelText('List of StackScripts') - .should('be.visible') - .within(() => { - // Scroll to the bottom of the StackScripts list, confirm Cloud fetches StackScripts, - // then confirm that list updates with the new StackScripts shown. - cy.get('tr').last().scrollIntoView(); - cy.wait('@getStackScripts').then((xhr) => { - const stackScripts = xhr.response?.body['data'] as - | StackScript[] - | undefined; - if (!stackScripts) { - throw new Error( - 'Unexpected response received when fetching StackScripts' + // Fetch all public Images to later use while filtering StackScripts. + cy.defer(() => + depaginate((page) => getImages({ page }, { is_public: true })) + ).then((publicImages: Image[]) => { + cy.visitWithLogin('/stackscripts/community'); + cy.wait('@getStackScripts'); + + // Confirm that empty state is not shown. + cy.get('[data-qa-stackscript-empty-msg="true"]').should('not.exist'); + cy.findByText('Automate deployment scripts').should('not.exist'); + + // Confirm that scrolling to the bottom of the StackScripts list causes + // pagination to occur automatically. Perform this check 3 times. + for (let i = 0; i < 3; i += 1) { + cy.findByLabelText('List of StackScripts') + .should('be.visible') + .within(() => { + // Scroll to the bottom of the StackScripts list, confirm Cloud fetches StackScripts, + // then confirm that list updates with the new StackScripts shown. + cy.get('tr').last().scrollIntoView(); + cy.wait('@getStackScripts').then((xhr) => { + const stackScripts = xhr.response?.body['data'] as + | StackScript[] + | undefined; + + if (!stackScripts) { + throw new Error( + 'Unexpected response received when fetching StackScripts' + ); + } + + // Cloud Manager hides certain StackScripts from the landing page (although they can + // still be found via search). It does this if either condition is met: + // + // - The StackScript is only compatible with deprecated Images + // - The StackScript is only compatible with LKE Images + // + // As a consequence, we can't use the API response directly to assert + // that content is shown in the list. We need to apply identical filters + // to the response first, then assert the content using that data. + const filteredStackScripts = stackScripts.filter( + (stackScript: StackScript) => { + const hasNonDeprecatedImages = stackScript.images.some( + (stackScriptImage) => { + return !!publicImages.find( + (publicImage) => publicImage.id === stackScriptImage + ); + } + ); + + const usesKubeImage = stackScript.images.some( + (stackScriptImage) => isLinodeKubeImageId(stackScriptImage) + ); + return hasNonDeprecatedImages && !usesKubeImage; + } ); - } - cy.contains( - `${stackScripts[0].username} / ${stackScripts[0].label}` - ).should('be.visible'); + + cy.contains( + `${filteredStackScripts[0].username} / ${filteredStackScripts[0].label}` + ).should('be.visible'); + }); }); - }); - } + } + }); }); /* From 0daff029061efd8318ca2c56bee561434d31f7c3 Mon Sep 17 00:00:00 2001 From: Joe D'Amore Date: Thu, 22 Aug 2024 10:23:41 -0400 Subject: [PATCH 2/3] Rename `smoke-community-stackscrips.spec.ts` to `smoke-community-stackscripts.spec.ts` --- ...y-stackscrips.spec.ts => smoke-community-stackscripts.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/manager/cypress/e2e/core/stackscripts/{smoke-community-stackscrips.spec.ts => smoke-community-stackscripts.spec.ts} (100%) diff --git a/packages/manager/cypress/e2e/core/stackscripts/smoke-community-stackscrips.spec.ts b/packages/manager/cypress/e2e/core/stackscripts/smoke-community-stackscripts.spec.ts similarity index 100% rename from packages/manager/cypress/e2e/core/stackscripts/smoke-community-stackscrips.spec.ts rename to packages/manager/cypress/e2e/core/stackscripts/smoke-community-stackscripts.spec.ts From 90631465e2b555876a6387d7c35d1b3624e34ca8 Mon Sep 17 00:00:00 2001 From: Joe D'Amore Date: Thu, 22 Aug 2024 10:29:10 -0400 Subject: [PATCH 3/3] Added changeset: Resolve StackScripts pagination test failure --- packages/manager/.changeset/pr-10811-tests-1724336950451.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/manager/.changeset/pr-10811-tests-1724336950451.md diff --git a/packages/manager/.changeset/pr-10811-tests-1724336950451.md b/packages/manager/.changeset/pr-10811-tests-1724336950451.md new file mode 100644 index 00000000000..6f4175005c7 --- /dev/null +++ b/packages/manager/.changeset/pr-10811-tests-1724336950451.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tests +--- + +Resolve StackScripts pagination test failure ([#10811](https://github.com/linode/manager/pull/10811))