decidim-forms 0.27.10 → 0.28.0.rc4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/cells/decidim/forms/answer_readonly/show.erb +1 -1
  4. data/app/cells/decidim/forms/matrix_readonly/show.erb +1 -1
  5. data/app/cells/decidim/forms/question_readonly/show.erb +8 -8
  6. data/app/cells/decidim/forms/question_readonly/title_and_description.erb +8 -0
  7. data/app/cells/decidim/forms/question_readonly_cell.rb +7 -0
  8. data/app/cells/decidim/forms/step_navigation/show.erb +13 -26
  9. data/app/cells/decidim/forms/step_navigation_cell.rb +7 -0
  10. data/app/commands/decidim/forms/answer_questionnaire.rb +31 -11
  11. data/app/controllers/decidim/forms/admin/concerns/has_questionnaire.rb +4 -4
  12. data/app/controllers/decidim/forms/admin/concerns/has_questionnaire_answers.rb +1 -1
  13. data/app/controllers/decidim/forms/concerns/has_questionnaire.rb +3 -3
  14. data/app/forms/decidim/forms/answer_form.rb +7 -3
  15. data/app/forms/decidim/forms/questionnaire_form.rb +1 -1
  16. data/app/helpers/decidim/forms/admin/application_helper.rb +1 -1
  17. data/app/helpers/decidim/forms/admin/concerns/has_questionnaire_answers_url_helper.rb +2 -2
  18. data/app/models/decidim/forms/answer.rb +1 -1
  19. data/app/models/decidim/forms/display_condition.rb +2 -2
  20. data/app/models/decidim/forms/question.rb +0 -4
  21. data/app/models/decidim/forms/questionnaire.rb +1 -1
  22. data/app/packs/entrypoints/decidim_forms.js +4 -0
  23. data/app/packs/src/decidim/forms/admin/collapsible_questions.js +12 -6
  24. data/app/packs/src/decidim/forms/admin/forms.js +7 -7
  25. data/app/packs/src/decidim/forms/display_conditions.component.js +3 -3
  26. data/app/packs/src/decidim/forms/forms.js +15 -9
  27. data/app/packs/src/decidim/forms/option_attached_inputs.component.js +1 -1
  28. data/app/packs/stylesheets/decidim/forms/forms.scss +82 -52
  29. data/app/packs/stylesheets/decidim/forms/questionnaire-answers-pdf.scss +13 -13
  30. data/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb +2 -2
  31. data/app/presenters/decidim/forms/admin_log/questionnaire_presenter.rb +2 -2
  32. data/app/presenters/decidim/forms/answer_option_presenter.rb +1 -1
  33. data/app/queries/decidim/forms/questionnaire_participants.rb +1 -1
  34. data/app/views/decidim/forms/admin/questionnaires/_answer_option.html.erb +1 -1
  35. data/app/views/decidim/forms/admin/questionnaires/_answer_option_template.html.erb +1 -1
  36. data/app/views/decidim/forms/admin/questionnaires/_display_condition.html.erb +2 -2
  37. data/app/views/decidim/forms/admin/questionnaires/_display_condition_template.html.erb +1 -1
  38. data/app/views/decidim/forms/admin/questionnaires/_form.html.erb +52 -74
  39. data/app/views/decidim/forms/admin/questionnaires/_matrix_row.html.erb +1 -1
  40. data/app/views/decidim/forms/admin/questionnaires/_matrix_row_template.html.erb +1 -1
  41. data/app/views/decidim/forms/admin/questionnaires/_question.html.erb +147 -135
  42. data/app/views/decidim/forms/admin/questionnaires/_separator.html.erb +15 -13
  43. data/app/views/decidim/forms/admin/questionnaires/_title_and_description.html.erb +69 -63
  44. data/app/views/decidim/forms/admin/questionnaires/answers/export/_answer.html.erb +4 -4
  45. data/app/views/decidim/forms/admin/questionnaires/answers/export/pdf.html.erb +1 -1
  46. data/app/views/decidim/forms/admin/questionnaires/answers/index.html.erb +41 -45
  47. data/app/views/decidim/forms/admin/questionnaires/answers/show.html.erb +13 -18
  48. data/app/views/decidim/forms/admin/questionnaires/edit.html.erb +33 -6
  49. data/app/views/decidim/forms/questionnaires/_answer.html.erb +31 -27
  50. data/app/views/decidim/forms/questionnaires/_questionnaire.html.erb +78 -0
  51. data/app/views/decidim/forms/questionnaires/_questionnaire_readonly.html.erb +11 -0
  52. data/app/views/decidim/forms/questionnaires/answers/_files.html.erb +1 -1
  53. data/app/views/decidim/forms/questionnaires/answers/_long_answer.html.erb +3 -1
  54. data/app/views/decidim/forms/questionnaires/answers/_matrix_multiple.html.erb +44 -41
  55. data/app/views/decidim/forms/questionnaires/answers/_matrix_single.html.erb +44 -41
  56. data/app/views/decidim/forms/questionnaires/answers/_multiple_option.html.erb +7 -6
  57. data/app/views/decidim/forms/questionnaires/answers/_separator.html.erb +1 -1
  58. data/app/views/decidim/forms/questionnaires/answers/_short_answer.html.erb +3 -1
  59. data/app/views/decidim/forms/questionnaires/answers/_single_option.html.erb +13 -12
  60. data/app/views/decidim/forms/questionnaires/answers/_sorting.html.erb +9 -12
  61. data/app/views/decidim/forms/questionnaires/answers/_title_and_description.html.erb +1 -1
  62. data/app/views/decidim/forms/questionnaires/show.html.erb +35 -144
  63. data/config/initializers/wicked_pdf.rb +1 -1
  64. data/config/locales/ar.yml +0 -6
  65. data/config/locales/bg.yml +0 -177
  66. data/config/locales/ca.yml +7 -2
  67. data/config/locales/cs.yml +8 -3
  68. data/config/locales/de.yml +9 -4
  69. data/config/locales/el.yml +7 -2
  70. data/config/locales/en.yml +8 -3
  71. data/config/locales/es-MX.yml +7 -2
  72. data/config/locales/es-PY.yml +7 -2
  73. data/config/locales/es.yml +7 -2
  74. data/config/locales/eu.yml +8 -3
  75. data/config/locales/fi-plain.yml +7 -2
  76. data/config/locales/fi.yml +8 -3
  77. data/config/locales/fr-CA.yml +8 -3
  78. data/config/locales/fr.yml +8 -3
  79. data/config/locales/gl.yml +0 -4
  80. data/config/locales/hu.yml +3 -9
  81. data/config/locales/id-ID.yml +0 -4
  82. data/config/locales/it.yml +0 -6
  83. data/config/locales/ja.yml +6 -1
  84. data/config/locales/lb.yml +0 -6
  85. data/config/locales/lt.yml +7 -2
  86. data/config/locales/lv.yml +0 -6
  87. data/config/locales/nl.yml +0 -6
  88. data/config/locales/no.yml +0 -6
  89. data/config/locales/pl.yml +6 -8
  90. data/config/locales/pt-BR.yml +0 -25
  91. data/config/locales/pt.yml +0 -6
  92. data/config/locales/ro-RO.yml +19 -14
  93. data/config/locales/ru.yml +0 -3
  94. data/config/locales/sk.yml +0 -6
  95. data/config/locales/sv.yml +32 -43
  96. data/config/locales/tr-TR.yml +0 -6
  97. data/config/locales/zh-CN.yml +0 -6
  98. data/config/locales/zh-TW.yml +7 -2
  99. data/lib/decidim/forms/engine.rb +8 -0
  100. data/lib/decidim/forms/test/factories.rb +37 -51
  101. data/lib/decidim/forms/test/shared_examples/has_questionnaire.rb +129 -239
  102. data/lib/decidim/forms/test/shared_examples/manage_questionnaire_answers.rb +18 -18
  103. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_display_conditions.rb +14 -14
  104. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_questions.rb +60 -78
  105. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb +6 -6
  106. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_questions.rb +25 -25
  107. data/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb +9 -9
  108. data/lib/decidim/forms/user_answers_serializer.rb +1 -1
  109. data/lib/decidim/forms/version.rb +1 -1
  110. metadata +23 -18
  111. data/app/packs/src/decidim/forms/autosortable_checkboxes.component.js +0 -83
  112. data/config/locales/he-IL.yml +0 -1
  113. data/decidim-forms.gemspec +0 -34
@@ -7,16 +7,14 @@ shared_examples_for "has questionnaire" do
7
7
  it "does not allow answering the questionnaire" do
8
8
  visit questionnaire_public_path
9
9
 
10
- expect(page).to have_i18n_content(questionnaire.title, upcase: true)
11
- expect(page).to have_i18n_content(questionnaire.description, strip_tags: true)
10
+ expect(page).to have_i18n_content(questionnaire.title)
11
+ expect(page).to have_i18n_content(questionnaire.description)
12
12
 
13
13
  expect(page).not_to have_css(".form.answer-questionnaire")
14
14
 
15
- within ".questionnaire-question_readonly" do
15
+ within "[data-question-readonly]" do
16
16
  expect(page).to have_i18n_content(question.body)
17
17
  end
18
-
19
- expect(page).to have_content("Sign in with your account or sign up to answer the form.")
20
18
  end
21
19
  end
22
20
 
@@ -28,8 +26,8 @@ shared_examples_for "has questionnaire" do
28
26
  it "allows answering the questionnaire" do
29
27
  visit questionnaire_public_path
30
28
 
31
- expect(page).to have_i18n_content(questionnaire.title, upcase: true)
32
- expect(page).to have_i18n_content(questionnaire.description, strip_tags: true)
29
+ expect(page).to have_i18n_content(questionnaire.title)
30
+ expect(page).to have_i18n_content(questionnaire.description)
33
31
 
34
32
  fill_in question.body["en"], with: "My first answer"
35
33
 
@@ -39,9 +37,7 @@ shared_examples_for "has questionnaire" do
39
37
  click_button "Submit"
40
38
  end
41
39
 
42
- within ".success.flash" do
43
- expect(page).to have_content("successfully")
44
- end
40
+ expect(page).to have_admin_callout(callout_success)
45
41
 
46
42
  visit questionnaire_public_path
47
43
 
@@ -50,31 +46,31 @@ shared_examples_for "has questionnaire" do
50
46
  end
51
47
 
52
48
  context "with multiple steps" do
53
- let!(:separator) { create(:questionnaire_question, questionnaire: questionnaire, position: 1, question_type: :separator) }
54
- let!(:question2) { create(:questionnaire_question, questionnaire: questionnaire, position: 2) }
49
+ let!(:separator) { create(:questionnaire_question, questionnaire:, position: 1, question_type: :separator) }
50
+ let!(:question2) { create(:questionnaire_question, questionnaire:, position: 2) }
55
51
 
56
52
  before do
57
53
  visit questionnaire_public_path
58
54
  end
59
55
 
60
56
  it "allows answering the first questionnaire" do
61
- expect(page).to have_content("STEP 1 OF 2")
57
+ expect(page).to have_content("Step 1 of 2")
62
58
 
63
- within ".answer-questionnaire__submit" do
64
- expect(page).to have_no_content("Back")
59
+ within ".answer-questionnaire__submit", match: :first do
60
+ expect(page).not_to have_content("Back")
65
61
  end
66
62
 
67
63
  answer_first_questionnaire
68
64
 
69
- expect(page).to have_no_selector(".success.flash")
65
+ expect(page).not_to have_selector(".success.flash")
70
66
  end
71
67
 
72
68
  it "allows revisiting previously-answered questionnaires with my answers" do
73
69
  answer_first_questionnaire
74
70
 
75
- click_link "Back"
71
+ click_button "Back"
76
72
 
77
- expect(page).to have_content("STEP 1 OF 2")
73
+ expect(page).to have_content("Step 1 of 2")
78
74
  expect(page).to have_field("questionnaire_responses_0", with: "My first answer")
79
75
  end
80
76
 
@@ -84,9 +80,7 @@ shared_examples_for "has questionnaire" do
84
80
  check "questionnaire_tos_agreement"
85
81
  accept_confirm { click_button "Submit" }
86
82
 
87
- within ".success.flash" do
88
- expect(page).to have_content("successfully")
89
- end
83
+ expect(page).to have_admin_callout(callout_success)
90
84
 
91
85
  visit questionnaire_public_path
92
86
 
@@ -94,13 +88,13 @@ shared_examples_for "has questionnaire" do
94
88
  end
95
89
 
96
90
  def answer_first_questionnaire
97
- expect(page).to have_no_selector("#questionnaire_tos_agreement")
91
+ within "#step-0" do
92
+ expect(page).not_to have_selector("#questionnaire_tos_agreement")
98
93
 
99
- fill_in question.body["en"], with: "My first answer"
100
- within ".answer-questionnaire__submit" do
101
- click_link "Continue"
94
+ fill_in question.body["en"], with: "My first answer"
95
+ click_button "Continue"
102
96
  end
103
- expect(page).to have_content("STEP 2 OF 2")
97
+ expect(page).to have_content("Step 2 of 2")
104
98
  end
105
99
  end
106
100
 
@@ -110,7 +104,7 @@ shared_examples_for "has questionnaire" do
110
104
  fill_in question.body["en"], with: "My first answer"
111
105
 
112
106
  dismiss_page_unload do
113
- page.find(".logo-wrapper a").click
107
+ page.find(".main-bar__logo a").click
114
108
  end
115
109
 
116
110
  expect(page).to have_current_path questionnaire_public_path
@@ -120,7 +114,7 @@ shared_examples_for "has questionnaire" do
120
114
  let!(:question) do
121
115
  create(
122
116
  :questionnaire_question,
123
- questionnaire: questionnaire,
117
+ questionnaire:,
124
118
  question_type: "single_option",
125
119
  position: 0,
126
120
  options: [
@@ -131,7 +125,7 @@ shared_examples_for "has questionnaire" do
131
125
  end
132
126
 
133
127
  before do
134
- answer = create(:answer, id: 1, questionnaire: questionnaire, question: question)
128
+ answer = create(:answer, id: 1, questionnaire:, question:)
135
129
 
136
130
  answer.choices.create!(
137
131
  answer_option: Decidim::Forms::AnswerOption.first,
@@ -142,21 +136,24 @@ shared_examples_for "has questionnaire" do
142
136
  it "does not leak defaults from other answers" do
143
137
  visit questionnaire_public_path
144
138
 
145
- expect(page).to have_no_selector("input[type=radio]:checked")
139
+ expect(page).not_to have_field(type: "radio", checked: true)
146
140
  end
147
141
  end
148
142
 
149
143
  shared_examples_for "a correctly ordered questionnaire" do
150
144
  it "displays the questions ordered by position starting with one" do
151
- form_fields = all(".answer-questionnaire .row")
145
+ form_fields = all(".answer-questionnaire__question")
152
146
 
153
- expect(form_fields[0]).to have_i18n_content(question.body).and have_content("1. ")
154
- expect(form_fields[1]).to have_i18n_content(other_question.body).and have_content("2. ")
147
+ expect(form_fields[0]).to have_i18n_content(question.body)
148
+ expect(form_fields[1]).to have_i18n_content(other_question.body)
149
+ 2.times do |index|
150
+ expect(form_fields[index]).to have_css("[data-answer-idx='#{index + 1}']")
151
+ end
155
152
  end
156
153
  end
157
154
 
158
155
  context "and submitting a fresh form" do
159
- let!(:other_question) { create(:questionnaire_question, questionnaire: questionnaire, position: 1) }
156
+ let!(:other_question) { create(:questionnaire_question, questionnaire:, position: 1) }
160
157
 
161
158
  before do
162
159
  visit questionnaire_public_path
@@ -166,7 +163,7 @@ shared_examples_for "has questionnaire" do
166
163
  end
167
164
 
168
165
  context "and rendering a form after errors" do
169
- let!(:other_question) { create(:questionnaire_question, questionnaire: questionnaire, position: 1) }
166
+ let!(:other_question) { create(:questionnaire_question, questionnaire:, position: 1) }
170
167
 
171
168
  before do
172
169
  visit questionnaire_public_path
@@ -180,7 +177,7 @@ shared_examples_for "has questionnaire" do
180
177
  let!(:question) do
181
178
  create(
182
179
  :questionnaire_question,
183
- questionnaire: questionnaire,
180
+ questionnaire:,
184
181
  question_type: "short_answer",
185
182
  position: 0,
186
183
  mandatory: true
@@ -208,7 +205,7 @@ shared_examples_for "has questionnaire" do
208
205
  context "when max_characters value is 0" do
209
206
  let(:max_characters) { 0 }
210
207
 
211
- it "doesn't show message indicating number of characters left" do
208
+ it "does not show message indicating number of characters left" do
212
209
  visit questionnaire_public_path
213
210
 
214
211
  expect(page).not_to have_content("characters left")
@@ -224,11 +221,8 @@ shared_examples_for "has questionnaire" do
224
221
  end
225
222
 
226
223
  it "submits the form and shows errors" do
227
- within ".alert.flash" do
228
- expect(page).to have_content("problem")
229
- end
230
-
231
- expect(page).to have_content("can't be blank")
224
+ expect(page).to have_admin_callout(callout_failure)
225
+ expect(page).to have_content("cannot be blank")
232
226
  end
233
227
  end
234
228
 
@@ -240,12 +234,12 @@ shared_examples_for "has questionnaire" do
240
234
  end
241
235
 
242
236
  it "shows errors without submitting the form" do
243
- expect(page).to have_no_selector ".alert.flash"
237
+ expect(page).not_to have_selector ".alert.flash"
244
238
  different_error = I18n.t("decidim.forms.questionnaires.answer.max_choices_alert")
245
239
  expect(different_error).to eq("There are too many choices selected")
246
240
  expect(page).not_to have_content(different_error)
247
241
 
248
- expect(page).to have_content("can't be blank")
242
+ expect(page).to have_content("cannot be blank")
249
243
  end
250
244
  end
251
245
 
@@ -253,7 +247,7 @@ shared_examples_for "has questionnaire" do
253
247
  let!(:question) do
254
248
  create(
255
249
  :questionnaire_question,
256
- questionnaire: questionnaire,
250
+ questionnaire:,
257
251
  question_type: "single_option",
258
252
  position: 0,
259
253
  mandatory: true,
@@ -273,16 +267,13 @@ shared_examples_for "has questionnaire" do
273
267
  end
274
268
 
275
269
  it "submits the form and shows errors" do
276
- within ".alert.flash" do
277
- expect(page).to have_content("problem")
278
- end
279
-
280
- expect(page).to have_content("can't be blank")
270
+ expect(page).to have_admin_callout(callout_failure)
271
+ expect(page).to have_content("cannot be blank")
281
272
  end
282
273
  end
283
274
 
284
275
  context "when a question has a rich text description" do
285
- let!(:question) { create(:questionnaire_question, questionnaire: questionnaire, position: 0, description: { en: "<b>This question is important</b>" }) }
276
+ let!(:question) { create(:questionnaire_question, questionnaire:, position: 0, description: { en: "<b>This question is important</b>" }) }
286
277
 
287
278
  it "properly interprets HTML descriptions" do
288
279
  visit questionnaire_public_path
@@ -297,9 +288,9 @@ shared_examples_for "has questionnaire" do
297
288
  let!(:question) do
298
289
  create(
299
290
  :questionnaire_question,
300
- questionnaire: questionnaire,
301
- question_type: question_type,
302
- max_characters: max_characters,
291
+ questionnaire:,
292
+ question_type:,
293
+ max_characters:,
303
294
  position: 1,
304
295
  options: [
305
296
  { "body" => answer_option_bodies[0] },
@@ -312,7 +303,7 @@ shared_examples_for "has questionnaire" do
312
303
  let!(:other_question) do
313
304
  create(
314
305
  :questionnaire_question,
315
- questionnaire: questionnaire,
306
+ questionnaire:,
316
307
  question_type: "multiple_option",
317
308
  max_choices: 2,
318
309
  position: 2,
@@ -332,7 +323,7 @@ shared_examples_for "has questionnaire" do
332
323
  let(:question_type) { "single_option" }
333
324
 
334
325
  it "renders them as radio buttons with attached text fields disabled by default" do
335
- expect(page).to have_selector(".radio-button-collection input[type=radio]", count: 3)
326
+ expect(page).to have_selector(".js-radio-button-collection input[type=radio]", count: 3)
336
327
 
337
328
  expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", disabled: true, count: 1)
338
329
 
@@ -348,10 +339,7 @@ shared_examples_for "has questionnaire" do
348
339
  check "questionnaire_tos_agreement"
349
340
  accept_confirm { click_button "Submit" }
350
341
 
351
- within ".success.flash" do
352
- expect(page).to have_content("successfully")
353
- end
354
-
342
+ expect(page).to have_admin_callout(callout_success)
355
343
  expect(Decidim::Forms::Answer.first.choices.first.custom_body).to eq("Cacatua")
356
344
  end
357
345
 
@@ -366,10 +354,7 @@ shared_examples_for "has questionnaire" do
366
354
  check "questionnaire_tos_agreement"
367
355
  accept_confirm { click_button "Submit" }
368
356
 
369
- within ".alert.flash" do
370
- expect(page).to have_content("There was a problem answering")
371
- end
372
-
357
+ expect(page).to have_admin_callout("There was a problem answering")
373
358
  expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", with: "Cacatua")
374
359
  end
375
360
 
@@ -380,7 +365,7 @@ shared_examples_for "has questionnaire" do
380
365
  let(:question_type) { "multiple_option" }
381
366
 
382
367
  it "renders them as check boxes with attached text fields disabled by default" do
383
- expect(page.first(".check-box-collection")).to have_selector("input[type=checkbox]", count: 3)
368
+ expect(page.first(".js-check-box-collection")).to have_field(type: "checkbox", count: 3)
384
369
 
385
370
  expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", disabled: true, count: 1)
386
371
 
@@ -396,10 +381,7 @@ shared_examples_for "has questionnaire" do
396
381
  check "questionnaire_tos_agreement"
397
382
  accept_confirm { click_button "Submit" }
398
383
 
399
- within ".success.flash" do
400
- expect(page).to have_content("successfully")
401
- end
402
-
384
+ expect(page).to have_admin_callout(callout_success)
403
385
  expect(Decidim::Forms::Answer.first.choices.first.custom_body).to eq("Cacatua")
404
386
  end
405
387
 
@@ -414,10 +396,7 @@ shared_examples_for "has questionnaire" do
414
396
  check "questionnaire_tos_agreement"
415
397
  accept_confirm { click_button "Submit" }
416
398
 
417
- within ".alert.flash" do
418
- expect(page).to have_content("There was a problem answering")
419
- end
420
-
399
+ expect(page).to have_admin_callout("There was a problem answering")
421
400
  expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", with: "Cacatua")
422
401
  end
423
402
 
@@ -427,7 +406,7 @@ shared_examples_for "has questionnaire" do
427
406
 
428
407
  context "when question type is long answer" do
429
408
  let(:max_characters) { 0 }
430
- let!(:question) { create(:questionnaire_question, questionnaire: questionnaire, question_type: "long_answer", max_characters: max_characters) }
409
+ let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "long_answer", max_characters:) }
431
410
 
432
411
  it "renders the answer as a textarea" do
433
412
  visit questionnaire_public_path
@@ -440,12 +419,12 @@ shared_examples_for "has questionnaire" do
440
419
 
441
420
  context "when question type is short answer" do
442
421
  let(:max_characters) { 0 }
443
- let!(:question) { create(:questionnaire_question, questionnaire: questionnaire, question_type: "short_answer", max_characters: max_characters) }
422
+ let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "short_answer", max_characters:) }
444
423
 
445
424
  it "renders the answer as a text field" do
446
425
  visit questionnaire_public_path
447
426
 
448
- expect(page).to have_selector("input[type=text]#questionnaire_responses_0")
427
+ expect(page).to have_field(id: "questionnaire_responses_0")
449
428
  end
450
429
 
451
430
  it_behaves_like "question has a character limit"
@@ -453,12 +432,12 @@ shared_examples_for "has questionnaire" do
453
432
 
454
433
  context "when question type is single option" do
455
434
  let(:answer_options) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } }
456
- let!(:question) { create(:questionnaire_question, questionnaire: questionnaire, question_type: "single_option", options: answer_options) }
435
+ let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "single_option", options: answer_options) }
457
436
 
458
437
  it "renders answers as a collection of radio buttons" do
459
438
  visit questionnaire_public_path
460
439
 
461
- expect(page).to have_selector(".radio-button-collection input[type=radio]", count: 2)
440
+ expect(page).to have_selector(".js-radio-button-collection input[type=radio]", count: 2)
462
441
 
463
442
  choose answer_options[0]["body"][:en]
464
443
 
@@ -466,9 +445,7 @@ shared_examples_for "has questionnaire" do
466
445
 
467
446
  accept_confirm { click_button "Submit" }
468
447
 
469
- within ".success.flash" do
470
- expect(page).to have_content("successfully")
471
- end
448
+ expect(page).to have_admin_callout(callout_success)
472
449
 
473
450
  visit questionnaire_public_path
474
451
 
@@ -479,14 +456,14 @@ shared_examples_for "has questionnaire" do
479
456
 
480
457
  context "when question type is multiple option" do
481
458
  let(:answer_options) { Array.new(3) { { "body" => Decidim::Faker::Localized.sentence } } }
482
- let!(:question) { create(:questionnaire_question, questionnaire: questionnaire, question_type: "multiple_option", options: answer_options) }
459
+ let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "multiple_option", options: answer_options) }
483
460
 
484
461
  it "renders answers as a collection of radio buttons" do
485
462
  visit questionnaire_public_path
486
463
 
487
- expect(page).to have_selector(".check-box-collection input[type=checkbox]", count: 3)
464
+ expect(page).to have_selector(".js-check-box-collection input[type=checkbox]", count: 3)
488
465
 
489
- expect(page).to have_no_content("Max choices:")
466
+ expect(page).not_to have_content("Max choices:")
490
467
 
491
468
  check answer_options[0]["body"][:en]
492
469
  check answer_options[1]["body"][:en]
@@ -495,9 +472,7 @@ shared_examples_for "has questionnaire" do
495
472
 
496
473
  accept_confirm { click_button "Submit" }
497
474
 
498
- within ".success.flash" do
499
- expect(page).to have_content("successfully")
500
- end
475
+ expect(page).to have_admin_callout(callout_success)
501
476
 
502
477
  visit questionnaire_public_path
503
478
 
@@ -522,29 +497,23 @@ shared_examples_for "has questionnaire" do
522
497
 
523
498
  accept_confirm { click_button "Submit" }
524
499
 
525
- within ".alert.flash" do
526
- expect(page).to have_content("There was a problem answering")
527
- end
528
-
500
+ expect(page).to have_admin_callout("There was a problem answering")
529
501
  expect(page).to have_content("are too many")
530
502
 
531
503
  uncheck answer_options[2]["body"][:en]
532
504
 
533
505
  accept_confirm { click_button "Submit" }
534
506
 
535
- within ".success.flash" do
536
- expect(page).to have_content("successfully")
537
- end
507
+ expect(page).to have_admin_callout(callout_success)
538
508
  end
539
509
  end
540
510
 
541
- context "when question type is sorting and mandatory" do
511
+ context "when question type is sorting" do
542
512
  let!(:question) do
543
513
  create(
544
514
  :questionnaire_question,
545
- questionnaire: questionnaire,
515
+ questionnaire:,
546
516
  question_type: "sorting",
547
- mandatory: true,
548
517
  options: [
549
518
  { "body" => { "en" => "chocolate" } },
550
519
  { "body" => { "en" => "like" } },
@@ -555,90 +524,32 @@ shared_examples_for "has questionnaire" do
555
524
  )
556
525
  end
557
526
 
558
- it "renders the question answers as a collection of check boxes sortable on click" do
527
+ it "renders the question answers as a collection of divs sortable on drag and drop" do
559
528
  visit questionnaire_public_path
560
529
 
561
- expect(page).to have_selector(".sortable-check-box-collection input[type=checkbox]", count: 5)
562
-
563
- expect(page).to have_content("chocolate\nlike\nWe\ndark\nall")
530
+ expect(page).to have_selector("div.answer-questionnaire__sorting.js-collection-input", count: 5)
564
531
 
565
- check "We"
566
- check "all"
567
- check "like"
568
- check "dark"
569
- check "chocolate"
570
-
571
- expect(page).to have_content("1. We\n2. all\n3. like\n4. dark\n5. chocolate")
532
+ %w(We all like dark chocolate).each do |term|
533
+ expect(page).to have_content(term)
534
+ end
572
535
  end
573
536
 
574
537
  it "properly saves valid sortings" do
575
538
  visit questionnaire_public_path
576
539
 
577
- check "We"
578
- check "all"
579
- check "like"
580
- check "dark"
581
- check "chocolate"
540
+ %w(We all like dark chocolate).reverse.each do |text|
541
+ find("div.answer-questionnaire__sorting", text:).drag_to(find("div.answer-questionnaire__sorting", match: :first))
542
+ end
582
543
 
583
544
  check "questionnaire_tos_agreement"
584
545
 
585
546
  accept_confirm { click_button "Submit" }
586
547
 
587
- within ".success.flash" do
588
- expect(page).to have_content("successfully")
589
- end
590
-
548
+ expect(page).to have_admin_callout(callout_success)
591
549
  expect(Decidim::Forms::Answer.first.choices.pluck(:position, :body)).to eq(
592
550
  [[0, "We"], [1, "all"], [2, "like"], [3, "dark"], [4, "chocolate"]]
593
551
  )
594
552
  end
595
-
596
- it "displays errors on incomplete sortings" do
597
- visit questionnaire_public_path
598
-
599
- check "We"
600
-
601
- accept_confirm { click_button "Submit" }
602
-
603
- within ".alert.flash" do
604
- expect(page).to have_content("problem")
605
- end
606
-
607
- expect(page).to have_content("are not complete")
608
- end
609
-
610
- it "displays maintains sorting order if errors" do
611
- visit questionnaire_public_path
612
-
613
- check "We"
614
- check "dark"
615
- check "chocolate"
616
-
617
- accept_confirm { click_button "Submit" }
618
-
619
- within ".alert.flash" do
620
- expect(page).to have_content("problem")
621
- end
622
-
623
- # Check the next round to ensure a re-submission conserves status
624
- expect(page).to have_content("are not complete")
625
- expect(page).to have_content("1. We\n2. dark\n3. chocolate\nlike\nall")
626
-
627
- checkboxes = page.all("input[type=checkbox]")
628
-
629
- checkboxes[0].uncheck
630
- check "We"
631
- check "all"
632
-
633
- accept_confirm { click_button "Submit" }
634
-
635
- within ".alert.flash" do
636
- expect(page).to have_content("problem")
637
- end
638
-
639
- expect(page).to have_content("are not complete")
640
- expect(page).to have_content("1. dark\n2. chocolate\n3. We\n4. all\nlike")
641
- end
642
553
  end
643
554
 
644
555
  context "when question type is matrix_single" do
@@ -649,23 +560,23 @@ shared_examples_for "has questionnaire" do
649
560
  let!(:question) do
650
561
  create(
651
562
  :questionnaire_question,
652
- questionnaire: questionnaire,
563
+ questionnaire:,
653
564
  question_type: "matrix_single",
654
565
  rows: matrix_rows,
655
566
  options: answer_options,
656
- mandatory: mandatory
567
+ mandatory:
657
568
  )
658
569
  end
659
570
 
660
571
  it "renders the question answers as a collection of radio buttons" do
661
572
  visit questionnaire_public_path
662
573
 
663
- expect(page).to have_selector(".radio-button-collection input[type=radio]", count: 4)
574
+ expect(page).to have_selector(".js-radio-button-collection input[type=radio]", count: 4)
664
575
 
665
576
  expect(page).to have_content(matrix_rows.map { |row| row["body"]["en"] }.join("\n"))
666
577
  expect(page).to have_content(answer_options.map { |option| option["body"]["en"] }.join(" "))
667
578
 
668
- radio_buttons = page.all(".radio-button-collection input[type=radio]")
579
+ radio_buttons = page.all(".js-radio-button-collection input[type=radio]")
669
580
 
670
581
  choose radio_buttons.first[:id]
671
582
  choose radio_buttons.last[:id]
@@ -674,9 +585,7 @@ shared_examples_for "has questionnaire" do
674
585
 
675
586
  accept_confirm { click_button "Submit" }
676
587
 
677
- within ".success.flash" do
678
- expect(page).to have_content("successfully")
679
- end
588
+ expect(page).to have_admin_callout(callout_success)
680
589
 
681
590
  visit questionnaire_public_path
682
591
 
@@ -692,16 +601,14 @@ shared_examples_for "has questionnaire" do
692
601
  it "preserves the chosen answers if submission not correct" do
693
602
  visit questionnaire_public_path
694
603
 
695
- radio_buttons = page.all(".radio-button-collection input[type=radio]")
604
+ radio_buttons = page.all(".js-radio-button-collection input[type=radio]")
696
605
  choose radio_buttons[1][:id]
697
606
 
698
607
  accept_confirm { click_button "Submit" }
699
608
 
700
- within ".alert.flash" do
701
- expect(page).to have_content("There was a problem answering")
702
- end
609
+ expect(page).to have_admin_callout("There was a problem answering")
703
610
 
704
- radio_buttons = page.all(".radio-button-collection input[type=radio]")
611
+ radio_buttons = page.all(".js-radio-button-collection input[type=radio]")
705
612
  expect(radio_buttons.pluck(:checked)).to eq([nil, "true", nil, nil])
706
613
  end
707
614
 
@@ -711,16 +618,13 @@ shared_examples_for "has questionnaire" do
711
618
  it "shows an error if the question is mandatory and the answer is not complete" do
712
619
  visit questionnaire_public_path
713
620
 
714
- radio_buttons = page.all(".radio-button-collection input[type=radio]")
621
+ radio_buttons = page.all(".js-radio-button-collection input[type=radio]")
715
622
  choose radio_buttons[0][:id]
716
623
 
717
624
  check "questionnaire_tos_agreement"
718
625
  accept_confirm { click_button "Submit" }
719
626
 
720
- within ".alert.flash" do
721
- expect(page).to have_content("There was a problem answering")
722
- end
723
-
627
+ expect(page).to have_admin_callout("There was a problem answering")
724
628
  expect(page).to have_content("Choices are not complete")
725
629
  end
726
630
  end
@@ -735,24 +639,24 @@ shared_examples_for "has questionnaire" do
735
639
  let!(:question) do
736
640
  create(
737
641
  :questionnaire_question,
738
- questionnaire: questionnaire,
642
+ questionnaire:,
739
643
  question_type: "matrix_multiple",
740
644
  rows: matrix_rows,
741
645
  options: answer_options,
742
- max_choices: max_choices,
743
- mandatory: mandatory
646
+ max_choices:,
647
+ mandatory:
744
648
  )
745
649
  end
746
650
 
747
651
  it "renders the question answers as a collection of check boxes" do
748
652
  visit questionnaire_public_path
749
653
 
750
- expect(page).to have_selector(".check-box-collection input[type=checkbox]", count: 6)
654
+ expect(page).to have_selector(".js-check-box-collection input[type=checkbox]", count: 6)
751
655
 
752
656
  expect(page).to have_content(matrix_rows.map { |row| row["body"]["en"] }.join("\n"))
753
657
  expect(page).to have_content(answer_options.map { |option| option["body"]["en"] }.join(" "))
754
658
 
755
- checkboxes = page.all(".check-box-collection input[type=checkbox]")
659
+ checkboxes = page.all(".js-check-box-collection input[type=checkbox]")
756
660
 
757
661
  check checkboxes[0][:id]
758
662
  check checkboxes[1][:id]
@@ -762,9 +666,7 @@ shared_examples_for "has questionnaire" do
762
666
 
763
667
  accept_confirm { click_button "Submit" }
764
668
 
765
- within ".success.flash" do
766
- expect(page).to have_content("successfully")
767
- end
669
+ expect(page).to have_admin_callout(callout_success)
768
670
 
769
671
  visit questionnaire_public_path
770
672
 
@@ -786,7 +688,7 @@ shared_examples_for "has questionnaire" do
786
688
 
787
689
  expect(page).to have_content("Max choices: 2")
788
690
 
789
- checkboxes = page.all(".check-box-collection input[type=checkbox]")
691
+ checkboxes = page.all(".js-check-box-collection input[type=checkbox]")
790
692
 
791
693
  check checkboxes[0][:id]
792
694
  check checkboxes[1][:id]
@@ -809,21 +711,16 @@ shared_examples_for "has questionnaire" do
809
711
 
810
712
  accept_confirm { click_button "Submit" }
811
713
 
812
- within ".alert.flash" do
813
- expect(page).to have_content("There was a problem answering")
814
- end
815
-
714
+ expect(page).to have_admin_callout("There was a problem answering")
816
715
  expect(page).to have_content("are too many")
817
716
 
818
- checkboxes = page.all(".check-box-collection input[type=checkbox]")
717
+ checkboxes = page.all(".js-check-box-collection input[type=checkbox]")
819
718
 
820
719
  uncheck checkboxes[5][:id]
821
720
 
822
721
  accept_confirm { click_button "Submit" }
823
722
 
824
- within ".success.flash" do
825
- expect(page).to have_content("successfully")
826
- end
723
+ expect(page).to have_admin_callout(callout_success)
827
724
  end
828
725
  end
829
726
 
@@ -833,16 +730,13 @@ shared_examples_for "has questionnaire" do
833
730
  it "shows an error" do
834
731
  visit questionnaire_public_path
835
732
 
836
- checkboxes = page.all(".check-box-collection input[type=checkbox]")
733
+ checkboxes = page.all(".js-check-box-collection input[type=checkbox]")
837
734
  check checkboxes[0][:id]
838
735
 
839
736
  check "questionnaire_tos_agreement"
840
737
  accept_confirm { click_button "Submit" }
841
738
 
842
- within ".alert.flash" do
843
- expect(page).to have_content("There was a problem answering")
844
- end
845
-
739
+ expect(page).to have_admin_callout("There was a problem answering")
846
740
  expect(page).to have_content("Choices are not complete")
847
741
  end
848
742
  end
@@ -853,7 +747,7 @@ shared_examples_for "has questionnaire" do
853
747
  it "preserves the chosen answers" do
854
748
  visit questionnaire_public_path
855
749
 
856
- checkboxes = page.all(".check-box-collection input[type=checkbox]")
750
+ checkboxes = page.all(".js-check-box-collection input[type=checkbox]")
857
751
  check checkboxes[0][:id]
858
752
  check checkboxes[1][:id]
859
753
  check checkboxes[2][:id]
@@ -862,11 +756,9 @@ shared_examples_for "has questionnaire" do
862
756
  check "questionnaire_tos_agreement"
863
757
  accept_confirm { click_button "Submit" }
864
758
 
865
- within ".alert.flash" do
866
- expect(page).to have_content("There was a problem answering")
867
- end
759
+ expect(page).to have_admin_callout("There was a problem answering")
868
760
 
869
- checkboxes = page.all(".check-box-collection input[type=checkbox]")
761
+ checkboxes = page.all(".js-check-box-collection input[type=checkbox]")
870
762
  expect(checkboxes.pluck(:checked)).to eq(["true", "true", "true", nil, nil, "true"])
871
763
  end
872
764
  end
@@ -882,11 +774,11 @@ shared_examples_for "has questionnaire" do
882
774
  end
883
775
  end
884
776
  let(:condition_question_options) { [] }
885
- let!(:question) { create(:questionnaire_question, questionnaire: questionnaire, position: 2) }
777
+ let!(:question) { create(:questionnaire_question, questionnaire:, position: 2) }
886
778
  let!(:conditioned_question_id) { "#questionnaire_responses_1" }
887
779
  let!(:condition_question) do
888
780
  create(:questionnaire_question,
889
- questionnaire: questionnaire,
781
+ questionnaire:,
890
782
  question_type: condition_question_type,
891
783
  position: 1,
892
784
  options: condition_question_options)
@@ -897,8 +789,8 @@ shared_examples_for "has questionnaire" do
897
789
  let!(:display_condition) do
898
790
  create(:display_condition,
899
791
  condition_type: "answered",
900
- question: question,
901
- condition_question: condition_question)
792
+ question:,
793
+ condition_question:)
902
794
  end
903
795
 
904
796
  before do
@@ -989,8 +881,8 @@ shared_examples_for "has questionnaire" do
989
881
  let!(:display_condition) do
990
882
  create(:display_condition,
991
883
  condition_type: "not_answered",
992
- question: question,
993
- condition_question: condition_question)
884
+ question:,
885
+ condition_question:)
994
886
  end
995
887
 
996
888
  before do
@@ -1069,8 +961,8 @@ shared_examples_for "has questionnaire" do
1069
961
  let!(:display_condition) do
1070
962
  create(:display_condition,
1071
963
  condition_type: "equal",
1072
- question: question,
1073
- condition_question: condition_question,
964
+ question:,
965
+ condition_question:,
1074
966
  answer_option: condition_question.answer_options.first)
1075
967
  end
1076
968
 
@@ -1125,8 +1017,8 @@ shared_examples_for "has questionnaire" do
1125
1017
  let!(:display_condition) do
1126
1018
  create(:display_condition,
1127
1019
  condition_type: "not_equal",
1128
- question: question,
1129
- condition_question: condition_question,
1020
+ question:,
1021
+ condition_question:,
1130
1022
  answer_option: condition_question.answer_options.first)
1131
1023
  end
1132
1024
 
@@ -1182,9 +1074,9 @@ shared_examples_for "has questionnaire" do
1182
1074
  let!(:display_condition) do
1183
1075
  create(:display_condition,
1184
1076
  condition_type: "match",
1185
- question: question,
1186
- condition_question: condition_question,
1187
- condition_value: condition_value)
1077
+ question:,
1078
+ condition_question:,
1079
+ condition_value:)
1188
1080
  end
1189
1081
 
1190
1082
  before do
@@ -1197,7 +1089,7 @@ shared_examples_for "has questionnaire" do
1197
1089
  it "shows the question only if the condition is fulfilled" do
1198
1090
  expect_question_to_be_visible(false)
1199
1091
 
1200
- fill_in "questionnaire_responses_0", with: "Aren't we all expecting #{condition_value[:en]}?"
1092
+ fill_in "questionnaire_responses_0", with: "Are not we all expecting #{condition_value[:en]}?"
1201
1093
  change_focus
1202
1094
 
1203
1095
  expect_question_to_be_visible(true)
@@ -1220,7 +1112,7 @@ shared_examples_for "has questionnaire" do
1220
1112
  it "shows the question only if the condition is fulfilled" do
1221
1113
  expect_question_to_be_visible(false)
1222
1114
 
1223
- fill_in "questionnaire_responses_0", with: "Aren't we all expecting #{condition_value[:en]}?"
1115
+ fill_in "questionnaire_responses_0", with: "Are not we all expecting #{condition_value[:en]}?"
1224
1116
  change_focus
1225
1117
 
1226
1118
  expect_question_to_be_visible(true)
@@ -1318,13 +1210,13 @@ shared_examples_for "has questionnaire" do
1318
1210
  [
1319
1211
  create(:display_condition,
1320
1212
  condition_type: "answered",
1321
- question: question,
1322
- condition_question: condition_question,
1213
+ question:,
1214
+ condition_question:,
1323
1215
  mandatory: true),
1324
1216
  create(:display_condition,
1325
1217
  condition_type: "not_equal",
1326
- question: question,
1327
- condition_question: condition_question,
1218
+ question:,
1219
+ condition_question:,
1328
1220
  mandatory: true,
1329
1221
  answer_option: condition_question.answer_options.second)
1330
1222
  ]
@@ -1350,14 +1242,14 @@ shared_examples_for "has questionnaire" do
1350
1242
  [
1351
1243
  create(:display_condition,
1352
1244
  condition_type: "equal",
1353
- question: question,
1354
- condition_question: condition_question,
1245
+ question:,
1246
+ condition_question:,
1355
1247
  mandatory: false,
1356
1248
  answer_option: condition_question.answer_options.first),
1357
1249
  create(:display_condition,
1358
1250
  condition_type: "not_equal",
1359
- question: question,
1360
- condition_question: condition_question,
1251
+ question:,
1252
+ condition_question:,
1361
1253
  mandatory: false,
1362
1254
  answer_option: condition_question.answer_options.third)
1363
1255
  ]
@@ -1383,19 +1275,19 @@ shared_examples_for "has questionnaire" do
1383
1275
 
1384
1276
  context "when a mandatory question has conditions that have not been fulfilled" do
1385
1277
  let!(:condition_question_type) { "short_answer" }
1386
- let!(:question) { create(:questionnaire_question, questionnaire: questionnaire, position: 2, mandatory: true) }
1278
+ let!(:question) { create(:questionnaire_question, questionnaire:, position: 2, mandatory: true) }
1387
1279
  let!(:display_conditions) do
1388
1280
  [
1389
1281
  create(:display_condition,
1390
1282
  condition_type: "match",
1391
- question: question,
1392
- condition_question: condition_question,
1283
+ question:,
1284
+ condition_question:,
1393
1285
  condition_value: { en: "hey", es: "ey", ca: "ei" },
1394
1286
  mandatory: true)
1395
1287
  ]
1396
1288
  end
1397
1289
 
1398
- it "doesn't throw error" do
1290
+ it "does not throw error" do
1399
1291
  visit questionnaire_public_path
1400
1292
 
1401
1293
  fill_in condition_question.body["en"], with: "My first answer"
@@ -1404,9 +1296,7 @@ shared_examples_for "has questionnaire" do
1404
1296
 
1405
1297
  accept_confirm { click_button "Submit" }
1406
1298
 
1407
- within ".success.flash" do
1408
- expect(page).to have_content("successfully")
1409
- end
1299
+ expect(page).to have_admin_callout(callout_success)
1410
1300
  end
1411
1301
  end
1412
1302
  end
@@ -1415,7 +1305,7 @@ shared_examples_for "has questionnaire" do
1415
1305
  private
1416
1306
 
1417
1307
  def expect_question_to_be_visible(visible)
1418
- expect(page).to have_css(conditioned_question_id, visible: visible)
1308
+ expect(page).to have_css(conditioned_question_id, visible:)
1419
1309
  end
1420
1310
 
1421
1311
  def change_focus