Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terms of service checkbox bug #3237

Merged
merged 3 commits into from
Oct 26, 2020
Merged

Conversation

raamSoftwire
Copy link
Contributor

@raamSoftwire raamSoftwire commented Oct 23, 2020

Context

The terms of service checkbox doesn't persist answer if there is a validation error with the email address on the sign up page.

Changes proposed in this pull request

Edit the sign up form template to read in the @sign_up_form object for the checkbox value.

Guidance to review

To test this manually:

  • Create new account on staging
  • Navigate to terms of service agreement page
  • Check checkbox, but omit email address
  • Submit page
  • Get returned to page without checkbox persisted.

Link to Trello card

https://trello.com/c/zWvC0NDW/2035-bug-terms-of-service-checkbox-doesnt-persist-answer-if-there-is-a-validation-error-with-the-email-address

Things to check

  • This code does not rely on migrations in the same Pull Request
  • If this code includes a migration adding or changing columns, it also backfills existing records for consistency
  • API release notes have been updated if necessary
  • New environment variables have been added to the Azure config

@tijmenb tijmenb temporarily deployed to apply-for-te-2035-bug-t-64ukar October 23, 2020 10:06 Inactive
@@ -29,7 +29,7 @@
<li>checking you’re safe to work with children</li>
</ul>

<%= f.govuk_check_box :accept_ts_and_cs, true, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %>
<%= f.govuk_check_box :accept_ts_and_cs, @sign_up_form.accept_ts_and_cs, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves the bug, but I'm not convinced it is the correct solution. I've had a look through the docs which suggests that this is the attribute for controlling the checkbox value.

But having a look at other checkboxes in the codebase, we haven't implemented similar changes elsewhere. The second attribute is left as true rather than taking in the property on the object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'true' seems to work just as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'true' does work on the page but I ran in to some difficulty when writing the tests.

Both true and 'true' add a value='true' attribute to the input element in both the unchecked and checked states, which meant that you couldn't distinguish between the states for the test. I don't really understand how it is working on the page.

@sign_up_form.accept_ts_and_cs only adds value='on' in the checked state, which is means we can test it easily and it is easier to reason about how it is working.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a bit to understand this!

For my understanding: what the form builder does is compare @sign_up_form.accept_ts_and_cs with whatever is the second argument to govuk_check_box.

  • When we use the boolean true, the boolean is cast to the string "true" as the value=. This means that the for compares true == "true"
  • When we use "true" or any other string, it will work because we compare the the correct things
  • When we use @sign_up_form.accept_ts_and_cs, this is initially nil, so no value= is provided. When submitting we then submit the string "on", which is compared correctly again

@raamSoftwire raamSoftwire changed the title 2035 bug terms of service checkbox Terms of service checkbox bug Oct 23, 2020
Copy link
Contributor

@tvararu tvararu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, LGTM once we add a system spec 👍

.gitignore Show resolved Hide resolved
@@ -29,7 +29,7 @@
<li>checking you’re safe to work with children</li>
</ul>

<%= f.govuk_check_box :accept_ts_and_cs, true, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %>
<%= f.govuk_check_box :accept_ts_and_cs, @sign_up_form.accept_ts_and_cs, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'true' seems to work just as well

@tvararu tvararu added the Candidate Candidate facing issue label Oct 23, 2020
@tijmenb tijmenb temporarily deployed to apply-for-te-2035-bug-t-64ukar October 26, 2020 10:54 Inactive
@raamSoftwire raamSoftwire force-pushed the 2035-bug-terms-of-service-checkbox branch from 1bb2340 to febd895 Compare October 26, 2020 10:55
@tijmenb tijmenb temporarily deployed to apply-for-te-2035-bug-t-64ukar October 26, 2020 10:55 Inactive
@raamSoftwire raamSoftwire marked this pull request as ready for review October 26, 2020 11:12
end

def and_the_ts_and_cs_are_still_checked
expect(find_field(t('authentication.sign_up.accept_terms_checkbox')).value).to eq 'on'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capybara has a cool helper for this:

Suggested change
expect(find_field(t('authentication.sign_up.accept_terms_checkbox')).value).to eq 'on'
expect(page).to have_checked_field t('authentication.sign_up.accept_terms_checkbox')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've added that in now

@@ -29,7 +29,7 @@
<li>checking you’re safe to work with children</li>
</ul>

<%= f.govuk_check_box :accept_ts_and_cs, true, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %>
<%= f.govuk_check_box :accept_ts_and_cs, @sign_up_form.accept_ts_and_cs, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a bit to understand this!

For my understanding: what the form builder does is compare @sign_up_form.accept_ts_and_cs with whatever is the second argument to govuk_check_box.

  • When we use the boolean true, the boolean is cast to the string "true" as the value=. This means that the for compares true == "true"
  • When we use "true" or any other string, it will work because we compare the the correct things
  • When we use @sign_up_form.accept_ts_and_cs, this is initially nil, so no value= is provided. When submitting we then submit the string "on", which is compared correctly again

@raamSoftwire raamSoftwire force-pushed the 2035-bug-terms-of-service-checkbox branch from febd895 to b73ce0b Compare October 26, 2020 16:14
@tijmenb tijmenb temporarily deployed to apply-for-te-2035-bug-t-64ukar October 26, 2020 16:15 Inactive
@raamSoftwire
Copy link
Contributor Author

Thanks @tijmenb for explaining what is going on and for raising the issue in the form builder repo. I've tidied up my commits and tested it all and so I think this is now ready to merge in.

Copy link
Contributor

@tijmenb tijmenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice, thanks!

@raamSoftwire raamSoftwire merged commit bf149f0 into master Oct 26, 2020
@raamSoftwire raamSoftwire deleted the 2035-bug-terms-of-service-checkbox branch October 26, 2020 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Candidate Candidate facing issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants