From 1f90430dee47866d48c237d799612afe51e9ae09 Mon Sep 17 00:00:00 2001 From: nixocio Date: Thu, 1 Feb 2024 13:20:51 -0500 Subject: [PATCH] Update collection upload tests Update collection upload tests This one is levearging https://github.com/ansible/ansible-ui/pull/1536 to generate the collections. Also update the hub collection update command, and delete collection and related namespace after test. --- cypress/e2e/hub/collections.cy.ts | 69 +++++++++++-------------------- cypress/support/commands.ts | 2 +- cypress/support/hub-commands.ts | 34 +++++++-------- 3 files changed, 42 insertions(+), 63 deletions(-) diff --git a/cypress/e2e/hub/collections.cy.ts b/cypress/e2e/hub/collections.cy.ts index ef545ecf4e..bca6dbfd03 100644 --- a/cypress/e2e/hub/collections.cy.ts +++ b/cypress/e2e/hub/collections.cy.ts @@ -1,76 +1,57 @@ +// @ts-nocheck import { randomString } from '../../../framework/utils/random-string'; import { hubAPI } from '../../support/formatApiPathForHub'; import { Collections } from './constants'; -describe.skip('Collections- List View', () => { +describe('Collections- List View', () => { //**Important to know: //**In order to upload a collection, a namespace must first exist containing the first word of the collection file name //**The only way to get rid of a collection's artifact is to choose the following option: //**Delete entire collection from repository //**If the artifact isn't deleted when the collection is deleted, and a user tries to create //**a new collection by uploading the same file again, Hub will not allow it. - let namespace: string; before(() => { - namespace = 'hub_e2e_col_namespace' + randomString(5).toLowerCase(); cy.hubLogin(); - cy.getNamespace(namespace); - cy.addAndApproveMultiCollections(1); - }); - - it('it should render the collections page', () => { - cy.navigateTo('hub', Collections.url); - cy.verifyPageTitle(Collections.title); - }); - - after(() => { - cy.cleanupCollections(namespace, 'community'); - cy.deleteNamespace(namespace); }); - it.skip('user can upload and then delete a new collection', () => { - cy.getOrCreateCollection().then((thisCollection) => { - const thisCollectionName = thisCollection?.split('-').slice(-2, -1).toString(); + it('user can upload and delete collection', () => { + const namespace = `upload_namespace_${randomString(3, undefined, { isLowercase: true })}`; + cy.createNamespace(namespace); + const collection = randomString(5, undefined, { isLowercase: true }).replace(/\d/g, ''); + cy.galaxykit(`collection upload ${namespace} ${collection} --skip-upload`).then((result) => { cy.navigateTo('hub', Collections.url); cy.verifyPageTitle(Collections.title); - cy.get('[data-cy="upload-collection"]').click(); - cy.uploadHubCollectionFile(`collection-files/` + thisCollection, thisCollection); + const filePath = result?.filename as string; + cy.uploadHubCollectionFile(filePath); cy.get('input[id="radio-non-pipeline"]').click(); cy.get('[data-cy="row-0"]').within(() => { cy.get('input').click(); }); - cy.intercept('POST', hubAPI`/v3/plugin/ansible/content/community/collections/artifacts/`).as( - 'collection' - ); cy.get('[data-cy="Submit"]').click(); - cy.wait('@collection').then((resp) => { - expect(resp?.response?.statusCode).to.eql(202); - expect(resp?.response?.statusMessage).to.eql('Accepted'); - expect(resp?.responseWaited).to.eql(true); - }); - cy.reload(); - cy.get('[data-cy="hub-collections"]').click(); + cy.clickButton(/^Clear all filters$/); + cy.navigateTo('hub', Collections.url); + cy.url().should('include', 'collections'); cy.verifyPageTitle(Collections.title); - cy.get('[data-cy="app-description"]').should( - 'contain', - 'Collections are a packaged unit of Ansible content that includes roles, modules, plugins, and other components, making it easier to share and reuse automation functionality.' - ); cy.get('[data-cy="table-view"]').click(); - cy.clickTableRowKebabAction(thisCollectionName, 'delete-entire-collection-from-system'); - cy.get('[data-ouia-component-id="confirm"]').click(); - cy.intercept( - 'DELETE', - hubAPI`/v3/plugin/ansible/content/community/collections/index/${namespace}/${thisCollectionName}/` - ).as('deleted'); - cy.get('[data-ouia-component-id="submit"]').click(); - cy.wait('@deleted').then((deleted) => { - expect(deleted?.response?.statusCode).to.eq(202); - }); + cy.searchAndDisplayResource(collection); + cy.get('[data-cy="actions-column-cell"]').click(); + cy.get('[data-cy="delete-entire-collection-from-system"]').click({ force: true }); + cy.get('#confirm').click(); + cy.clickButton(/^Delete collections/); + cy.contains(/^Success$/); cy.clickButton(/^Close$/); cy.clickButton(/^Clear all filters$/); + + cy.deleteNamespace(namespace); }); }); + it('it should render the collections page', () => { + cy.navigateTo('hub', Collections.url); + cy.verifyPageTitle(Collections.title); + }); + it('should call galaxykit without error', () => { cy.galaxykit('collection -h'); }); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 06eea98697..9ba1e85893 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -941,7 +941,7 @@ declare global { failOnStatusCode?: boolean; } ): Cypress.Chainable; - uploadHubCollectionFile(hubFilePath: string, hubFileName: string): Cypress.Chainable; + uploadHubCollectionFile(hubFilePath: string): Cypress.Chainable; createNamespace(namespaceName: string): Cypress.Chainable; getNamespace(namespaceName: string): Cypress.Chainable; deleteNamespace(namespaceName: string): Cypress.Chainable; diff --git a/cypress/support/hub-commands.ts b/cypress/support/hub-commands.ts index 10471cab1f..c0c75f5df4 100644 --- a/cypress/support/hub-commands.ts +++ b/cypress/support/hub-commands.ts @@ -12,7 +12,7 @@ import { escapeForShellCommand } from './utils'; const apiPrefix = Cypress.env('HUB_API_PREFIX') as string; -// GalaxyKit Integration: To invoke `galaxykit` commands for generating resources +// GalaxyKit Integration: To invoke `galaxykit` commands for generating resource Cypress.Commands.add('galaxykit', (operation: string, ...args: string[]) => { const adminUsername = Cypress.env('HUB_USERNAME') as string; const adminPassword = Cypress.env('HUB_PASSWORD') as string; @@ -37,9 +37,15 @@ Cypress.Commands.add('galaxykit', (operation: string, ...args: string[]) => { } }); - cy.log(`stdout: ${stdout}`).then(() => { - return stdout.split('\n').filter((s) => !!s); - }); + cy.log(`stdout: ${stdout}`); + + let parsedStdout: unknown; + try { + parsedStdout = JSON.parse(stdout); + } catch (e) { + parsedStdout = stdout.split('\n').filter((s) => !!s); + } + return cy.wrap(parsedStdout); }); }); @@ -87,20 +93,12 @@ Cypress.Commands.add( } ); -Cypress.Commands.add('uploadHubCollectionFile', (hubFilePath: string, hubFileName: string) => { - cy.fixture(hubFilePath, 'binary') - .then(Cypress.Blob.binaryStringToBlob) - .then((fileContent) => { - cy.get('input[id="file-upload-file-filename"]').attachFile( - { - fileContent, - fileName: hubFileName, - filePath: hubFilePath, - mimeType: 'application/gzip', - }, - { subjectType: 'drag-n-drop' } - ); - }); +Cypress.Commands.add('uploadHubCollectionFile', (hubFilePath: string) => { + cy.get('[data-cy="upload-collection"]').click(); + cy.get('#file-upload-file-browse-button').click(); + cy.get('input[id="file-upload-file-filename"]').selectFile(hubFilePath, { + action: 'drag-drop', + }); }); Cypress.Commands.add('addAndApproveMultiCollections', (numberOfCollections = 1) => {