From ca813b74f807bed5b7356abd51a493cb432a2da7 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Thu, 12 Sep 2024 12:43:29 +0200 Subject: [PATCH 1/6] fix: update answer_options custom route --- decidim-templates/lib/decidim/templates/admin_engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decidim-templates/lib/decidim/templates/admin_engine.rb b/decidim-templates/lib/decidim/templates/admin_engine.rb index 11223db98affe..2d26b6869b7ca 100644 --- a/decidim-templates/lib/decidim/templates/admin_engine.rb +++ b/decidim-templates/lib/decidim/templates/admin_engine.rb @@ -44,7 +44,7 @@ class AdminEngine < ::Rails::Engine end end - get "/questionnaire_template/questionnaire/answer_options", to: "questionnaires#answer_options", as: "answer_options_template" + get "/questionnaire_template/questionnaire/answer_options", to: "questionnaire_templates/questionnaires#answer_options", as: "answer_options_template" root to: "questionnaire_templates#index" end From 06717b28526435ae152ec73b7c37dd21e965bad6 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Mon, 16 Sep 2024 11:55:25 +0200 Subject: [PATCH 2/6] test: add system test for getting answer options --- ...ondtion_on_questionnaire_templates_spec.rb | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 decidim-templates/spec/system/admin/admin_adds_display_condtion_on_questionnaire_templates_spec.rb diff --git a/decidim-templates/spec/system/admin/admin_adds_display_condtion_on_questionnaire_templates_spec.rb b/decidim-templates/spec/system/admin/admin_adds_display_condtion_on_questionnaire_templates_spec.rb new file mode 100644 index 0000000000000..119c8cf76ec5e --- /dev/null +++ b/decidim-templates/spec/system/admin/admin_adds_display_condtion_on_questionnaire_templates_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "Admin adds display condition to template's questionnaire question and gets the answer options" do + let!(:organization) { create(:organization) } + let!(:user) { create(:user, :admin, :confirmed, organization:) } + let(:template) { create(:questionnaire_template, organization:) } + let(:matrix_rows) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } } + let(:answer_options) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } } + + before do + switch_to_host(organization.host) + login_as user, scope: :user + end + + it "adds display condition to questionnaire question" do + questionnaire = template.templatable + question_one = create(:questionnaire_question, mandatory: true, question_type: "matrix_single", rows: matrix_rows, options: answer_options, questionnaire:) + question_two = create(:questionnaire_question, :with_answer_options, questionnaire:) + + visit decidim_admin_templates.edit_questionnaire_path(template.id) + # expand question two + find("[data-controls=panel-questionnaire_question_#{question_two.id}-question-card]").click + # add display condition + find(".add-display-condition").click + # select question + select translated(question_one.body), from: "questionnaire[questions][#{question_two.id}][display_conditions][questionnaire-display-condition-id][decidim_condition_question_id]" + # select equal + select "Equal", from: "questionnaire[questions][#{question_two.id}][display_conditions][questionnaire-display-condition-id][condition_type]" + # validate we have the 2 answer options from question one in the select + select = find("#questionnaire_questions_#{question_two.id}_display_conditions_questionnaire-display-condition-id_decidim_answer_option_id") + expect(select).to have_content(translated(question_one.answer_options.first.body)) + expect(select).to have_content(translated(question_one.answer_options.last.body)) + end +end From 99e92d49adf54ec8bad90ea3c0128143e682dd4c Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Mon, 16 Sep 2024 12:01:08 +0200 Subject: [PATCH 3/6] refactor: update file's name --- ...min_adds_display_condition_on_questionnaire_templates_spec.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename decidim-templates/spec/system/admin/{admin_adds_display_condtion_on_questionnaire_templates_spec.rb => admin_adds_display_condition_on_questionnaire_templates_spec.rb} (100%) diff --git a/decidim-templates/spec/system/admin/admin_adds_display_condtion_on_questionnaire_templates_spec.rb b/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb similarity index 100% rename from decidim-templates/spec/system/admin/admin_adds_display_condtion_on_questionnaire_templates_spec.rb rename to decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb From 438662c9f4983ffce0fe50101c702daa2cbc8c70 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Mon, 16 Sep 2024 12:01:54 +0200 Subject: [PATCH 4/6] refactor: file's name --- ...ndition_on_questionnaire_templates_spec.rb | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb b/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb index 119c8cf76ec5e..e69de29bb2d1d 100644 --- a/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb +++ b/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -describe "Admin adds display condition to template's questionnaire question and gets the answer options" do - let!(:organization) { create(:organization) } - let!(:user) { create(:user, :admin, :confirmed, organization:) } - let(:template) { create(:questionnaire_template, organization:) } - let(:matrix_rows) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } } - let(:answer_options) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } } - - before do - switch_to_host(organization.host) - login_as user, scope: :user - end - - it "adds display condition to questionnaire question" do - questionnaire = template.templatable - question_one = create(:questionnaire_question, mandatory: true, question_type: "matrix_single", rows: matrix_rows, options: answer_options, questionnaire:) - question_two = create(:questionnaire_question, :with_answer_options, questionnaire:) - - visit decidim_admin_templates.edit_questionnaire_path(template.id) - # expand question two - find("[data-controls=panel-questionnaire_question_#{question_two.id}-question-card]").click - # add display condition - find(".add-display-condition").click - # select question - select translated(question_one.body), from: "questionnaire[questions][#{question_two.id}][display_conditions][questionnaire-display-condition-id][decidim_condition_question_id]" - # select equal - select "Equal", from: "questionnaire[questions][#{question_two.id}][display_conditions][questionnaire-display-condition-id][condition_type]" - # validate we have the 2 answer options from question one in the select - select = find("#questionnaire_questions_#{question_two.id}_display_conditions_questionnaire-display-condition-id_decidim_answer_option_id") - expect(select).to have_content(translated(question_one.answer_options.first.body)) - expect(select).to have_content(translated(question_one.answer_options.last.body)) - end -end From 5294b55dfb62ca07a4490eac2bbd5e9dcb96d08f Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Mon, 16 Sep 2024 13:57:34 +0200 Subject: [PATCH 5/6] test: updat e test file --- ...ndition_on_questionnaire_templates_spec.rb | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb b/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb index e69de29bb2d1d..28fd066f578cf 100644 --- a/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb +++ b/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "Admin adds display condition to template's questionniaire question" do + let!(:organization) { create(:organization) } + let!(:user) { create(:user, :admin, :confirmed, organization:) } + let(:template) { create(:questionnaire_template, organization:) } + let(:matrix_rows) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } } + let(:answer_options) { Array.new(2) { { "body" => Decidim::Faker::Localized.sentence } } } + + before do + switch_to_host(organization.host) + login_as user, scope: :user + end + + it "adds display condition to questionnaire question" do + questionnaire = template.templatable + question_one = create(:questionnaire_question, mandatory: true, question_type: "matrix_single", rows: matrix_rows, options: answer_options, questionnaire:) + question_two = create(:questionnaire_question, :with_answer_options, questionnaire:) + + visit decidim_admin_templates.edit_questionnaire_path(template.id) + # expand question two + find("[data-controls=panel-questionnaire_question_#{question_two.id}-question-card]").click + # add display condition + find(".add-display-condition").click + # select question + select translated(question_one.body), from: "questionnaire[questions][#{question_two.id}][display_conditions][questionnaire-display-condition-id][decidim_condition_question_id]" + # select equal + select "Equal", from: "questionnaire[questions][#{question_two.id}][display_conditions][questionnaire-display-condition-id][condition_type]" + # validate we have the 2 answer options from question one in the select + select = find("#questionnaire_questions_#{question_two.id}_display_conditions_questionnaire-display-condition-id_decidim_answer_option_id") + expect(select).to have_content(translated(question_one.answer_options.first.body)) + expect(select).to have_content(translated(question_one.answer_options.last.body)) + end +end From 0dd33e06208366c927772cd95d8c183536548a00 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Mon, 16 Sep 2024 14:03:04 +0200 Subject: [PATCH 6/6] refactor: update spelling --- ...in_adds_display_condition_on_questionnaire_templates_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb b/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb index 28fd066f578cf..4bf6a1d8eda1d 100644 --- a/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb +++ b/decidim-templates/spec/system/admin/admin_adds_display_condition_on_questionnaire_templates_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "Admin adds display condition to template's questionniaire question" do +describe "Admin adds display condition to template's questionnaire question" do let!(:organization) { create(:organization) } let!(:user) { create(:user, :admin, :confirmed, organization:) } let(:template) { create(:questionnaire_template, organization:) }