diff --git a/frontend/blog_portal/cypress/e2e/signup_page.cy.ts b/frontend/blog_portal/cypress/e2e/signup_page.cy.ts new file mode 100644 index 0000000..0752e66 --- /dev/null +++ b/frontend/blog_portal/cypress/e2e/signup_page.cy.ts @@ -0,0 +1,67 @@ +describe("signup page", function () { + beforeEach(function () { + cy.resetDb(); + cy.clearMail(); + }); + + it("creates an unconfirmed user and redirects to check-email", function () { + cy.visit("/signup"); + cy.get('input[type="email"]').type("alice@example.com"); + cy.get('input[autocomplete="username"]').type("alice"); + cy.contains("button", "Continue").click(); + + cy.location("pathname").should("eq", "/check-email"); + cy.contains("h1", "Check your email").should("be.visible"); + + cy.getMail().then(function (inbox) { + expect(inbox.messages).to.have.length(1); + expect(inbox.messages[0].To[0].Address).to.equal( + "alice@example.com", + ); + }); + }); + + it("surfaces a 409 when the email is already registered", function () { + cy.seedConfirmedUser({ + email: "alice@example.com", + displayName: "alice", + password: "longenoughpassword", + }); + cy.clearMail(); + + cy.visit("/signup"); + cy.get('input[type="email"]').type("alice@example.com"); + cy.get('input[autocomplete="username"]').type("alice2"); + cy.contains("button", "Continue").click(); + + cy.location("pathname").should("eq", "/signup"); + cy.contains(".error", "email already registered").should("be.visible"); + }); + + it("surfaces a 409 when the display name is taken", function () { + cy.seedConfirmedUser({ + email: "alice@example.com", + displayName: "alice", + password: "longenoughpassword", + }); + cy.clearMail(); + + cy.visit("/signup"); + cy.get('input[type="email"]').type("other@example.com"); + cy.get('input[autocomplete="username"]').type("alice"); + cy.contains("button", "Continue").click(); + + cy.location("pathname").should("eq", "/signup"); + cy.contains(".error", "displayName already taken").should("be.visible"); + }); + + it("blocks invalid display name characters client-side", function () { + cy.visit("/signup"); + cy.get('input[type="email"]').type("alice@example.com"); + cy.get('input[autocomplete="username"]').type("Has Spaces"); + cy.contains("button", "Continue").click(); + + cy.location("pathname").should("eq", "/signup"); + cy.get('input[autocomplete="username"]:invalid').should("exist"); + }); +});