Skip to content
Snippets Groups Projects

Draft: Resolve "Implement user journey tests"

Open trantzas requested to merge 26-implement-user-journey-tests into develop
1 file
+ 0
26178
Compare changes
  • Side-by-side
  • Inline
+ 131
0
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(2) > .container > .row > :nth-child(2) > a > .btn",
"/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");
});
});
});
});
Loading