Skip to content

Commit b17ba15

Browse files
committed
Refactor answer-form selector expect checking
1 parent 0258811 commit b17ba15

1 file changed

Lines changed: 13 additions & 25 deletions

File tree

spec/features/questions/conditions_questions_spec.rb

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@
6767
# 27 - 8 = 19 (Questions left)
6868
expect(page).to have_text('17/19 answered')
6969

70-
condition.remove_data.each.map do |question_id|
71-
expect(page).to have_no_selector("#answer-form-#{question_id}")
72-
end
73-
74-
expected_remaining_question_ids = @all_questions_ids - condition.remove_data
75-
76-
expected_remaining_question_ids.each.map do |question_id|
77-
expect(page).to have_selector("#answer-form-#{question_id}")
78-
end
70+
check_remove_data_effect_on_answer_form_selectors(condition.remove_data)
7971

8072
# Now uncheck checkbox_conditional_question answer.
8173
within("#answer-form-#{@conditional_questions[:checkbox].id}") do
@@ -144,15 +136,8 @@
144136
# 24 -8 + 1 = 17 (Answers left)
145137
# 27 - 8 = 19 (Questions left)
146138
expect(page).to have_text('17/19 answered')
147-
condition.remove_data.each.map do |question_id|
148-
expect(page).to have_no_selector("#answer-form-#{question_id}")
149-
end
150-
151-
expected_remaining_question_ids = @all_questions_ids - condition.remove_data
152139

153-
expected_remaining_question_ids.each.map do |question_id|
154-
expect(page).to have_selector("#answer-form-#{question_id}")
155-
end
140+
check_remove_data_effect_on_answer_form_selectors(condition.remove_data)
156141

157142
# Now for radiobutton_conditional_question answer, there in no unchoose option,
158143
# so we switch options to a different option without any conditions.
@@ -223,15 +208,8 @@
223208
# 24 -8 + 1 = 17 (Answers left)
224209
# 27 - 8 = 19 (Questions left)
225210
expect(page).to have_text('17/19 answered')
226-
condition.remove_data.each.map do |question_id|
227-
expect(page).to have_no_selector("#answer-form-#{question_id}")
228-
end
229-
230-
expected_remaining_question_ids = @all_questions_ids - condition.remove_data
231211

232-
expected_remaining_question_ids.each.map do |question_id|
233-
expect(page).to have_selector("#answer-form-#{question_id}")
234-
end
212+
check_remove_data_effect_on_answer_form_selectors(condition.remove_data)
235213

236214
# Now select another option for dropdown_conditional_question.
237215
within("#answer-form-#{@conditional_questions[:dropdown].id}") do
@@ -350,4 +328,14 @@ def go_to_write_plan_page_and_verify_answered
350328
# 24 non-conditional questions in total answered.
351329
expect(page).to have_text('24/27 answered')
352330
end
331+
332+
def check_remove_data_effect_on_answer_form_selectors(remove_data)
333+
@all_questions_ids.each do |question_id|
334+
if remove_data.include?(question_id)
335+
expect(page).to have_no_selector("#answer-form-#{question_id}")
336+
else
337+
expect(page).to have_selector("#answer-form-#{question_id}")
338+
end
339+
end
340+
end
353341
end

0 commit comments

Comments
 (0)