Skip to content

Commit

Permalink
[RHOAIENG-10454] mock cypress test flake: pipelines.cy.ts 'imports a …
Browse files Browse the repository at this point in the history
…new pipeline'
  • Loading branch information
jpuzz0 committed Jul 26, 2024
1 parent d0de08d commit d403812
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Contextual } from '~/__tests__/cypress/cypress/pages/components/Contextual';
import { DashboardCodeEditor } from '~/__tests__/cypress/cypress/pages/components/DashboardCodeEditor';
import type { PipelineRecurringRunKFv2 } from '~/concepts/pipelines/kfTypes';
import type {
PipelineKFv2,
PipelineRecurringRunKFv2,
PipelineVersionKFv2,
} from '~/concepts/pipelines/kfTypes';

class TaskDrawer extends Contextual<HTMLElement> {
findInputArtifacts() {
Expand Down Expand Up @@ -179,6 +183,29 @@ class PipelineDetails extends PipelinesTopology {
this.findActionsDropdown().click();
cy.findByRole('menuitem', { name: label }).click();
}

mockGetPipeline(namespace: string, pipeline: PipelineKFv2): Cypress.Chainable<null> {
return cy.interceptOdh(
'GET /api/service/pipelines/:namespace/:serviceName/apis/v2beta1/pipelines/:pipelineId',
{ path: { namespace, serviceName: 'dspa', pipelineId: pipeline.pipeline_id } },
pipeline,
);
}

mockGetPipelineVersion(pipelineId: string, version: PipelineVersionKFv2, namespace: string) {
return cy.interceptOdh(
'GET /api/service/pipelines/:namespace/:serviceName/apis/v2beta1/pipelines/:pipelineId/versions/:pipelineVersionId',
{
path: {
namespace,
pipelineId,
serviceName: 'dspa',
pipelineVersionId: version.pipeline_version_id,
},
},
version,
);
}
}

class PipelineRecurringRunDetails extends RunDetails {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
configurePipelineServerModal,
viewPipelineServerModal,
PipelineSort,
pipelineDetails,
} from '~/__tests__/cypress/cypress/pages/pipelines';
import { deleteModal } from '~/__tests__/cypress/cypress/pages/components/DeleteModal';
import {
Expand Down Expand Up @@ -580,12 +581,9 @@ describe('Pipelines', () => {
pipelineImportModal.fillPipelineName('New pipeline');
pipelineImportModal.fillPipelineDescription('New pipeline description');
pipelineImportModal.uploadPipelineYaml(pipelineYamlPath);
pipelinesTable
.mockGetPipelines([initialMockPipeline, uploadedMockPipeline], projectName)
.as('refreshPipelines');
pipelineImportModal.submit();

// Wait for upload/fetch requests
// Wait for pipeline upload
cy.wait('@uploadPipeline').then((interception) => {
// Note: contain is used instead of equals as different browser engines will add a different boundary
// to the body - the aim is to not limit these tests to working with one specific engine.
Expand All @@ -601,11 +599,9 @@ describe('Pipelines', () => {
});
});

cy.wait('@refreshPipelines').then((interception) => {
expect(interception.request.query).to.include({
sort_by: 'created_at desc',
});
});
pipelinesTable.mockGetPipelines([initialMockPipeline, uploadedMockPipeline], projectName);
pipelineDetails.mockGetPipeline(projectName, uploadedMockPipeline);
pipelineDetails.mockGetPipelineVersion('new-pipeline', initialMockPipelineVersion, projectName);

cy.url().should(
'include',
Expand Down Expand Up @@ -633,7 +629,7 @@ describe('Pipelines', () => {
it('imports a new pipeline by url', () => {
initIntercepts({});
pipelinesGlobal.visit(projectName);
const createPipelineAndVersionParams = {
const uploadPipelineAndVersionParams = {
pipeline: {
display_name: 'New pipeline',
},
Expand All @@ -644,15 +640,15 @@ describe('Pipelines', () => {
},
},
};
const createdMockPipeline = buildMockPipelineV2(createPipelineAndVersionParams.pipeline);
const createdMockPipeline = buildMockPipelineV2(uploadPipelineAndVersionParams.pipeline);
const createdVersion = buildMockPipelineVersionV2(
createPipelineAndVersionParams.pipeline_version,
uploadPipelineAndVersionParams.pipeline_version,
);

// Intercept upload/re-fetch of pipelines
pipelineImportModal
.mockCreatePipelineAndVersion(createPipelineAndVersionParams, projectName)
.as('createPipelineAndVersion');
.mockCreatePipelineAndVersion(uploadPipelineAndVersionParams, projectName)
.as('uploadPipelineAndVersion');
pipelinesTable.mockGetPipelines([initialMockPipeline], projectName);
pipelinesTable.mockGetPipelineVersions([createdVersion], 'new-pipeline', projectName);

Expand All @@ -667,14 +663,14 @@ describe('Pipelines', () => {
pipelineImportModal.fillPipelineName('New pipeline');
pipelineImportModal.findImportPipelineRadio().check();
pipelineImportModal.findPipelineUrlInput().type('https://example.com/pipeline.yaml');
pipelinesTable
.mockGetPipelines([initialMockPipeline, createdMockPipeline], projectName)
.as('refreshPipelines');
pipelineImportModal.submit();

// Wait for upload/fetch requests
cy.wait('@createPipelineAndVersion');
cy.wait('@refreshPipelines');
// Wait for pipeline upload
cy.wait('@uploadPipelineAndVersion');

pipelinesTable.mockGetPipelines([initialMockPipeline, createdMockPipeline], projectName);
pipelineDetails.mockGetPipeline(projectName, createdMockPipeline);
pipelineDetails.mockGetPipelineVersion('new-pipeline', createdVersion, projectName);

cy.url().should(
'include',
Expand Down

0 comments on commit d403812

Please sign in to comment.