|
41 | 41 | describe 'conditions with action_type remove' do |
42 | 42 | feature 'User answers a checkboxes question with a condition' do |
43 | 43 | scenario 'User answers chooses checkbox option with a condition', :js do |
| 44 | + answer_id = @conditional_questions[:checkbox].id |
44 | 45 | condition = create(:condition, question: @conditional_questions[:checkbox], |
45 | 46 | option_list: [@conditional_questions[:checkbox].question_options[2].id], |
46 | 47 | action_type: 'remove', |
|
56 | 57 | go_to_write_plan_page_and_verify_answered |
57 | 58 |
|
58 | 59 | # Answer the checkbox_conditional_question. |
59 | | - within("#answer-form-#{@conditional_questions[:checkbox].id}") do |
| 60 | + within("#answer-form-#{answer_id}") do |
60 | 61 | check @conditional_questions[:checkbox].question_options[2].text |
61 | | - click_button 'Save' |
62 | 62 | end |
63 | 63 |
|
64 | | - expect(page).to have_text('Answered just now') |
| 64 | + check_answer_save_statuses(answer_id) |
65 | 65 | # Expect 8 questions and answers that have ids in condition.remove_data to be removed, and 1 new answer added: |
66 | 66 | # 24 -8 + 1 = 17 (Answers left) |
67 | 67 | # 27 - 8 = 19 (Questions left) |
|
70 | 70 | check_remove_data_effect_on_answer_form_selectors(condition.remove_data) |
71 | 71 |
|
72 | 72 | # Now uncheck checkbox_conditional_question answer. |
73 | | - within("#answer-form-#{@conditional_questions[:checkbox].id}") do |
| 73 | + within("#answer-form-#{answer_id}") do |
74 | 74 | uncheck @conditional_questions[:checkbox].question_options[2].text |
75 | | - click_button 'Save' |
76 | 75 | end |
77 | 76 |
|
| 77 | + check_answer_save_statuses(answer_id) |
78 | 78 | # Expect 27 questions to appear again, but the 8 answers that were removed should not be there. |
79 | 79 | # Also 1 answer should be removed as we unchecked @conditional_questions[:checkbox].question_options[2].text |
80 | 80 | # 17 (from previous check) - 1 = 16 |
81 | 81 | expect(page).to have_text('16/27 answered') |
82 | 82 | end |
83 | 83 |
|
84 | 84 | scenario 'User answers chooses checkbox option without a condition', :js do |
| 85 | + answer_id = @conditional_questions[:checkbox].id |
85 | 86 | create(:condition, question: @conditional_questions[:checkbox], |
86 | 87 | option_list: [@conditional_questions[:checkbox].question_options[1].id], |
87 | 88 | action_type: 'remove', |
|
95 | 96 | go_to_write_plan_page_and_verify_answered |
96 | 97 |
|
97 | 98 | # Answer the checkbox_conditional_question |
98 | | - within("#answer-form-#{@conditional_questions[:checkbox].id}") do |
| 99 | + within("#answer-form-#{answer_id}") do |
99 | 100 | check @conditional_questions[:checkbox].question_options[0].text |
100 | | - click_button 'Save' |
101 | 101 | end |
102 | 102 |
|
103 | | - expect(page).to have_text('Answered just now') |
| 103 | + check_answer_save_statuses(answer_id) |
104 | 104 |
|
105 | 105 | # Check questions answered in progress bar. |
106 | 106 | expect(page).to have_text('25/27 answered') |
|
109 | 109 |
|
110 | 110 | feature 'User answers a radiobutton question with a condition' do |
111 | 111 | scenario 'User answers selects radiobutton option with a condition', :js do |
| 112 | + answer_id = @conditional_questions[:radiobutton].id |
112 | 113 | condition = create(:condition, question: @conditional_questions[:radiobutton], |
113 | 114 | option_list: [@conditional_questions[:radiobutton].question_options[2].id], |
114 | 115 | action_type: 'remove', |
|
124 | 125 | go_to_write_plan_page_and_verify_answered |
125 | 126 |
|
126 | 127 | # Answer the radiobutton_conditional_question. |
127 | | - within("#answer-form-#{@conditional_questions[:radiobutton].id}") do |
| 128 | + within("#answer-form-#{answer_id}") do |
128 | 129 | choose @conditional_questions[:radiobutton].question_options[2].text |
129 | | - click_button 'Save' |
130 | 130 | end |
131 | 131 |
|
132 | | - expect(page).to have_text('Answered just now') |
| 132 | + check_answer_save_statuses(answer_id) |
133 | 133 |
|
134 | 134 | # Check questions answered in progress bar. |
135 | 135 | # Expect 8 questions and answers that have ids in condition.remove_data to be removed, and 1 new answer added: |
|
141 | 141 |
|
142 | 142 | # Now for radiobutton_conditional_question answer, there in no unchoose option, |
143 | 143 | # so we switch options to a different option without any conditions. |
144 | | - within("#answer-form-#{@conditional_questions[:radiobutton].id}") do |
| 144 | + within("#answer-form-#{answer_id}") do |
145 | 145 | choose @conditional_questions[:radiobutton].question_options[0].text |
146 | | - click_button 'Save' |
147 | 146 | end |
148 | 147 |
|
| 148 | + check_answer_save_statuses(answer_id) |
149 | 149 | # Check questions answered in progress bar. |
150 | 150 | # Expect 27 questions to appear again, but the 8 answers that were removed should not be there. |
151 | 151 | # Also 1 answer should be removed as we unchecked @conditional_questions[:radiobutton].question_options[2].text |
|
154 | 154 | end |
155 | 155 |
|
156 | 156 | scenario 'User answers selects radiobutton option without a condition', :js do |
| 157 | + answer_id = @conditional_questions[:radiobutton].id |
157 | 158 | create(:condition, question: @conditional_questions[:radiobutton], |
158 | 159 | option_list: [@conditional_questions[:radiobutton].question_options[1].id], |
159 | 160 | action_type: 'remove', |
|
167 | 168 | go_to_write_plan_page_and_verify_answered |
168 | 169 |
|
169 | 170 | # Answer the radiobutton_conditional_question. |
170 | | - within("#answer-form-#{@conditional_questions[:radiobutton].id}") do |
| 171 | + within("#answer-form-#{answer_id}") do |
171 | 172 | choose @conditional_questions[:radiobutton].question_options[0].text |
172 | | - click_button 'Save' |
173 | 173 | end |
174 | 174 |
|
175 | | - expect(page).to have_text('Answered just now') |
| 175 | + check_answer_save_statuses(answer_id) |
176 | 176 |
|
177 | 177 | # Check questions answered in progress bar. |
178 | 178 | expect(page).to have_text('25/27 answered') |
|
181 | 181 |
|
182 | 182 | feature 'User answers a dropdown question with a condition' do |
183 | 183 | scenario 'User answers chooses dropdown option with a condition', :js do |
| 184 | + answer_id = @conditional_questions[:dropdown].id |
184 | 185 | condition = create(:condition, question: @conditional_questions[:dropdown], |
185 | 186 | option_list: [@conditional_questions[:dropdown].question_options[2].id], |
186 | 187 | action_type: 'remove', |
|
196 | 197 | go_to_write_plan_page_and_verify_answered |
197 | 198 |
|
198 | 199 | # Answer the dropdown_conditional_question |
199 | | - within("#answer-form-#{@conditional_questions[:dropdown].id}") do |
| 200 | + within("#answer-form-#{answer_id}") do |
200 | 201 | select(@conditional_questions[:dropdown].question_options[2].text, from: 'answer_question_option_ids') |
201 | | - click_button 'Save' |
202 | 202 | end |
203 | 203 |
|
204 | | - expect(page).to have_text('Answered just now') |
| 204 | + check_answer_save_statuses(answer_id) |
205 | 205 |
|
206 | 206 | # Check questions answered in progress bar. |
207 | 207 | # Expect 8 questions and answers that have ids in condition.remove_data to be removed, and 1 new answer added: |
|
212 | 212 | check_remove_data_effect_on_answer_form_selectors(condition.remove_data) |
213 | 213 |
|
214 | 214 | # Now select another option for dropdown_conditional_question. |
215 | | - within("#answer-form-#{@conditional_questions[:dropdown].id}") do |
| 215 | + within("#answer-form-#{answer_id}") do |
216 | 216 | select(@conditional_questions[:dropdown].question_options[1].text, from: 'answer_question_option_ids') |
217 | | - click_button 'Save' |
218 | 217 | end |
219 | 218 |
|
| 219 | + check_answer_save_statuses(answer_id) |
220 | 220 | # Check questions answered in progress bar. |
221 | 221 | # Expect 27 questions to appear again, but the 8 answers that were removed should not be there. |
222 | 222 | # 17 (from previous check as we switched answer from same dropdown) |
223 | 223 | expect(page).to have_text('17/27 answered') |
224 | 224 | end |
225 | 225 |
|
226 | 226 | scenario 'User answers select dropdown option without a condition', :js do |
| 227 | + answer_id = @conditional_questions[:dropdown].id |
227 | 228 | create(:condition, question: @conditional_questions[:dropdown], |
228 | 229 | option_list: [@conditional_questions[:dropdown].question_options[1].id], |
229 | 230 | action_type: 'remove', |
|
237 | 238 | go_to_write_plan_page_and_verify_answered |
238 | 239 |
|
239 | 240 | # Answer the dropdown_conditional_question. |
240 | | - within("#answer-form-#{@conditional_questions[:dropdown].id}") do |
| 241 | + within("#answer-form-#{answer_id}") do |
241 | 242 | select(@conditional_questions[:dropdown].question_options[0].text, from: 'answer_question_option_ids') |
242 | | - click_button 'Save' |
243 | 243 | end |
244 | 244 |
|
245 | | - expect(page).to have_text('Answered just now') |
| 245 | + check_answer_save_statuses(answer_id) |
246 | 246 |
|
247 | 247 | # Check questions answered in progress bar. |
248 | 248 | expect(page).to have_text('25/27 answered') |
|
251 | 251 | end |
252 | 252 | describe 'conditions with action_type add_webhook' do |
253 | 253 | scenario 'User answers chooses checkbox option with a condition (with action_type: add_webhook)', :js do |
| 254 | + answer_id = @conditional_questions[:checkbox].id |
254 | 255 | condition = create(:condition, :webhook, question: @conditional_questions[:checkbox], |
255 | 256 | option_list: [@conditional_questions[:checkbox].question_options[2].id]) |
256 | 257 |
|
257 | 258 | go_to_write_plan_page_and_verify_answered |
258 | 259 |
|
259 | 260 | # Answer the checkbox_conditional_question. |
260 | | - within("#answer-form-#{@conditional_questions[:checkbox].id}") do |
| 261 | + within("#answer-form-#{answer_id}") do |
261 | 262 | check @conditional_questions[:checkbox].question_options[2].text |
262 | 263 | end |
263 | 264 |
|
264 | | - expect(page).to have_text('Answered just now') |
| 265 | + check_answer_save_statuses(answer_id) |
265 | 266 |
|
266 | 267 | # Check questions answered in progress bar. |
267 | 268 | # Expect one extra answer to be added. |
|
271 | 272 | end |
272 | 273 |
|
273 | 274 | scenario 'User answers chooses radiobutton option with a condition (with action_type: add_webhook)', :js do |
| 275 | + answer_id = @conditional_questions[:radiobutton].id |
274 | 276 | condition = create(:condition, |
275 | 277 | :webhook, |
276 | 278 | question: @conditional_questions[:radiobutton], |
|
280 | 282 |
|
281 | 283 | # Now for radiobutton_conditional_question answer, there in no unchoose option, |
282 | 284 | # so we switch options to a different option without any conditions. |
283 | | - within("#answer-form-#{@conditional_questions[:radiobutton].id}") do |
| 285 | + within("#answer-form-#{answer_id}") do |
284 | 286 | choose @conditional_questions[:radiobutton].question_options[0].text |
285 | 287 | end |
286 | 288 |
|
287 | | - expect(page).to have_text('Answered just now') |
| 289 | + check_answer_save_statuses(answer_id) |
288 | 290 |
|
289 | 291 | # Check questions answered in progress bar. |
290 | 292 | # Expect one extra answer to be added. |
|
294 | 296 | end |
295 | 297 |
|
296 | 298 | scenario 'User answers chooses dropdown option with a condition (with action_type: add_webhook)', :js do |
| 299 | + answer_id = @conditional_questions[:dropdown].id |
297 | 300 | condition = create(:condition, :webhook, question: @conditional_questions[:dropdown], |
298 | 301 | option_list: [@conditional_questions[:dropdown].question_options[2].id]) |
299 | 302 |
|
300 | 303 | go_to_write_plan_page_and_verify_answered |
301 | 304 |
|
302 | 305 | # Answer the dropdown_conditional_question |
303 | | - within("#answer-form-#{@conditional_questions[:dropdown].id}") do |
| 306 | + within("#answer-form-#{answer_id}") do |
304 | 307 | select(@conditional_questions[:dropdown].question_options[2].text, from: 'answer_question_option_ids') |
305 | 308 | end |
306 | 309 |
|
307 | | - expect(page).to have_text('Answered just now') |
| 310 | + check_answer_save_statuses(answer_id) |
308 | 311 |
|
309 | 312 | # Check questions answered in progress bar. |
310 | 313 | # Expect one extra answer to be added. |
@@ -338,4 +341,15 @@ def check_remove_data_effect_on_answer_form_selectors(remove_data) |
338 | 341 | end |
339 | 342 | end |
340 | 343 | end |
| 344 | + |
| 345 | + # Checks for 'Saving' and 'Answered just now' messages |
| 346 | + def check_answer_save_statuses(answer_id) |
| 347 | + within("#answer-status-#{answer_id}") do |
| 348 | + saving_span = find('span.status[data-status="saving"]') |
| 349 | + expect(saving_span.text).to include('Saving') |
| 350 | + # We use `first()` because there are multiple span elements with `saved-at` status |
| 351 | + saved_span = first('span.status[data-status="saved-at"]') |
| 352 | + expect(saved_span.text).to include('Answered just now') |
| 353 | + end |
| 354 | + end |
341 | 355 | end |
0 commit comments