Move dashboard poll partial to component
This commit is contained in:
@@ -372,28 +372,6 @@
|
||||
padding: $line-height;
|
||||
}
|
||||
|
||||
.poll-card {
|
||||
background: #e7f3fd;
|
||||
border-radius: rem-calc(4);
|
||||
margin-bottom: $line-height;
|
||||
min-height: $line-height * 9;
|
||||
padding: $line-height;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
|
||||
.button {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.community-poll {
|
||||
border-bottom: 1px solid $border;
|
||||
margin-bottom: $line-height;
|
||||
|
||||
21
app/assets/stylesheets/dashboard/poll.scss
Normal file
21
app/assets/stylesheets/dashboard/poll.scss
Normal file
@@ -0,0 +1,21 @@
|
||||
.dashboard-poll .poll-card {
|
||||
background: #e7f3fd;
|
||||
border-radius: rem-calc(4);
|
||||
margin-bottom: $line-height;
|
||||
min-height: $line-height * 9;
|
||||
padding: $line-height;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
|
||||
.button {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<div id="<%= dom_id(poll) %>" class="small-12 medium-6 large-4 column end">
|
||||
<div id="<%= dom_id(poll) %>" class="dashboard-poll small-12 medium-6 large-4 column end">
|
||||
<div class="poll-card" data-equalizer-watch="poll-cards">
|
||||
<h4><%= link_to poll.title, proposal_poll_path(proposal, poll) %></h4>
|
||||
<span class="small">
|
||||
13
app/components/dashboard/poll_component.rb
Normal file
13
app/components/dashboard/poll_component.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Dashboard::PollComponent < ApplicationComponent
|
||||
attr_reader :poll
|
||||
|
||||
def initialize(poll)
|
||||
@poll = poll
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def proposal
|
||||
poll.related
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
<% if @polls.any? %>
|
||||
<div class="row expanded margin-top" data-equalizer="poll-cards" data-equalize-on="medium">
|
||||
<%= render @polls %>
|
||||
<% @polls.each do |poll| %>
|
||||
<%= render Dashboard::PollComponent.new(poll) %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
60
spec/components/dashboard/poll_component_spec.rb
Normal file
60
spec/components/dashboard/poll_component_spec.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Dashboard::PollComponent do
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
let(:proposal) { create(:proposal, :draft) }
|
||||
|
||||
before { sign_in(proposal.author) }
|
||||
|
||||
describe "Poll card content" do
|
||||
describe "actions visibility" do
|
||||
it "shows edit link for upcoming polls" do
|
||||
upcoming = create(:poll, related: proposal, starts_at: 1.week.from_now)
|
||||
|
||||
render_inline Dashboard::PollComponent.new(upcoming)
|
||||
|
||||
page.find("div#poll_#{upcoming.id}") do |poll_card|
|
||||
expect(poll_card).to have_link "Edit survey",
|
||||
href: edit_proposal_dashboard_poll_path(proposal, upcoming)
|
||||
expect(poll_card).not_to have_link "View results"
|
||||
end
|
||||
end
|
||||
|
||||
it "shows results link for current polls" do
|
||||
current = create(:poll, related: proposal)
|
||||
|
||||
render_inline Dashboard::PollComponent.new(current)
|
||||
|
||||
page.find("div#poll_#{current.id}") do |poll_card|
|
||||
expect(poll_card).not_to have_link "Edit survey"
|
||||
expect(poll_card).to have_link "View results", href: results_proposal_poll_path(proposal, current)
|
||||
end
|
||||
end
|
||||
|
||||
it "shows results link for expired polls" do
|
||||
expired = create(:poll, :expired, related: proposal)
|
||||
|
||||
render_inline Dashboard::PollComponent.new(expired)
|
||||
|
||||
page.find("div#poll_#{expired.id}") do |poll_card|
|
||||
expect(poll_card).not_to have_link "Edit survey"
|
||||
expect(poll_card).to have_link "View results", href: results_proposal_poll_path(proposal, expired)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "renders poll title and dates" do
|
||||
expired = create(:poll, :expired, related: proposal)
|
||||
|
||||
render_inline Dashboard::PollComponent.new(expired)
|
||||
|
||||
page.find("div#poll_#{expired.id}") do |poll_card|
|
||||
expect(page).to have_content I18n.l(expired.starts_at.to_date)
|
||||
expect(page).to have_content I18n.l(expired.ends_at.to_date)
|
||||
expect(page).to have_link expired.title
|
||||
expect(page).to have_link expired.title, href: proposal_poll_path(proposal, expired)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -123,26 +123,6 @@ describe "Polls" do
|
||||
expect(page).to have_content("Edit poll")
|
||||
end
|
||||
|
||||
scenario "Edit poll is not allowed for current polls" do
|
||||
poll = create(:poll, related: proposal)
|
||||
|
||||
visit proposal_dashboard_polls_path(proposal)
|
||||
|
||||
within "div#poll_#{poll.id}" do
|
||||
expect(page).not_to have_content("Edit survey")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Edit poll is not allowed for expired polls" do
|
||||
poll = create(:poll, :expired, related: proposal)
|
||||
|
||||
visit proposal_dashboard_polls_path(proposal)
|
||||
|
||||
within "div#poll_#{poll.id}" do
|
||||
expect(page).not_to have_content("Edit survey")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Edit poll should allow to remove questions" do
|
||||
poll = create(:poll, related: proposal, starts_at: 1.week.from_now)
|
||||
create(:poll_question, poll: poll)
|
||||
@@ -224,36 +204,6 @@ describe "Polls" do
|
||||
expect(page).to have_content(poll.name)
|
||||
end
|
||||
|
||||
scenario "View results not available for upcoming polls" do
|
||||
poll = create(:poll, related: proposal, starts_at: 1.week.from_now)
|
||||
|
||||
visit proposal_dashboard_polls_path(proposal)
|
||||
|
||||
within "div#poll_#{poll.id}" do
|
||||
expect(page).not_to have_content("View results")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "View results available for current polls" do
|
||||
poll = create(:poll, related: proposal)
|
||||
|
||||
visit proposal_dashboard_polls_path(proposal)
|
||||
|
||||
within "div#poll_#{poll.id}" do
|
||||
expect(page).to have_content("View results")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "View results available for expired polls" do
|
||||
poll = create(:poll, :expired, related: proposal)
|
||||
|
||||
visit proposal_dashboard_polls_path(proposal)
|
||||
|
||||
within "div#poll_#{poll.id}" do
|
||||
expect(page).to have_content("View results")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "View results redirects to results in public zone" do
|
||||
poll = create(:poll, :expired, related: proposal)
|
||||
|
||||
@@ -276,18 +226,4 @@ describe "Polls" do
|
||||
|
||||
expect(find_field("Show results")).not_to be_checked
|
||||
end
|
||||
|
||||
scenario "Poll card" do
|
||||
poll = create(:poll, :expired, related: proposal)
|
||||
|
||||
visit proposal_dashboard_polls_path(proposal)
|
||||
|
||||
within "div#poll_#{poll.id}" do
|
||||
expect(page).to have_content(I18n.l(poll.starts_at.to_date))
|
||||
expect(page).to have_content(I18n.l(poll.ends_at.to_date))
|
||||
expect(page).to have_link(poll.title)
|
||||
expect(page).to have_link(poll.title, href: proposal_poll_path(proposal, poll))
|
||||
expect(page).to have_link("View results", href: results_proposal_poll_path(proposal, poll))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user