Extract component to render dashboard polls
Just like we usually do when reorganizing code.
This commit is contained in:
5
app/components/dashboard/polls_component.html.erb
Normal file
5
app/components/dashboard/polls_component.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<div class="row expanded margin-top" data-equalizer="poll-cards" data-equalize-on="medium">
|
||||
<% polls.each do |poll| %>
|
||||
<%= render Dashboard::PollComponent.new(poll) %>
|
||||
<% end %>
|
||||
</div>
|
||||
11
app/components/dashboard/polls_component.rb
Normal file
11
app/components/dashboard/polls_component.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Dashboard::PollsComponent < ApplicationComponent
|
||||
attr_reader :polls
|
||||
|
||||
def initialize(polls)
|
||||
@polls = polls
|
||||
end
|
||||
|
||||
def render?
|
||||
polls.any?
|
||||
end
|
||||
end
|
||||
@@ -3,13 +3,7 @@
|
||||
<div class="small-12 medium-9 column">
|
||||
<%= Setting["proposals.poll_description"] %>
|
||||
|
||||
<% if @polls.any? %>
|
||||
<div class="row expanded margin-top" data-equalizer="poll-cards" data-equalize-on="medium">
|
||||
<% @polls.each do |poll| %>
|
||||
<%= render Dashboard::PollComponent.new(poll) %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render Dashboard::PollsComponent.new(@polls) %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column">
|
||||
|
||||
@@ -9,27 +9,13 @@ describe Dashboard::PollComponent do
|
||||
|
||||
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
|
||||
expect(page).not_to have_link "Edit survey"
|
||||
expect(page).to have_link "View results", href: results_proposal_poll_path(proposal, current)
|
||||
end
|
||||
|
||||
it "shows results link for expired polls" do
|
||||
@@ -37,10 +23,17 @@ describe Dashboard::PollComponent do
|
||||
|
||||
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)
|
||||
expect(page).not_to have_link "Edit survey"
|
||||
expect(page).to have_link "View results", href: results_proposal_poll_path(proposal, expired)
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
expect(page).to have_link "Edit survey", href: edit_proposal_dashboard_poll_path(proposal, upcoming)
|
||||
expect(page).not_to have_link "View results"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,12 +42,10 @@ describe Dashboard::PollComponent do
|
||||
|
||||
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
|
||||
|
||||
9
spec/components/dashboard/polls_component_spec.rb
Normal file
9
spec/components/dashboard/polls_component_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Dashboard::PollsComponent do
|
||||
it "is not rendered when there aren't any polls" do
|
||||
render_inline Dashboard::PollsComponent.new(Poll.none)
|
||||
|
||||
expect(page).not_to be_rendered
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user