-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix display condition answer option in templates (#589)
* fix: add controller to match custom route in decidim-templates * chore: update comment explanation in file * test: add system test for adding display condition * test: update test * test: update test again * refactor: update with rubocop
- Loading branch information
1 parent
3373514
commit b728bf0
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
app/controllers/decidim/templates/admin/questionnaires_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Templates | ||
module Admin | ||
# This controller is added to match the route "/questionnaire_template/questionnaire/answer_options(.:format)" in decidim-templates | ||
# TO DO : delete it when the correction on route is integrated | ||
class QuestionnairesController < Admin::ApplicationController | ||
include Decidim::Forms::Admin::Concerns::HasQuestionnaire | ||
|
||
def answer_options | ||
respond_to do |format| | ||
format.json do | ||
question_id = params["id"] | ||
question = Decidim::Forms::Question.find_by(id: question_id) | ||
render json: question.answer_options.map { |answer_option| Decidim::Forms::AnswerOptionPresenter.new(answer_option).as_json } if question.present? | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
spec/system/admin/admin_updates_question_in_questionnaire_templates_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe "Admin adds display condition to template's questionniaire question", type: :system do | ||
let!(:organization) { create(:organization) } | ||
let!(:user) { create(:user, :admin, :confirmed, organization: organization) } | ||
let(:template) { create(:questionnaire_template, organization: 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: questionnaire) | ||
question_two = create(:questionnaire_question, :with_answer_options, questionnaire: questionnaire) | ||
|
||
visit decidim_admin_templates.edit_questionnaire_path(template.id) | ||
# expand question two | ||
find("[data-toggle$=button--expand-question-questionnaire_question_#{question_two.id}]").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 |