From 5fa6db2226bad276edddc37db2e92df85b1889b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 13 Jun 2024 14:48:03 +0200 Subject: [PATCH] Rename HTML attributes referencing poll options Since now poll question answers have been renamed to poll question options, using HTML IDs, classes and data attributes named `answer` was confusing. --- app/assets/javascripts/options.js | 2 +- app/assets/javascripts/polls.js | 10 +++++----- app/assets/javascripts/questions.js | 2 +- app/assets/javascripts/sortable.js | 2 +- app/assets/stylesheets/dashboard.scss | 2 +- app/assets/stylesheets/mixins/icons.scss | 2 +- app/assets/stylesheets/participation.scss | 10 +++++----- .../polls/questions/options_component.html.erb | 2 +- .../polls/questions/question_component.html.erb | 2 +- app/components/polls/questions/question_component.rb | 2 +- .../polls/questions/read_more_component.html.erb | 8 ++++---- .../polls/results/question_component.html.erb | 2 +- app/views/admin/poll/questions/options/edit.html.erb | 2 +- app/views/admin/poll/questions/options/new.html.erb | 2 +- .../admin/poll/questions/options/videos/edit.html.erb | 2 +- .../admin/poll/questions/options/videos/index.html.erb | 2 +- .../admin/poll/questions/options/videos/new.html.erb | 2 +- app/views/admin/poll/questions/show.html.erb | 2 +- app/views/dashboard/polls/_question_fields.html.erb | 4 ++-- .../dashboard/polls/_question_option_fields.html.erb | 4 ++-- app/views/polls/_gallery.html.erb | 2 +- app/views/polls/questions/options.js.erb | 2 +- app/views/polls/show.html.erb | 2 +- .../polls/questions/question_component_spec.rb | 4 ++-- spec/support/common_actions/polls.rb | 2 +- spec/system/dashboard/polls_spec.rb | 4 ++-- spec/system/polls/polls_spec.rb | 8 ++++---- spec/system/polls/questions_spec.rb | 2 +- spec/system/polls/results_spec.rb | 10 +++++----- spec/system/polls/votation_types_spec.rb | 4 ++-- spec/system/polls/voter_spec.rb | 10 +++++----- 31 files changed, 58 insertions(+), 58 deletions(-) diff --git a/app/assets/javascripts/options.js b/app/assets/javascripts/options.js index 0e1050769..f67e98e63 100644 --- a/app/assets/javascripts/options.js +++ b/app/assets/javascripts/options.js @@ -19,7 +19,7 @@ return max_order; }, nestedOptions: function() { - $(".js-answers").each(function(index, options) { + $(".js-options").each(function(index, options) { App.Options.initializeOptions(options); }); }, diff --git a/app/assets/javascripts/polls.js b/app/assets/javascripts/polls.js index b066546d8..742042ac3 100644 --- a/app/assets/javascripts/polls.js +++ b/app/assets/javascripts/polls.js @@ -4,19 +4,19 @@ initialize: function() { $(".zoom-link").on("click", function(event) { var option; - option = $(event.target).closest("div.answer"); + option = $(event.target).closest("div.option"); if ($(option).hasClass("medium-6")) { $(option).removeClass("medium-6"); - $(option).addClass("answer-divider"); + $(option).addClass("option-divider"); if (!$(option).hasClass("first")) { - $(option).insertBefore($(option).prev("div.answer")); + $(option).insertBefore($(option).prev("div.option")); } } else { $(option).addClass("medium-6"); - $(option).removeClass("answer-divider"); + $(option).removeClass("option-divider"); if (!$(option).hasClass("first")) { - $(option).insertAfter($(option).next("div.answer")); + $(option).insertAfter($(option).next("div.option")); } } }); diff --git a/app/assets/javascripts/questions.js b/app/assets/javascripts/questions.js index a90e47298..59058d6c1 100644 --- a/app/assets/javascripts/questions.js +++ b/app/assets/javascripts/questions.js @@ -3,7 +3,7 @@ App.Questions = { nestedQuestions: function() { $(".js-questions").on("cocoon:after-insert", function(e, new_question) { - App.Options.initializeOptions($(new_question).find(".js-answers")); + App.Options.initializeOptions($(new_question).find(".js-options")); }); }, initialize: function() { diff --git a/app/assets/javascripts/sortable.js b/app/assets/javascripts/sortable.js index ed085d5bd..69fa1da2e 100644 --- a/app/assets/javascripts/sortable.js +++ b/app/assets/javascripts/sortable.js @@ -6,7 +6,7 @@ update: function() { var new_order; new_order = $(this).sortable("toArray", { - attribute: "data-answer-id" + attribute: "data-option-id" }); $.ajax({ url: $(this).data("js-url"), diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index 746f7b1a2..d4d6afdfb 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -423,7 +423,7 @@ margin-bottom: $line-height; } -.answer-fields { +.option-fields { background: #fbfbfb; border: 1px solid $border; margin-bottom: $line-height; diff --git a/app/assets/stylesheets/mixins/icons.scss b/app/assets/stylesheets/mixins/icons.scss index bbf01a4ee..e6a81cea8 100644 --- a/app/assets/stylesheets/mixins/icons.scss +++ b/app/assets/stylesheets/mixins/icons.scss @@ -1597,7 +1597,7 @@ $font-awesome-icons: ( } .configure-link, - .answers-link { + .options-link { @include has-fa-icon(tools, solid); } diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index bc5148df7..a93f32562 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1400,7 +1400,7 @@ } .poll-more-info, -.poll-more-info-answers { +.poll-more-info-options { .read-more { margin-bottom: $line-height; @@ -1416,7 +1416,7 @@ border-top: 1px solid #eee; } -.poll-more-info-answers { +.poll-more-info-options { @include full-width-background; @include full-width-border(top, 1px solid #eee); @include full-width-border(bottom, 1px solid #eee); @@ -1426,14 +1426,14 @@ border-right: 2px solid; } - .answer-divider { + .option-divider { border-bottom: 2px solid; border-right: 0 !important; margin-bottom: $line-height; padding-bottom: $line-height; } - .answer-description { + .option-description { height: 100%; &.short { @@ -1544,7 +1544,7 @@ } } -.poll-question-answers { +.poll-question-options { @include flex-with-gap($line-height * 0.25); flex-wrap: wrap; diff --git a/app/components/polls/questions/options_component.html.erb b/app/components/polls/questions/options_component.html.erb index c9c8ff7e7..b687ed249 100644 --- a/app/components/polls/questions/options_component.html.erb +++ b/app/components/polls/questions/options_component.html.erb @@ -1,4 +1,4 @@ -
+
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %> <% question_options.each do |question_option| %> <% if already_answered?(question_option) %> diff --git a/app/components/polls/questions/question_component.html.erb b/app/components/polls/questions/question_component.html.erb index 263da5203..46563a87b 100644 --- a/app/components/polls/questions/question_component.html.erb +++ b/app/components/polls/questions/question_component.html.erb @@ -9,7 +9,7 @@ <% end %> -
+
<%= render Polls::Questions::OptionsComponent.new(question) %>
diff --git a/app/components/polls/questions/question_component.rb b/app/components/polls/questions/question_component.rb index 212bb03ed..ba52796b5 100644 --- a/app/components/polls/questions/question_component.rb +++ b/app/components/polls/questions/question_component.rb @@ -7,7 +7,7 @@ class Polls::Questions::QuestionComponent < ApplicationComponent def options_read_more_links safe_join(question.options_with_read_more.map do |option| - link_to option.title, "#answer_#{option.id}" + link_to option.title, "#option_#{option.id}" end, ", ") end end diff --git a/app/components/polls/questions/read_more_component.html.erb b/app/components/polls/questions/read_more_component.html.erb index 3bcfad2f2..90d4e382e 100644 --- a/app/components/polls/questions/read_more_component.html.erb +++ b/app/components/polls/questions/read_more_component.html.erb @@ -1,21 +1,21 @@

<%= question.title %>

<% question.options_with_read_more.each do |option| %> -
" id="answer_<%= option.id %>"> +
" id="option_<%= option.id %>">

<%= option.title %>

<% if option.description.present? %> -
+
<%= wysiwyg(option.description) %>
diff --git a/app/views/polls/questions/options.js.erb b/app/views/polls/questions/options.js.erb index f906184a5..1cfab79f7 100644 --- a/app/views/polls/questions/options.js.erb +++ b/app/views/polls/questions/options.js.erb @@ -1 +1 @@ -$("#<%= dom_id(@question) %>_answers").html("<%= j render Polls::Questions::OptionsComponent.new(@question) %>"); +$("#<%= dom_id(@question) %>_options").html("<%= j render Polls::Questions::OptionsComponent.new(@question) %>"); diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 0ccbeaad1..f90679a9d 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -44,7 +44,7 @@
-
+
<%= render Polls::Questions::ReadMoreComponent.with_collection(@questions) %>
diff --git a/spec/components/polls/questions/question_component_spec.rb b/spec/components/polls/questions/question_component_spec.rb index f695a2887..607906ad6 100644 --- a/spec/components/polls/questions/question_component_spec.rb +++ b/spec/components/polls/questions/question_component_spec.rb @@ -11,8 +11,8 @@ describe Polls::Questions::QuestionComponent do poll_question = page.find("#poll_question_#{question.id}") expect(poll_question).to have_content("Read more about") - expect(poll_question).to have_link("Answer A", href: "#answer_#{option_a.id}") - expect(poll_question).to have_link("Answer B", href: "#answer_#{option_b.id}") + expect(poll_question).to have_link("Answer A", href: "#option_#{option_a.id}") + expect(poll_question).to have_link("Answer B", href: "#option_#{option_b.id}") expect(poll_question).to have_content("Answer A, Answer B") end end diff --git a/spec/support/common_actions/polls.rb b/spec/support/common_actions/polls.rb index 5fdd3e309..ad277c948 100644 --- a/spec/support/common_actions/polls.rb +++ b/spec/support/common_actions/polls.rb @@ -2,7 +2,7 @@ module Polls def vote_for_poll_via_web(poll, question, option) visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do click_button option expect(page).to have_button("You have voted #{option}") diff --git a/spec/system/dashboard/polls_spec.rb b/spec/system/dashboard/polls_spec.rb index 1f57c708b..0f7d3d61b 100644 --- a/spec/system/dashboard/polls_spec.rb +++ b/spec/system/dashboard/polls_spec.rb @@ -174,7 +174,7 @@ describe "Polls" do click_link "Edit survey" end - within ".js-questions .js-answers" do + within ".js-questions .js-options" do expect(page).to have_css ".nested-fields", count: 2 within first(".nested-fields") do click_link class: "delete" @@ -188,7 +188,7 @@ describe "Polls" do visit edit_proposal_dashboard_poll_path(proposal, poll) - within ".js-questions .js-answers" do + within ".js-questions .js-options" do expect(page).to have_css ".nested-fields", count: 1 end end diff --git a/spec/system/polls/polls_spec.rb b/spec/system/polls/polls_spec.rb index ffde159e0..5d1dfc788 100644 --- a/spec/system/polls/polls_spec.rb +++ b/spec/system/polls/polls_spec.rb @@ -206,7 +206,7 @@ describe "Polls" do login_as user visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do click_button "Vote Yes" expect(page).to have_button "You have voted Yes" @@ -223,7 +223,7 @@ describe "Polls" do login_as user visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do click_button "Yes" expect(page).to have_button "You have voted Yes" @@ -266,7 +266,7 @@ describe "Polls" do login_as user visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do click_button "Yes" expect(page).to have_button "You have voted Yes" @@ -301,7 +301,7 @@ describe "Polls" do expect(page).to have_content "You have already participated in a physical booth. " \ "You can not participate again." - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do expect(page).to have_content("Yes") expect(page).to have_content("No") diff --git a/spec/system/polls/questions_spec.rb b/spec/system/polls/questions_spec.rb index a495095aa..197e20088 100644 --- a/spec/system/polls/questions_spec.rb +++ b/spec/system/polls/questions_spec.rb @@ -18,7 +18,7 @@ describe "Poll Questions" do visit poll_path(poll) - within "#poll_more_info_answers" do + within "#poll_more_info_options" do expect(page).to have_content "Pedestrian road" expect(page).to have_css "img[alt='Trees on both sides of the road']" end diff --git a/spec/system/polls/results_spec.rb b/spec/system/polls/results_spec.rb index e73465196..78b45d997 100644 --- a/spec/system/polls/results_spec.rb +++ b/spec/system/polls/results_spec.rb @@ -39,14 +39,14 @@ describe "Poll Results" do expect(page).to have_content(question2.title) within("#question_#{question1.id}_results_table") do - expect(find("#answer_#{option1.id}_result")).to have_content("2 (66.67%)") - expect(find("#answer_#{option2.id}_result")).to have_content("1 (33.33%)") + expect(find("#option_#{option1.id}_result")).to have_content("2 (66.67%)") + expect(find("#option_#{option2.id}_result")).to have_content("1 (33.33%)") end within("#question_#{question2.id}_results_table") do - expect(find("#answer_#{option3.id}_result")).to have_content("1 (33.33%)") - expect(find("#answer_#{option4.id}_result")).to have_content("1 (33.33%)") - expect(find("#answer_#{option5.id}_result")).to have_content("1 (33.33%)") + expect(find("#option_#{option3.id}_result")).to have_content("1 (33.33%)") + expect(find("#option_#{option4.id}_result")).to have_content("1 (33.33%)") + expect(find("#option_#{option5.id}_result")).to have_content("1 (33.33%)") end end diff --git a/spec/system/polls/votation_types_spec.rb b/spec/system/polls/votation_types_spec.rb index 51efb7f2c..46d444376 100644 --- a/spec/system/polls/votation_types_spec.rb +++ b/spec/system/polls/votation_types_spec.rb @@ -17,7 +17,7 @@ describe "Poll Votation Type" do expect(page).to have_button("Vote Yes") expect(page).to have_button("Vote No") - within "#poll_question_#{question.id}_answers" do + within "#poll_question_#{question.id}_options" do click_button "Yes" expect(page).to have_button("You have voted Yes") @@ -40,7 +40,7 @@ describe "Poll Votation Type" do expect(page).to have_button("Vote Answer B") expect(page).to have_button("Vote Answer C") - within "#poll_question_#{question.id}_answers" do + within "#poll_question_#{question.id}_options" do click_button "Vote Answer A" expect(page).to have_button("You have voted Answer A") diff --git a/spec/system/polls/voter_spec.rb b/spec/system/polls/voter_spec.rb index 640670524..da1a8ff2a 100644 --- a/spec/system/polls/voter_spec.rb +++ b/spec/system/polls/voter_spec.rb @@ -20,7 +20,7 @@ describe "Voter" do login_as user visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do click_button "Vote Yes" expect(page).to have_button("You have voted Yes") @@ -44,7 +44,7 @@ describe "Voter" do expect(page).to have_content("You have already participated in this poll.") expect(page).to have_content("If you vote again it will be overwritten") - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do click_button "You have voted Yes" expect(page).to have_button("Vote Yes") @@ -63,7 +63,7 @@ describe "Voter" do login_as user visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do expect(page).to have_link("Yes", href: verification_path) expect(page).to have_link("No", href: verification_path) end @@ -171,7 +171,7 @@ describe "Voter" do login_as user visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do expect(page).not_to have_button("Yes") end expect(page).to have_content "You have already participated in a physical booth. " \ @@ -211,7 +211,7 @@ describe "Voter" do visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do + within("#poll_question_#{question.id}_options") do expect(page).not_to have_button("Yes") end