Browse Source

CLDC-642: Soft validation UI bug fix (#82)

* Soft validation UI needs to be on both questions being validated

* Fix whether the box is checked or not

* All checkboxes are integers now

* Fix

* Use enums as well for consistency

* Use capybara matcher for less flakiness

* Click link already waits

* Add a retry to our fetch so tests are more resilient to intermittent network issues
pull/85/head
Daniel Baark 3 years ago committed by GitHub
parent
commit
dbef8dfba4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/constants/db_enums.rb
  2. 14
      app/javascript/controllers/soft_validations_controller.js
  3. 1
      app/models/case_log.rb
  4. 2
      app/validations/soft_validations.rb
  5. 3
      app/views/form/_validation_override_question.html.erb
  6. 9
      config/forms/2021_2022.json
  7. 2
      spec/features/case_log_spec.rb

7
app/constants/db_enums.rb

@ -213,6 +213,13 @@ module DbEnums
} }
end end
def self.override_soft_validation
{
"No" => 0,
"Yes" => 1,
}
end
def self.benefits def self.benefits
{ {
"All" => 1, "All" => 1,

14
app/javascript/controllers/soft_validations_controller.js

@ -5,8 +5,13 @@ export default class extends Controller {
initialize() { initialize() {
let url = window.location.href + "/soft_validations" let url = window.location.href + "/soft_validations"
this.fetch_retry(url, { headers: { accept: "application/json" } }, 2)
}
fetch_retry(url, options, n) {
let self = this
let div = this.overrideTarget let div = this.overrideTarget
fetch(url, { headers: { accept: "application/json" } }) fetch(url, options)
.then(response => response.json()) .then(response => response.json())
.then((response) => { .then((response) => {
if(response["show"]){ if(response["show"]){
@ -22,7 +27,10 @@ export default class extends Controller {
button.checked = false button.checked = false
}) })
} }
} })
) .catch(function(error) {
if (n === 1) throw error
return self.fetch_retry(url, options, n - 1)
})
} }
} }

1
app/models/case_log.rb

@ -65,6 +65,7 @@ class CaseLog < ApplicationRecord
enum leftreg: DbEnums.leftreg, _suffix: true enum leftreg: DbEnums.leftreg, _suffix: true
enum illness: DbEnums.illness, _suffix: true enum illness: DbEnums.illness, _suffix: true
enum preg_occ: DbEnums.pregnancy, _suffix: true enum preg_occ: DbEnums.pregnancy, _suffix: true
enum override_net_income_validation: DbEnums.override_soft_validation, _suffix: true
enum housingneeds_a: DbEnums.polar, _suffix: true enum housingneeds_a: DbEnums.polar, _suffix: true
enum housingneeds_b: DbEnums.polar, _suffix: true enum housingneeds_b: DbEnums.polar, _suffix: true
enum housingneeds_c: DbEnums.polar, _suffix: true enum housingneeds_c: DbEnums.polar, _suffix: true

2
app/validations/soft_validations.rb

@ -8,7 +8,7 @@ module SoftValidations
end end
def soft_errors_overridden? def soft_errors_overridden?
!public_send(soft_errors.keys.first).zero? if soft_errors.present? public_send(soft_errors.keys.first) == "Yes" if soft_errors.present?
end end
private private

3
app/views/form/_validation_override_question.html.erb

@ -8,7 +8,8 @@
hint: { text: "soft-validations-placeholder-hint-text" } do %> hint: { text: "soft-validations-placeholder-hint-text" } do %>
<%= f.govuk_check_box page_info["soft_validations"]&.keys&.first, page_info["soft_validations"]&.keys&.first, <%= f.govuk_check_box page_info["soft_validations"]&.keys&.first, page_info["soft_validations"]&.keys&.first,
label: { text: "Yes" } label: { text: "Yes" },
checked: @case_log[page_info["soft_validations"]&.keys&.first] == "Yes"
%> %>
<% end %> <% end %>
</div> </div>

9
config/forms/2021_2022.json

@ -315,6 +315,15 @@
"10": "Prefer not to say" "10": "Prefer not to say"
} }
} }
},
"soft_validations": {
"override_net_income_validation": {
"check_answer_label": "Net income confirmed?",
"type": "validation_override",
"answer_options": {
"override_net_income_validation": "Yes"
}
}
} }
}, },
"household_number_of_other_members": { "household_number_of_other_members": {

2
spec/features/case_log_spec.rb

@ -431,7 +431,7 @@ RSpec.describe "Test Features" do
fill_in("case-log-earnings-field", with: income_under_soft_limit) fill_in("case-log-earnings-field", with: income_under_soft_limit)
click_button("Save and continue") click_button("Save and continue")
click_link(text: "Back") click_link(text: "Back")
expect(page).not_to have_content("Are you sure this is correct?") expect(page).to have_no_content("Are you sure this is correct?")
end end
it "does not clear the confirmation question if the page is returned to using the back button and the amount is still over the soft limit", js: true do it "does not clear the confirmation question if the page is returned to using the back button and the amount is still over the soft limit", js: true do

Loading…
Cancel
Save