diff --git a/frontend/blog_portal/cypress/e2e/confirm_email_page.cy.ts b/frontend/blog_portal/cypress/e2e/confirm_email_page.cy.ts new file mode 100644 index 0000000..09415f5 --- /dev/null +++ b/frontend/blog_portal/cypress/e2e/confirm_email_page.cy.ts @@ -0,0 +1,48 @@ +describe("confirm email page", function () { + beforeEach(function () { + cy.resetDb(); + cy.clearMail(); + }); + + it("redirects to /login when no token is present", function () { + cy.visit("/confirm-email"); + cy.location("pathname").should("eq", "/login"); + }); + + it("sets the password and redirects to /login on success", function () { + cy.signupViaApi({ + email: "alice@example.com", + displayName: "alice", + }); + cy.fetchLatestConfirmToken("alice@example.com").then(function (token) { + cy.visit(`/confirm-email?token=${token}`); + cy.get('input[type="password"]').type("longenoughpassword"); + cy.contains("button", "Confirm").click(); + + cy.location("pathname").should("eq", "/login"); + + cy.loginViaApi({ + email: "alice@example.com", + password: "longenoughpassword", + }); + }); + }); + + it("shows the backend error when password is too short", function () { + cy.signupViaApi({ + email: "alice@example.com", + displayName: "alice", + }); + cy.fetchLatestConfirmToken("alice@example.com").then(function (token) { + cy.visit(`/confirm-email?token=${token}`); + cy.get('input[type="password"]') + .invoke("removeAttr", "minlength") + .type("short"); + cy.contains("button", "Confirm").click(); + + cy.contains(".error", "password must be at least 8").should( + "be.visible", + ); + }); + }); +});