TIDE/frontend/blog_portal/cypress/e2e/login_page.cy.ts

41 lines
1.2 KiB
TypeScript

describe("login page", function () {
beforeEach(function () {
cy.resetDb();
cy.clearMail();
cy.seedConfirmedUser({
email: "alice@example.com",
displayName: "alice",
password: "longenoughpassword",
});
});
it("logs in with valid credentials and shows the user in the header", function () {
cy.visit("/login");
cy.get('input[type="email"]').type("alice@example.com");
cy.get('input[type="password"]').type("longenoughpassword");
cy.contains("button", "Log in").click();
cy.location("pathname").should("eq", "/");
cy.get(".app-header").contains("alice").should("be.visible");
});
it("shows an error on wrong password", function () {
cy.visit("/login");
cy.get('input[type="email"]').type("alice@example.com");
cy.get('input[type="password"]').type("wrongpassword");
cy.contains("button", "Log in").click();
cy.location("pathname").should("eq", "/login");
cy.contains(".error", "invalid credentials").should("be.visible");
});
it("redirects authenticated users away from /login", function () {
cy.loginViaApi({
email: "alice@example.com",
password: "longenoughpassword",
});
cy.visit("/login");
cy.location("pathname").should("eq", "/");
});
});