Skip to content

Commit

Permalink
fix unregistered
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Apr 4, 2024
1 parent 43876d6 commit 8f1169d
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Decidim
module ActionDelegator
# This controller handles user profile actions for this module
class QuestionsSummaryController < ActionDelegator::ApplicationController
include Decidim::Consultations::NeedsQuestion

def show
render partial: "decidim/consultations/question_votes/callout"
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- insert_before '.table-list' -->

<%= render "decidim/action_delegator/admin/consultations/ongoing_consultation_warning", consultation: current_consultation %>
<%= render "decidim/action_delegator/admin/consultations/ongoing_consultation_warning", consultation: current_consultation %>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- insert_before "erb[loud]:contains('javascript_pack_tag')" -->

<%= javascript_pack_tag "decidim_action_delegator_questions" %>

Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<!-- insert_before 'h2' -->

<%= render partial: "decidim/consultations/question_votes/callout" %>
<% if user_signed_in? %>
<div id="user-answers-summary" data-summary-path="<%= decidim_action_delegator.questions_summary_path(current_question) %>">
<%= render partial: "decidim/consultations/question_votes/callout" %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "src/decidim/action_delegator/questions.js";
import "src/decidim/action_delegator/summary.js";

require.context("../images", true)

Expand Down
24 changes: 24 additions & 0 deletions app/packs/src/decidim/action_delegator/summary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$(() => {
const $usersAnswers = $("#user-answers-summary");
const path = $usersAnswers.data("summaryPath");
let $button = $("#consultations-questions-summary-button");
let $modal = $("#consultations-questions-summary-modal");
const $div = $(".question-vote-cabin").parent();
const openModal = (evt) => {
evt.preventDefault();
$modal.foundation("open");
};

$button.on("click", openModal);

$div.bind("DOMSubtreeModified", function() {
// console.log("tree changed", path);
$usersAnswers.load(path, () => {
$button = $usersAnswers.find("#consultations-questions-summary-button");
$modal = $usersAnswers.find("#consultations-questions-summary-modal");
// console.log("usersanswer loaded")
$usersAnswers.foundation();
$button.on("click", openModal);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<div class="callout <%= alert_class %>">
<p>
<%= t("action_delegator.questions.callout_text", scope: "decidim", voted: voted_questions, total: total_published_questions) %>
<a href="#" class="text-primary" data-open="consultations-questions-modal"><%= t("action_delegator.questions.callout_link_text", scope: "decidim") %></a>
<a href="#" class="text-primary" id="consultations-questions-summary-button"><%= t("action_delegator.questions.callout_link_text", scope: "decidim") %></a>
</p>
</div>

<div class="reveal" id="consultations-questions-modal" data-reveal>
<div class="reveal" id="consultations-questions-summary-modal" data-reveal>
<h4><%= t("action_delegator.questions.modal.modal_votes_title", scope: "decidim", title: translated_attribute(current_question.consultation.title)) %></h4>
<p class="lead">
<table class="table-list">
Expand Down
7 changes: 6 additions & 1 deletion lib/decidim/action_delegator/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ class Engine < ::Rails::Engine
routes do
# Add engine routes here
authenticate(:user) do
resources :user_delegations, controller: :user_delegations
resources :user_delegations, controller: :user_delegations, only: [:index]
root to: "user_delegations#index"
end
# scope "/questions/:question_slug/" do
# get :summary, to: "questions_summary#index", as: :question_summary
# end
resources :questions_summary, param: :slug, only: [:show]
# get "/questions_summary/:slug", to: "decidim/action_delegator/question_summaries#index", as: "question_callout_summary"
end

config.to_prepare do
Expand Down
55 changes: 47 additions & 8 deletions spec/system/consultation_question_vote_callout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,72 @@
let!(:consultation) { create :consultation, :published, organization: organization }
let!(:question) { create :question, consultation: consultation }
let!(:hihglighted_question) { create :question, consultation: consultation, decidim_scope_id: consultation.decidim_highlighted_scope_id }
let!(:response1) { create :response, question: question }
let!(:response2) { create :response, question: question }
let(:user) { create :user, :confirmed, :admin, organization: organization }
let(:enabled) { true }

before do
allow(Decidim::ActionDelegator).to receive(:remove_duplicated_highlighted_questions).and_return(enabled)

switch_to_host(organization.host)
login_as user, scope: :user
visit decidim_consultations.consultation_path(consultation)
click_link("Take part", match: :first)
end

context "when user logged in" do
before do
login_as user, scope: :user
visit decidim_consultations.consultation_path(consultation)
click_link("Take part", match: :first)
end

it "can visit the consultation" do
expect(page).to have_content("Review the summary of your vote here")
expect(page).to have_content(I18n.t("decidim.questions.vote_button.vote").upcase)
expect(page).to have_content("You have answered 0 from a total of 1 questions")
within "#vote_button" do
expect(page).to have_content("Vote")
end
expect(page).to have_content("You have answered 0 from a total of 2 questions")
end

it "renders callout" do
click_link("Review the summary of your vote here")
within "#consultations-questions-modal" do
within "#consultations-questions-summary-modal" do
expect(page).to have_content("Did you answer?")
expect(page).to have_content("Your votes in \"#{question.title["en"]}\"")
expect(page).to have_content(I18n.t("decidim.action_delegator.questions.modal.modal_votes_title"))
expect(page).to have_content("Your votes in \"#{consultation.title["en"]}\"")
expect(page).to have_link("No, take me there", href: decidim_consultations.question_path(question))
expect(page).to have_link("No, take me there", href: decidim_consultations.question_path(hihglighted_question))
end
end

it "changes the callout" do
expect(page).to have_content("You have answered 0 from a total of 2 questions")
click_link("Review the summary of your vote here")
within "#consultations-questions-summary-modal" do
expect(page).to have_link("No, take me there", href: decidim_consultations.question_path(question))
find(".close-button").click
end
click_link("Vote")
click_button response1.body["en"]
click_button "Confirm"
expect(page).to have_content("You have answered 1 from a total of 2 questions")
click_link("Review the summary of your vote here")
within "#consultations-questions-summary-modal" do
expect(page).to have_link("Yes", href: decidim_consultations.question_path(question))
end
end
end

context "when user is not logged in" do
before do
visit decidim_consultations.consultation_path(consultation)
click_link("Take part", match: :first)
end

it "can visit the consultation" do
expect(page).not_to have_content("Review the summary of your vote here")
within "#vote_button" do
expect(page).to have_content("Vote")
end
expect(page).not_to have_content("You have answered 0 from a total of 2 questions")
end
end
end

0 comments on commit 8f1169d

Please sign in to comment.