Skip to content

Commit

Permalink
Add e2e tests for signup form changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zlwaterfield committed Mar 28, 2024
1 parent 9dd2501 commit ecc3035
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
50 changes: 50 additions & 0 deletions cypress/e2e/signup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `[email protected]`
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')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ export function SignupForm(): JSX.Element | null {
<>
<SignupPanel2 />
<div className="flex justify-center">
<LemonButton icon={<IconArrowLeft />} onClick={() => setPanel(panel - 1)} size="small" center>
<LemonButton
icon={<IconArrowLeft />}
onClick={() => setPanel(panel - 1)}
size="small"
center
data-attr="signup-go-back"
>
or go back
</LemonButton>
</div>
Expand Down

0 comments on commit ecc3035

Please sign in to comment.