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

increase card timeout and delete active wait #1

Merged
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: 4 additions & 1 deletion frontend/src/__tests__/cypress/cypress/pages/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class Resources {
}

getCardView() {
return new CardView(() => cy.findByTestId('learning-center-card-view'));
return new CardView(() =>
// When using custom resources it can take up to 3 minutes to show in view due to polling
cy.findByTestId('learning-center-card-view', { timeout: 180000 }).should('exist'),
);
}

getListView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getResourceValues,
cleanupCustomResources,
} from '~/__tests__/cypress/cypress/utils/resourceUtils';
import { waitAndCheckResources } from '~/__tests__/cypress/cypress/utils/resourceCheckUtils';
import { checkResources } from '~/__tests__/cypress/cypress/utils/resourceCheckUtils';

describe('Create a custom resource Quickstart by using Dashboard CRDs', () => {
let resourcesData: ResourcesData;
Expand All @@ -26,9 +26,9 @@ describe('Create a custom resource Quickstart by using Dashboard CRDs', () => {
});
});

// after(() => {
// return cleanupCustomResources(resourcesData);
// });
after(() => {
return cleanupCustomResources(resourcesData);
});

it('Upload custom resource and verify', () => {
cy.step('Log into the application');
Expand All @@ -38,7 +38,7 @@ describe('Create a custom resource Quickstart by using Dashboard CRDs', () => {
resources.visit();

cy.step('Check for newly created resources');
waitAndCheckResources([
checkResources([
{
name: resourceNames.quickStartName,
metaDataName: resourceNames.quickStartMetaDataName,
Expand Down
44 changes: 16 additions & 28 deletions frontend/src/__tests__/cypress/cypress/utils/resourceCheckUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ interface ResourceInfo {
description: string; // This can be retained if needed for logging, but we won't use it for assertions.
}

export const waitAndCheckResources = (resourceInfoList: ResourceInfo[]) => {
const timeout = 60000; // Total timeout of 1 minute
const checkInterval = 5000; // Check every 5 seconds
export const checkResources = (resourceInfoList: ResourceInfo[]) => {
cy.log(`Starting resource check for ${resourceInfoList.length} resources.`);

const checkResource = (resourceInfo: ResourceInfo, startTime: number) => {
// If the total timeout has been reached, log that the resource is missing
if (Date.now() - startTime >= timeout) {
cy.log(`Timeout reached. Resource not found: ${resourceInfo.name}`);
return; // Stop checking this resource
}

cy.log(`Searching for resource: ${resourceInfo.name}`);
resourceInfoList.forEach((resourceInfo) => {
cy.log(`Checking for resource: ${resourceInfo.name}`);

// Clear the search input and type the resource name
resources.getLearningCenterToolbar().findSearchInput().clear().type(resourceInfo.name);
Expand All @@ -26,21 +19,16 @@ export const waitAndCheckResources = (resourceInfoList: ResourceInfo[]) => {
cy.wait(1000); // Adjust this if necessary based on your app's response time

// Check if the resource card is visible by looking for its metadata name
resources.getCardView().getCard(resourceInfo.metaDataName).find().then(($card) => {
if ($card.length > 0 && $card.is(':visible')) {
cy.log(`✅ Resource found: ${resourceInfo.name}`);
} else {
cy.log(`Resource not found yet: ${resourceInfo.name}`);
// Wait before checking again
cy.wait(checkInterval).then(() => checkResource(resourceInfo, startTime));
}
});
};

// Start checking each resource independently
const startTime = Date.now();

resourceInfoList.forEach((resourceInfo) => {
checkResource(resourceInfo, startTime);
resources
.getCardView()
.getCard(resourceInfo.metaDataName)
.find()
.then(($card) => {
if ($card.length > 0 && $card.is(':visible')) {
cy.log(`✅ Resource found: ${resourceInfo.name}`);
} else {
cy.log(`❌ Resource not found: ${resourceInfo.name}`);
}
});
});
};
};