@@ -783,42 +783,74 @@ Cypress.Commands.add('checkGitRepoAfterUpgrade', (repoName, fleetNamespace='flee
783783 cy . verifyTableRow ( 0 , / A c t i v e | M o d i f i e d / , repoName ) ;
784784} ) ;
785785
786+ Cypress . Commands . add ( 'currentClusterResourceCount' , ( clusterName ) => {
787+ cy . accesMenuSelection ( 'Continuous Delivery' , 'Clusters' ) ;
788+ cy . contains ( '.title' , 'Clusters' ) . should ( 'be.visible' ) ;
789+ cy . filterInSearchBox ( clusterName ) ;
790+ cy . verifyTableRow ( 0 , 'Active' , clusterName ) ;
791+ cy . get ( 'td.col-link-detail > span' ) . contains ( clusterName ) . click ( ) ;
792+ cy . get ( "div[primary-color-var='--sizzle-success'] div[class='data compact'] > h1" )
793+ . invoke ( 'text' )
794+ . then ( ( clusterResourceCountText ) => {
795+ // Convert to integer
796+ const clusterCurrentResourceCount = parseInt ( clusterResourceCountText . trim ( ) , 10 ) ;
797+ cy . log ( "Resource count on each cluster is: " + clusterCurrentResourceCount ) ;
798+ cy . wrap ( clusterCurrentResourceCount ) . as ( 'clusterCurrentResourceCount' ) ;
799+ } )
800+ } )
801+
786802Cypress . Commands . add ( 'gitRepoResourceCountAsInteger' , ( repoName , fleetNamespace = 'fleet-local' ) => {
787803 cy . accesMenuSelection ( 'Continuous Delivery' , 'Git Repos' ) ;
788804 cy . fleetNamespaceToggle ( fleetNamespace ) ;
789805 cy . verifyTableRow ( 0 , 'Active' , repoName ) ;
790806 cy . contains ( repoName ) . click ( )
791807 cy . get ( '.primaryheader > h1' ) . contains ( repoName ) . should ( 'be.visible' )
792808
793- // Get the Resource count text from UI and convert it into integer.
794809 cy . get ( "div[data-testid='gitrepo-deployment-summary'] div[class='count']" )
795810 . invoke ( 'text' )
796- . then ( ( countText ) => {
797- // Add '7' default resource count available on each cluster.
798- const gitRepoResourceCount = parseInt ( countText . trim ( ) , 10 ) + 7 ;
799- cy . log ( "GitRepo Resource count is: " + gitRepoResourceCount ) ;
800- cy . wrap ( gitRepoResourceCount ) . as ( 'gitRepoResourceCount' ) ;
811+ . then ( ( gitRepoResourceCountText ) => {
812+ const gitRepoTotalResourceCount = parseInt ( gitRepoResourceCountText . trim ( ) , 10 ) ;
813+ cy . log ( "GitRepo Resource count is: " + gitRepoTotalResourceCount ) ;
814+ cy . wrap ( gitRepoTotalResourceCount ) . as ( 'gitRepoTotalResourceCount' ) ;
801815 } )
802816} )
803817
804- Cypress . Commands . add ( 'compareClusterResourceCount ' , ( clusterName ) => {
805- // Check the resource count from each cluster matches with resources created by GitRepo .
818+ Cypress . Commands . add ( 'actualResourceOnCluster ' , ( clusterName ) => {
819+ // Get Cluster Resources before GitRepo created.
806820 cy . accesMenuSelection ( 'Continuous Delivery' , 'Clusters' ) ;
807821 cy . contains ( '.title' , 'Clusters' ) . should ( 'be.visible' ) ;
808822 cy . filterInSearchBox ( clusterName ) ;
809823 cy . verifyTableRow ( 0 , 'Active' , clusterName ) ;
810824 cy . get ( 'td.col-link-detail > span' ) . contains ( clusterName ) . click ( ) ;
825+ // Get resources from the cluster page after GitRepo install.
826+ cy . get ( "div[primary-color-var='--sizzle-success'] div[class='data compact'] > h1" )
827+ . invoke ( 'text' )
828+ . then ( ( clusterResourceCountText ) => {
829+ const resourceCountOnCluster = parseInt ( clusterResourceCountText . trim ( ) , 10 ) ;
830+ cy . log ( "Resource count on each cluster is: " + resourceCountOnCluster ) ;
831+ cy . get ( '@clusterCurrentResourceCount' ) . then ( ( clusterCurrentResourceCount ) => {
832+ // Remove default 6/7 resources from Total resources available
833+ // on single cluster after GitRepo install it's resources.
834+ const actualResourceOnCluster = resourceCountOnCluster - clusterCurrentResourceCount ;
835+ cy . wrap ( actualResourceOnCluster ) . as ( 'actualResourceOnCluster' ) ;
836+ } )
837+ } )
838+ } )
811839
840+ Cypress . Commands . add ( 'compareClusterResourceCount' , ( multipliedResourceCount = true ) => {
812841 // Get the stored 'gitRepoResourceCount' value and
813- // compare with existing resource count from cluster.
814- cy . get ( '@gitRepoResourceCount' ) . then ( ( gitRepoResourceCount ) => {
815- cy . get ( "div[primary-color-var='--sizzle-success'] div[class='data compact'] > h1" )
816- . invoke ( 'text' )
817- . then ( ( clusterResourceCountText ) => {
818- // Covert it into integer and then compare with resources created via GitRepo.
819- const resourceCountOnCluster = parseInt ( clusterResourceCountText . trim ( ) , 10 ) ;
820- cy . log ( "Resource count on each cluster is: " + resourceCountOnCluster ) ;
821- expect ( gitRepoResourceCount ) . to . equal ( resourceCountOnCluster ) ;
842+ // Multipy 'actualResourceOnCluster' 3 times because 3 clusters.
843+ // Compare final result with the 'gitRepoTotalResourceCount'.
844+ cy . get ( '@actualResourceOnCluster' ) . then ( ( actualResourceOnCluster ) => {
845+ cy . get ( '@gitRepoTotalResourceCount' ) . then ( ( gitRepoTotalResourceCount ) => {
846+ // When 'sameResourceEachCluster' is true then each cluster has
847+ // 'actualResourceOnCluster' is equal to 'gitRepoResourceCount'
848+ if ( multipliedResourceCount ) {
849+ expect ( gitRepoTotalResourceCount ) . to . equal ( actualResourceOnCluster * 3 ) ;
850+ }
851+ else {
852+ expect ( gitRepoTotalResourceCount ) . to . equal ( actualResourceOnCluster ) ;
853+ }
822854 } )
823855 } )
824856} )
0 commit comments