Skip to content

Commit ed5eca6

Browse files
authored
Merge pull request #40 from alphagov/main-7285-create-ui-for-factcheck-unhappy-path
MAIN-7285 - Add frontend handling for "unhappy" fact check response
2 parents e66aac7 + c4e1066 commit ed5eca6

File tree

7 files changed

+72
-4
lines changed

7 files changed

+72
-4
lines changed

app/views/application/confirm_response.html.erb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<% content_for :title_context, @form_data[:page_title] %>
33
<% content_for :back_link, respond_path(back: :true) %>
44
<% content_for :title, t("fact_check_verification.heading") %>
5+
<% if @errors.any? %>
6+
<% content_for :error_summary, render(partial: "application/errors/submission_error_summary") %>
7+
<% end %>
58
<div class="govuk-grid-row">
69
<div class="govuk-grid-column-two-thirds">
710
<%= form_with url: confirm_response_path,
@@ -21,8 +24,16 @@
2124
t("fact_check_response.correct") :
2225
t("fact_check_response.incorrect"),
2326
},
24-
],
25-
margin_bottom: 6,
27+
(@form_data[:status] == "incorrect" ? {
28+
field: t("fact_check_verification.factual_errors"),
29+
edit: {
30+
href: respond_path(back: :true),
31+
text: t("fact_check_verification.change_link"),
32+
},
33+
value: simple_format(@form_data[:details]),
34+
} : nil),
35+
].compact,
36+
margin_bottom: 9,
2637
} %>
2738

2839
<%= render "govuk_publishing_components/components/heading", {

app/views/application/confirmations/_response_error_summary.html.erb renamed to app/views/application/errors/_response_error_summary.html.erb

File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%= render "govuk_publishing_components/components/error_alert", {
2+
id: "api_submission_failed",
3+
message: t("fact_check_verification.error_heading"),
4+
description: t("fact_check_verification.error_description"),
5+
} %>

app/views/application/fact_check_response.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<% content_for :back_link, "_blank" %>
44
<% content_for :title, t("fact_check_response.heading") %>
55
<% if @errors.any? %>
6-
<% content_for :error_summary, render(partial: "application/confirmations/response_error_summary") %>
6+
<% content_for :error_summary, render(partial: "application/errors/response_error_summary") %>
77
<% end %>
88
<div class="govuk-grid-row">
99
<div class="govuk-grid-column-two-thirds">
@@ -30,7 +30,7 @@
3030
text: t("fact_check_response.incorrect"),
3131
id: "incorrect",
3232
checked: @errors[:details].present? || @form_data.present? && @form_data["status"] == "incorrect",
33-
conditional: render(partial: "application/confirmations/factual_error_textarea"),
33+
conditional: render(partial: "application/partials/factual_error_textarea"),
3434
},
3535
],
3636
} %>

app/views/application/confirmations/_factual_error_textarea.html.erb renamed to app/views/application/partials/_factual_error_textarea.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
name: "fact_check_response[details]",
77
textarea_id: "fact_check_details",
88
hint: sanitize(t("fact_check_response.factual_errors_hint")),
9+
value: @form_data&.dig("details"),
910
error: @errors[:details].presence,
11+
error_message: @errors[:details].present? ? t("fact_check_response.factual_errors_empty_field") : nil,
1012
rows: 18,
1113
} %>

config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ en:
2929
send_response: "Now send your response"
3030
send_response_warning: "Only one fact check response can be submitted. Make sure you’ve discussed this with colleagues first."
3131
confirm_button: "Confirm and send"
32+
error_heading: "There was a problem"
33+
error_description: "Please try submitting again"
3234
fact_check_submitted:
3335
fact_check_submitted: "Fact check submitted"
3436
fact_check_description: "Your response has been sent"

spec/controllers/fact_check_response_controller_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,53 @@
6363
expect(page).to have_text(I18n.t("fact_check_response.continue_button"))
6464
expect(page).to have_checked_field(I18n.t("fact_check_response.correct"), visible: :all)
6565
end
66+
67+
it "allows the user to enter content into the factual error textbox and have it persist to confirmation" do
68+
visit respond_path
69+
70+
expect(page).to have_text(I18n.t("fact_check_response.heading"))
71+
expect(page).to have_text(I18n.t("fact_check_response.form_heading"))
72+
expect(page).to have_text(I18n.t("fact_check_response.correct"))
73+
expect(page).to have_text(I18n.t("fact_check_response.incorrect"))
74+
expect(page).to have_button(I18n.t("fact_check_response.continue_button"))
75+
76+
choose(I18n.t("fact_check_response.incorrect"), allow_label_click: true)
77+
page.fill_in "fact_check_details", with: "Fact check error detail test string"
78+
79+
click_button(I18n.t("fact_check_response.continue_button"))
80+
81+
expect(page).to have_text(I18n.t("fact_check_response.incorrect"))
82+
expect(page).to have_text(I18n.t("fact_check_verification.factual_errors"))
83+
expect(page).to have_text("Fact check error detail test string")
84+
end
85+
86+
it "allows the user to click the change link without losing the detail contents for an incorrect response" do
87+
visit respond_path
88+
89+
expect(page).to have_text(I18n.t("fact_check_response.heading"))
90+
expect(page).to have_text(I18n.t("fact_check_response.form_heading"))
91+
expect(page).to have_text(I18n.t("fact_check_response.correct"))
92+
expect(page).to have_text(I18n.t("fact_check_response.incorrect"))
93+
expect(page).to have_button(I18n.t("fact_check_response.continue_button"))
94+
95+
choose(I18n.t("fact_check_response.incorrect"), allow_label_click: true)
96+
page.fill_in "fact_check_details", with: "Fact check error detail test string"
97+
98+
click_button(I18n.t("fact_check_response.continue_button"))
99+
100+
expect(page).to have_text(I18n.t("fact_check_response.incorrect"))
101+
expect(page).to have_text(I18n.t("fact_check_verification.factual_errors"))
102+
expect(page).to have_text("Fact check error detail test string")
103+
104+
click_link(I18n.t("fact_check_verification.change_link"), match: :first)
105+
106+
expect(page).to have_text(I18n.t("fact_check_response.heading"))
107+
expect(page).to have_text(I18n.t("fact_check_response.form_heading"))
108+
expect(page).to have_text(I18n.t("fact_check_response.correct"))
109+
expect(page).to have_text(I18n.t("fact_check_response.incorrect"))
110+
expect(page).to have_text(I18n.t("fact_check_response.continue_button"))
111+
expect(page).to have_checked_field(I18n.t("fact_check_response.incorrect"), visible: :all)
112+
expect(page).to have_text("Fact check error detail test string")
113+
end
66114
end
67115
end

0 commit comments

Comments
 (0)