Retain registration form data on failed submission (#13614)

* Retain registration form data on failed submission

* Remove unnecessary command

* Apply suggestions from code review

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Fix e2e test

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
This commit is contained in:
Michael Kohl 2021-05-04 10:52:20 +07:00 committed by GitHub
parent 198f778b32
commit aee05b4597
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View file

@ -4,7 +4,7 @@
<%= flash[:notice] %>
</div>
<% end %>
<%= form_for(User.new, as: :user, data: { testid: "registration-form" }, url: registration_path(:user)) do |f| %>
<%= form_for(@user, as: :user, data: { testid: "registration-form" }, url: registration_path(:user)) do |f| %>
<% if defined?(resource) && resource&.errors&.any? %>
<div class="crayons-card crayons-card--secondary crayons-notice crayons-notice--danger" role="alert" data-testid="signup-errors">
<div class="crayons-card__header">

View file

@ -0,0 +1,27 @@
describe('Sign up with email', () => {
beforeEach(() => {
cy.testSetup();
cy.visit('/enter?state=new-user');
});
// Regression test for #11099
it('should preserve the form data on unsuccesful submissions', () => {
cy.findByRole('link', { name: /Sign up with Email/ }).click();
cy.findByLabelText('Profile image').attachFile('images/admin-image.png');
cy.findByLabelText('Name').type('Sloan');
cy.findByLabelText('Username').type('s');
cy.findByLabelText('Email').type('sloan@example.com');
cy.findByLabelText('Password').type('password');
cy.findByLabelText('Password confirmation').type('password');
cy.findByRole('button', { name: 'Sign up' }).click();
// The validation failed but the user's data is not lost
cy.get('li')
.contains('Username is too short (minimum is 2 characters)')
.should('be.visible');
cy.findByLabelText('Name').should('have.value', 'Sloan');
cy.findByLabelText('Username').should('have.value', 's');
cy.findByLabelText('Email').should('have.value', 'sloan@example.com');
});
});

View file

@ -11,6 +11,7 @@ seeder = Seeder.new
Settings::UserExperience.public = true
SiteConfig.waiting_on_first_user = false
Settings::Authentication.allow_email_password_registration = true
##############################################################################