decidim-forms 0.27.9 → 0.28.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/cells/decidim/forms/answer_readonly/show.erb +1 -1
- data/app/cells/decidim/forms/matrix_readonly/show.erb +1 -1
- data/app/cells/decidim/forms/question_readonly/show.erb +8 -8
- data/app/cells/decidim/forms/question_readonly/title_and_description.erb +8 -0
- data/app/cells/decidim/forms/question_readonly_cell.rb +7 -0
- data/app/cells/decidim/forms/step_navigation/show.erb +13 -26
- data/app/cells/decidim/forms/step_navigation_cell.rb +7 -0
- data/app/commands/decidim/forms/answer_questionnaire.rb +31 -11
- data/app/controllers/decidim/forms/admin/concerns/has_questionnaire.rb +4 -4
- data/app/controllers/decidim/forms/admin/concerns/has_questionnaire_answers.rb +1 -1
- data/app/controllers/decidim/forms/concerns/has_questionnaire.rb +3 -3
- data/app/forms/decidim/forms/answer_form.rb +7 -3
- data/app/forms/decidim/forms/questionnaire_form.rb +1 -1
- data/app/helpers/decidim/forms/admin/application_helper.rb +1 -1
- data/app/helpers/decidim/forms/admin/concerns/has_questionnaire_answers_url_helper.rb +2 -2
- data/app/models/decidim/forms/answer.rb +1 -1
- data/app/models/decidim/forms/display_condition.rb +2 -2
- data/app/models/decidim/forms/question.rb +0 -4
- data/app/models/decidim/forms/questionnaire.rb +1 -1
- data/app/packs/entrypoints/decidim_forms.js +4 -0
- data/app/packs/src/decidim/forms/admin/collapsible_questions.js +12 -6
- data/app/packs/src/decidim/forms/admin/forms.js +7 -7
- data/app/packs/src/decidim/forms/display_conditions.component.js +3 -3
- data/app/packs/src/decidim/forms/forms.js +15 -9
- data/app/packs/src/decidim/forms/option_attached_inputs.component.js +1 -1
- data/app/packs/stylesheets/decidim/forms/forms.scss +82 -52
- data/app/packs/stylesheets/decidim/forms/questionnaire-answers-pdf.scss +13 -13
- data/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb +2 -2
- data/app/presenters/decidim/forms/admin_log/questionnaire_presenter.rb +2 -2
- data/app/presenters/decidim/forms/answer_option_presenter.rb +1 -1
- data/app/queries/decidim/forms/questionnaire_participants.rb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/_answer_option.html.erb +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.html.erb +2 -2
- data/app/views/decidim/forms/admin/questionnaires/_display_condition_template.html.erb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/_form.html.erb +52 -74
- data/app/views/decidim/forms/admin/questionnaires/_matrix_row.html.erb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/_matrix_row_template.html.erb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/_question.html.erb +147 -135
- data/app/views/decidim/forms/admin/questionnaires/_separator.html.erb +15 -13
- data/app/views/decidim/forms/admin/questionnaires/_title_and_description.html.erb +69 -63
- data/app/views/decidim/forms/admin/questionnaires/answers/export/_answer.html.erb +4 -4
- data/app/views/decidim/forms/admin/questionnaires/answers/export/pdf.html.erb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/answers/index.html.erb +41 -45
- data/app/views/decidim/forms/admin/questionnaires/answers/show.html.erb +13 -18
- data/app/views/decidim/forms/admin/questionnaires/edit.html.erb +33 -6
- data/app/views/decidim/forms/questionnaires/_answer.html.erb +31 -27
- data/app/views/decidim/forms/questionnaires/_questionnaire.html.erb +78 -0
- data/app/views/decidim/forms/questionnaires/_questionnaire_readonly.html.erb +11 -0
- data/app/views/decidim/forms/questionnaires/answers/_files.html.erb +1 -1
- data/app/views/decidim/forms/questionnaires/answers/_long_answer.html.erb +3 -1
- data/app/views/decidim/forms/questionnaires/answers/_matrix_multiple.html.erb +44 -41
- data/app/views/decidim/forms/questionnaires/answers/_matrix_single.html.erb +44 -41
- data/app/views/decidim/forms/questionnaires/answers/_multiple_option.html.erb +7 -6
- data/app/views/decidim/forms/questionnaires/answers/_separator.html.erb +1 -1
- data/app/views/decidim/forms/questionnaires/answers/_short_answer.html.erb +3 -1
- data/app/views/decidim/forms/questionnaires/answers/_single_option.html.erb +13 -12
- data/app/views/decidim/forms/questionnaires/answers/_sorting.html.erb +9 -12
- data/app/views/decidim/forms/questionnaires/answers/_title_and_description.html.erb +1 -1
- data/app/views/decidim/forms/questionnaires/show.html.erb +35 -144
- data/config/initializers/wicked_pdf.rb +1 -1
- data/config/locales/ar.yml +0 -6
- data/config/locales/bg.yml +0 -177
- data/config/locales/ca.yml +7 -2
- data/config/locales/cs.yml +8 -3
- data/config/locales/de.yml +9 -4
- data/config/locales/el.yml +7 -2
- data/config/locales/en.yml +8 -3
- data/config/locales/es-MX.yml +7 -2
- data/config/locales/es-PY.yml +7 -2
- data/config/locales/es.yml +7 -2
- data/config/locales/eu.yml +8 -3
- data/config/locales/fi-plain.yml +7 -2
- data/config/locales/fi.yml +8 -3
- data/config/locales/fr-CA.yml +8 -3
- data/config/locales/fr.yml +8 -3
- data/config/locales/gl.yml +0 -4
- data/config/locales/hu.yml +3 -9
- data/config/locales/id-ID.yml +0 -4
- data/config/locales/it.yml +0 -6
- data/config/locales/ja.yml +6 -1
- data/config/locales/lb.yml +0 -6
- data/config/locales/lt.yml +7 -2
- data/config/locales/lv.yml +0 -6
- data/config/locales/nl.yml +0 -6
- data/config/locales/no.yml +0 -6
- data/config/locales/pl.yml +6 -8
- data/config/locales/pt-BR.yml +0 -25
- data/config/locales/pt.yml +0 -6
- data/config/locales/ro-RO.yml +19 -14
- data/config/locales/ru.yml +0 -3
- data/config/locales/sk.yml +0 -6
- data/config/locales/sv.yml +32 -43
- data/config/locales/tr-TR.yml +0 -6
- data/config/locales/zh-CN.yml +0 -6
- data/config/locales/zh-TW.yml +7 -2
- data/lib/decidim/forms/engine.rb +8 -0
- data/lib/decidim/forms/test/factories.rb +37 -51
- data/lib/decidim/forms/test/shared_examples/has_questionnaire.rb +129 -239
- data/lib/decidim/forms/test/shared_examples/manage_questionnaire_answers.rb +18 -18
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_display_conditions.rb +14 -14
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_questions.rb +60 -78
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb +6 -6
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_questions.rb +25 -25
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb +9 -9
- data/lib/decidim/forms/user_answers_serializer.rb +1 -1
- data/lib/decidim/forms/version.rb +1 -1
- metadata +23 -18
- data/app/packs/src/decidim/forms/autosortable_checkboxes.component.js +0 -83
- data/config/locales/he-IL.yml +0 -1
- data/decidim-forms.gemspec +0 -34
@@ -5,13 +5,13 @@ require "spec_helper"
|
|
5
5
|
shared_examples_for "manage questionnaire answers" do
|
6
6
|
let(:first_type) { "short_answer" }
|
7
7
|
let!(:first) do
|
8
|
-
create :questionnaire_question, questionnaire
|
8
|
+
create :questionnaire_question, questionnaire:, position: 1, question_type: first_type
|
9
9
|
end
|
10
10
|
let!(:second) do
|
11
|
-
create :questionnaire_question, questionnaire
|
11
|
+
create :questionnaire_question, questionnaire:, position: 2, question_type: "single_option"
|
12
12
|
end
|
13
13
|
let!(:third) do
|
14
|
-
create :questionnaire_question, questionnaire
|
14
|
+
create :questionnaire_question, questionnaire:, position: 3, question_type: "files"
|
15
15
|
end
|
16
16
|
let(:questions) do
|
17
17
|
[first, second, third]
|
@@ -25,10 +25,10 @@ shared_examples_for "manage questionnaire answers" do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
context "when there are answers" do
|
28
|
-
let!(:answer1) { create :answer, questionnaire
|
29
|
-
let!(:answer2) { create :answer, body: "second answer", questionnaire
|
30
|
-
let!(:answer3) { create :answer, questionnaire
|
31
|
-
let!(:file_answer) { create :answer, :with_attachments, questionnaire
|
28
|
+
let!(:answer1) { create :answer, questionnaire:, question: first }
|
29
|
+
let!(:answer2) { create :answer, body: "second answer", questionnaire:, question: first }
|
30
|
+
let!(:answer3) { create :answer, questionnaire:, question: second }
|
31
|
+
let!(:file_answer) { create :answer, :with_attachments, questionnaire:, question: third, body: nil, user: answer3.user, session_token: answer3.session_token }
|
32
32
|
|
33
33
|
it "shows the answer admin link" do
|
34
34
|
visit questionnaire_edit_path
|
@@ -76,25 +76,25 @@ shared_examples_for "manage questionnaire answers" do
|
|
76
76
|
|
77
77
|
context "when multiple answer choice" do
|
78
78
|
let(:first_type) { "multiple_option" }
|
79
|
-
let!(:answer1) { create :answer, questionnaire
|
79
|
+
let!(:answer1) { create :answer, questionnaire:, question: first, body: nil }
|
80
80
|
let!(:answer_option) { create :answer_option, question: first }
|
81
|
-
let!(:answer_choice) { create :answer_choice, answer: answer1, answer_option
|
82
|
-
|
83
|
-
before do
|
84
|
-
find_all("a.action-icon.action-icon--eye").first.click
|
85
|
-
end
|
81
|
+
let!(:answer_choice) { create :answer_choice, answer: answer1, answer_option:, body: translated(answer_option.body, locale: I18n.locale) }
|
86
82
|
|
87
83
|
it "shows the answers page with custom body" do
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
new_window = window_opened_by { find_all("a.action-icon.action-icon--eye").first.click }
|
85
|
+
|
86
|
+
page.within_window(new_window) do
|
87
|
+
within "#answers" do
|
88
|
+
expect(page).to have_css("dt", text: translated(first.body))
|
89
|
+
expect(page).to have_css("li", text: translated(answer_option.body))
|
90
|
+
end
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
context "and managing individual answer page" do
|
97
|
-
let!(:answer11) { create :answer, questionnaire
|
97
|
+
let!(:answer11) { create :answer, questionnaire:, body: "", user: answer1.user, question: second }
|
98
98
|
|
99
99
|
before do
|
100
100
|
visit questionnaire_edit_path
|
@@ -133,7 +133,7 @@ shared_examples_for "manage questionnaire answers" do
|
|
133
133
|
end
|
134
134
|
|
135
135
|
context "when the file answer does not have a title for the attachment" do
|
136
|
-
let!(:file_answer) { create :answer, questionnaire
|
136
|
+
let!(:file_answer) { create :answer, questionnaire:, question: third, body: nil, user: answer3.user, session_token: answer3.session_token }
|
137
137
|
|
138
138
|
before do
|
139
139
|
create :attachment, :with_image, attached_to: file_answer, title: {}, description: {}
|
@@ -14,18 +14,18 @@ shared_examples_for "add display conditions" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
context "when questionnaire has only one question" do
|
17
|
-
let!(:question) { create(:questionnaire_question, questionnaire
|
17
|
+
let!(:question) { create(:questionnaire_question, questionnaire:, body:, question_type: "short_answer") }
|
18
18
|
|
19
19
|
before do
|
20
20
|
visit_questionnaire_edit_path_and_expand_all
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
24
|
-
expect(page).
|
23
|
+
it "does not display an add display condition button" do
|
24
|
+
expect(page).not_to have_button("Add display condition")
|
25
25
|
end
|
26
26
|
|
27
27
|
context "when creating a new question" do
|
28
|
-
it "disables the add display condition button if the question
|
28
|
+
it "disables the add display condition button if the question has not been saved" do
|
29
29
|
within "form.edit_questionnaire" do
|
30
30
|
click_button "Add question"
|
31
31
|
expand_all_questions
|
@@ -40,21 +40,21 @@ shared_examples_for "add display conditions" do
|
|
40
40
|
let!(:question_short_answer) do
|
41
41
|
create(:questionnaire_question,
|
42
42
|
position: 0,
|
43
|
-
questionnaire
|
43
|
+
questionnaire:,
|
44
44
|
body: Decidim::Faker::Localized.sentence,
|
45
45
|
question_type: "short_answer")
|
46
46
|
end
|
47
47
|
let!(:question_long_answer) do
|
48
48
|
create(:questionnaire_question,
|
49
49
|
position: 1,
|
50
|
-
questionnaire
|
50
|
+
questionnaire:,
|
51
51
|
body: Decidim::Faker::Localized.sentence,
|
52
52
|
question_type: "long_answer")
|
53
53
|
end
|
54
54
|
let!(:question_single_option) do
|
55
55
|
create(:questionnaire_question,
|
56
56
|
position: 2,
|
57
|
-
questionnaire
|
57
|
+
questionnaire:,
|
58
58
|
body: Decidim::Faker::Localized.sentence,
|
59
59
|
question_type: "single_option",
|
60
60
|
options: answer_options)
|
@@ -62,7 +62,7 @@ shared_examples_for "add display conditions" do
|
|
62
62
|
let!(:question_multiple_option) do
|
63
63
|
create(:questionnaire_question,
|
64
64
|
position: 3,
|
65
|
-
questionnaire
|
65
|
+
questionnaire:,
|
66
66
|
body: Decidim::Faker::Localized.sentence,
|
67
67
|
question_type: "multiple_option",
|
68
68
|
options: answer_options)
|
@@ -85,14 +85,14 @@ shared_examples_for "add display conditions" do
|
|
85
85
|
select question_single_option.body["en"], from: "Question"
|
86
86
|
select "Answered", from: "Condition"
|
87
87
|
|
88
|
-
expect(page).
|
89
|
-
expect(page).
|
88
|
+
expect(page).not_to have_select("Answer option")
|
89
|
+
expect(page).not_to have_css("[id$=condition_value_en]", visible: :visible)
|
90
90
|
|
91
91
|
select question_single_option.body["en"], from: "Question"
|
92
92
|
select "Equal", from: "Condition"
|
93
93
|
|
94
94
|
expect(page).to have_select("Answer option")
|
95
|
-
expect(page).
|
95
|
+
expect(page).not_to have_css("[id$=condition_value_en]", visible: :visible)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -101,7 +101,7 @@ shared_examples_for "add display conditions" do
|
|
101
101
|
within_add_display_condition do
|
102
102
|
options = questions.map { |question| question["body"]["en"] }
|
103
103
|
options << "Select a question"
|
104
|
-
expect(page).to have_select("Question", options:
|
104
|
+
expect(page).to have_select("Question", options:)
|
105
105
|
|
106
106
|
within "select[id$=decidim_condition_question_id]" do
|
107
107
|
elements = page.all("option[data-type]")
|
@@ -149,7 +149,7 @@ shared_examples_for "add display conditions" do
|
|
149
149
|
options = answer_options.map { |option| option["body"]["en"] }
|
150
150
|
options << "Select answer option"
|
151
151
|
|
152
|
-
expect(page).to have_select("Answer option", options
|
152
|
+
expect(page).to have_select("Answer option", options:, wait: 5)
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
@@ -164,7 +164,7 @@ shared_examples_for "add display conditions" do
|
|
164
164
|
it "loads a mandatory field with false value" do
|
165
165
|
within_add_display_condition do
|
166
166
|
expect(page).to have_selector("[id$=mandatory]")
|
167
|
-
expect(page).
|
167
|
+
expect(page).not_to have_selector("[id$=mandatory][checked]")
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -3,6 +3,38 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
shared_examples_for "add questions" do
|
6
|
+
shared_examples_for "updating the max choices selector according to the configured options" do
|
7
|
+
it "updates them" do
|
8
|
+
expect(page).not_to have_select("Maximum number of choices")
|
9
|
+
|
10
|
+
select "Multiple option", from: "Type"
|
11
|
+
expect(page).to have_select("Maximum number of choices", options: %w(Any 2))
|
12
|
+
|
13
|
+
click_button "Add answer option"
|
14
|
+
expect(page).to have_select("Maximum number of choices", options: %w(Any 2 3))
|
15
|
+
|
16
|
+
click_button "Add answer option"
|
17
|
+
expect(page).to have_select("Maximum number of choices", options: %w(Any 2 3 4))
|
18
|
+
|
19
|
+
within(".questionnaire-question-answer-option:last-of-type") { click_button "Remove" }
|
20
|
+
expect(page).to have_select("Maximum number of choices", options: %w(Any 2 3))
|
21
|
+
|
22
|
+
within(".questionnaire-question-answer-option:last-of-type") { click_button "Remove" }
|
23
|
+
expect(page).to have_select("Maximum number of choices", options: %w(Any 2))
|
24
|
+
|
25
|
+
click_button "Add question"
|
26
|
+
expand_all_questions
|
27
|
+
|
28
|
+
within(".questionnaire-question:last-of-type") do
|
29
|
+
select multiple_option_string, from: "Type"
|
30
|
+
expect(page).to have_select("Maximum number of choices", options: %w(Any 2))
|
31
|
+
|
32
|
+
select single_option_string, from: "Type"
|
33
|
+
expect(page).not_to have_select("Maximum number of choices")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
6
38
|
it "adds a few questions and separators to the questionnaire" do
|
7
39
|
fields_body = ["This is the first question", "This is the second question", "This is the first title and description"]
|
8
40
|
|
@@ -43,7 +75,7 @@ shared_examples_for "add questions" do
|
|
43
75
|
within ".questionnaire-question" do
|
44
76
|
fill_in find_nested_form_field_locator("body_en"), with: "Body"
|
45
77
|
|
46
|
-
fill_in_editor find_nested_form_field_locator("description_en", visible: false), with: "<strong>Superkalifragilistic description</strong>"
|
78
|
+
fill_in_editor find_nested_form_field_locator("description_en", visible: false), with: "<p>\n<strong>Superkalifragilistic description</strong>\n</p>"
|
47
79
|
end
|
48
80
|
|
49
81
|
click_button "Save"
|
@@ -72,7 +104,7 @@ shared_examples_for "add questions" do
|
|
72
104
|
within ".questionnaire-question" do
|
73
105
|
fill_in find_nested_form_field_locator("body_en"), with: "Body"
|
74
106
|
|
75
|
-
fill_in_editor find_nested_form_field_locator("description_en", visible: false), with: "<strong>Superkalifragilistic description</strong>"
|
107
|
+
fill_in_editor find_nested_form_field_locator("description_en", visible: false), with: "<p>\n<strong>Superkalifragilistic description</strong>\n</p>"
|
76
108
|
end
|
77
109
|
|
78
110
|
click_button "Save"
|
@@ -119,7 +151,7 @@ shared_examples_for "add questions" do
|
|
119
151
|
end
|
120
152
|
end
|
121
153
|
|
122
|
-
expect(page).
|
154
|
+
expect(page).not_to have_content "Add answer option"
|
123
155
|
|
124
156
|
page.all(".questionnaire-question").each do |question|
|
125
157
|
within question do
|
@@ -158,24 +190,24 @@ shared_examples_for "add questions" do
|
|
158
190
|
expand_all_questions
|
159
191
|
|
160
192
|
select "Long answer", from: "Type"
|
161
|
-
expect(page).
|
162
|
-
expect(page).
|
193
|
+
expect(page).not_to have_selector(".questionnaire-question-answer-option")
|
194
|
+
expect(page).not_to have_selector(".questionnaire-question-matrix-row")
|
163
195
|
|
164
196
|
select "Single option", from: "Type"
|
165
197
|
expect(page).to have_selector(".questionnaire-question-answer-option", count: 2)
|
166
|
-
expect(page).
|
198
|
+
expect(page).not_to have_selector(".questionnaire-question-matrix-row")
|
167
199
|
|
168
200
|
select "Multiple option", from: "Type"
|
169
201
|
expect(page).to have_selector(".questionnaire-question-answer-option", count: 2)
|
170
|
-
expect(page).
|
202
|
+
expect(page).not_to have_selector(".questionnaire-question-matrix-row")
|
171
203
|
|
172
204
|
select "Matrix (Multiple option)", from: "Type"
|
173
205
|
expect(page).to have_selector(".questionnaire-question-answer-option", count: 2)
|
174
206
|
expect(page).to have_selector(".questionnaire-question-matrix-row", count: 2)
|
175
207
|
|
176
208
|
select "Short answer", from: "Type"
|
177
|
-
expect(page).
|
178
|
-
expect(page).
|
209
|
+
expect(page).not_to have_selector(".questionnaire-question-answer-option")
|
210
|
+
expect(page).not_to have_selector(".questionnaire-question-matrix-row")
|
179
211
|
|
180
212
|
select "Matrix (Single option)", from: "Type"
|
181
213
|
expect(page).to have_selector(".questionnaire-question-answer-option", count: 2)
|
@@ -363,12 +395,15 @@ shared_examples_for "add questions" do
|
|
363
395
|
click_link "English", match: :first
|
364
396
|
|
365
397
|
expect(page).to have_nested_field("body_en", with: "Bye")
|
366
|
-
expect(page).
|
367
|
-
expect(page).
|
398
|
+
expect(page).not_to have_selector(nested_form_field_selector("body_ca"))
|
399
|
+
expect(page).not_to have_content("Adeu")
|
368
400
|
end
|
369
401
|
end
|
370
402
|
|
371
403
|
context "when adding a multiple option question" do
|
404
|
+
let(:multiple_option_string) { "Multiple option" }
|
405
|
+
let(:single_option_string) { "Single option" }
|
406
|
+
|
372
407
|
before do
|
373
408
|
visit questionnaire_edit_path
|
374
409
|
|
@@ -381,56 +416,31 @@ shared_examples_for "add questions" do
|
|
381
416
|
fill_in find_nested_form_field_locator("body_en"), with: "This is the first question"
|
382
417
|
end
|
383
418
|
|
384
|
-
expect(page).
|
385
|
-
expect(page).
|
419
|
+
expect(page).not_to have_content "Add answer option"
|
420
|
+
expect(page).not_to have_select("Maximum number of choices")
|
386
421
|
end
|
387
422
|
end
|
388
423
|
|
389
424
|
it "updates the free text option selector according to the selected question type" do
|
390
|
-
expect(page).
|
425
|
+
expect(page).not_to have_selector("input[type=checkbox][id$=_free_text]")
|
391
426
|
|
392
427
|
select "Multiple option", from: "Type"
|
393
428
|
expect(page).to have_selector("input[type=checkbox][id$=_free_text]")
|
394
429
|
|
395
430
|
select "Short answer", from: "Type"
|
396
|
-
expect(page).
|
431
|
+
expect(page).not_to have_selector("input[type=checkbox][id$=_free_text]")
|
397
432
|
|
398
433
|
select "Single option", from: "Type"
|
399
434
|
expect(page).to have_selector("input[type=checkbox][id$=_free_text]")
|
400
435
|
end
|
401
436
|
|
402
|
-
|
403
|
-
expect(page).to have_no_select("Maximum number of choices")
|
404
|
-
|
405
|
-
select "Multiple option", from: "Type"
|
406
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2))
|
407
|
-
|
408
|
-
click_button "Add answer option"
|
409
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2 3))
|
410
|
-
|
411
|
-
click_button "Add answer option"
|
412
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2 3 4))
|
413
|
-
|
414
|
-
within(".questionnaire-question-answer-option:last-of-type") { click_button "Remove" }
|
415
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2 3))
|
416
|
-
|
417
|
-
within(".questionnaire-question-answer-option:last-of-type") { click_button "Remove" }
|
418
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2))
|
419
|
-
|
420
|
-
click_button "Add question"
|
421
|
-
expand_all_questions
|
422
|
-
|
423
|
-
within(".questionnaire-question:last-of-type") do
|
424
|
-
select "Multiple option", from: "Type"
|
425
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2))
|
426
|
-
|
427
|
-
select "Single option", from: "Type"
|
428
|
-
expect(page).to have_no_select("Maximum number of choices")
|
429
|
-
end
|
430
|
-
end
|
437
|
+
it_behaves_like "updating the max choices selector according to the configured options"
|
431
438
|
end
|
432
439
|
|
433
440
|
context "when adding a matrix question" do
|
441
|
+
let(:multiple_option_string) { "Matrix (Multiple option)" }
|
442
|
+
let(:single_option_string) { "Matrix (Single option)" }
|
443
|
+
|
434
444
|
before do
|
435
445
|
visit questionnaire_edit_path
|
436
446
|
|
@@ -442,53 +452,25 @@ shared_examples_for "add questions" do
|
|
442
452
|
fill_in find_nested_form_field_locator("body_en"), with: "This is the first question"
|
443
453
|
end
|
444
454
|
|
445
|
-
expect(page).
|
446
|
-
expect(page).
|
447
|
-
expect(page).
|
455
|
+
expect(page).not_to have_content "Add answer option"
|
456
|
+
expect(page).not_to have_content "Add row"
|
457
|
+
expect(page).not_to have_select("Maximum number of choices")
|
448
458
|
end
|
449
459
|
end
|
450
460
|
|
451
461
|
it "updates the free text option selector according to the selected question type" do
|
452
|
-
expect(page).
|
462
|
+
expect(page).not_to have_selector("input[type=checkbox][id$=_free_text]")
|
453
463
|
|
454
464
|
select "Matrix (Multiple option)", from: "Type"
|
455
465
|
expect(page).to have_selector("input[type=checkbox][id$=_free_text]")
|
456
466
|
|
457
467
|
select "Short answer", from: "Type"
|
458
|
-
expect(page).
|
468
|
+
expect(page).not_to have_selector("input[type=checkbox][id$=_free_text]")
|
459
469
|
|
460
470
|
select "Matrix (Single option)", from: "Type"
|
461
471
|
expect(page).to have_selector("input[type=checkbox][id$=_free_text]")
|
462
472
|
end
|
463
473
|
|
464
|
-
|
465
|
-
expect(page).to have_no_select("Maximum number of choices")
|
466
|
-
|
467
|
-
select "Matrix (Multiple option)", from: "Type"
|
468
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2))
|
469
|
-
|
470
|
-
click_button "Add answer option"
|
471
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2 3))
|
472
|
-
|
473
|
-
click_button "Add answer option"
|
474
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2 3 4))
|
475
|
-
|
476
|
-
within(".questionnaire-question-answer-option:last-of-type") { click_button "Remove" }
|
477
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2 3))
|
478
|
-
|
479
|
-
within(".questionnaire-question-answer-option:last-of-type") { click_button "Remove" }
|
480
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2))
|
481
|
-
|
482
|
-
click_button "Add question"
|
483
|
-
expand_all_questions
|
484
|
-
|
485
|
-
within(".questionnaire-question:last-of-type") do
|
486
|
-
select "Matrix (Multiple option)", from: "Type"
|
487
|
-
expect(page).to have_select("Maximum number of choices", options: %w(Any 2))
|
488
|
-
|
489
|
-
select "Matrix (Single option)", from: "Type"
|
490
|
-
expect(page).to have_no_select("Maximum number of choices")
|
491
|
-
end
|
492
|
-
end
|
474
|
+
it_behaves_like "updating the max choices selector according to the configured options"
|
493
475
|
end
|
494
476
|
end
|
data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb
CHANGED
@@ -5,17 +5,17 @@ require "spec_helper"
|
|
5
5
|
shared_examples_for "update display conditions" do
|
6
6
|
context "when loading a saved display condition" do
|
7
7
|
let!(:condition_question_type) { "short_answer" }
|
8
|
-
let!(:condition_question) { create(:questionnaire_question, questionnaire
|
9
|
-
let!(:question) { create(:questionnaire_question, questionnaire
|
8
|
+
let!(:condition_question) { create(:questionnaire_question, questionnaire:, question_type: condition_question_type, position: 1) }
|
9
|
+
let!(:question) { create(:questionnaire_question, questionnaire:, question_type: "short_answer", position: 2) }
|
10
10
|
let!(:condition_type) { :answered }
|
11
11
|
let!(:answer_option) { nil }
|
12
12
|
|
13
13
|
let!(:display_condition) do
|
14
14
|
create(:display_condition,
|
15
|
-
question
|
16
|
-
condition_question
|
17
|
-
condition_type
|
18
|
-
answer_option:
|
15
|
+
question:,
|
16
|
+
condition_question:,
|
17
|
+
condition_type:,
|
18
|
+
answer_option:)
|
19
19
|
end
|
20
20
|
|
21
21
|
before do
|
@@ -4,7 +4,7 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
shared_examples_for "update questions" do
|
6
6
|
context "when a questionnaire has an existing question" do
|
7
|
-
let!(:question) { create(:questionnaire_question, questionnaire
|
7
|
+
let!(:question) { create(:questionnaire_question, questionnaire:, body:) }
|
8
8
|
|
9
9
|
before do
|
10
10
|
visit questionnaire_edit_path
|
@@ -28,7 +28,7 @@ shared_examples_for "update questions" do
|
|
28
28
|
visit_questionnaire_edit_path_and_expand_all
|
29
29
|
|
30
30
|
expect(page).to have_selector("input[value='Modified question']")
|
31
|
-
expect(page).
|
31
|
+
expect(page).not_to have_selector("input[value='This is the first question']")
|
32
32
|
expect(page).to have_selector("input#questionnaire_questions_#{question.id}_mandatory[checked]")
|
33
33
|
expect(page).to have_selector("input#questionnaire_questions_#{question.id}_max_characters[value='30']")
|
34
34
|
expect(page).to have_selector("select#questionnaire_questions_#{question.id}_question_type option[value='long_answer'][selected]")
|
@@ -53,11 +53,11 @@ shared_examples_for "update questions" do
|
|
53
53
|
expand_all_questions
|
54
54
|
|
55
55
|
expect(page).to have_admin_callout("There was a problem saving")
|
56
|
-
expect(page).to have_content("
|
56
|
+
expect(page).to have_content("cannot be blank", count: 5) # emtpy question, 2 empty default answer options, 2 empty default matrix rows
|
57
57
|
expect(page).to have_content("must be greater than or equal to 0", count: 1)
|
58
58
|
|
59
59
|
expect(page).to have_selector("input[value='']")
|
60
|
-
expect(page).
|
60
|
+
expect(page).not_to have_selector("input[value='This is the first question']")
|
61
61
|
expect(page).to have_selector("input#questionnaire_questions_#{question.id}_mandatory[checked]")
|
62
62
|
expect(page).to have_selector("input#questionnaire_questions_#{question.id}_max_characters[value='-3']")
|
63
63
|
expect(page).to have_select("Maximum number of choices", selected: "2")
|
@@ -79,7 +79,7 @@ shared_examples_for "update questions" do
|
|
79
79
|
|
80
80
|
within ".questionnaire-question" do
|
81
81
|
expect(page).to have_selector(".card-title", text: "#1")
|
82
|
-
expect(page).
|
82
|
+
expect(page).not_to have_button("Up")
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -104,7 +104,7 @@ shared_examples_for "update questions" do
|
|
104
104
|
it "cannot be moved up" do
|
105
105
|
within "form.edit_questionnaire" do
|
106
106
|
within ".questionnaire-question" do
|
107
|
-
expect(page).
|
107
|
+
expect(page).not_to have_button("Up")
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -112,14 +112,14 @@ shared_examples_for "update questions" do
|
|
112
112
|
it "cannot be moved down" do
|
113
113
|
within "form.edit_questionnaire" do
|
114
114
|
within ".questionnaire-question" do
|
115
|
-
expect(page).
|
115
|
+
expect(page).not_to have_button("Down")
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
121
|
context "when a questionnaire has a title and description" do
|
122
|
-
let!(:question) { create(:questionnaire_question, :title_and_description, questionnaire
|
122
|
+
let!(:question) { create(:questionnaire_question, :title_and_description, questionnaire:, body: title_and_description_body) }
|
123
123
|
|
124
124
|
before do
|
125
125
|
visit questionnaire_edit_path
|
@@ -140,7 +140,7 @@ shared_examples_for "update questions" do
|
|
140
140
|
visit_questionnaire_edit_path_and_expand_all
|
141
141
|
|
142
142
|
expect(page).to have_selector("input[value='Modified title and description']")
|
143
|
-
expect(page).
|
143
|
+
expect(page).not_to have_selector("input[value='This is the first title and description']")
|
144
144
|
end
|
145
145
|
|
146
146
|
it "re-renders the form when the information is invalid and displays errors" do
|
@@ -157,9 +157,9 @@ shared_examples_for "update questions" do
|
|
157
157
|
expand_all_questions
|
158
158
|
|
159
159
|
expect(page).to have_admin_callout("There was a problem saving")
|
160
|
-
expect(page).to have_content("
|
160
|
+
expect(page).to have_content("cannot be blank", count: 1)
|
161
161
|
expect(page).to have_selector("input[value='']")
|
162
|
-
expect(page).
|
162
|
+
expect(page).not_to have_selector("input[value='This is the first title and description']")
|
163
163
|
end
|
164
164
|
|
165
165
|
it "preserves deleted status across submission failures" do
|
@@ -177,7 +177,7 @@ shared_examples_for "update questions" do
|
|
177
177
|
|
178
178
|
within ".questionnaire-question" do
|
179
179
|
expect(page).to have_selector(".card-title", text: "#1")
|
180
|
-
expect(page).
|
180
|
+
expect(page).not_to have_button("Up")
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
@@ -202,7 +202,7 @@ shared_examples_for "update questions" do
|
|
202
202
|
it "cannot be moved up" do
|
203
203
|
within "form.edit_questionnaire" do
|
204
204
|
within ".questionnaire-question" do
|
205
|
-
expect(page).
|
205
|
+
expect(page).not_to have_button("Up")
|
206
206
|
end
|
207
207
|
end
|
208
208
|
end
|
@@ -210,7 +210,7 @@ shared_examples_for "update questions" do
|
|
210
210
|
it "cannot be moved down" do
|
211
211
|
within "form.edit_questionnaire" do
|
212
212
|
within ".questionnaire-question" do
|
213
|
-
expect(page).
|
213
|
+
expect(page).not_to have_button("Down")
|
214
214
|
end
|
215
215
|
end
|
216
216
|
end
|
@@ -220,8 +220,8 @@ shared_examples_for "update questions" do
|
|
220
220
|
let!(:question) do
|
221
221
|
create(
|
222
222
|
:questionnaire_question,
|
223
|
-
questionnaire
|
224
|
-
body
|
223
|
+
questionnaire:,
|
224
|
+
body:,
|
225
225
|
question_type: "single_option",
|
226
226
|
options: [
|
227
227
|
{ "body" => { "en" => "cacatua" } },
|
@@ -278,12 +278,12 @@ shared_examples_for "update questions" do
|
|
278
278
|
end
|
279
279
|
|
280
280
|
context "when a questionnaire has an existing question with matrix rows" do
|
281
|
-
let!(:other_question) { create(:questionnaire_question, questionnaire
|
281
|
+
let!(:other_question) { create(:questionnaire_question, questionnaire:, position: 1) }
|
282
282
|
let!(:question) do
|
283
283
|
create(
|
284
284
|
:questionnaire_question,
|
285
|
-
questionnaire
|
286
|
-
body
|
285
|
+
questionnaire:,
|
286
|
+
body:,
|
287
287
|
question_type: "matrix_single",
|
288
288
|
position: 2,
|
289
289
|
options: [
|
@@ -345,11 +345,11 @@ shared_examples_for "update questions" do
|
|
345
345
|
|
346
346
|
context "when a questionnaire has multiple existing questions" do
|
347
347
|
let!(:question1) do
|
348
|
-
create(:questionnaire_question, questionnaire
|
348
|
+
create(:questionnaire_question, questionnaire:, body: first_body, position: 0)
|
349
349
|
end
|
350
350
|
|
351
351
|
let!(:question2) do
|
352
|
-
create(:questionnaire_question, questionnaire
|
352
|
+
create(:questionnaire_question, questionnaire:, body: second_body, position: 1)
|
353
353
|
end
|
354
354
|
|
355
355
|
let(:first_body) do
|
@@ -510,7 +510,7 @@ shared_examples_for "update questions" do
|
|
510
510
|
expect do
|
511
511
|
click_button "Add question"
|
512
512
|
expand_all_questions
|
513
|
-
end.to change { page.all(".
|
513
|
+
end.to change { page.all(".editor-toolbar").size }.by(1)
|
514
514
|
end
|
515
515
|
|
516
516
|
it "properly decides which button to show after adding/removing answer options" do
|
@@ -521,7 +521,7 @@ shared_examples_for "update questions" do
|
|
521
521
|
select "Single option", from: "Type"
|
522
522
|
|
523
523
|
within ".questionnaire-question-answer-options-list" do
|
524
|
-
expect(page).
|
524
|
+
expect(page).not_to have_button("Remove")
|
525
525
|
end
|
526
526
|
|
527
527
|
click_button "Add answer option"
|
@@ -533,7 +533,7 @@ shared_examples_for "update questions" do
|
|
533
533
|
end
|
534
534
|
|
535
535
|
within ".questionnaire-question-answer-options-list" do
|
536
|
-
expect(page).
|
536
|
+
expect(page).not_to have_button("Remove")
|
537
537
|
end
|
538
538
|
end
|
539
539
|
|
@@ -542,7 +542,7 @@ shared_examples_for "update questions" do
|
|
542
542
|
|
543
543
|
within ".questionnaire-question:last-of-type" do
|
544
544
|
within ".questionnaire-question-answer-options-list" do
|
545
|
-
expect(page).
|
545
|
+
expect(page).not_to have_button("Remove")
|
546
546
|
end
|
547
547
|
end
|
548
548
|
end
|