-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement weighted results display on public interface (#171)
* add weighted result * add tests * add tests * add file to the lib/overrides_spec.rb * add file to the lib/overrides_spec.rb
- Loading branch information
1 parent
504980f
commit b481bde
Showing
8 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
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
4 changes: 4 additions & 0 deletions
4
...overrides/decidim/consultations/consultations/_question/replace_vote_info.html.erb.deface
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,4 @@ | ||
<!-- replace_contents "erb[silent]:contains('if question.results_published?')" | ||
closing_selector "erb[silent]:contains('else')" --> | ||
|
||
<%= render partial: "decidim/action_delegator/consultations/link_with_results", locals: { question: question } %> |
3 changes: 3 additions & 0 deletions
3
app/overrides/decidim/consultations/questions/_results/replace_results.html.erb.deface
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,3 @@ | ||
<!-- replace_contents ".card--list" --> | ||
|
||
<%= render partial: "decidim/action_delegator/consultations/questions/weight_results", locals: { response: response, question: question } %> |
11 changes: 11 additions & 0 deletions
11
app/views/decidim/action_delegator/consultations/_link_with_results.html.erb
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,11 @@ | ||
<%= link_to decidim_consultations.question_path(question), class: "button expanded button--sc" do %> | ||
<%= t "consultations.question.view_results", scope: "decidim" %> | ||
<% if question.most_weighted_voted_response.present? %> | ||
<span class="button__info"><%= translated_attribute question.most_weighted_voted_response.title %></span> | ||
<span class="button__info"> | ||
<%= question.most_weighted_voted_response.votes_count %> | ||
<%= t "consultations.question.votes_out_of", scope: "decidim", count: question.most_weighted_voted_response.votes_count %> | ||
<%= question.total_weighted_votes %> | ||
</span> | ||
<% end %> | ||
<% end %> |
8 changes: 8 additions & 0 deletions
8
app/views/decidim/action_delegator/consultations/questions/_weight_results.html.erb
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,8 @@ | ||
<% question.responses_sorted_by_weighted_votes[question.id].each do |response| %> | ||
<div class=card--list__item> | ||
<div class="card--list__text"><%= translated_attribute response.title %></div> | ||
<div class="card--list__data"> | ||
<span class="card--list__data__number"><%= response.votes_count %></span> | ||
</div> | ||
</div> | ||
<% 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
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
55 changes: 55 additions & 0 deletions
55
spec/system/decidim/action_delegator/weighted_results_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,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe "Weighted results", type: :system do | ||
let(:organization) { create :organization, available_locales: [:en] } | ||
let(:user) { create(:user, :admin, :confirmed, organization: organization) } | ||
|
||
let(:consultation) { create(:consultation, :finished, :published_results, organization: organization) } | ||
let!(:question) { create(:question, consultation: consultation) } | ||
let!(:responses) do | ||
Array.new(2) { |i| create(:response, question: question, title: { "en" => "Option #{i + 1} Title" }) } | ||
end | ||
|
||
let!(:other_user) { create(:user, :confirmed, organization: organization) } | ||
|
||
let(:setting) { create(:setting, consultation: consultation) } | ||
let(:ponderation1) { create(:ponderation, setting: setting, name: "consumer", weight: 4) } | ||
|
||
before do | ||
# Regular vote | ||
question.votes.create(author: user, response: responses.first) | ||
# Vote of a user with membership | ||
question.votes.create(author: other_user, response: responses.last) | ||
|
||
create(:participant, setting: setting, decidim_user: other_user, ponderation: ponderation1) | ||
|
||
switch_to_host(organization.host) | ||
login_as user, scope: :user | ||
visit decidim_consultations.consultation_path(consultation) | ||
end | ||
|
||
it "displays weighted results" do | ||
expect(page).to have_content("Option 2") | ||
expect(page).to have_content("4 votes out of 5") | ||
end | ||
|
||
context "when visiting the question page" do | ||
before do | ||
visit decidim_consultations.question_path(question) | ||
end | ||
|
||
it "displays weighted results" do | ||
within first(".card--list__item") do | ||
expect(page).to have_content("Option 2") | ||
expect(page).to have_content(4) | ||
end | ||
|
||
within all(".card--list__item")[1] do | ||
expect(page).to have_content("Option 1") | ||
expect(page).to have_content(1) | ||
end | ||
end | ||
end | ||
end |