diff --git a/tests/cypress/e2e/unit_tests/p1_fleet.spec.ts b/tests/cypress/e2e/unit_tests/p1_fleet.spec.ts index 60516cc..edba108 100644 --- a/tests/cypress/e2e/unit_tests/p1_fleet.spec.ts +++ b/tests/cypress/e2e/unit_tests/p1_fleet.spec.ts @@ -1249,3 +1249,31 @@ if (!/\/2\.7/.test(Cypress.env('rancher_version')) && !/\/2\.8/.test(Cypress.env ) }) }; + +if (!/\/2\.7/.test(Cypress.env('rancher_version')) && !/\/2\.8/.test(Cypress.env('rancher_version'))) { + describe('Test Fleet Resource Count', { tags: '@p1'}, () => { + qase(155, + it("Fleet-155: Test clusters resource count is correct", { tags: '@fleet-155' }, () => { + const repoName = 'default-cluster-count-155' + const branch = "master" + const path = "simple" + const repoUrl = "https://github.com/rancher/fleet-examples" + + cy.addFleetGitRepo({ repoName, repoUrl, branch, path }); + cy.clickButton('Create'); + cy.checkGitRepoStatus(repoName, '1 / 1', '6 / 6'); + + // Get the Resource count from GitRepo and store it. + cy.gitRepoResourceCountAsInteger(repoName, 'fleet-default'); + + // Compare Resource count from GitRepo(stored) + // with resource count from each downstream cluster. + dsAllClusterList.forEach((dsCluster) => { + cy.compareClusterResourceCount(dsCluster); + }) + + cy.deleteAllFleetRepos(); + }) + ) + }); +} diff --git a/tests/cypress/support/commands.ts b/tests/cypress/support/commands.ts index 0d0aeac..00ada0b 100644 --- a/tests/cypress/support/commands.ts +++ b/tests/cypress/support/commands.ts @@ -669,3 +669,43 @@ Cypress.Commands.add('checkGitRepoAfterUpgrade', (repoName, fleetNamespace='flee cy.filterInSearchBox(repoName); cy.verifyTableRow(0, /Active|Modified/, repoName); }); + +Cypress.Commands.add('gitRepoResourceCountAsInteger', (repoName, fleetNamespace='fleet-local') => { + cy.accesMenuSelection('Continuous Delivery', 'Git Repos'); + cy.fleetNamespaceToggle(fleetNamespace); + cy.verifyTableRow(0, 'Active', repoName); + cy.contains(repoName).click() + cy.get('.primaryheader > h1').contains(repoName).should('be.visible') + + // Get the Resource count text from UI and convert it into integer. + cy.get("div[data-testid='gitrepo-deployment-summary'] div[class='count']") + .invoke('text') + .then((countText) => { + // Add '7' default resource count available on each cluster. + const gitRepoResourceCount = parseInt(countText.trim(), 10) + 7; + cy.log("GitRepo Resource count is: " + gitRepoResourceCount); + cy.wrap(gitRepoResourceCount).as('gitRepoResourceCount'); + }) +}) + +Cypress.Commands.add('compareClusterResourceCount', (clusterName) => { + // Check the resource count from each cluster matches with resources created by GitRepo. + cy.accesMenuSelection('Continuous Delivery', 'Clusters'); + cy.contains('.title', 'Clusters').should('be.visible'); + cy.filterInSearchBox(clusterName); + cy.verifyTableRow(0, 'Active', clusterName); + cy.get('td.col-link-detail > span').contains(clusterName).click(); + + // Get the stored 'gitRepoResourceCount' value and + // compare with existing resource count from cluster. + cy.get('@gitRepoResourceCount').then((gitRepoResourceCount) => { + cy.get("div[primary-color-var='--sizzle-success'] div[class='data compact'] > h1") + .invoke('text') + .then((clusterResourceCountText) => { + // Covert it into integer and then compare with resources created via GitRepo. + const resourceCountOnCluster = parseInt(clusterResourceCountText.trim(), 10); + cy.log("Resource count on each cluster is: " + resourceCountOnCluster); + expect(gitRepoResourceCount).to.equal(resourceCountOnCluster); + }) + }) +}) diff --git a/tests/cypress/support/e2e.ts b/tests/cypress/support/e2e.ts index c55a7c4..56aae4a 100644 --- a/tests/cypress/support/e2e.ts +++ b/tests/cypress/support/e2e.ts @@ -53,6 +53,8 @@ declare global { verifyJobDeleted(repoName: string, verifyJobDeletedEvent?: boolean ): Chainable; typeIntoCanvasTermnal(textToType: string): Chainable; checkGitRepoAfterUpgrade(repoName: string, fleetNamespace?: string): Chainable; + gitRepoResourceCountAsInteger(repoName: string, fleetNamespace?: string): Chainable; + compareClusterResourceCount(clusterName: string): Chainable; } } }