Commit a2d417af authored by Michail Tzanatos's avatar Michail Tzanatos
Browse files

bug fixes

parent c2d41a96
Loading
Loading
Loading
Loading
Loading
+28 −21
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ Cypress.Commands.add("loginPath", (selector, path) => {
  cy.authUser();
});

//navigate through all the dropdowns, all the dropdown items and nested items
Cypress.Commands.add("navigateThroughDropdowns", (headerTitle: string) => {
  cy.get('[data-cy^="dropdown-"]').its('length').then((dropdownCount: number) => {

@@ -110,29 +111,29 @@ Cypress.Commands.add("navigateThroughDropdowns", (headerTitle: string) => {
        .should('have.length.greaterThan', 0);
    };

    const processDropdown = (di: number) => {
      if (di >= dropdownCount) return;
    const processDropdown = (dropdownIndex: number) => {
      if (dropdownIndex >= dropdownCount) return;

      const dropdownSelector = `[data-cy="dropdown-${di}"]`;
      const itemPattern = `[data-cy^="dropdown-${di}-item-"]`;
      const dropdownSelector = `[data-cy="dropdown-${dropdownIndex}"]`;
      const itemPattern = `[data-cy^="dropdown-${dropdownIndex}-item-"]`;

      ensureDropdownOpen(dropdownSelector, itemPattern);

      cy.get(itemPattern).its('length').then((itemCount: number) => {
        if (itemCount === 0) {
          cy.log(`Dropdown ${di} had no items, skipping.`);
          processDropdown(di + 1);
          cy.log(`Dropdown ${dropdownIndex} had no items, skipping.`);
          processDropdown(dropdownIndex + 1);
          return;
        }

        const processItem = (ii: number) => {
          if (ii >= itemCount) {
            cy.log(`Finished dropdown ${di}`);
            processDropdown(di + 1);
        const processItem = (itemIndex: number) => {
          if (itemIndex >= itemCount) {
            cy.log(`Finished dropdown ${dropdownIndex}`);
            processDropdown(dropdownIndex + 1);
            return;
          }

          const itemSelector = `[data-cy="dropdown-${di}-item-${ii}"]`;
          const itemSelector = `[data-cy="dropdown-${dropdownIndex}-item-${itemIndex}"]`;

          ensureDropdownOpen(dropdownSelector, itemPattern);

@@ -145,23 +146,25 @@ Cypress.Commands.add("navigateThroughDropdowns", (headerTitle: string) => {

              cy.get('body').then(() => {
                cy.location('pathname').then((newPath) => {
                  // if a redirect doesn't happen when an item is clicked, it has nested subitems
                  if (newPath === initialPath && itemText !== headerTitle) {
                    const nestedPattern = `[data-cy^="dropdown-${di}-item-${ii}-subitem-"]`;
                    const nestedPattern = `[data-cy^="dropdown-${dropdownIndex}-item-${itemIndex}-subitem-"]`;
                    cy.get(nestedPattern).its('length').then((nestedCount: number) => {
                      if (nestedCount === 0) {
                        processItem(ii + 1);
                        processItem(itemIndex + 1);
                        return;
                      }

                      const processNested = (nk: number) => {
                        if (nk >= nestedCount) {
                          processItem(ii + 1);
                      const processNested = (nestedIndex: number) => {
                        if (nestedIndex >= nestedCount) {
                          processItem(itemIndex + 1);
                          return;
                        }

                        const nestedSelector = `[data-cy="dropdown-${di}-item-${ii}-subitem-${nk}"]`;
                        const nestedSelector = `[data-cy="dropdown-${dropdownIndex}-item-${itemIndex}-subitem-${nestedIndex}"]`;
                        cy.get(nestedSelector).filter(':visible').should('exist').click();

                        // a dialog may exist in place of a nested subitem
                        cy.get('body').then(($bodyAfterNested) => {
                          const dialogExists =
                            $bodyAfterNested.find('mat-dialog').length > 0 ||
@@ -173,16 +176,17 @@ Cypress.Commands.add("navigateThroughDropdowns", (headerTitle: string) => {
                            cy.wait(200);
                            ensureDropdownOpen(dropdownSelector, itemPattern);
                            cy.get(itemSelector).filter(':visible').click();
                            processNested(nk + 1);
                            processNested(nestedIndex + 1);
                          } else {
                            cy.location('pathname').then((afterNestedPath) => {
                              if (afterNestedPath !== initialPath) {
                                cy.location("pathname").should("not.equal", initialPath);
                                cy.go('back');
                                cy.wait(200);
                              }
                              ensureDropdownOpen(dropdownSelector, itemPattern);
                              cy.get(itemSelector).filter(':visible').click();
                              processNested(nk + 1);
                              processNested(nestedIndex + 1);
                            });
                          }
                        });
@@ -191,11 +195,14 @@ Cypress.Commands.add("navigateThroughDropdowns", (headerTitle: string) => {
                      processNested(0);
                    });
                  } else if (itemText === headerTitle) {
                    processItem(ii + 1);
                    // if the redirect doesn't happen, then we are at the item of the initial route
                    cy.location("pathname").should("equal", initialPath);
                    processItem(itemIndex + 1);
                  } else {
                    cy.location("pathname").should("not.equal", initialPath);
                    cy.go('back');
                    cy.wait(200);
                    processItem(ii + 1);
                    processItem(itemIndex + 1);
                  }
                });
              });
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@
    "ngx-progressbar": "~9.0.0",
    "ngx-toastr": "~15.2.2",
    "rxjs": "~7.4.0",
    "timing-object": "~3.1.93",
    "tslib": "~2.0.0",
    "wait-on": "^8.0.4",
    "zone.js": "~0.11.8"