decidim-forms 0.29.6 → 0.30.0.rc1
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.
- checksums.yaml +4 -4
- data/app/cells/decidim/forms/step_navigation_cell.rb +18 -5
- data/app/commands/decidim/forms/admin/update_questionnaire.rb +1 -82
- data/app/commands/decidim/forms/admin/update_questions.rb +109 -0
- data/app/commands/decidim/forms/answer_questionnaire.rb +10 -3
- data/app/controllers/decidim/forms/admin/concerns/has_questionnaire.rb +39 -3
- data/app/controllers/decidim/forms/admin/concerns/has_questionnaire_answers.rb +2 -2
- data/app/controllers/decidim/forms/concerns/has_questionnaire.rb +12 -4
- data/app/forms/decidim/forms/admin/display_condition_form.rb +1 -1
- data/app/forms/decidim/forms/admin/questionnaire_form.rb +0 -9
- data/app/forms/decidim/forms/admin/questions_form.rb +18 -0
- data/app/forms/decidim/forms/answer_choice_form.rb +5 -0
- data/app/forms/decidim/forms/answer_form.rb +1 -0
- data/app/forms/decidim/forms/questionnaire_form.rb +7 -0
- data/app/helpers/decidim/forms/admin/concerns/has_questionnaire_answers_pagination_helper.rb +1 -1
- data/app/helpers/decidim/forms/admin/concerns/has_questionnaire_answers_url_helper.rb +5 -5
- data/app/jobs/decidim/forms/export_questionnaire_answers_job.rb +5 -1
- data/app/models/decidim/forms/answer_choice.rb +0 -2
- data/app/models/decidim/forms/answer_option.rb +1 -1
- data/app/models/decidim/forms/question.rb +10 -0
- data/app/packs/entrypoints/decidim_forms.js +0 -1
- data/app/packs/entrypoints/decidim_forms_admin.js +6 -0
- data/app/packs/src/decidim/forms/admin/publish_answers_buttons.js +72 -0
- data/app/packs/src/decidim/forms/forms.js +4 -25
- data/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb +1 -1
- data/app/presenters/decidim/forms/admin_log/question_presenter.rb +31 -0
- data/app/queries/decidim/forms/questionnaire_user_answers.rb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/_answer_option_template.html.erb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/_display_condition_template.html.erb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/_form.html.erb +0 -89
- data/app/views/decidim/forms/admin/questionnaires/_matrix_row_template.html.erb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/_question.html.erb +14 -4
- data/app/views/decidim/forms/admin/questionnaires/_questions_form.html.erb +80 -0
- data/app/views/decidim/forms/admin/questionnaires/_separator.html.erb +10 -3
- data/app/views/decidim/forms/admin/questionnaires/_title_and_description.html.erb +11 -1
- data/app/views/decidim/forms/admin/questionnaires/edit.html.erb +0 -20
- data/app/views/decidim/forms/admin/questionnaires/edit_questions.html.erb +47 -0
- data/app/views/decidim/forms/questionnaires/_answer.html.erb +1 -1
- data/app/views/decidim/forms/questionnaires/_questionnaire.html.erb +8 -1
- data/app/views/decidim/forms/questionnaires/answers/_files.html.erb +1 -1
- data/app/views/decidim/forms/questionnaires/answers/_long_answer.html.erb +1 -1
- data/app/views/decidim/forms/questionnaires/answers/_short_answer.html.erb +1 -1
- data/app/views/decidim/forms/questionnaires/answers/_sorting.html.erb +12 -6
- data/app/views/decidim/forms/questionnaires/edit.html.erb +47 -0
- data/app/views/decidim/forms/questionnaires/show.html.erb +13 -2
- data/config/assets.rb +1 -2
- data/config/locales/ar.yml +18 -1
- data/config/locales/bg.yml +42 -2
- data/config/locales/ca.yml +59 -13
- data/config/locales/cs.yml +54 -8
- data/config/locales/de.yml +56 -10
- data/config/locales/el.yml +41 -2
- data/config/locales/en.yml +51 -5
- data/config/locales/es-MX.yml +61 -15
- data/config/locales/es-PY.yml +61 -15
- data/config/locales/es.yml +60 -14
- data/config/locales/eu.yml +58 -12
- data/config/locales/fi-plain.yml +56 -10
- data/config/locales/fi.yml +56 -10
- data/config/locales/fr-CA.yml +51 -13
- data/config/locales/fr.yml +51 -13
- data/config/locales/ga-IE.yml +9 -0
- data/config/locales/gl.yml +11 -1
- data/config/locales/hu.yml +14 -1
- data/config/locales/id-ID.yml +9 -1
- data/config/locales/it.yml +31 -3
- data/config/locales/ja.yml +13 -12
- data/config/locales/lb.yml +32 -1
- data/config/locales/lt.yml +41 -2
- data/config/locales/lv.yml +15 -1
- data/config/locales/nl.yml +29 -0
- data/config/locales/no.yml +33 -0
- data/config/locales/pl.yml +43 -2
- data/config/locales/pt-BR.yml +35 -0
- data/config/locales/pt.yml +31 -0
- data/config/locales/ro-RO.yml +50 -17
- data/config/locales/ru.yml +3 -2
- data/config/locales/sk.yml +12 -1
- data/config/locales/sl.yml +7 -0
- data/config/locales/sv.yml +17 -15
- data/config/locales/tr-TR.yml +27 -0
- data/config/locales/val-ES.yml +2 -0
- data/config/locales/zh-CN.yml +27 -0
- data/config/locales/zh-TW.yml +41 -2
- data/db/migrate/20190315203056_add_session_token_to_decidim_forms_answers.rb +1 -1
- data/db/migrate/20241122142230_add_survey_answers_published_at_to_questions.rb +7 -0
- data/decidim-forms.gemspec +1 -2
- data/lib/decidim/api/answer_option_type.rb +1 -1
- data/lib/decidim/api/question_type.rb +4 -4
- data/lib/decidim/api/questionnaire_type.rb +4 -4
- data/lib/decidim/exporters/form_pdf.rb +114 -11
- data/lib/decidim/forms/download_your_data_user_answers_serializer.rb +0 -4
- data/lib/decidim/forms/test/factories.rb +2 -2
- data/lib/decidim/forms/test/shared_examples/has_questionnaire.rb +46 -7
- data/lib/decidim/forms/test/shared_examples/manage_questionnaire_answers.rb +17 -17
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_display_conditions.rb +19 -21
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_questions.rb +70 -94
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb +15 -18
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_questions.rb +115 -247
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb +3 -29
- data/lib/decidim/forms/version.rb +1 -1
- data/lib/decidim/forms.rb +0 -1
- metadata +18 -33
- data/app/packs/entrypoints/decidim_questionnaire_answers_pdf.js +0 -1
- data/app/packs/entrypoints/decidim_questionnaire_answers_pdf.scss +0 -1
- data/app/packs/stylesheets/decidim/forms/questionnaire-answers-pdf.scss +0 -69
- data/app/views/decidim/forms/admin/questionnaires/answers/export/_answer.html.erb +0 -31
- data/app/views/decidim/forms/admin/questionnaires/answers/export/pdf.html.erb +0 -13
- data/app/views/layouts/decidim/forms/admin/questionnaires/questionnaire_answers.html.erb +0 -12
- data/config/initializers/wicked_pdf.rb +0 -26
- data/config/locales/ca-IT.yml +0 -192
- data/lib/decidim/exporters/form_pdf_controller_helper.rb +0 -13
|
@@ -7,68 +7,61 @@ shared_examples_for "update questions" do
|
|
|
7
7
|
let!(:question) { create(:questionnaire_question, questionnaire:, body:) }
|
|
8
8
|
|
|
9
9
|
before do
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
click_on "Save"
|
|
11
|
+
visit_manage_questions_and_expand_all
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it "modifies the question when the information is valid" do
|
|
15
|
-
within "
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
select "Long answer", from: "Type"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
click_on "Save"
|
|
15
|
+
within ".questionnaire-question" do
|
|
16
|
+
fill_in "questions_questions_#{question.id}_body_en", with: "Modified question"
|
|
17
|
+
fill_in "questions_questions_#{question.id}_max_characters", with: 30
|
|
18
|
+
check "Mandatory"
|
|
19
|
+
select "Long answer", from: "Type"
|
|
24
20
|
end
|
|
25
21
|
|
|
22
|
+
click_on "Save"
|
|
23
|
+
|
|
26
24
|
expect(page).to have_admin_callout("successfully")
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
visit_manage_questions_and_expand_all
|
|
29
27
|
|
|
30
28
|
expect(page).to have_css("input[value='Modified question']")
|
|
31
29
|
expect(page).to have_no_css("input[value='This is the first question']")
|
|
32
|
-
expect(page).to have_css("input#
|
|
33
|
-
expect(page).to have_css("input#
|
|
34
|
-
expect(page).to have_css("select#
|
|
30
|
+
expect(page).to have_css("input#questions_questions_#{question.id}_mandatory[checked]")
|
|
31
|
+
expect(page).to have_css("input#questions_questions_#{question.id}_max_characters[value='30']")
|
|
32
|
+
expect(page).to have_css("select#questions_questions_#{question.id}_question_type option[value='long_answer'][selected]")
|
|
35
33
|
end
|
|
36
34
|
|
|
37
35
|
it "re-renders the form when the information is invalid and displays errors" do
|
|
38
36
|
expand_all_questions
|
|
39
37
|
|
|
40
|
-
within "
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
select "2", from: "Maximum number of choices"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
click_on "Save"
|
|
38
|
+
within ".questionnaire-question" do
|
|
39
|
+
expect(page).to have_content("Statement*")
|
|
40
|
+
fill_in "questions_questions_#{question.id}_body_en", with: ""
|
|
41
|
+
fill_in "questions_questions_#{question.id}_max_characters", with: -3
|
|
42
|
+
check "Mandatory"
|
|
43
|
+
select "Matrix (Multiple option)", from: "Type"
|
|
44
|
+
select "2", from: "Maximum number of choices"
|
|
51
45
|
end
|
|
52
46
|
|
|
53
|
-
|
|
47
|
+
click_on "Save"
|
|
48
|
+
click_on "Expand all questions"
|
|
54
49
|
|
|
55
50
|
expect(page).to have_admin_callout("There was a problem saving")
|
|
56
|
-
expect(page).to have_content("cannot be blank", count: 5)
|
|
51
|
+
expect(page).to have_content("cannot be blank", count: 5)
|
|
57
52
|
expect(page).to have_content("must be greater than or equal to 0", count: 1)
|
|
58
53
|
|
|
59
54
|
expect(page).to have_css("input[value='']")
|
|
60
55
|
expect(page).to have_no_css("input[value='This is the first question']")
|
|
61
|
-
expect(page).to have_css("input#
|
|
62
|
-
expect(page).to have_css("input#
|
|
56
|
+
expect(page).to have_css("input#questions_questions_#{question.id}_mandatory[checked]")
|
|
57
|
+
expect(page).to have_css("input#questions_questions_#{question.id}_max_characters[value='-3']")
|
|
58
|
+
expect(page).to have_css("select#questions_questions_#{question.id}_question_type option[value='matrix_multiple'][selected]")
|
|
63
59
|
expect(page).to have_select("Maximum number of choices", selected: "2")
|
|
64
|
-
expect(page).to have_css("select#questionnaire_questions_#{question.id}_question_type option[value='matrix_multiple'][selected]")
|
|
65
60
|
end
|
|
66
61
|
|
|
67
62
|
it "preserves deleted status across submission failures" do
|
|
68
|
-
within "
|
|
69
|
-
|
|
70
|
-
click_on "Remove"
|
|
71
|
-
end
|
|
63
|
+
within ".questionnaire-question" do
|
|
64
|
+
click_on "Remove"
|
|
72
65
|
end
|
|
73
66
|
|
|
74
67
|
click_on "Add question"
|
|
@@ -84,36 +77,28 @@ shared_examples_for "update questions" do
|
|
|
84
77
|
end
|
|
85
78
|
|
|
86
79
|
it "removes the question" do
|
|
87
|
-
within "
|
|
88
|
-
|
|
89
|
-
click_on "Remove"
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
click_on "Save"
|
|
80
|
+
within ".questionnaire-question" do
|
|
81
|
+
click_on "Remove"
|
|
93
82
|
end
|
|
94
83
|
|
|
84
|
+
click_on "Save"
|
|
85
|
+
|
|
95
86
|
expect(page).to have_admin_callout("successfully")
|
|
96
87
|
|
|
97
|
-
|
|
88
|
+
click_on "Manage questions"
|
|
98
89
|
|
|
99
|
-
|
|
100
|
-
expect(page).to have_css(".questionnaire-question", count: 0)
|
|
101
|
-
end
|
|
90
|
+
expect(page).to have_css(".questionnaire-question", count: 0)
|
|
102
91
|
end
|
|
103
92
|
|
|
104
93
|
it "cannot be moved up" do
|
|
105
|
-
within "
|
|
106
|
-
|
|
107
|
-
expect(page).to have_no_button("Up")
|
|
108
|
-
end
|
|
94
|
+
within ".questionnaire-question" do
|
|
95
|
+
expect(page).to have_no_button("Up")
|
|
109
96
|
end
|
|
110
97
|
end
|
|
111
98
|
|
|
112
99
|
it "cannot be moved down" do
|
|
113
|
-
within "
|
|
114
|
-
|
|
115
|
-
expect(page).to have_no_button("Down")
|
|
116
|
-
end
|
|
100
|
+
within ".questionnaire-question" do
|
|
101
|
+
expect(page).to have_no_button("Down")
|
|
117
102
|
end
|
|
118
103
|
end
|
|
119
104
|
end
|
|
@@ -122,22 +107,20 @@ shared_examples_for "update questions" do
|
|
|
122
107
|
let!(:question) { create(:questionnaire_question, :title_and_description, questionnaire:, body: title_and_description_body) }
|
|
123
108
|
|
|
124
109
|
before do
|
|
125
|
-
|
|
126
|
-
|
|
110
|
+
click_on "Save"
|
|
111
|
+
visit_manage_questions_and_expand_all
|
|
127
112
|
end
|
|
128
113
|
|
|
129
114
|
it "modifies the question when the information is valid" do
|
|
130
|
-
within "
|
|
131
|
-
|
|
132
|
-
fill_in "questionnaire_questions_#{question.id}_body_en", with: "Modified title and description"
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
click_on "Save"
|
|
115
|
+
within ".questionnaire-question" do
|
|
116
|
+
fill_in "questions_questions_#{question.id}_body_en", with: "Modified title and description"
|
|
136
117
|
end
|
|
137
118
|
|
|
119
|
+
click_on "Save"
|
|
120
|
+
|
|
138
121
|
expect(page).to have_admin_callout("successfully")
|
|
139
122
|
|
|
140
|
-
|
|
123
|
+
visit_manage_questions_and_expand_all
|
|
141
124
|
|
|
142
125
|
expect(page).to have_css("input[value='Modified title and description']")
|
|
143
126
|
expect(page).to have_no_css("input[value='This is the first title and description']")
|
|
@@ -146,14 +129,12 @@ shared_examples_for "update questions" do
|
|
|
146
129
|
it "re-renders the form when the information is invalid and displays errors" do
|
|
147
130
|
expand_all_questions
|
|
148
131
|
|
|
149
|
-
within "
|
|
150
|
-
|
|
151
|
-
fill_in "questionnaire_questions_#{question.id}_body_en", with: ""
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
click_on "Save"
|
|
132
|
+
within ".questionnaire-question" do
|
|
133
|
+
fill_in "questions_questions_#{question.id}_body_en", with: ""
|
|
155
134
|
end
|
|
156
135
|
|
|
136
|
+
click_on "Save"
|
|
137
|
+
|
|
157
138
|
expand_all_questions
|
|
158
139
|
|
|
159
140
|
expect(page).to have_admin_callout("There was a problem saving")
|
|
@@ -163,10 +144,8 @@ shared_examples_for "update questions" do
|
|
|
163
144
|
end
|
|
164
145
|
|
|
165
146
|
it "preserves deleted status across submission failures" do
|
|
166
|
-
within "
|
|
167
|
-
|
|
168
|
-
click_on "Remove"
|
|
169
|
-
end
|
|
147
|
+
within ".questionnaire-question" do
|
|
148
|
+
click_on "Remove"
|
|
170
149
|
end
|
|
171
150
|
|
|
172
151
|
click_on "Add question"
|
|
@@ -182,36 +161,28 @@ shared_examples_for "update questions" do
|
|
|
182
161
|
end
|
|
183
162
|
|
|
184
163
|
it "removes the question" do
|
|
185
|
-
within "
|
|
186
|
-
|
|
187
|
-
click_on "Remove"
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
click_on "Save"
|
|
164
|
+
within ".questionnaire-question" do
|
|
165
|
+
click_on "Remove"
|
|
191
166
|
end
|
|
192
167
|
|
|
168
|
+
click_on "Save"
|
|
169
|
+
|
|
193
170
|
expect(page).to have_admin_callout("successfully")
|
|
194
171
|
|
|
195
|
-
|
|
172
|
+
click_on "Manage questions"
|
|
196
173
|
|
|
197
|
-
|
|
198
|
-
expect(page).to have_css(".questionnaire-question", count: 0)
|
|
199
|
-
end
|
|
174
|
+
expect(page).to have_css(".questionnaire-question", count: 0)
|
|
200
175
|
end
|
|
201
176
|
|
|
202
177
|
it "cannot be moved up" do
|
|
203
|
-
within "
|
|
204
|
-
|
|
205
|
-
expect(page).to have_no_button("Up")
|
|
206
|
-
end
|
|
178
|
+
within ".questionnaire-question" do
|
|
179
|
+
expect(page).to have_no_button("Up")
|
|
207
180
|
end
|
|
208
181
|
end
|
|
209
182
|
|
|
210
183
|
it "cannot be moved down" do
|
|
211
|
-
within "
|
|
212
|
-
|
|
213
|
-
expect(page).to have_no_button("Down")
|
|
214
|
-
end
|
|
184
|
+
within ".questionnaire-question" do
|
|
185
|
+
expect(page).to have_no_button("Down")
|
|
215
186
|
end
|
|
216
187
|
end
|
|
217
188
|
end
|
|
@@ -233,7 +204,8 @@ shared_examples_for "update questions" do
|
|
|
233
204
|
end
|
|
234
205
|
|
|
235
206
|
before do
|
|
236
|
-
|
|
207
|
+
click_on "Save"
|
|
208
|
+
click_on "Manage questions"
|
|
237
209
|
end
|
|
238
210
|
|
|
239
211
|
it "allows deleting answer options" do
|
|
@@ -245,35 +217,31 @@ shared_examples_for "update questions" do
|
|
|
245
217
|
|
|
246
218
|
click_on "Save"
|
|
247
219
|
|
|
248
|
-
|
|
220
|
+
visit_manage_questions_and_expand_all
|
|
249
221
|
|
|
250
222
|
expect(page).to have_css(".questionnaire-question-answer-option", count: 2)
|
|
251
223
|
end
|
|
252
224
|
|
|
253
225
|
it "still removes the question even if previous editions rendered the options invalid" do
|
|
254
|
-
|
|
255
|
-
expect(page).to have_css(".questionnaire-question", count: 1)
|
|
256
|
-
|
|
257
|
-
expand_all_questions
|
|
226
|
+
expect(page).to have_css(".questionnaire-question", count: 1)
|
|
258
227
|
|
|
259
|
-
|
|
260
|
-
fill_in find_nested_form_field_locator("body_en"), with: ""
|
|
261
|
-
end
|
|
228
|
+
expand_all_questions
|
|
262
229
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
230
|
+
within ".questionnaire-question-answer-option:first-of-type" do
|
|
231
|
+
fill_in find_nested_form_field_locator("body_en"), with: ""
|
|
232
|
+
end
|
|
266
233
|
|
|
267
|
-
|
|
234
|
+
within ".questionnaire-question" do
|
|
235
|
+
click_on "Remove", match: :first
|
|
268
236
|
end
|
|
269
237
|
|
|
238
|
+
click_on "Save"
|
|
239
|
+
|
|
270
240
|
expect(page).to have_admin_callout("successfully")
|
|
271
241
|
|
|
272
|
-
|
|
242
|
+
visit_manage_questions_and_expand_all
|
|
273
243
|
|
|
274
|
-
|
|
275
|
-
expect(page).to have_css(".questionnaire-question", count: 0)
|
|
276
|
-
end
|
|
244
|
+
expect(page).to have_css(".questionnaire-question", count: 0)
|
|
277
245
|
end
|
|
278
246
|
end
|
|
279
247
|
|
|
@@ -300,7 +268,8 @@ shared_examples_for "update questions" do
|
|
|
300
268
|
end
|
|
301
269
|
|
|
302
270
|
before do
|
|
303
|
-
|
|
271
|
+
click_on "Save"
|
|
272
|
+
visit_manage_questions_and_expand_all
|
|
304
273
|
end
|
|
305
274
|
|
|
306
275
|
it "allows deleting matrix rows" do
|
|
@@ -310,7 +279,7 @@ shared_examples_for "update questions" do
|
|
|
310
279
|
|
|
311
280
|
click_on "Save"
|
|
312
281
|
|
|
313
|
-
|
|
282
|
+
visit_manage_questions_and_expand_all
|
|
314
283
|
|
|
315
284
|
within ".questionnaire-question:last-of-type" do
|
|
316
285
|
expect(page).to have_css(".questionnaire-question-matrix-row", count: 2)
|
|
@@ -319,27 +288,23 @@ shared_examples_for "update questions" do
|
|
|
319
288
|
end
|
|
320
289
|
|
|
321
290
|
it "still removes the question even if previous editions rendered the rows invalid" do
|
|
322
|
-
|
|
323
|
-
expect(page).to have_css(".questionnaire-question", count: 2)
|
|
324
|
-
|
|
325
|
-
within ".questionnaire-question-matrix-row:first-of-type" do
|
|
326
|
-
fill_in find_nested_form_field_locator("body_en"), with: ""
|
|
327
|
-
end
|
|
291
|
+
expect(page).to have_css(".questionnaire-question", count: 2)
|
|
328
292
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
293
|
+
within ".questionnaire-question-matrix-row:first-of-type" do
|
|
294
|
+
fill_in find_nested_form_field_locator("body_en"), with: ""
|
|
295
|
+
end
|
|
332
296
|
|
|
333
|
-
|
|
297
|
+
within ".questionnaire-question:last-of-type" do
|
|
298
|
+
click_on "Remove", match: :first
|
|
334
299
|
end
|
|
335
300
|
|
|
301
|
+
click_on "Save"
|
|
302
|
+
|
|
336
303
|
expect(page).to have_admin_callout("successfully")
|
|
337
304
|
|
|
338
|
-
|
|
305
|
+
visit_manage_questions_and_expand_all
|
|
339
306
|
|
|
340
|
-
|
|
341
|
-
expect(page).to have_css(".questionnaire-question", count: 1)
|
|
342
|
-
end
|
|
307
|
+
expect(page).to have_css(".questionnaire-question", count: 1)
|
|
343
308
|
end
|
|
344
309
|
end
|
|
345
310
|
|
|
@@ -352,10 +317,6 @@ shared_examples_for "update questions" do
|
|
|
352
317
|
create(:questionnaire_question, questionnaire:, body: second_body, position: 1)
|
|
353
318
|
end
|
|
354
319
|
|
|
355
|
-
let!(:question3) do
|
|
356
|
-
create(:questionnaire_question, questionnaire:, body: third_body, position: 2)
|
|
357
|
-
end
|
|
358
|
-
|
|
359
320
|
let(:first_body) do
|
|
360
321
|
{ en: "First", ca: "Primera", es: "Primera" }
|
|
361
322
|
end
|
|
@@ -364,13 +325,9 @@ shared_examples_for "update questions" do
|
|
|
364
325
|
{ en: "Second", ca: "Segona", es: "Segunda" }
|
|
365
326
|
end
|
|
366
327
|
|
|
367
|
-
let(:third_body) do
|
|
368
|
-
{ en: "Third", ca: "Tercera", es: "Tercera" }
|
|
369
|
-
end
|
|
370
|
-
|
|
371
328
|
before do
|
|
372
|
-
|
|
373
|
-
|
|
329
|
+
click_on "Save"
|
|
330
|
+
visit_manage_questions_and_expand_all
|
|
374
331
|
end
|
|
375
332
|
|
|
376
333
|
shared_examples_for "switching questions order" do
|
|
@@ -387,6 +344,26 @@ shared_examples_for "update questions" do
|
|
|
387
344
|
end
|
|
388
345
|
end
|
|
389
346
|
|
|
347
|
+
context "when moving a question up" do
|
|
348
|
+
before do
|
|
349
|
+
within ".questionnaire-question:last-of-type" do
|
|
350
|
+
click_on "Up"
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
it_behaves_like "switching questions order"
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
context "when moving a question down" do
|
|
358
|
+
before do
|
|
359
|
+
within ".questionnaire-question:first-of-type" do
|
|
360
|
+
click_on "Down"
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
it_behaves_like "switching questions order"
|
|
365
|
+
end
|
|
366
|
+
|
|
390
367
|
describe "collapsible questions" do
|
|
391
368
|
context "when clicking on Expand all button" do
|
|
392
369
|
it "expands all questions" do
|
|
@@ -482,37 +459,16 @@ shared_examples_for "update questions" do
|
|
|
482
459
|
click_on "Add question"
|
|
483
460
|
expand_all_questions
|
|
484
461
|
|
|
485
|
-
|
|
486
|
-
expect(
|
|
487
|
-
|
|
488
|
-
within question_cards[1] do
|
|
489
|
-
expect(find("input[name*='[body_en]']").value).to eq("Second")
|
|
490
|
-
end
|
|
491
|
-
within question_cards[2] do
|
|
492
|
-
expect(find("input[name*='[body_en]']").value).to eq("Third")
|
|
493
|
-
end
|
|
462
|
+
expect(page.find(".questionnaire-question:nth-of-type(1)")).to look_like_first_question
|
|
463
|
+
expect(page.find(".questionnaire-question:nth-of-type(2)")).to look_like_intermediate_question
|
|
464
|
+
expect(page.find(".questionnaire-question:nth-of-type(3)")).to look_like_last_question
|
|
494
465
|
|
|
495
466
|
within ".questionnaire-question:first-of-type" do
|
|
496
467
|
click_on "Remove"
|
|
497
468
|
end
|
|
498
469
|
|
|
499
|
-
|
|
500
|
-
expect(
|
|
501
|
-
|
|
502
|
-
# Check that the first question is now what was previously the second
|
|
503
|
-
within remaining_cards.first do
|
|
504
|
-
expect(find("input[name*='[body_en]']").value).to eq("Second")
|
|
505
|
-
end
|
|
506
|
-
|
|
507
|
-
# Check that the second question is now what was previously the third
|
|
508
|
-
within remaining_cards[1] do
|
|
509
|
-
expect(find("input[name*='[body_en]']").value).to eq("Third")
|
|
510
|
-
end
|
|
511
|
-
|
|
512
|
-
# The last question should be the new empty question
|
|
513
|
-
within remaining_cards.last do
|
|
514
|
-
expect(find("input[name*='[body_en]']").value).to eq("")
|
|
515
|
-
end
|
|
470
|
+
expect(page.all(".questionnaire-question").first).to look_like_first_question
|
|
471
|
+
expect(page.all(".questionnaire-question").last).to look_like_last_question
|
|
516
472
|
end
|
|
517
473
|
|
|
518
474
|
it "does not duplicate editors when adding new questions" do
|
|
@@ -556,94 +512,6 @@ shared_examples_for "update questions" do
|
|
|
556
512
|
end
|
|
557
513
|
end
|
|
558
514
|
|
|
559
|
-
context "when reordering questions with drag and drop", :js do
|
|
560
|
-
before do
|
|
561
|
-
expand_all_questions
|
|
562
|
-
end
|
|
563
|
-
|
|
564
|
-
it "allows moving questions using drag and drop" do
|
|
565
|
-
question_cards = all(".questionnaire-question")
|
|
566
|
-
|
|
567
|
-
# Verify initial order by checking the body field values
|
|
568
|
-
within question_cards[0] do
|
|
569
|
-
expect(find("input[name*='[body_en]']").value).to eq("First")
|
|
570
|
-
end
|
|
571
|
-
within question_cards[1] do
|
|
572
|
-
expect(find("input[name*='[body_en]']").value).to eq("Second")
|
|
573
|
-
end
|
|
574
|
-
within question_cards[2] do
|
|
575
|
-
expect(find("input[name*='[body_en]']").value).to eq("Third")
|
|
576
|
-
end
|
|
577
|
-
|
|
578
|
-
# JavaScript to simulate drag and drop.
|
|
579
|
-
page.execute_script(<<~JS)
|
|
580
|
-
var questions = document.querySelectorAll('.questionnaire-question');
|
|
581
|
-
var container = questions[0].parentNode;
|
|
582
|
-
var second = questions[1];
|
|
583
|
-
var first = questions[0];
|
|
584
|
-
|
|
585
|
-
// Move second question before first
|
|
586
|
-
container.insertBefore(second, first);
|
|
587
|
-
|
|
588
|
-
// Update position values
|
|
589
|
-
var updatedQuestions = container.querySelectorAll('.questionnaire-question');
|
|
590
|
-
updatedQuestions.forEach(function(question, index) {
|
|
591
|
-
var positionInput = question.querySelector('input[name$="[position]"]');
|
|
592
|
-
if (positionInput) positionInput.value = index;
|
|
593
|
-
});
|
|
594
|
-
JS
|
|
595
|
-
|
|
596
|
-
sleep 0.5
|
|
597
|
-
|
|
598
|
-
question_cards = all(".questionnaire-question")
|
|
599
|
-
within question_cards[0] do
|
|
600
|
-
expect(find("input[name*='[body_en]']").value).to eq("Second")
|
|
601
|
-
end
|
|
602
|
-
within question_cards[1] do
|
|
603
|
-
expect(find("input[name*='[body_en]']").value).to eq("First")
|
|
604
|
-
end
|
|
605
|
-
within question_cards[2] do
|
|
606
|
-
expect(find("input[name*='[body_en]']").value).to eq("Third")
|
|
607
|
-
end
|
|
608
|
-
end
|
|
609
|
-
|
|
610
|
-
it "persists drag and drop changes when saving" do
|
|
611
|
-
# Move second question to last position
|
|
612
|
-
page.execute_script(<<~JS)
|
|
613
|
-
var questions = document.querySelectorAll('.questionnaire-question');
|
|
614
|
-
var container = questions[0].parentNode;
|
|
615
|
-
var second = questions[1];
|
|
616
|
-
|
|
617
|
-
container.appendChild(second);
|
|
618
|
-
|
|
619
|
-
// Update the positions of questions
|
|
620
|
-
var updatedQuestions = container.querySelectorAll('.questionnaire-question');
|
|
621
|
-
updatedQuestions.forEach(function(question, index) {
|
|
622
|
-
var positionInput = question.querySelector('input[name$="[position]"]');
|
|
623
|
-
if (positionInput) positionInput.value = index;
|
|
624
|
-
});
|
|
625
|
-
JS
|
|
626
|
-
|
|
627
|
-
sleep 0.5
|
|
628
|
-
|
|
629
|
-
click_on "Save"
|
|
630
|
-
expect(page).to have_admin_callout("successfully")
|
|
631
|
-
|
|
632
|
-
visit_manage_questions_and_expand_all
|
|
633
|
-
|
|
634
|
-
question_cards = all(".questionnaire-question")
|
|
635
|
-
within question_cards[0] do
|
|
636
|
-
expect(find("input[name*='[body_en]']").value).to eq("First")
|
|
637
|
-
end
|
|
638
|
-
within question_cards[1] do
|
|
639
|
-
expect(find("input[name*='[body_en]']").value).to eq("Third")
|
|
640
|
-
end
|
|
641
|
-
within question_cards[2] do
|
|
642
|
-
expect(find("input[name*='[body_en]']").value).to eq("Second")
|
|
643
|
-
end
|
|
644
|
-
end
|
|
645
|
-
end
|
|
646
|
-
|
|
647
515
|
private
|
|
648
516
|
|
|
649
517
|
def look_like_first_question
|
|
@@ -24,30 +24,9 @@ shared_examples_for "manage questionnaires" do
|
|
|
24
24
|
}
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
it "updates the questionnaire" do
|
|
28
|
-
visit questionnaire_edit_path
|
|
29
|
-
|
|
30
|
-
new_description = {
|
|
31
|
-
en: "<p>New description</p>",
|
|
32
|
-
ca: "<p>Nova descripció</p>",
|
|
33
|
-
es: "<p>Nueva descripción</p>"
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
within "form.edit_questionnaire" do
|
|
37
|
-
fill_in_i18n_editor(:questionnaire_description, "#questionnaire-description-tabs", new_description)
|
|
38
|
-
click_on "Save"
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
expect(page).to have_admin_callout("successfully")
|
|
42
|
-
|
|
43
|
-
visit questionnaire_public_path
|
|
44
|
-
|
|
45
|
-
expect(page).to have_content("New description")
|
|
46
|
-
end
|
|
47
|
-
|
|
48
27
|
context "when the questionnaire is not already answered" do
|
|
49
28
|
before do
|
|
50
|
-
visit
|
|
29
|
+
visit manage_questions_path
|
|
51
30
|
end
|
|
52
31
|
|
|
53
32
|
it_behaves_like "add questions"
|
|
@@ -61,7 +40,7 @@ shared_examples_for "manage questionnaires" do
|
|
|
61
40
|
let!(:answer) { create(:answer, questionnaire:, question:) }
|
|
62
41
|
|
|
63
42
|
it "cannot modify questionnaire questions" do
|
|
64
|
-
visit
|
|
43
|
+
visit manage_questions_path
|
|
65
44
|
|
|
66
45
|
expect(page).to have_no_content("Add question")
|
|
67
46
|
expect(page).to have_no_content("Remove")
|
|
@@ -112,13 +91,8 @@ shared_examples_for "manage questionnaires" do
|
|
|
112
91
|
find(".button.expand-all").click
|
|
113
92
|
end
|
|
114
93
|
|
|
115
|
-
def visit_questionnaire_edit_path_and_expand_all
|
|
116
|
-
visit questionnaire_edit_path
|
|
117
|
-
expand_all_questions
|
|
118
|
-
end
|
|
119
|
-
|
|
120
94
|
def visit_manage_questions_and_expand_all
|
|
121
|
-
|
|
95
|
+
click_on "Manage questions"
|
|
122
96
|
expand_all_questions
|
|
123
97
|
end
|
|
124
98
|
end
|