Commit c8962a0d authored by Kostis Trantzas's avatar Kostis Trantzas
Browse files

Resolve "Implement user journey tests"

parent b575e0de
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ npm-debug.log
yarn-error.log
testem.log
/typings
.env
cypress/fixtures
cypress/screenshots
cypress/downloads

# System Files
.DS_Store

cypress.config.ts

0 → 100644
+31 −0
Original line number Diff line number Diff line
import { defineConfig } from "cypress";
import * as dotenv from "dotenv";

dotenv.config( { path: 'cypress/.env'});

export default defineConfig({
  
  e2e: {
    setupNodeEvents(on, config) {
      require("ts-node").register({
        project: "tsconfig.json",
      });
      return config;
    },
    baseUrl: process.env.CYPRESS_BASE_URL,
    pageLoadTimeout: 16000,
    viewportWidth: 1500,
    viewportHeight: 900,
    env: {
      username: process.env.CYPRESS_username,
      password: process.env.CYPRESS_password,
      authURL: process.env.CYPRESS_AUTH_URL,
      authRealm: process.env.CYPRESS_AUTH_REALM,
      resetCredentials: process.env.CYPRESS_RESET_CREDENTIALS,
      registration: process.env.CYPRESS_REGISTRATION

      
    }
  },
});

cypress/default.env

0 → 100644
+7 −0
Original line number Diff line number Diff line
CYPRESS_username=admin
CYPRESS_password=openslice
CYPRESS_BASE_URL=http://localhost:4200/
CYPRESS_AUTH_URL=https://portal.openslice.eu/
CYPRESS_AUTH_REALM=/auth/realms/openslice/protocol/openid-connect/auth
CYPRESS_RESET_CREDENTIALS=/auth/realms/openslice/login-actions/reset-credentials
CYPRESS_REGISTRATION=/auth/realms/openslice/login-actions/registration
 No newline at end of file

cypress/e2e/auth.cy.ts

0 → 100644
+131 −0
Original line number Diff line number Diff line
describe("user authentication", () => {
  beforeEach(() => {
    cy.visit(window.location.origin);
  });

  it("should block unauthenticated user from entering a protected route", () => {
    cy.fixture("routes.json").then((data) => {
      cy.log(data.routes);
      for (let route of data.routes) {
        cy.intercept(route);
        cy.log(route);
        cy.visit(route);
        cy.location("pathname").should("equal", "/");
      }
    });
  });
  it("should display login errors when nothing is typed", () => {
    cy.get(":nth-child(1) > .nav-link").click();
    cy.location("pathname").should("equal", "/services");
    cy.get(".btn").should("contain", "Sign In").click();
    cy.origin(Cypress.env("authURL"), () => {
      cy.location("pathname").should("equal", Cypress.env("authRealm"));
      cy.get("#kc-login").click();
      cy.get("#input-error")
        .should("be.visible")
        .and("contain", "Invalid username or password.");
      cy.get('[aria-invalid="true"]').should("have.length", 2); //the 2 input fields should have selector aria-invalid = 'true'
    });
  });
  it("should display login errors when credentials are wrong", () => {
    cy.get(":nth-child(1) > .nav-link").click();
    cy.location("pathname").should("equal", "/services");
    cy.get(".btn").should("contain", "Sign In").click();
    cy.origin(Cypress.env("authURL"), () => {
      cy.location("pathname").should("equal", Cypress.env("authRealm"));

      cy.get("#username").type("test").blur();
      cy.get("#password").type("test").blur();
      cy.get("#kc-login").click();
      cy.get("#input-error")
        .should("be.visible")
        .and("contain", "Invalid username or password.");
      cy.get('[aria-invalid="true"]').should("have.length", 2); //the 2 input fields should have selector aria-invalid = 'true'
    });
  });
  it("should login, logout", () => {
    cy.loginPath(
      ":nth-child(1) > .nav-link",
      "/services"
    );
    cy.get("#navbarDropdown2").click();
    cy.window().then((win) => {
      expect(win.localStorage.getItem("access_token")).to.exist;
    });

    cy.get(
      ":nth-child(2) > .dropdown > .dropdown-menu > :nth-child(8)"
    ).click();
    cy.location("pathname").should("equal", "/");
  });
  it("forget password should work", () => {
    cy.get(":nth-child(1) > .nav-link").click();
    cy.location("pathname").should("equal", "/services");
    cy.get(".btn").should("contain", "Sign In").click();
    cy.origin(Cypress.env("authURL"), () => {
      cy.location("pathname").should("equal", Cypress.env("authRealm"));
      cy.get(":nth-child(2) > span > a").click();
      cy.log(Cypress.env("resetCredentials"));
      cy.location("pathname").should("equal", Cypress.env("resetCredentials"));
      cy.get("#username").should("exist");
    });
  });
  context("register form", () => {
    beforeEach(() => {
      cy.get(":nth-child(1) > .nav-link").click();
      cy.location("pathname").should("equal", "/services");
      cy.get(".btn").should("contain", "Sign In").click();
      cy.origin(Cypress.env("authURL"), () => {
        cy.location("pathname").should("equal", Cypress.env("authRealm"));
        cy.get("#kc-registration > span > a").click();
        cy.location("pathname").should("equal", Cypress.env("registration"));
      });
    });
    it("register form should not be empty when submitted", () => {
      cy.origin(Cypress.env("authURL") + Cypress.env("registration"), () => {
        cy.get(".pf-c-button").click();
        cy.get("#input-error-firstname")
          .should("exist")
          .and("contain", "Please specify first name.");
        cy.get("#input-error-lastname")
          .should("exist")
          .and("contain", "Please specify last name.");
        cy.get("#input-error-email")
          .should("exist")
          .and("contain", "Please specify email.");
        cy.get("#input-error-username")
          .should("exist")
          .and("contain", "Please specify username.");
        cy.get("#input-error-password")
          .should("exist")
          .and("contain", "Please specify password.");
      });
    });
    it("invalid email", () => {
      cy.origin(Cypress.env("authURL") + Cypress.env("registration"), () => {
        cy.get("#email").type("email");
        cy.get(".pf-c-button").click();
        cy.get("#input-error-email")
          .should("exist")
          .and("contain", "Invalid email address.");
        cy.get("#email").type("@example.com");
        cy.get(".pf-c-button").click();
        cy.get("#input-error-email").should("not.exist");
      });
    });
    it("confirm password field should be the same with password", () => {
      cy.origin(Cypress.env("authURL") + Cypress.env("registration"), () => {
        cy.get("#password").type("123");
        cy.get("#password-confirm").type("1234");
        cy.get(".pf-c-button").click();
        cy.get("#input-error-password-confirm")
          .should("exist")
          .and("contain", "Password confirmation doesn't match.");
        cy.get("#password").type("123");
        cy.get("#password-confirm").type("123");
        cy.get(".pf-c-button").click();
        cy.get("#input-error-password-confirm").should("not.exist");
      });
    });
  });
});
+41 −0
Original line number Diff line number Diff line
describe('logged user journeys', () => {
  beforeEach(() => {
      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", "/");
  });


  it('logs in through services', () => {
    cy.loginPath('[data-cy="servicesPortal"]', '/services');
    cy.location("pathname").should("equal", "/services/services_marketplace");
    cy.navigateThroughDropdowns("Services Marketplace");
    
  });

  it('logs in through resources', () => {
    cy.loginPath('[data-cy="resourcesPortal"]', '/resources');
    cy.location("pathname").should("equal", "/resources/resource_inventory");
    cy.navigateThroughDropdowns("Resource Inventory");

  });


  it('logs in through testing', () => {
    cy.loginPath('[data-cy="testingPortal"]', '/testing');
    cy.location("pathname").should("equal", "/testing/service_tests");
    cy.navigateThroughDropdowns("Test Instances");
  });

  
  it('logs in through products', () => {
    cy.loginPath('[data-cy="productsPortal"]', '/products');
    cy.location("pathname").should("equal", "/products/marketplace");
    cy.navigateThroughDropdowns("");
  });
})
 No newline at end of file
Loading