Skip to content

Commit df04fc6

Browse files
committed
Show the none of the above question on the edit question page
If "Yes, and let people provide a different answer" was selected for "Should the list include an option for ‘None of the above’?", show the question that will be asked on the edit question page with a link to change it. If the question is optional, show " (optional)" after the question.
1 parent 5bdda2a commit df04fc6

5 files changed

Lines changed: 105 additions & 3 deletions

File tree

app/components/page_settings_summary_component/view.html.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@
5353
href: @change_selections_options_path,
5454
visually_hidden_text: t("page_settings_summary.selection.include_none_of_the_above")) %>
5555
<% end %>
56+
<% if selection_none_of_the_above_question_text.present? %>
57+
<%= summary_list.with_row do |row| %>
58+
<%= row.with_key(text: t("page_settings_summary.selection.none_of_the_above_question")) %>
59+
<%= row.with_value(text: selection_none_of_the_above_question_text) %>
60+
<%= row.with_action(text: t("page_settings_summary.change"),
61+
href: change_selections_none_of_the_above_question_path,
62+
visually_hidden_text: t("page_settings_summary.selection.none_of_the_above_question")) %>
63+
<% end %>
64+
<% end %>
5665
<% end %>
5766

5867
<% if show_text_settings_summary %>

app/components/page_settings_summary_component/view.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def before_render
2020
@change_text_settings_path = change_text_settings_path
2121
@change_selections_only_one_option_path = change_selections_only_one_option_path
2222
@change_selections_options_path = change_selections_options_path
23+
@change_selections_none_of_the_above_question_path = change_selections_none_of_the_above_question_path
2324
end
2425

2526
private
@@ -45,6 +46,15 @@ def selection_options
4546
answer_settings[:selection_options]
4647
end
4748

49+
def selection_none_of_the_above_question_text
50+
none_of_the_above_question = answer_settings[:none_of_the_above_question]
51+
return unless @draft_question.is_optional? && none_of_the_above_question
52+
53+
return "#{none_of_the_above_question[:question_text]} (optional)" if none_of_the_above_question[:is_optional] == "true"
54+
55+
none_of_the_above_question[:question_text]
56+
end
57+
4858
def change_answer_type_path
4959
if is_new_question?
5060
type_of_answer_new_path(form_id: @draft_question.form_id)
@@ -98,6 +108,14 @@ def change_selections_options_path
98108
selection_options_edit_path_for_draft_question(@draft_question)
99109
end
100110

111+
def change_selections_none_of_the_above_question_path
112+
return unless @draft_question.answer_type == "selection"
113+
114+
return selection_none_of_the_above_new_path(form_id: @draft_question.form_id) if is_new_question?
115+
116+
selection_none_of_the_above_edit_path(form_id: @draft_question.form_id, page_id: @draft_question.page_id)
117+
end
118+
101119
def change_text_settings_path
102120
return unless @draft_question.answer_type == "text"
103121

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,7 @@ en:
13101310
how_many_selections: How many options can people select
13111311
include_none_of_the_above: Include an option for ‘None of the above’
13121312
'no': 'No'
1313+
none_of_the_above_question: If ‘None of the above’ is selected
13131314
options: Options
13141315
options_count: "%{number_of_options} options:"
13151316
options_summary: Show %{number_of_options} options

spec/components/page_settings_summary_component/view_spec.rb

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
let(:new_selection_type_path) { selection_type_new_path(form_id: draft_question.form_id) }
2828
let(:edit_selection_options_path) { selection_options_edit_path(form_id: draft_question.form_id, page_id: draft_question.page_id) }
2929
let(:new_selection_options_path) { selection_options_new_path(form_id: draft_question.form_id) }
30+
let(:edit_selection_none_of_the_above_path) { selection_none_of_the_above_edit_path(form_id: draft_question.form_id, page_id: draft_question.page_id) }
31+
let(:new_selection_none_of_the_above_path) { selection_none_of_the_above_new_path(form_id: draft_question.form_id) }
3032

3133
before do
3234
allow(errors).to receive(:has_key?).with(:selection_options).and_return(selection_options_error_messages.present?)
@@ -122,7 +124,7 @@
122124
end
123125
end
124126

125-
context "when 'None of the above' is a setting" do
127+
context "when 'None of the above' option is included" do
126128
let(:draft_question) { build :selection_draft_question, is_optional: true }
127129

128130
it "renders the selection settings" do
@@ -139,6 +141,45 @@
139141
expect(rows[3].find(".govuk-summary-list__key")).to have_text "Include an option for ‘None of the above’"
140142
expect(rows[3].find(".govuk-summary-list__value")).to have_text "Yes"
141143
end
144+
145+
context "when there is a question if 'None of the above' is selected" do
146+
let(:draft_question) { build :selection_draft_question, :with_mandatory_none_of_the_above_question }
147+
148+
it "includes a row for the none of the above question" do
149+
rows = page.find_all(".govuk-summary-list__row")
150+
151+
expect(rows.length).to eq(5)
152+
expect(rows[4].find(".govuk-summary-list__key")).to have_text I18n.t("page_settings_summary.selection.none_of_the_above_question")
153+
end
154+
155+
it "has a link to change the none of the above question" do
156+
expect(page).to have_link("Change #{I18n.t('page_settings_summary.selection.none_of_the_above_question')}", href: edit_selection_none_of_the_above_path)
157+
end
158+
159+
context "when the none of the above question is mandatory" do
160+
it "indicates that the none of the above question is mandatory" do
161+
rows = page.find_all(".govuk-summary-list__row")
162+
expect(rows[4].find(".govuk-summary-list__value")).to have_text "Enter your own option"
163+
end
164+
end
165+
166+
context "when the none of the above question is optional" do
167+
let(:draft_question) { build :selection_draft_question, :with_optional_none_of_the_above_question }
168+
169+
it "indicates that the none of the above question is optional" do
170+
rows = page.find_all(".govuk-summary-list__row")
171+
expect(rows[4].find(".govuk-summary-list__value")).to have_text "Enter your own option (optional)"
172+
end
173+
end
174+
end
175+
176+
context "when there is not a question if 'None of the above' is selected" do
177+
it "does not include a row for the none of the above question" do
178+
rows = page.find_all(".govuk-summary-list__row")
179+
180+
expect(rows.length).to eq(4)
181+
end
182+
end
142183
end
143184

144185
it "renders the selection settings" do
@@ -199,7 +240,7 @@
199240
end
200241

201242
context "when creating a new question" do
202-
let(:draft_question) { build :selection_draft_question, page_id: nil }
243+
let(:draft_question) { build :selection_draft_question, :with_mandatory_none_of_the_above_question, page_id: nil }
203244

204245
it "has a link to change the answer type" do
205246
expect(page).to have_link("Change #{I18n.t('page_settings_summary.answer_type')}", href: new_answer_type_path)

spec/factories/models/draft_questions.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,42 @@
5555
end
5656

5757
factory :selection_draft_question do
58+
transient do
59+
only_one_option { "true" }
60+
selection_options { [{ name: "Option 1" }, { name: "Option 2" }] }
61+
end
62+
5863
question_text { Faker::Lorem.question }
5964
answer_type { "selection" }
60-
answer_settings { { only_one_option: "true", selection_options: [{ name: "Option 1" }, { name: "Option 2" }] } }
65+
answer_settings { { only_one_option:, selection_options: } }
66+
67+
trait :with_optional_none_of_the_above_question do
68+
is_optional { true }
69+
answer_settings do
70+
{
71+
only_one_option:,
72+
selection_options:,
73+
none_of_the_above_question: {
74+
question_text: "Enter your own option",
75+
is_optional: "true",
76+
},
77+
}
78+
end
79+
end
80+
81+
trait :with_mandatory_none_of_the_above_question do
82+
is_optional { true }
83+
answer_settings do
84+
{
85+
only_one_option:,
86+
selection_options:,
87+
none_of_the_above_question: {
88+
question_text: "Enter your own option",
89+
is_optional: "false",
90+
},
91+
}
92+
end
93+
end
6194
end
6295

6396
factory :text_draft_question do

0 commit comments

Comments
 (0)