Commit 973c3942 authored by Michail Tzanatos's avatar Michail Tzanatos
Browse files

fixed logged user journeys

parent 40d7e294
Loading
Loading
Loading
Loading
+77 −91
Original line number Diff line number Diff line
@@ -3,99 +3,85 @@ describe('logged user journeys', () => {
      cy.visit(window.location.origin);        
      
  });
    afterEach(() => {
      //log user out after each test
      cy.get('#navbarDropdown2').click();
      cy.get(':nth-child(2) > .dropdown > .dropdown-menu > :nth-child(8)').click();
      cy.location("pathname").should("equal", "/");
    });
  // afterEach(() => {
  //   //log user out after each test
  //   cy.get('#navbarDropdown2').click();
  //   cy.get(':nth-child(2) > .dropdown > .dropdown-menu > :nth-child(8)').click();
  //   cy.location("pathname").should("equal", "/");
  // });

  // it.only('logs in through services', () => {
  //   cy.loginPath('[data-cy="servicesPortal"]', '/services');
  //   //back on services marketplace after login
  //   cy.location("pathname").should("equal", "/services/services_marketplace");
  //   //check every 'Manage Services' dropdown item
  //   cy.get(':nth-child(2) > #navbarDropdown').click();
  //   let i=1; 
  //   cy.get('.dropdown-item').each(($el) => {
      
  //     cy.wrap($el).click(); // Click the link
  //     cy.get(':nth-child(1) > .cdk-column-actions > .btn').first().click();
  //     //does the dialog open?
  //     cy.get('mat-dialog-container').should('exist');
  //     cy.go('back');
  //     cy.get(':nth-child(2) > #navbarDropdown').click();
  //     i = i+1;
  //     cy.log(`${i}`);
  //     if(i>2) {
  //       cy.log("it returns now");
  //       return false;
  //     }
  //   });
  //   //access the service specs dropdown
  //   cy.get('#navbarDropdown1').click();
  //   let j=0;
  //   for(let i=1; i<=2; i++) {
  //     cy.get(`.dropdown-submenu > .dropdown-menu > :nth-child(${i}) `).click();
  //     cy.location("pathname").should("not.equal", "/services/services_marketplace");
  //     cy.go('back');
  //     cy.get(':nth-child(2) > #navbarDropdown').click();
  //     cy.get('#navbarDropdown1').click();
  //   }
  //   //check the rest dropdown items
  //   cy.get(':nth-child(4) > .dropdown-item').click();
  //   cy.get('mat-dialog-container').should('exist');
  //   cy.go('back');
  //   cy.get(':nth-child(2) > #navbarDropdown').click();
    
  //   //'Manage Entities' dropdown
  //   cy.manageEntities(':nth-child(3) > #navbarDropdown', 2);
    
  // });

  it('logs in through services', () => {
      cy.loginPath(':nth-child(2) > .container > .row > :nth-child(2) > a > .btn', '/services');
      //back on services marketplace after login
    cy.loginPath('[data-cy="servicesPortal"]', '/services');
    cy.location("pathname").should("equal", "/services/services_marketplace");
      //check every 'Manage Services' dropdown item
      cy.get(':nth-child(2) > #navbarDropdown').click();
      let i=0; 
      cy.get('.show .dropdown-item').each(($el) => {
        i++;
        cy.wrap($el).click(); // Click the link
        cy.get(':nth-child(1) > .cdk-column-actions > .btn').first().click();

        //does the dialog open?
        cy.get('mat-dialog-container').should('exist');
        cy.go('back');
        cy.get(':nth-child(2) > #navbarDropdown').click();
        if(i>1) {
          return false;
        }
      });
      //access the service specs dropdown
      cy.get('#navbarDropdown1').click();
      let j=0;
      for(let i=1; i<=2; i++) {
        cy.get(`.dropdown-submenu > .dropdown-menu > :nth-child(${i}) `).click();
        cy.location("pathname").should("not.equal", "/services/services_marketplace");
        cy.go('back');
        cy.get(':nth-child(2) > #navbarDropdown').click();
        cy.get('#navbarDropdown1').click();
      }
      //check the rest dropdown items
      cy.get(':nth-child(4) > .dropdown-item').click();
      cy.get('mat-dialog-container').should('exist');
      cy.go('back');
      cy.get(':nth-child(2) > #navbarDropdown').click();
    cy.navigateThroughDropdowns("Services Marketplace");
    cy.manageEntities(':nth-child(3) > #navbarDropdown', 2);
    cy.manageEntities(':nth-child(4) > #navbarDropdown', 3);

      //'Manage Entities' dropdown
      cy.manageEntities(':nth-child(3) > #navbarDropdown', '.jumbotron-heading > .btn', 2, 2);
    
  });
    it('logs in through resources', () => {
      cy.loginPath(':nth-child(3) > .container > .row > .order-md-1 > a > .btn', '/resources');
      cy.location("pathname").should("equal", "/resources/resource_catalogs");
      cy.get('.text-md-right > .btn').click();
      cy.get('mat-dialog-container').should('exist');
      cy.go('back');
      cy.get('#navbarDropdown').click();
      cy.get('.show > :nth-child(2) > .dropdown-item').click();
      cy.location("pathname").should("equal", "/resources/resource_categories");
      cy.get('.text-md-right > .btn').click();
      cy.location("pathname").should("equal", "/resources/resource_categories_update");
      cy.go('back');

      cy.get('#navbarDropdown').click();
      cy.get('#navbarDropdown1').click();
      for(let i=1; i<=2; i++) {
        cy.get(`.dropdown-submenu > .dropdown-menu > :nth-child(${i}) `).click();
        cy.location("pathname").should("not.equal", "/resources/resource_categories");
        cy.go('back');
        cy.get('#navbarDropdown').click();
        cy.get('#navbarDropdown1').click();
      }

      //resource inventory
      cy.get(':nth-child(5) > .dropdown-item').click();
  it('logs in through resources', () => {
    cy.loginPath('[data-cy="resourcesPortal"]', '/resources');
    cy.location("pathname").should("equal", "/resources/resource_inventory");
      cy.get('#navbarDropdown').click();
    cy.navigateThroughDropdowns("Resource Inventory");

      //resource pools
      cy.get(':nth-child(7) > .dropdown-item').click();
      cy.location("pathname").should("equal", "/resources/resource_pools");
      cy.get('#navbarDropdown').click();
  });

      //resource reservations
      cy.get(':nth-child(8) > .dropdown-item').click();
      cy.location("pathname").should("equal", "/resources/resource_reservations");

    });
  it('logs in through testing', () => {
      cy.loginPath(':nth-child(5) > .container > .row > .order-md-1 > a > .btn', '/testing');

      cy.manageEntities(':nth-child(1) > #navbarDropdown', '.text-md-right > .btn', 3, 2);
      cy.manageEntities(':nth-child(2) > #navbarDropdown', '.jumbotron-heading > .btn', 2, 2);
    cy.loginPath('[data-cy="testingPortal"]', '/testing');
    cy.manageEntities(':nth-child(1) > #navbarDropdown', 2);
    cy.manageEntities(':nth-child(2) > #navbarDropdown', 2);
  });

  
  it('logs in through products', () => {
      cy.loginPath(':nth-child(6) > .container > .row > :nth-child(2) > a > .btn', '/products');
      cy.manageEntities(':nth-child(2) > #navbarDropdown', '.text-md-right > .btn', 2, 4);
      cy.manageEntities(':nth-child(3) > #navbarDropdown', '.jumbotron-heading > .btn', 2, 2);
    cy.loginPath('[data-cy="productsPortal"]', '/products');
    cy.manageEntities(':nth-child(2) > #navbarDropdown', 4);
    cy.manageEntities(':nth-child(3) > #navbarDropdown', 2);
  });
})
 No newline at end of file
+0 −3
Original line number Diff line number Diff line
// const baseUrl = Cypress.config('baseUrl');

describe('user journey', () => {
  
  beforeEach(() => {
    //cy.visit(baseUrl);
    cy.visit(window.location.origin);
  })
  
+118 −19
Original line number Diff line number Diff line
@@ -7,7 +7,8 @@ declare namespace Cypress {
    navigateToProducts(selector): Chainable<any>;
    authUser(): Chainable<any>;
    loginPath(selector, path): Chainable<any>;
    manageEntities(selector, button, scndIndx, numOfItems): Chainable<any>;
    navigateThroughDropdowns(headerTitle): Chainable<any>;
    manageEntities(selector, numOfItems): Chainable<any>;
    checkProtectedRoutes(): Chainable<any>;
  }
}
@@ -91,26 +92,124 @@ Cypress.Commands.add("loginPath", (selector, path) => {
  cy.authUser();
});

Cypress.Commands.add(
  "manageEntities",
  (selector, button, scndIndx, numOfItems) => {
    for (let i = 1; i <= numOfItems; i++) {
      cy.get(selector).click();
      if (i == 2 && scndIndx == 3) {
        cy.get(
          `.nav-item.show > .dropdown-menu > :nth-child(3) > .dropdown-item`
        ).click();
        cy.go("back");
      } else
        cy.get(
          `.nav-item.show > .dropdown-menu > :nth-child(${i}) > .dropdown-item`
        ).click();
      cy.get(button).click();
      cy.go("back");
// Cypress.Commands.add(
//   "manageEntities",
//   (selector, numOfItems) => {
//     for (let i = 1; i <= numOfItems; i++) {
//       cy.get(selector).click();
//       cy.get(`.nav-item.open > #navbarDropdown > .dropdown-menu > :nth-child(${i}) > .dropdown-item`).click();
//       cy.get('.text-md-right > .btn, .jumbotron-heading > .btn').should('exist');
//       cy.go("back");
//     }
//   } 
// );

Cypress.Commands.add("navigateThroughDropdowns", (headerTitle: string) => {

  cy.get('[data-cy="dropdown"]').each(($dropdown, dropdownIndex) => {
    if (dropdownIndex > 0) {
      return;
    }
    cy.get('[data-cy="dropdown"]').eq(dropdownIndex).click();

    cy.get('[data-cy="dropdown-item-1"]').each(($item, itemIndex) => {
      cy.location('pathname').then((initialPath) => {

        cy.get('[data-cy="dropdown-item-1"]').eq(itemIndex).click();

        cy.get('body').then(($body) => {

          cy.location('pathname').then((newPath) => {

            if (newPath === initialPath && $item.text().trim() !== headerTitle) {
              cy.get('[data-cy="dropdown-item-2"]').each((nestedItem, nestedIndex) => {
                cy.get('[data-cy="dropdown-item-2"]').eq(nestedIndex).click();
                const dialogExists = $body.find('mat-dialog').length > 0;
                if(dialogExists) {
                  cy.get('#mat-dialog-0').should('be.visible');

                  cy.go('back');
                  cy.location('pathname').should('equal', initialPath);
                  cy.get('[data-cy="dropdown"]').eq(dropdownIndex).click();
                
                }
                else {
                  cy.location('pathname').should('not.equal', initialPath);

                  cy.go('back');
                  cy.location('pathname').should('equal', initialPath);
                  cy.get('[data-cy="dropdown"]').eq(dropdownIndex).click();
                  cy.get('[data-cy="dropdown-item-1"]').eq(itemIndex).click();
                }
              });

            } else if ($item.text().trim() === headerTitle) {
              cy.location('pathname').should('equal', initialPath);
              cy.get('[data-cy="dropdown"]').eq(dropdownIndex).click();

            } else {
              cy.location('pathname').should('not.equal', initialPath);
              cy.go('back');
              cy.location('pathname').should('equal', initialPath);
              cy.get('[data-cy="dropdown"]').eq(dropdownIndex).click();
            }

          });
          
        });

      });
    });
  });

});


Cypress.Commands.add("manageEntities", (selector, numOfItems) => {
  function clickItem(index) {
    if (index > numOfItems+1) return;

    cy.get(selector).click(); // open navbar dropdown

    cy.get('body').then(($body) => {
      const menuItem = $body.find(
        `.nav-item.open > #navbarDropdown > .dropdown-menu > :nth-child(${index}) > .dropdown-item`
      );

      if (menuItem.length === 0) {
        cy.log(`Skipping missing item at index ${index}`);
        cy.get('body').click();
        clickItem(index + 1);
        return;
      }

      cy.wrap(menuItem).click();

      cy.get('body').then(($page) => {
        const hasButton = $page.find('.text-md-right > .btn, .jumbotron-heading > .btn').length > 0;
        const hasHeader = $page.find('h2.shadowed').length > 0;

        expect(
          hasButton || hasHeader,
          `Expected either a button or a header on page for item ${index}`
        ).to.be.true;

        if (hasButton) {
          cy.get('.text-md-right > .btn, .jumbotron-heading > .btn')
            .first()
            .click();
        } else {
          cy.log(`Found header instead of button for item ${index}`);
        }

        cy.go('back').then(() => clickItem(index + 1));
      });
    });
  }

  clickItem(1);
});

Cypress.Commands.add("checkProtectedRoutes", () => {
  for (let route of Cypress.env("protectedRoutes")) {
    cy.intercept(route);
+41 −41

File changed.

Preview size limit exceeded, changes collapsed.