@@ -141,5 +141,78 @@ def select_options(select_field)
141141 end
142142 end
143143 end
144+
145+ context "when a page is a select from a list question" do
146+ let ( :pages ) do
147+ [
148+ build_stubbed ( :page , :with_selection_settings , id : 101 , selection_options :) ,
149+ build_stubbed ( :page , id : 102 ) ,
150+ build_stubbed ( :page , id : 103 ) ,
151+ ]
152+ end
153+
154+ let ( :selection_options ) do
155+ [ { name : "Yes" , value : "Yes" } , { name : "No" , value : "No" } ]
156+ end
157+
158+ it "has inputs for each answer option" do
159+ render_page
160+
161+ expect ( rendered ) . to have_selector ( ".govuk-summary-list" ) do |summary_list |
162+ rows = summary_list . find_all ( ".govuk-summary-list__row" )
163+
164+ expect ( rows [ 0 ] ) . to have_selector ( '.govuk-select[name="forms_routes_input[routes_attributes][0][goto]"]' )
165+ expect ( rows [ 0 ] ) . to have_selector ( 'input[name="forms_routes_input[routes_attributes][0][page_id]"][value="101"]' , visible : :hidden )
166+ expect ( rows [ 0 ] ) . to have_selector ( 'input[name="forms_routes_input[routes_attributes][0][answer_value]"][value="Yes"]' , visible : :hidden )
167+
168+ expect ( rows [ 0 ] ) . to have_selector ( '.govuk-select[name="forms_routes_input[routes_attributes][1][goto]"]' )
169+ expect ( rows [ 0 ] ) . to have_selector ( 'input[name="forms_routes_input[routes_attributes][1][page_id]"][value="101"]' , visible : :hidden )
170+ expect ( rows [ 0 ] ) . to have_selector ( 'input[name="forms_routes_input[routes_attributes][1][answer_value]"][value="No"]' , visible : :hidden )
171+
172+ expect ( rows [ 1 ] ) . to have_selector ( '.govuk-select[name="forms_routes_input[routes_attributes][2][goto]"]' )
173+ expect ( rows [ 1 ] ) . to have_selector ( 'input[name="forms_routes_input[routes_attributes][2][page_id]"][value="102"]' , visible : :hidden )
174+
175+ expect ( rows [ 2 ] ) . not_to have_selector ( ".govuk-select" )
176+ end
177+ end
178+
179+ context "with more than 10 options" do
180+ let ( :selection_options ) do
181+ ( 1 ..11 ) . map do |i |
182+ { name : "Option #{ i } " , value : "Option #{ i } " }
183+ end
184+ end
185+
186+ it "has one route input for that question" do
187+ render_page
188+
189+ expect ( rendered ) . to have_selector ( ".govuk-summary-list" ) do |summary_list |
190+ rows = summary_list . find_all ( ".govuk-summary-list__row" )
191+
192+ expect ( rows [ 0 ] ) . to have_selector ( ".govuk-select" , count : 1 )
193+ expect ( rows [ 1 ] ) . to have_selector ( ".govuk-select" , count : 1 )
194+ expect ( rows [ 2 ] ) . not_to have_selector ( ".govuk-select" )
195+ end
196+ end
197+
198+ it "has content explaining that routes cannot be added" do
199+ render_page
200+
201+ expected_content = <<~TEXT
202+ This question has a list with more than 10 options.
203+
204+ You cannot add routes from answers if the question has more than 10 options.
205+ TEXT
206+
207+ expect ( rendered ) . to have_selector ( ".govuk-summary-list" ) do |summary_list |
208+ rows = summary_list . find_all ( ".govuk-summary-list__row" )
209+
210+ expect ( rows [ 0 ] ) . to have_text ( expected_content )
211+ expect ( rows [ 1 ] ) . not_to have_text ( expected_content )
212+ expect ( rows [ 2 ] ) . not_to have_text ( expected_content )
213+ end
214+ end
215+ end
216+ end
144217 end
145218end
0 commit comments