add cypress login spec
This commit is contained in:
parent
75ada812bc
commit
9db7920f80
1 changed files with 41 additions and 0 deletions
41
frontend/blog_portal/cypress/e2e/login_page.cy.ts
Normal file
41
frontend/blog_portal/cypress/e2e/login_page.cy.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
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", "/");
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue