decidim-forms 0.30.1 → 0.31.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/README.md +10 -10
- data/app/cells/decidim/forms/matrix_readonly/show.erb +1 -1
- data/app/cells/decidim/forms/matrix_readonly_cell.rb +3 -3
- data/app/cells/decidim/forms/question_readonly/show.erb +5 -5
- data/app/cells/decidim/forms/question_readonly/title_and_description.erb +3 -3
- data/app/cells/decidim/forms/response_readonly_cell.rb +9 -0
- data/app/cells/decidim/forms/step_navigation/show.erb +3 -3
- data/app/cells/decidim/forms/step_navigation_cell.rb +3 -3
- data/app/commands/decidim/forms/admin/update_questions.rb +6 -6
- data/app/commands/decidim/forms/{answer_questionnaire.rb → response_questionnaire.rb} +35 -35
- data/app/controllers/decidim/forms/admin/concerns/has_questionnaire.rb +12 -12
- data/app/controllers/decidim/forms/admin/concerns/{has_questionnaire_answers.rb → has_questionnaire_responses.rb} +23 -19
- data/app/controllers/decidim/forms/concerns/has_questionnaire.rb +38 -33
- data/app/forms/decidim/forms/admin/display_condition_form.rb +14 -14
- data/app/forms/decidim/forms/admin/question_form.rb +3 -3
- data/app/forms/decidim/forms/admin/{answer_option_form.rb → response_option_form.rb} +3 -3
- data/app/forms/decidim/forms/questionnaire_form.rb +8 -9
- data/app/forms/decidim/forms/{answer_choice_form.rb → response_choice_form.rb} +5 -5
- data/app/forms/decidim/forms/{answer_form.rb → response_form.rb} +9 -9
- data/app/helpers/decidim/forms/admin/application_helper.rb +2 -2
- data/app/helpers/decidim/forms/admin/concerns/{has_questionnaire_answers_pagination_helper.rb → has_questionnaire_responses_pagination_helper.rb} +4 -4
- data/app/helpers/decidim/forms/admin/concerns/{has_questionnaire_answers_url_helper.rb → has_questionnaire_responses_url_helper.rb} +5 -5
- data/app/helpers/decidim/forms/admin/questionnaire_responses_helper.rb +32 -0
- data/app/helpers/decidim/forms/application_helper.rb +1 -2
- data/app/jobs/decidim/forms/{export_questionnaire_answers_job.rb → export_questionnaire_responses_job.rb} +5 -5
- data/app/models/decidim/forms/display_condition.rb +20 -20
- data/app/models/decidim/forms/question.rb +14 -13
- data/app/models/decidim/forms/question_matrix_row.rb +1 -1
- data/app/models/decidim/forms/questionnaire.rb +11 -6
- data/app/models/decidim/forms/{answer.rb → response.rb} +9 -9
- data/app/models/decidim/forms/response_choice.rb +22 -0
- data/app/models/decidim/forms/{answer_option.rb → response_option.rb} +5 -5
- data/app/packs/entrypoints/decidim_forms_admin.js +3 -3
- data/app/packs/src/decidim/forms/admin/collapsible_questions.js +12 -10
- data/app/packs/src/decidim/forms/admin/forms.js +35 -35
- data/app/packs/src/decidim/forms/admin/{publish_answers_buttons.js → publish_responses_buttons.js} +12 -12
- data/app/packs/src/decidim/forms/display_conditions.component.js +12 -12
- data/app/packs/src/decidim/forms/forms.js +4 -4
- data/app/packs/stylesheets/decidim/forms/forms.scss +2 -2
- data/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb +13 -13
- data/app/presenters/decidim/forms/admin/{questionnaire_answer_presenter.rb → questionnaire_response_presenter.rb} +15 -15
- data/app/presenters/decidim/forms/admin_log/question_presenter.rb +3 -3
- data/app/presenters/decidim/forms/{answer_option_presenter.rb → response_option_presenter.rb} +2 -2
- data/app/queries/decidim/forms/questionnaire_participant.rb +5 -5
- data/app/queries/decidim/forms/questionnaire_participants.rb +6 -6
- data/app/queries/decidim/forms/questionnaire_user_responses.rb +32 -0
- data/app/views/decidim/forms/admin/questionnaires/_display_condition.html.erb +9 -9
- data/app/views/decidim/forms/admin/questionnaires/_form.html.erb +2 -2
- data/app/views/decidim/forms/admin/questionnaires/_matrix_row.html.erb +3 -3
- data/app/views/decidim/forms/admin/questionnaires/_question.html.erb +16 -16
- data/app/views/decidim/forms/admin/questionnaires/_questions_form.html.erb +11 -10
- data/app/views/decidim/forms/admin/questionnaires/{_answer_option.html.erb → _response_option.html.erb} +7 -7
- data/app/views/decidim/forms/admin/questionnaires/_response_option_template.html.erb +7 -0
- data/app/views/decidim/forms/admin/questionnaires/_separator.html.erb +10 -7
- data/app/views/decidim/forms/admin/questionnaires/_title_and_description.html.erb +7 -7
- data/app/views/decidim/forms/admin/questionnaires/edit.html.erb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/edit_questions.html.erb +8 -8
- data/app/views/decidim/forms/admin/questionnaires/responses/index.html.erb +80 -0
- data/app/views/decidim/forms/admin/questionnaires/responses/show.html.erb +43 -0
- data/app/views/decidim/forms/questionnaires/_questionnaire.html.erb +22 -26
- data/app/views/decidim/forms/questionnaires/_questionnaire_readonly.html.erb +8 -3
- data/app/views/decidim/forms/questionnaires/_response.html.erb +61 -0
- data/app/views/decidim/forms/questionnaires/edit.html.erb +2 -2
- data/app/views/decidim/forms/questionnaires/responses/_files.html.erb +1 -0
- data/app/views/decidim/forms/questionnaires/responses/_long_response.html.erb +3 -0
- data/app/views/decidim/forms/questionnaires/{answers → responses}/_matrix_multiple.html.erb +16 -15
- data/app/views/decidim/forms/questionnaires/{answers → responses}/_matrix_single.html.erb +17 -16
- data/app/views/decidim/forms/questionnaires/responses/_multiple_option.html.erb +26 -0
- data/app/views/decidim/forms/questionnaires/responses/_separator.html.erb +1 -0
- data/app/views/decidim/forms/questionnaires/responses/_short_response.html.erb +3 -0
- data/app/views/decidim/forms/questionnaires/responses/_single_option.html.erb +33 -0
- data/app/views/decidim/forms/questionnaires/responses/_sorting.html.erb +26 -0
- data/app/views/decidim/forms/questionnaires/responses/_title_and_description.html.erb +1 -0
- data/app/views/decidim/forms/questionnaires/show.html.erb +10 -10
- data/config/assets.rb +2 -2
- data/config/locales/ar.yml +0 -22
- data/config/locales/bg.yml +3 -36
- data/config/locales/ca-IT.yml +73 -73
- data/config/locales/ca.yml +73 -73
- data/config/locales/cs.yml +72 -75
- data/config/locales/de.yml +72 -72
- data/config/locales/el.yml +3 -36
- data/config/locales/en.yml +83 -83
- data/config/locales/es-MX.yml +75 -75
- data/config/locales/es-PY.yml +75 -75
- data/config/locales/es.yml +73 -73
- data/config/locales/eu.yml +72 -72
- data/config/locales/fi-plain.yml +71 -71
- data/config/locales/fi.yml +69 -69
- data/config/locales/fr-CA.yml +70 -67
- data/config/locales/fr.yml +70 -67
- data/config/locales/ga-IE.yml +0 -7
- data/config/locales/gl.yml +0 -22
- data/config/locales/hu.yml +0 -22
- data/config/locales/id-ID.yml +0 -22
- data/config/locales/it.yml +3 -40
- data/config/locales/ja.yml +80 -80
- data/config/locales/lb.yml +3 -36
- data/config/locales/lt.yml +3 -36
- data/config/locales/lv.yml +0 -22
- data/config/locales/nl.yml +3 -36
- data/config/locales/no.yml +3 -36
- data/config/locales/pl.yml +3 -36
- data/config/locales/pt-BR.yml +3 -36
- data/config/locales/pt.yml +3 -36
- data/config/locales/ro-RO.yml +22 -51
- data/config/locales/ru.yml +0 -9
- data/config/locales/sk.yml +0 -22
- data/config/locales/sl.yml +0 -5
- data/config/locales/sv.yml +83 -55
- data/config/locales/tr-TR.yml +3 -36
- data/config/locales/zh-CN.yml +3 -36
- data/config/locales/zh-TW.yml +3 -36
- data/db/migrate/20190315203056_add_session_token_to_decidim_forms_answers.rb +1 -1
- data/db/migrate/20250314150250_rename_answer_to_response_in_decidim_forms.rb +30 -0
- data/db/migrate/20250319130003_change_question_types_in_questions.rb +14 -0
- data/lib/decidim/api/question_matrix_row_type.rb +13 -0
- data/lib/decidim/api/question_type.rb +4 -3
- data/lib/decidim/api/questionnaire_type.rb +1 -0
- data/lib/decidim/api/response_option_type.rb +13 -0
- data/lib/decidim/exporters/form_pdf.rb +33 -33
- data/lib/decidim/forms/api.rb +2 -1
- data/lib/decidim/forms/{download_your_data_user_answers_serializer.rb → download_your_data_user_responses_serializer.rb} +3 -3
- data/lib/decidim/forms/engine.rb +2 -2
- data/lib/decidim/forms/test/factories.rb +24 -24
- data/lib/decidim/forms/test/shared_examples/has_questionnaire.rb +179 -178
- data/lib/decidim/forms/test/shared_examples/manage_questionnaire_responses.rb +159 -0
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_display_conditions.rb +19 -19
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_questions.rb +44 -44
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb +10 -10
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_questions.rb +18 -18
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb +4 -4
- data/lib/decidim/forms/test.rb +1 -1
- data/lib/decidim/forms/user_responses_serializer.rb +110 -0
- data/lib/decidim/forms/version.rb +1 -1
- data/lib/decidim/forms.rb +2 -2
- metadata +48 -45
- data/app/cells/decidim/forms/answer_readonly_cell.rb +0 -9
- data/app/helpers/decidim/forms/admin/questionnaire_answers_helper.rb +0 -30
- data/app/models/decidim/forms/answer_choice.rb +0 -22
- data/app/queries/decidim/forms/questionnaire_user_answers.rb +0 -32
- data/app/views/decidim/forms/admin/questionnaires/_answer_option_template.html.erb +0 -7
- data/app/views/decidim/forms/admin/questionnaires/answers/index.html.erb +0 -49
- data/app/views/decidim/forms/admin/questionnaires/answers/show.html.erb +0 -43
- data/app/views/decidim/forms/questionnaires/_answer.html.erb +0 -61
- data/app/views/decidim/forms/questionnaires/answers/_files.html.erb +0 -1
- data/app/views/decidim/forms/questionnaires/answers/_long_answer.html.erb +0 -3
- data/app/views/decidim/forms/questionnaires/answers/_multiple_option.html.erb +0 -25
- data/app/views/decidim/forms/questionnaires/answers/_separator.html.erb +0 -1
- data/app/views/decidim/forms/questionnaires/answers/_short_answer.html.erb +0 -3
- data/app/views/decidim/forms/questionnaires/answers/_single_option.html.erb +0 -32
- data/app/views/decidim/forms/questionnaires/answers/_sorting.html.erb +0 -26
- data/app/views/decidim/forms/questionnaires/answers/_title_and_description.html.erb +0 -1
- data/lib/decidim/api/answer_option_type.rb +0 -13
- data/lib/decidim/forms/test/shared_examples/manage_questionnaire_answers.rb +0 -149
- data/lib/decidim/forms/user_answers_serializer.rb +0 -105
- /data/app/cells/decidim/forms/{answer_readonly → response_readonly}/show.erb +0 -0
@@ -4,14 +4,14 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
shared_examples_for "has questionnaire" do
|
6
6
|
context "when the user is not logged in" do
|
7
|
-
it "does not allow
|
7
|
+
it "does not allow responding the questionnaire" do
|
8
8
|
visit questionnaire_public_path
|
9
9
|
see_questionnaire_questions
|
10
10
|
|
11
11
|
expect(page).to have_i18n_content(questionnaire.title)
|
12
12
|
expect(page).to have_i18n_content(questionnaire.description, strip_tags: true)
|
13
13
|
|
14
|
-
expect(page).to have_no_css(".form.
|
14
|
+
expect(page).to have_no_css(".form.response-questionnaire")
|
15
15
|
|
16
16
|
within "[data-question-readonly]" do
|
17
17
|
expect(page).to have_i18n_content(question.body)
|
@@ -37,7 +37,7 @@ shared_examples_for "has questionnaire" do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
it "allows
|
40
|
+
it "allows responding the questionnaire" do
|
41
41
|
visit questionnaire_public_path
|
42
42
|
|
43
43
|
expect(page).to have_i18n_content(questionnaire.title)
|
@@ -45,7 +45,7 @@ shared_examples_for "has questionnaire" do
|
|
45
45
|
|
46
46
|
see_questionnaire_questions
|
47
47
|
|
48
|
-
fill_in question.body["en"], with: "My first
|
48
|
+
fill_in question.body["en"], with: "My first response"
|
49
49
|
|
50
50
|
check "questionnaire_tos_agreement"
|
51
51
|
|
@@ -58,7 +58,7 @@ shared_examples_for "has questionnaire" do
|
|
58
58
|
visit questionnaire_public_path
|
59
59
|
see_questionnaire_questions
|
60
60
|
|
61
|
-
expect(page).to have_content("You have already
|
61
|
+
expect(page).to have_content("You have already responded this form.")
|
62
62
|
expect(page).to have_no_i18n_content(question.body)
|
63
63
|
end
|
64
64
|
|
@@ -67,7 +67,7 @@ shared_examples_for "has questionnaire" do
|
|
67
67
|
create(
|
68
68
|
:questionnaire_question,
|
69
69
|
questionnaire:,
|
70
|
-
question_type: "
|
70
|
+
question_type: "short_response",
|
71
71
|
position: 0,
|
72
72
|
mandatory: true
|
73
73
|
)
|
@@ -79,9 +79,9 @@ shared_examples_for "has questionnaire" do
|
|
79
79
|
|
80
80
|
it "it renders the asterisk as a separated element" do
|
81
81
|
see_questionnaire_questions
|
82
|
-
within "label.
|
82
|
+
within "label.response-questionnaire__question-label" do
|
83
83
|
expect(page).to have_content(translated_attribute(question.body).to_s)
|
84
|
-
within "span.label-required
|
84
|
+
within "span.label-required" do
|
85
85
|
expect(page).to have_content("*")
|
86
86
|
expect(page).to have_content("Required field")
|
87
87
|
end
|
@@ -98,29 +98,29 @@ shared_examples_for "has questionnaire" do
|
|
98
98
|
see_questionnaire_questions
|
99
99
|
end
|
100
100
|
|
101
|
-
it "allows
|
101
|
+
it "allows responding the first questionnaire" do
|
102
102
|
expect(page).to have_content("Step 1 of 2")
|
103
103
|
|
104
|
-
within ".
|
104
|
+
within ".response-questionnaire__submit", match: :first do
|
105
105
|
expect(page).to have_no_content("Back")
|
106
106
|
end
|
107
107
|
|
108
|
-
|
108
|
+
response_first_questionnaire
|
109
109
|
|
110
110
|
expect(page).to have_no_css(".success.flash")
|
111
111
|
end
|
112
112
|
|
113
|
-
it "allows revisiting previously-
|
114
|
-
|
113
|
+
it "allows revisiting previously-responded questionnaires with my responses" do
|
114
|
+
response_first_questionnaire
|
115
115
|
|
116
116
|
click_on "Back"
|
117
117
|
|
118
118
|
expect(page).to have_content("Step 1 of 2")
|
119
|
-
expect(page).to have_field("questionnaire_responses_0", with: "My first
|
119
|
+
expect(page).to have_field("questionnaire_responses_0", with: "My first response")
|
120
120
|
end
|
121
121
|
|
122
|
-
it "finishes the submission when
|
123
|
-
|
122
|
+
it "finishes the submission when responding the last questionnaire" do
|
123
|
+
response_first_questionnaire
|
124
124
|
|
125
125
|
check "questionnaire_tos_agreement"
|
126
126
|
accept_confirm { click_on "Submit" }
|
@@ -130,32 +130,32 @@ shared_examples_for "has questionnaire" do
|
|
130
130
|
visit questionnaire_public_path
|
131
131
|
see_questionnaire_questions
|
132
132
|
|
133
|
-
expect(page).to have_content("You have already
|
133
|
+
expect(page).to have_content("You have already responded this form.")
|
134
134
|
end
|
135
135
|
|
136
|
-
def
|
136
|
+
def response_first_questionnaire
|
137
137
|
within "#step-0" do
|
138
138
|
expect(page).to have_no_css("#questionnaire_tos_agreement")
|
139
139
|
|
140
|
-
fill_in question.body["en"], with: "My first
|
140
|
+
fill_in question.body["en"], with: "My first response"
|
141
141
|
click_on "Continue"
|
142
142
|
end
|
143
143
|
expect(page).to have_content("Step 2 of 2")
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
-
it "requires confirmation when exiting mid-
|
147
|
+
it "requires confirmation when exiting mid-responding" do
|
148
148
|
visit questionnaire_public_path
|
149
149
|
see_questionnaire_questions
|
150
150
|
|
151
|
-
fill_in question.body["en"], with: "My first
|
151
|
+
fill_in question.body["en"], with: "My first response"
|
152
152
|
|
153
153
|
click_on translated_attribute(component.name)
|
154
154
|
|
155
155
|
expect(page).to have_current_path(questionnaire_public_path)
|
156
156
|
end
|
157
157
|
|
158
|
-
context "when the questionnaire has already been
|
158
|
+
context "when the questionnaire has already been responded by someone else" do
|
159
159
|
let!(:question) do
|
160
160
|
create(
|
161
161
|
:questionnaire_question,
|
@@ -170,15 +170,15 @@ shared_examples_for "has questionnaire" do
|
|
170
170
|
end
|
171
171
|
|
172
172
|
before do
|
173
|
-
|
173
|
+
response = create(:response, id: 1, questionnaire:, question:)
|
174
174
|
|
175
|
-
|
176
|
-
|
175
|
+
response.choices.create!(
|
176
|
+
response_option: Decidim::Forms::ResponseOption.first,
|
177
177
|
body: "Lalalilo"
|
178
178
|
)
|
179
179
|
end
|
180
180
|
|
181
|
-
it "does not leak defaults from other
|
181
|
+
it "does not leak defaults from other responses" do
|
182
182
|
visit questionnaire_public_path
|
183
183
|
see_questionnaire_questions
|
184
184
|
|
@@ -188,12 +188,12 @@ shared_examples_for "has questionnaire" do
|
|
188
188
|
|
189
189
|
shared_examples_for "a correctly ordered questionnaire" do
|
190
190
|
it "displays the questions ordered by position starting with one" do
|
191
|
-
form_fields = all(".
|
191
|
+
form_fields = all(".response-questionnaire__question")
|
192
192
|
|
193
193
|
expect(form_fields[0]).to have_i18n_content(question.body)
|
194
194
|
expect(form_fields[1]).to have_i18n_content(other_question.body)
|
195
195
|
2.times do |index|
|
196
|
-
expect(form_fields[index]).to have_css("[data-
|
196
|
+
expect(form_fields[index]).to have_css("[data-response-idx='#{index + 1}']")
|
197
197
|
end
|
198
198
|
end
|
199
199
|
end
|
@@ -226,7 +226,7 @@ shared_examples_for "has questionnaire" do
|
|
226
226
|
create(
|
227
227
|
:questionnaire_question,
|
228
228
|
questionnaire:,
|
229
|
-
question_type: "
|
229
|
+
question_type: "short_response",
|
230
230
|
position: 0,
|
231
231
|
mandatory: true
|
232
232
|
)
|
@@ -283,9 +283,10 @@ shared_examples_for "has questionnaire" do
|
|
283
283
|
accept_confirm { click_on "Submit" }
|
284
284
|
end
|
285
285
|
|
286
|
-
it "
|
287
|
-
expect(page).to
|
288
|
-
|
286
|
+
it "submits the form and shows errors" do
|
287
|
+
expect(page).to have_css ".alert.flash"
|
288
|
+
expect(page).to have_admin_callout(callout_failure)
|
289
|
+
different_error = I18n.t("decidim.forms.questionnaires.response.max_choices_alert")
|
289
290
|
expect(different_error).to eq("There are too many choices selected")
|
290
291
|
expect(page).to have_no_content(different_error)
|
291
292
|
|
@@ -335,7 +336,7 @@ shared_examples_for "has questionnaire" do
|
|
335
336
|
end
|
336
337
|
|
337
338
|
describe "free text options" do
|
338
|
-
let(:
|
339
|
+
let(:response_option_bodies) { Array.new(3) { Decidim::Faker::Localized.sentence } }
|
339
340
|
let(:max_characters) { 0 }
|
340
341
|
let!(:question) do
|
341
342
|
create(
|
@@ -345,9 +346,9 @@ shared_examples_for "has questionnaire" do
|
|
345
346
|
max_characters:,
|
346
347
|
position: 1,
|
347
348
|
options: [
|
348
|
-
{ "body" =>
|
349
|
-
{ "body" =>
|
350
|
-
{ "body" =>
|
349
|
+
{ "body" => response_option_bodies[0] },
|
350
|
+
{ "body" => response_option_bodies[1] },
|
351
|
+
{ "body" => response_option_bodies[2], "free_text" => true }
|
351
352
|
]
|
352
353
|
)
|
353
354
|
end
|
@@ -380,34 +381,34 @@ shared_examples_for "has questionnaire" do
|
|
380
381
|
|
381
382
|
expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", disabled: true, count: 1)
|
382
383
|
|
383
|
-
choose
|
384
|
+
choose response_option_bodies[2]["en"]
|
384
385
|
|
385
386
|
expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", disabled: false, count: 1)
|
386
387
|
end
|
387
388
|
|
388
389
|
it "saves the free text in a separate field if submission correct" do
|
389
|
-
choose
|
390
|
+
choose response_option_bodies[2]["en"]
|
390
391
|
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "Cacatua"
|
391
392
|
|
392
393
|
check "questionnaire_tos_agreement"
|
393
394
|
accept_confirm { click_on "Submit" }
|
394
395
|
|
395
396
|
expect(page).to have_admin_callout(callout_success)
|
396
|
-
expect(Decidim::Forms::
|
397
|
+
expect(Decidim::Forms::Response.first.choices.first.custom_body).to eq("Cacatua")
|
397
398
|
end
|
398
399
|
|
399
400
|
it "preserves the previous custom body if submission not correct" do
|
400
|
-
check other_question.
|
401
|
-
check other_question.
|
402
|
-
check other_question.
|
401
|
+
check other_question.response_options.first.body["en"]
|
402
|
+
check other_question.response_options.second.body["en"]
|
403
|
+
check other_question.response_options.third.body["en"]
|
403
404
|
|
404
|
-
choose
|
405
|
+
choose response_option_bodies[2]["en"]
|
405
406
|
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "Cacatua"
|
406
407
|
|
407
408
|
check "questionnaire_tos_agreement"
|
408
409
|
accept_confirm { click_on "Submit" }
|
409
410
|
|
410
|
-
expect(page).to have_admin_callout("There was a problem
|
411
|
+
expect(page).to have_admin_callout("There was a problem responding")
|
411
412
|
expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", with: "Cacatua")
|
412
413
|
end
|
413
414
|
|
@@ -422,20 +423,20 @@ shared_examples_for "has questionnaire" do
|
|
422
423
|
|
423
424
|
expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", disabled: true, count: 1)
|
424
425
|
|
425
|
-
check
|
426
|
+
check response_option_bodies[2]["en"]
|
426
427
|
|
427
428
|
expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", disabled: false, count: 1)
|
428
429
|
end
|
429
430
|
|
430
431
|
it "saves the free text in a separate field if submission correct" do
|
431
|
-
check
|
432
|
+
check response_option_bodies[2]["en"]
|
432
433
|
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "Cacatua"
|
433
434
|
|
434
435
|
check "questionnaire_tos_agreement"
|
435
436
|
accept_confirm { click_on "Submit" }
|
436
437
|
|
437
438
|
expect(page).to have_admin_callout(callout_success)
|
438
|
-
expect(Decidim::Forms::
|
439
|
+
expect(Decidim::Forms::Response.first.choices.first.custom_body).to eq("Cacatua")
|
439
440
|
end
|
440
441
|
|
441
442
|
it "preserves the previous custom body if submission not correct" do
|
@@ -443,13 +444,13 @@ shared_examples_for "has questionnaire" do
|
|
443
444
|
check "questionnaire_responses_1_choices_1_body"
|
444
445
|
check "questionnaire_responses_1_choices_2_body"
|
445
446
|
|
446
|
-
check
|
447
|
+
check response_option_bodies[2]["en"]
|
447
448
|
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "Cacatua"
|
448
449
|
|
449
450
|
check "questionnaire_tos_agreement"
|
450
451
|
accept_confirm { click_on "Submit" }
|
451
452
|
|
452
|
-
expect(page).to have_admin_callout("There was a problem
|
453
|
+
expect(page).to have_admin_callout("There was a problem responding")
|
453
454
|
expect(page).to have_field("questionnaire_responses_0_choices_2_custom_body", with: "Cacatua")
|
454
455
|
end
|
455
456
|
|
@@ -457,11 +458,11 @@ shared_examples_for "has questionnaire" do
|
|
457
458
|
end
|
458
459
|
end
|
459
460
|
|
460
|
-
context "when question type is long
|
461
|
+
context "when question type is long response" do
|
461
462
|
let(:max_characters) { 0 }
|
462
|
-
let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "
|
463
|
+
let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "long_response", max_characters:) }
|
463
464
|
|
464
|
-
it "renders the
|
465
|
+
it "renders the response as a textarea" do
|
465
466
|
visit questionnaire_public_path
|
466
467
|
see_questionnaire_questions
|
467
468
|
|
@@ -471,11 +472,11 @@ shared_examples_for "has questionnaire" do
|
|
471
472
|
it_behaves_like "question has a character limit"
|
472
473
|
end
|
473
474
|
|
474
|
-
context "when question type is short
|
475
|
+
context "when question type is short response" do
|
475
476
|
let(:max_characters) { 0 }
|
476
|
-
let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "
|
477
|
+
let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "short_response", max_characters:) }
|
477
478
|
|
478
|
-
it "renders the
|
479
|
+
it "renders the response as a text field" do
|
479
480
|
visit questionnaire_public_path
|
480
481
|
see_questionnaire_questions
|
481
482
|
|
@@ -486,16 +487,16 @@ shared_examples_for "has questionnaire" do
|
|
486
487
|
end
|
487
488
|
|
488
489
|
context "when question type is single option" do
|
489
|
-
let(:
|
490
|
-
let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "single_option", options:
|
490
|
+
let(:response_options) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } }
|
491
|
+
let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "single_option", options: response_options) }
|
491
492
|
|
492
|
-
it "renders
|
493
|
+
it "renders responses as a collection of radio buttons" do
|
493
494
|
visit questionnaire_public_path
|
494
495
|
see_questionnaire_questions
|
495
496
|
|
496
497
|
expect(page).to have_css(".js-radio-button-collection input[type=radio]", count: 2)
|
497
498
|
|
498
|
-
choose
|
499
|
+
choose response_options[0]["body"][:en]
|
499
500
|
|
500
501
|
check "questionnaire_tos_agreement"
|
501
502
|
|
@@ -506,16 +507,16 @@ shared_examples_for "has questionnaire" do
|
|
506
507
|
visit questionnaire_public_path
|
507
508
|
see_questionnaire_questions
|
508
509
|
|
509
|
-
expect(page).to have_content("You have already
|
510
|
+
expect(page).to have_content("You have already responded this form.")
|
510
511
|
expect(page).to have_no_i18n_content(question.body)
|
511
512
|
end
|
512
513
|
end
|
513
514
|
|
514
515
|
context "when question type is multiple option" do
|
515
|
-
let(:
|
516
|
-
let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "multiple_option", options:
|
516
|
+
let(:response_options) { Array.new(3) { { "body" => Decidim::Faker::Localized.sentence } } }
|
517
|
+
let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "multiple_option", options: response_options) }
|
517
518
|
|
518
|
-
it "renders
|
519
|
+
it "renders responses as a collection of radio buttons" do
|
519
520
|
visit questionnaire_public_path
|
520
521
|
see_questionnaire_questions
|
521
522
|
|
@@ -523,8 +524,8 @@ shared_examples_for "has questionnaire" do
|
|
523
524
|
|
524
525
|
expect(page).to have_no_content("Max choices:")
|
525
526
|
|
526
|
-
check
|
527
|
-
check
|
527
|
+
check response_options[0]["body"][:en]
|
528
|
+
check response_options[1]["body"][:en]
|
528
529
|
|
529
530
|
check "questionnaire_tos_agreement"
|
530
531
|
|
@@ -535,7 +536,7 @@ shared_examples_for "has questionnaire" do
|
|
535
536
|
visit questionnaire_public_path
|
536
537
|
see_questionnaire_questions
|
537
538
|
|
538
|
-
expect(page).to have_content("You have already
|
539
|
+
expect(page).to have_content("You have already responded this form.")
|
539
540
|
expect(page).to have_no_i18n_content(question.body)
|
540
541
|
end
|
541
542
|
|
@@ -547,9 +548,9 @@ shared_examples_for "has questionnaire" do
|
|
547
548
|
|
548
549
|
expect(page).to have_content("Max choices: 2")
|
549
550
|
|
550
|
-
check
|
551
|
-
check
|
552
|
-
check
|
551
|
+
check response_options[0]["body"][:en]
|
552
|
+
check response_options[1]["body"][:en]
|
553
|
+
check response_options[2]["body"][:en]
|
553
554
|
|
554
555
|
expect(page).to have_content("too many choices")
|
555
556
|
|
@@ -557,10 +558,10 @@ shared_examples_for "has questionnaire" do
|
|
557
558
|
|
558
559
|
accept_confirm { click_on "Submit" }
|
559
560
|
|
560
|
-
expect(page).to have_admin_callout("There was a problem
|
561
|
+
expect(page).to have_admin_callout("There was a problem responding")
|
561
562
|
expect(page).to have_content("are too many")
|
562
563
|
|
563
|
-
uncheck
|
564
|
+
uncheck response_options[2]["body"][:en]
|
564
565
|
|
565
566
|
accept_confirm { click_on "Submit" }
|
566
567
|
|
@@ -584,11 +585,11 @@ shared_examples_for "has questionnaire" do
|
|
584
585
|
)
|
585
586
|
end
|
586
587
|
|
587
|
-
it "renders the question
|
588
|
+
it "renders the question responses as a collection of divs sortable on drag and drop" do
|
588
589
|
visit questionnaire_public_path
|
589
590
|
see_questionnaire_questions
|
590
591
|
|
591
|
-
expect(page).to have_css("div.
|
592
|
+
expect(page).to have_css("div.response-questionnaire__sorting.js-collection-input", count: 5)
|
592
593
|
|
593
594
|
%w(We all like dark chocolate).each do |term|
|
594
595
|
expect(page).to have_content(term)
|
@@ -600,7 +601,7 @@ shared_examples_for "has questionnaire" do
|
|
600
601
|
see_questionnaire_questions
|
601
602
|
|
602
603
|
%w(We all like dark chocolate).reverse.each do |text|
|
603
|
-
find("div.
|
604
|
+
find("div.response-questionnaire__sorting", text:).drag_to(find("div.response-questionnaire__sorting", match: :first))
|
604
605
|
end
|
605
606
|
|
606
607
|
check "questionnaire_tos_agreement"
|
@@ -608,7 +609,7 @@ shared_examples_for "has questionnaire" do
|
|
608
609
|
accept_confirm { click_on "Submit" }
|
609
610
|
|
610
611
|
expect(page).to have_admin_callout(callout_success)
|
611
|
-
expect(Decidim::Forms::
|
612
|
+
expect(Decidim::Forms::Response.first.choices.pluck(:position, :body)).to eq(
|
612
613
|
[[0, "We"], [1, "all"], [2, "like"], [3, "dark"], [4, "chocolate"]]
|
613
614
|
)
|
614
615
|
end
|
@@ -616,7 +617,7 @@ shared_examples_for "has questionnaire" do
|
|
616
617
|
|
617
618
|
context "when question type is matrix_single" do
|
618
619
|
let(:matrix_rows) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } }
|
619
|
-
let(:
|
620
|
+
let(:response_options) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } }
|
620
621
|
let(:mandatory) { false }
|
621
622
|
|
622
623
|
let!(:question) do
|
@@ -625,19 +626,19 @@ shared_examples_for "has questionnaire" do
|
|
625
626
|
questionnaire:,
|
626
627
|
question_type: "matrix_single",
|
627
628
|
rows: matrix_rows,
|
628
|
-
options:
|
629
|
+
options: response_options,
|
629
630
|
mandatory:
|
630
631
|
)
|
631
632
|
end
|
632
633
|
|
633
|
-
it "renders the question
|
634
|
+
it "renders the question responses as a collection of radio buttons" do
|
634
635
|
visit questionnaire_public_path
|
635
636
|
see_questionnaire_questions
|
636
637
|
|
637
638
|
expect(page).to have_css(".js-radio-button-collection input[type=radio]", count: 4)
|
638
639
|
|
639
640
|
expect(page).to have_content(matrix_rows.map { |row| row["body"]["en"] }.join("\n"))
|
640
|
-
expect(page).to have_content(
|
641
|
+
expect(page).to have_content(response_options.map { |option| option["body"]["en"] }.join(" "))
|
641
642
|
|
642
643
|
radio_buttons = page.all(".js-radio-button-collection input[type=radio]")
|
643
644
|
|
@@ -653,16 +654,16 @@ shared_examples_for "has questionnaire" do
|
|
653
654
|
visit questionnaire_public_path
|
654
655
|
see_questionnaire_questions
|
655
656
|
|
656
|
-
expect(page).to have_content("You have already
|
657
|
+
expect(page).to have_content("You have already responded this form.")
|
657
658
|
expect(page).to have_no_i18n_content(question.body)
|
658
659
|
|
659
|
-
first_choice, last_choice = Decidim::Forms::
|
660
|
+
first_choice, last_choice = Decidim::Forms::Response.last.choices.pluck(:decidim_response_option_id, :decidim_question_matrix_row_id)
|
660
661
|
|
661
|
-
expect(first_choice).to eq([question.
|
662
|
-
expect(last_choice).to eq([question.
|
662
|
+
expect(first_choice).to eq([question.response_options.first.id, question.matrix_rows.first.id])
|
663
|
+
expect(last_choice).to eq([question.response_options.last.id, question.matrix_rows.last.id])
|
663
664
|
end
|
664
665
|
|
665
|
-
it "preserves the chosen
|
666
|
+
it "preserves the chosen responses if submission not correct" do
|
666
667
|
visit questionnaire_public_path
|
667
668
|
see_questionnaire_questions
|
668
669
|
|
@@ -671,16 +672,16 @@ shared_examples_for "has questionnaire" do
|
|
671
672
|
|
672
673
|
accept_confirm { click_on "Submit" }
|
673
674
|
|
674
|
-
expect(page).to have_admin_callout("There was a problem
|
675
|
+
expect(page).to have_admin_callout("There was a problem responding")
|
675
676
|
|
676
677
|
radio_buttons = page.all(".js-radio-button-collection input[type=radio]")
|
677
678
|
expect(radio_buttons.pluck(:checked)).to eq([nil, "true", nil, nil])
|
678
679
|
end
|
679
680
|
|
680
|
-
context "when the question is mandatory and the
|
681
|
+
context "when the question is mandatory and the response is not complete" do
|
681
682
|
let!(:mandatory) { true }
|
682
683
|
|
683
|
-
it "shows an error if the question is mandatory and the
|
684
|
+
it "shows an error if the question is mandatory and the response is not complete" do
|
684
685
|
visit questionnaire_public_path
|
685
686
|
see_questionnaire_questions
|
686
687
|
|
@@ -690,7 +691,7 @@ shared_examples_for "has questionnaire" do
|
|
690
691
|
check "questionnaire_tos_agreement"
|
691
692
|
accept_confirm { click_on "Submit" }
|
692
693
|
|
693
|
-
expect(page).to have_admin_callout("There was a problem
|
694
|
+
expect(page).to have_admin_callout("There was a problem responding")
|
694
695
|
expect(page).to have_content("Choices are not complete")
|
695
696
|
end
|
696
697
|
end
|
@@ -698,7 +699,7 @@ shared_examples_for "has questionnaire" do
|
|
698
699
|
|
699
700
|
context "when question type is matrix_multiple" do
|
700
701
|
let(:matrix_rows) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } }
|
701
|
-
let(:
|
702
|
+
let(:response_options) { Array.new(3) { { "body" => Decidim::Faker::Localized.sentence } } }
|
702
703
|
let(:max_choices) { nil }
|
703
704
|
let(:mandatory) { false }
|
704
705
|
|
@@ -708,20 +709,20 @@ shared_examples_for "has questionnaire" do
|
|
708
709
|
questionnaire:,
|
709
710
|
question_type: "matrix_multiple",
|
710
711
|
rows: matrix_rows,
|
711
|
-
options:
|
712
|
+
options: response_options,
|
712
713
|
max_choices:,
|
713
714
|
mandatory:
|
714
715
|
)
|
715
716
|
end
|
716
717
|
|
717
|
-
it "renders the question
|
718
|
+
it "renders the question responses as a collection of check boxes" do
|
718
719
|
visit questionnaire_public_path
|
719
720
|
see_questionnaire_questions
|
720
721
|
|
721
722
|
expect(page).to have_css(".js-check-box-collection input[type=checkbox]", count: 6)
|
722
723
|
|
723
724
|
expect(page).to have_content(matrix_rows.map { |row| row["body"]["en"] }.join("\n"))
|
724
|
-
expect(page).to have_content(
|
725
|
+
expect(page).to have_content(response_options.map { |option| option["body"]["en"] }.join(" "))
|
725
726
|
|
726
727
|
checkboxes = page.all(".js-check-box-collection input[type=checkbox]")
|
727
728
|
|
@@ -738,14 +739,14 @@ shared_examples_for "has questionnaire" do
|
|
738
739
|
visit questionnaire_public_path
|
739
740
|
see_questionnaire_questions
|
740
741
|
|
741
|
-
expect(page).to have_content("You have already
|
742
|
+
expect(page).to have_content("You have already responded this form.")
|
742
743
|
expect(page).to have_no_i18n_content(question.body)
|
743
744
|
|
744
|
-
first_choice, second_choice, third_choice = Decidim::Forms::
|
745
|
+
first_choice, second_choice, third_choice = Decidim::Forms::Response.last.choices.pluck(:decidim_response_option_id, :decidim_question_matrix_row_id)
|
745
746
|
|
746
|
-
expect(first_choice).to eq([question.
|
747
|
-
expect(second_choice).to eq([question.
|
748
|
-
expect(third_choice).to eq([question.
|
747
|
+
expect(first_choice).to eq([question.response_options.first.id, question.matrix_rows.first.id])
|
748
|
+
expect(second_choice).to eq([question.response_options.second.id, question.matrix_rows.first.id])
|
749
|
+
expect(third_choice).to eq([question.response_options.first.id, question.matrix_rows.last.id])
|
749
750
|
end
|
750
751
|
|
751
752
|
context "when the question has max_choices defined" do
|
@@ -780,7 +781,7 @@ shared_examples_for "has questionnaire" do
|
|
780
781
|
|
781
782
|
accept_confirm { click_on "Submit" }
|
782
783
|
|
783
|
-
expect(page).to have_admin_callout("There was a problem
|
784
|
+
expect(page).to have_admin_callout("There was a problem responding")
|
784
785
|
expect(page).to have_content("are too many")
|
785
786
|
|
786
787
|
checkboxes = page.all(".js-check-box-collection input[type=checkbox]")
|
@@ -793,7 +794,7 @@ shared_examples_for "has questionnaire" do
|
|
793
794
|
end
|
794
795
|
end
|
795
796
|
|
796
|
-
context "when the question is mandatory and the
|
797
|
+
context "when the question is mandatory and the response is not complete" do
|
797
798
|
let!(:mandatory) { true }
|
798
799
|
|
799
800
|
it "shows an error" do
|
@@ -806,7 +807,7 @@ shared_examples_for "has questionnaire" do
|
|
806
807
|
check "questionnaire_tos_agreement"
|
807
808
|
accept_confirm { click_on "Submit" }
|
808
809
|
|
809
|
-
expect(page).to have_admin_callout("There was a problem
|
810
|
+
expect(page).to have_admin_callout("There was a problem responding")
|
810
811
|
expect(page).to have_content("Choices are not complete")
|
811
812
|
end
|
812
813
|
end
|
@@ -814,7 +815,7 @@ shared_examples_for "has questionnaire" do
|
|
814
815
|
context "when the submission is not correct" do
|
815
816
|
let!(:max_choices) { 2 }
|
816
817
|
|
817
|
-
it "preserves the chosen
|
818
|
+
it "preserves the chosen responses" do
|
818
819
|
visit questionnaire_public_path
|
819
820
|
see_questionnaire_questions
|
820
821
|
|
@@ -827,7 +828,7 @@ shared_examples_for "has questionnaire" do
|
|
827
828
|
check "questionnaire_tos_agreement"
|
828
829
|
accept_confirm { click_on "Submit" }
|
829
830
|
|
830
|
-
expect(page).to have_admin_callout("There was a problem
|
831
|
+
expect(page).to have_admin_callout("There was a problem responding")
|
831
832
|
|
832
833
|
checkboxes = page.all(".js-check-box-collection input[type=checkbox]")
|
833
834
|
expect(checkboxes.pluck(:checked)).to eq(["true", "true", "true", nil, nil, "true"])
|
@@ -836,7 +837,7 @@ shared_examples_for "has questionnaire" do
|
|
836
837
|
end
|
837
838
|
|
838
839
|
describe "display conditions" do
|
839
|
-
let(:
|
840
|
+
let(:response_options) do
|
840
841
|
3.times.to_a.map do |x|
|
841
842
|
{
|
842
843
|
"body" => Decidim::Faker::Localized.sentence,
|
@@ -856,10 +857,10 @@ shared_examples_for "has questionnaire" do
|
|
856
857
|
end
|
857
858
|
|
858
859
|
context "when a question has a display condition" do
|
859
|
-
context "when condition is of type '
|
860
|
+
context "when condition is of type 'responded'" do
|
860
861
|
let!(:display_condition) do
|
861
862
|
create(:display_condition,
|
862
|
-
condition_type: "
|
863
|
+
condition_type: "responded",
|
863
864
|
question:,
|
864
865
|
condition_question:)
|
865
866
|
end
|
@@ -869,8 +870,8 @@ shared_examples_for "has questionnaire" do
|
|
869
870
|
see_questionnaire_questions
|
870
871
|
end
|
871
872
|
|
872
|
-
context "when the condition_question type is short
|
873
|
-
let!(:condition_question_type) { "
|
873
|
+
context "when the condition_question type is short response" do
|
874
|
+
let!(:condition_question_type) { "short_response" }
|
874
875
|
|
875
876
|
it "shows the question only if the condition is fulfilled" do
|
876
877
|
expect_question_to_be_visible(false)
|
@@ -887,8 +888,8 @@ shared_examples_for "has questionnaire" do
|
|
887
888
|
end
|
888
889
|
end
|
889
890
|
|
890
|
-
context "when the condition_question type is long
|
891
|
-
let!(:condition_question_type) { "
|
891
|
+
context "when the condition_question type is long response" do
|
892
|
+
let!(:condition_question_type) { "long_response" }
|
892
893
|
let!(:conditioned_question_id) { "#questionnaire_responses_0" }
|
893
894
|
|
894
895
|
it "shows the question only if the condition is fulfilled" do
|
@@ -908,16 +909,16 @@ shared_examples_for "has questionnaire" do
|
|
908
909
|
|
909
910
|
context "when the condition_question type is single option" do
|
910
911
|
let!(:condition_question_type) { "single_option" }
|
911
|
-
let!(:condition_question_options) {
|
912
|
+
let!(:condition_question_options) { response_options }
|
912
913
|
|
913
914
|
it "shows the question only if the condition is fulfilled" do
|
914
915
|
expect_question_to_be_visible(false)
|
915
916
|
|
916
|
-
choose condition_question.
|
917
|
+
choose condition_question.response_options.first.body["en"]
|
917
918
|
|
918
919
|
expect_question_to_be_visible(true)
|
919
920
|
|
920
|
-
choose condition_question.
|
921
|
+
choose condition_question.response_options.second.body["en"]
|
921
922
|
|
922
923
|
expect_question_to_be_visible(false)
|
923
924
|
end
|
@@ -925,34 +926,34 @@ shared_examples_for "has questionnaire" do
|
|
925
926
|
|
926
927
|
context "when the condition_question type is multiple option" do
|
927
928
|
let!(:condition_question_type) { "multiple_option" }
|
928
|
-
let!(:condition_question_options) {
|
929
|
+
let!(:condition_question_options) { response_options }
|
929
930
|
|
930
931
|
it "shows the question only if the condition is fulfilled" do
|
931
932
|
expect_question_to_be_visible(false)
|
932
933
|
|
933
|
-
check condition_question.
|
934
|
+
check condition_question.response_options.first.body["en"]
|
934
935
|
|
935
936
|
expect_question_to_be_visible(true)
|
936
937
|
|
937
|
-
uncheck condition_question.
|
938
|
+
uncheck condition_question.response_options.first.body["en"]
|
938
939
|
|
939
940
|
expect_question_to_be_visible(false)
|
940
941
|
|
941
|
-
check condition_question.
|
942
|
+
check condition_question.response_options.second.body["en"]
|
942
943
|
|
943
944
|
expect_question_to_be_visible(false)
|
944
945
|
|
945
|
-
check condition_question.
|
946
|
+
check condition_question.response_options.first.body["en"]
|
946
947
|
|
947
948
|
expect_question_to_be_visible(true)
|
948
949
|
end
|
949
950
|
end
|
950
951
|
end
|
951
952
|
|
952
|
-
context "when a question has a display condition of type '
|
953
|
+
context "when a question has a display condition of type 'not_responded'" do
|
953
954
|
let!(:display_condition) do
|
954
955
|
create(:display_condition,
|
955
|
-
condition_type: "
|
956
|
+
condition_type: "not_responded",
|
956
957
|
question:,
|
957
958
|
condition_question:)
|
958
959
|
end
|
@@ -962,8 +963,8 @@ shared_examples_for "has questionnaire" do
|
|
962
963
|
see_questionnaire_questions
|
963
964
|
end
|
964
965
|
|
965
|
-
context "when the condition_question type is short
|
966
|
-
let!(:condition_question_type) { "
|
966
|
+
context "when the condition_question type is short response" do
|
967
|
+
let!(:condition_question_type) { "short_response" }
|
967
968
|
|
968
969
|
it "shows the question only if the condition is fulfilled" do
|
969
970
|
expect_question_to_be_visible(true)
|
@@ -980,8 +981,8 @@ shared_examples_for "has questionnaire" do
|
|
980
981
|
end
|
981
982
|
end
|
982
983
|
|
983
|
-
context "when the condition_question type is long
|
984
|
-
let!(:condition_question_type) { "
|
984
|
+
context "when the condition_question type is long response" do
|
985
|
+
let!(:condition_question_type) { "long_response" }
|
985
986
|
let!(:conditioned_question_id) { "#questionnaire_responses_0" }
|
986
987
|
|
987
988
|
it "shows the question only if the condition is fulfilled" do
|
@@ -1001,12 +1002,12 @@ shared_examples_for "has questionnaire" do
|
|
1001
1002
|
|
1002
1003
|
context "when the condition_question type is single option" do
|
1003
1004
|
let!(:condition_question_type) { "single_option" }
|
1004
|
-
let!(:condition_question_options) {
|
1005
|
+
let!(:condition_question_options) { response_options }
|
1005
1006
|
|
1006
1007
|
it "shows the question only if the condition is fulfilled" do
|
1007
1008
|
expect_question_to_be_visible(true)
|
1008
1009
|
|
1009
|
-
choose condition_question.
|
1010
|
+
choose condition_question.response_options.first.body["en"]
|
1010
1011
|
|
1011
1012
|
expect_question_to_be_visible(false)
|
1012
1013
|
end
|
@@ -1014,16 +1015,16 @@ shared_examples_for "has questionnaire" do
|
|
1014
1015
|
|
1015
1016
|
context "when the condition_question type is multiple option" do
|
1016
1017
|
let!(:condition_question_type) { "multiple_option" }
|
1017
|
-
let!(:condition_question_options) {
|
1018
|
+
let!(:condition_question_options) { response_options }
|
1018
1019
|
|
1019
1020
|
it "shows the question only if the condition is fulfilled" do
|
1020
1021
|
expect_question_to_be_visible(true)
|
1021
1022
|
|
1022
|
-
check condition_question.
|
1023
|
+
check condition_question.response_options.first.body["en"]
|
1023
1024
|
|
1024
1025
|
expect_question_to_be_visible(false)
|
1025
1026
|
|
1026
|
-
uncheck condition_question.
|
1027
|
+
uncheck condition_question.response_options.first.body["en"]
|
1027
1028
|
|
1028
1029
|
expect_question_to_be_visible(true)
|
1029
1030
|
end
|
@@ -1036,7 +1037,7 @@ shared_examples_for "has questionnaire" do
|
|
1036
1037
|
condition_type: "equal",
|
1037
1038
|
question:,
|
1038
1039
|
condition_question:,
|
1039
|
-
|
1040
|
+
response_option: condition_question.response_options.first)
|
1040
1041
|
end
|
1041
1042
|
|
1042
1043
|
before do
|
@@ -1046,16 +1047,16 @@ shared_examples_for "has questionnaire" do
|
|
1046
1047
|
|
1047
1048
|
context "when the condition_question type is single option" do
|
1048
1049
|
let!(:condition_question_type) { "single_option" }
|
1049
|
-
let!(:condition_question_options) {
|
1050
|
+
let!(:condition_question_options) { response_options }
|
1050
1051
|
|
1051
1052
|
it "shows the question only if the condition is fulfilled" do
|
1052
1053
|
expect_question_to_be_visible(false)
|
1053
1054
|
|
1054
|
-
choose condition_question.
|
1055
|
+
choose condition_question.response_options.first.body["en"]
|
1055
1056
|
|
1056
1057
|
expect_question_to_be_visible(true)
|
1057
1058
|
|
1058
|
-
choose condition_question.
|
1059
|
+
choose condition_question.response_options.second.body["en"]
|
1059
1060
|
|
1060
1061
|
expect_question_to_be_visible(false)
|
1061
1062
|
end
|
@@ -1063,24 +1064,24 @@ shared_examples_for "has questionnaire" do
|
|
1063
1064
|
|
1064
1065
|
context "when the condition_question type is multiple option" do
|
1065
1066
|
let!(:condition_question_type) { "multiple_option" }
|
1066
|
-
let!(:condition_question_options) {
|
1067
|
+
let!(:condition_question_options) { response_options }
|
1067
1068
|
|
1068
1069
|
it "shows the question only if the condition is fulfilled" do
|
1069
1070
|
expect_question_to_be_visible(false)
|
1070
1071
|
|
1071
|
-
check condition_question.
|
1072
|
+
check condition_question.response_options.first.body["en"]
|
1072
1073
|
|
1073
1074
|
expect_question_to_be_visible(true)
|
1074
1075
|
|
1075
|
-
uncheck condition_question.
|
1076
|
+
uncheck condition_question.response_options.first.body["en"]
|
1076
1077
|
|
1077
1078
|
expect_question_to_be_visible(false)
|
1078
1079
|
|
1079
|
-
check condition_question.
|
1080
|
+
check condition_question.response_options.second.body["en"]
|
1080
1081
|
|
1081
1082
|
expect_question_to_be_visible(false)
|
1082
1083
|
|
1083
|
-
check condition_question.
|
1084
|
+
check condition_question.response_options.first.body["en"]
|
1084
1085
|
|
1085
1086
|
expect_question_to_be_visible(true)
|
1086
1087
|
end
|
@@ -1093,7 +1094,7 @@ shared_examples_for "has questionnaire" do
|
|
1093
1094
|
condition_type: "not_equal",
|
1094
1095
|
question:,
|
1095
1096
|
condition_question:,
|
1096
|
-
|
1097
|
+
response_option: condition_question.response_options.first)
|
1097
1098
|
end
|
1098
1099
|
|
1099
1100
|
before do
|
@@ -1103,16 +1104,16 @@ shared_examples_for "has questionnaire" do
|
|
1103
1104
|
|
1104
1105
|
context "when the condition_question type is single option" do
|
1105
1106
|
let!(:condition_question_type) { "single_option" }
|
1106
|
-
let!(:condition_question_options) {
|
1107
|
+
let!(:condition_question_options) { response_options }
|
1107
1108
|
|
1108
1109
|
it "shows the question only if the condition is fulfilled" do
|
1109
1110
|
expect_question_to_be_visible(false)
|
1110
1111
|
|
1111
|
-
choose condition_question.
|
1112
|
+
choose condition_question.response_options.second.body["en"]
|
1112
1113
|
|
1113
1114
|
expect_question_to_be_visible(true)
|
1114
1115
|
|
1115
|
-
choose condition_question.
|
1116
|
+
choose condition_question.response_options.first.body["en"]
|
1116
1117
|
|
1117
1118
|
expect_question_to_be_visible(false)
|
1118
1119
|
end
|
@@ -1120,24 +1121,24 @@ shared_examples_for "has questionnaire" do
|
|
1120
1121
|
|
1121
1122
|
context "when the condition_question type is multiple option" do
|
1122
1123
|
let!(:condition_question_type) { "multiple_option" }
|
1123
|
-
let!(:condition_question_options) {
|
1124
|
+
let!(:condition_question_options) { response_options }
|
1124
1125
|
|
1125
1126
|
it "shows the question only if the condition is fulfilled" do
|
1126
1127
|
expect_question_to_be_visible(false)
|
1127
1128
|
|
1128
|
-
check condition_question.
|
1129
|
+
check condition_question.response_options.second.body["en"]
|
1129
1130
|
|
1130
1131
|
expect_question_to_be_visible(true)
|
1131
1132
|
|
1132
|
-
uncheck condition_question.
|
1133
|
+
uncheck condition_question.response_options.second.body["en"]
|
1133
1134
|
|
1134
1135
|
expect_question_to_be_visible(false)
|
1135
1136
|
|
1136
|
-
check condition_question.
|
1137
|
+
check condition_question.response_options.first.body["en"]
|
1137
1138
|
|
1138
1139
|
expect_question_to_be_visible(false)
|
1139
1140
|
|
1140
|
-
check condition_question.
|
1141
|
+
check condition_question.response_options.second.body["en"]
|
1141
1142
|
|
1142
1143
|
expect_question_to_be_visible(true)
|
1143
1144
|
end
|
@@ -1159,8 +1160,8 @@ shared_examples_for "has questionnaire" do
|
|
1159
1160
|
see_questionnaire_questions
|
1160
1161
|
end
|
1161
1162
|
|
1162
|
-
context "when the condition_question type is short
|
1163
|
-
let!(:condition_question_type) { "
|
1163
|
+
context "when the condition_question type is short response" do
|
1164
|
+
let!(:condition_question_type) { "short_response" }
|
1164
1165
|
|
1165
1166
|
it "shows the question only if the condition is fulfilled" do
|
1166
1167
|
expect_question_to_be_visible(false)
|
@@ -1182,8 +1183,8 @@ shared_examples_for "has questionnaire" do
|
|
1182
1183
|
end
|
1183
1184
|
end
|
1184
1185
|
|
1185
|
-
context "when the condition_question type is long
|
1186
|
-
let!(:condition_question_type) { "
|
1186
|
+
context "when the condition_question type is long response" do
|
1187
|
+
let!(:condition_question_type) { "long_response" }
|
1187
1188
|
|
1188
1189
|
it "shows the question only if the condition is fulfilled" do
|
1189
1190
|
expect_question_to_be_visible(false)
|
@@ -1207,13 +1208,13 @@ shared_examples_for "has questionnaire" do
|
|
1207
1208
|
|
1208
1209
|
context "when the condition_question type is single option" do
|
1209
1210
|
let!(:condition_question_type) { "single_option" }
|
1210
|
-
let!(:condition_question_options) {
|
1211
|
-
let!(:condition_value) { { en: condition_question.
|
1211
|
+
let!(:condition_question_options) { response_options }
|
1212
|
+
let!(:condition_value) { { en: condition_question.response_options.first.body["en"].split.second.upcase } }
|
1212
1213
|
|
1213
1214
|
it "shows the question only if the condition is fulfilled" do
|
1214
1215
|
expect_question_to_be_visible(false)
|
1215
1216
|
|
1216
|
-
choose condition_question.
|
1217
|
+
choose condition_question.response_options.first.body["en"]
|
1217
1218
|
|
1218
1219
|
expect_question_to_be_visible(true)
|
1219
1220
|
end
|
@@ -1221,22 +1222,22 @@ shared_examples_for "has questionnaire" do
|
|
1221
1222
|
|
1222
1223
|
context "when the condition_question type is single option with free text" do
|
1223
1224
|
let!(:condition_question_type) { "single_option" }
|
1224
|
-
let!(:condition_question_options) {
|
1225
|
+
let!(:condition_question_options) { response_options }
|
1225
1226
|
let!(:condition_value) { { en: "forty two" } }
|
1226
1227
|
|
1227
1228
|
it "shows the question only if the condition is fulfilled" do
|
1228
1229
|
expect_question_to_be_visible(false)
|
1229
1230
|
|
1230
|
-
choose condition_question.
|
1231
|
-
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "The
|
1231
|
+
choose condition_question.response_options.third.body["en"]
|
1232
|
+
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "The response is #{condition_value[:en]}"
|
1232
1233
|
change_focus
|
1233
1234
|
|
1234
1235
|
expect_question_to_be_visible(true)
|
1235
1236
|
|
1236
|
-
choose condition_question.
|
1237
|
+
choose condition_question.response_options.first.body["en"]
|
1237
1238
|
expect_question_to_be_visible(false)
|
1238
1239
|
|
1239
|
-
choose condition_question.
|
1240
|
+
choose condition_question.response_options.third.body["en"]
|
1240
1241
|
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "oh no not 42 again"
|
1241
1242
|
change_focus
|
1242
1243
|
|
@@ -1246,25 +1247,25 @@ shared_examples_for "has questionnaire" do
|
|
1246
1247
|
|
1247
1248
|
context "when the condition_question type is multiple option" do
|
1248
1249
|
let!(:condition_question_type) { "multiple_option" }
|
1249
|
-
let!(:condition_question_options) {
|
1250
|
+
let!(:condition_question_options) { response_options }
|
1250
1251
|
let!(:condition_value) { { en: "forty two" } }
|
1251
1252
|
|
1252
1253
|
it "shows the question only if the condition is fulfilled" do
|
1253
1254
|
expect_question_to_be_visible(false)
|
1254
1255
|
|
1255
|
-
check condition_question.
|
1256
|
-
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "The
|
1256
|
+
check condition_question.response_options.third.body["en"]
|
1257
|
+
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "The response is #{condition_value[:en]}"
|
1257
1258
|
change_focus
|
1258
1259
|
|
1259
1260
|
expect_question_to_be_visible(true)
|
1260
1261
|
|
1261
|
-
check condition_question.
|
1262
|
+
check condition_question.response_options.first.body["en"]
|
1262
1263
|
expect_question_to_be_visible(true)
|
1263
1264
|
|
1264
|
-
uncheck condition_question.
|
1265
|
+
uncheck condition_question.response_options.third.body["en"]
|
1265
1266
|
expect_question_to_be_visible(false)
|
1266
1267
|
|
1267
|
-
check condition_question.
|
1268
|
+
check condition_question.response_options.third.body["en"]
|
1268
1269
|
fill_in "questionnaire_responses_0_choices_2_custom_body", with: "oh no not 42 again"
|
1269
1270
|
change_focus
|
1270
1271
|
|
@@ -1282,11 +1283,11 @@ shared_examples_for "has questionnaire" do
|
|
1282
1283
|
|
1283
1284
|
context "when all conditions are mandatory" do
|
1284
1285
|
let!(:condition_question_type) { "single_option" }
|
1285
|
-
let!(:condition_question_options) {
|
1286
|
+
let!(:condition_question_options) { response_options }
|
1286
1287
|
let!(:display_conditions) do
|
1287
1288
|
[
|
1288
1289
|
create(:display_condition,
|
1289
|
-
condition_type: "
|
1290
|
+
condition_type: "responded",
|
1290
1291
|
question:,
|
1291
1292
|
condition_question:,
|
1292
1293
|
mandatory: true),
|
@@ -1295,18 +1296,18 @@ shared_examples_for "has questionnaire" do
|
|
1295
1296
|
question:,
|
1296
1297
|
condition_question:,
|
1297
1298
|
mandatory: true,
|
1298
|
-
|
1299
|
+
response_option: condition_question.response_options.second)
|
1299
1300
|
]
|
1300
1301
|
end
|
1301
1302
|
|
1302
1303
|
it "is displayed only if all conditions are fulfilled" do
|
1303
1304
|
expect_question_to_be_visible(false)
|
1304
1305
|
|
1305
|
-
choose condition_question.
|
1306
|
+
choose condition_question.response_options.second.body["en"]
|
1306
1307
|
|
1307
1308
|
expect_question_to_be_visible(false)
|
1308
1309
|
|
1309
|
-
choose condition_question.
|
1310
|
+
choose condition_question.response_options.first.body["en"]
|
1310
1311
|
|
1311
1312
|
expect_question_to_be_visible(true)
|
1312
1313
|
end
|
@@ -1314,7 +1315,7 @@ shared_examples_for "has questionnaire" do
|
|
1314
1315
|
|
1315
1316
|
context "when all conditions are non-mandatory" do
|
1316
1317
|
let!(:condition_question_type) { "multiple_option" }
|
1317
|
-
let!(:condition_question_options) {
|
1318
|
+
let!(:condition_question_options) { response_options }
|
1318
1319
|
let!(:display_conditions) do
|
1319
1320
|
[
|
1320
1321
|
create(:display_condition,
|
@@ -1322,36 +1323,36 @@ shared_examples_for "has questionnaire" do
|
|
1322
1323
|
question:,
|
1323
1324
|
condition_question:,
|
1324
1325
|
mandatory: false,
|
1325
|
-
|
1326
|
+
response_option: condition_question.response_options.first),
|
1326
1327
|
create(:display_condition,
|
1327
1328
|
condition_type: "not_equal",
|
1328
1329
|
question:,
|
1329
1330
|
condition_question:,
|
1330
1331
|
mandatory: false,
|
1331
|
-
|
1332
|
+
response_option: condition_question.response_options.third)
|
1332
1333
|
]
|
1333
1334
|
end
|
1334
1335
|
|
1335
1336
|
it "is displayed if any of the conditions is fulfilled" do
|
1336
1337
|
expect_question_to_be_visible(false)
|
1337
1338
|
|
1338
|
-
check condition_question.
|
1339
|
+
check condition_question.response_options.first.body["en"]
|
1339
1340
|
|
1340
1341
|
expect_question_to_be_visible(true)
|
1341
1342
|
|
1342
|
-
uncheck condition_question.
|
1343
|
-
check condition_question.
|
1343
|
+
uncheck condition_question.response_options.first.body["en"]
|
1344
|
+
check condition_question.response_options.second.body["en"]
|
1344
1345
|
|
1345
1346
|
expect_question_to_be_visible(true)
|
1346
1347
|
|
1347
|
-
check condition_question.
|
1348
|
+
check condition_question.response_options.first.body["en"]
|
1348
1349
|
|
1349
1350
|
expect_question_to_be_visible(true)
|
1350
1351
|
end
|
1351
1352
|
end
|
1352
1353
|
|
1353
1354
|
context "when a mandatory question has conditions that have not been fulfilled" do
|
1354
|
-
let!(:condition_question_type) { "
|
1355
|
+
let!(:condition_question_type) { "short_response" }
|
1355
1356
|
let!(:question) { create(:questionnaire_question, questionnaire:, position: 2, mandatory: true) }
|
1356
1357
|
let!(:display_conditions) do
|
1357
1358
|
[
|
@@ -1368,7 +1369,7 @@ shared_examples_for "has questionnaire" do
|
|
1368
1369
|
visit questionnaire_public_path
|
1369
1370
|
see_questionnaire_questions
|
1370
1371
|
|
1371
|
-
fill_in condition_question.body["en"], with: "My first
|
1372
|
+
fill_in condition_question.body["en"], with: "My first response"
|
1372
1373
|
|
1373
1374
|
check "questionnaire_tos_agreement"
|
1374
1375
|
|