From ecc303514a9a8438f427bf6768ebfe6eb39ae867 Mon Sep 17 00:00:00 2001 From: Zach Waterfield Date: Thu, 28 Mar 2024 14:06:39 -0400 Subject: [PATCH] Add e2e tests for signup form changes --- cypress/e2e/signup.cy.ts | 50 +++++++++++++++++++ .../signup/signupForm/SignupForm.tsx | 8 ++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/signup.cy.ts b/cypress/e2e/signup.cy.ts index 8c660a69a93ff..af9dd1a1ed33c 100644 --- a/cypress/e2e/signup.cy.ts +++ b/cypress/e2e/signup.cy.ts @@ -66,6 +66,56 @@ describe('Signup', () => { cy.location('pathname').should('match', /\/verify_email\/[a-zA-Z0-9_.-]*/) }) + it.only('Can submit the signup form multiple times if there is a generic email set', () => { + cy.intercept('POST', '/api/signup/').as('signupRequest') + + // Create initial account + const email = `new_user+generic_error_test@posthog.com` + cy.get('[data-attr=signup-email]').type(email).should('have.value', email) + cy.get('[data-attr=password]').type('12345678').should('have.value', '12345678') + cy.get('[data-attr=signup-start]').click() + cy.get('[data-attr=signup-name]').type('Alice Bob').should('have.value', 'Alice Bob') + cy.get('[data-attr=signup-submit]').click() + + cy.wait('@signupRequest').then((interception) => { + expect(interception.request.body).to.have.property('first_name') + expect(interception.request.body.first_name).to.equal('Alice') + expect(interception.request.body).to.have.property('last_name') + expect(interception.request.body.last_name).to.equal('Bob') + }) + + cy.visit('/signup') + + // Try to recreate account with same email- should fail + cy.get('[data-attr=signup-email]').type(email).should('have.value', email) + cy.get('[data-attr=password]').type('12345678').should('have.value', '12345678') + cy.get('[data-attr=signup-start]').click() + cy.get('[data-attr=signup-name]').type('Alice Bob').should('have.value', 'Alice Bob') + cy.get('[data-attr=signup-submit]').click() + + cy.wait('@signupRequest').then((interception) => { + cy.get('.LemonBanner').should('contain', 'There is already an account with this email address.') + }) + + cy.get('[data-attr=signup-go-back]').click() + + // Update email to generic email + const newEmail = `new_user+${Math.floor(Math.random() * 10000)}@posthog.com` + cy.get('[data-attr=signup-email]').clear().type(newEmail).should('have.value', newEmail) + cy.get('[data-attr=signup-start]').click() + cy.get('[data-attr=signup-submit]').click() + + cy.wait('@signupRequest').then((interception) => { + expect(interception.request.body).to.have.property('first_name') + expect(interception.request.body.first_name).to.equal('Alice') + expect(interception.request.body).to.have.property('last_name') + expect(interception.request.body.last_name).to.equal('Bob') + }) + + // lazy regex for a guid + cy.location('pathname').should('match', /\/verify_email\/[a-zA-Z0-9_.-]*/) + }) + it('Can create user account with just a first name', () => { cy.intercept('POST', '/api/signup/').as('signupRequest') diff --git a/frontend/src/scenes/authentication/signup/signupForm/SignupForm.tsx b/frontend/src/scenes/authentication/signup/signupForm/SignupForm.tsx index 21789742d5c5c..d42af48cf1183 100644 --- a/frontend/src/scenes/authentication/signup/signupForm/SignupForm.tsx +++ b/frontend/src/scenes/authentication/signup/signupForm/SignupForm.tsx @@ -52,7 +52,13 @@ export function SignupForm(): JSX.Element | null { <>
- } onClick={() => setPanel(panel - 1)} size="small" center> + } + onClick={() => setPanel(panel - 1)} + size="small" + center + data-attr="signup-go-back" + > or go back