diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index c75202c4f..cbcb40f88 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -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; diff --git a/app/assets/stylesheets/dashboard/poll.scss b/app/assets/stylesheets/dashboard/poll.scss new file mode 100644 index 000000000..9235a79e1 --- /dev/null +++ b/app/assets/stylesheets/dashboard/poll.scss @@ -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; + } + } +} diff --git a/app/views/dashboard/polls/_poll.html.erb b/app/components/dashboard/poll_component.html.erb similarity index 94% rename from app/views/dashboard/polls/_poll.html.erb rename to app/components/dashboard/poll_component.html.erb index 4c3eca69d..55a28d88b 100644 --- a/app/views/dashboard/polls/_poll.html.erb +++ b/app/components/dashboard/poll_component.html.erb @@ -1,4 +1,4 @@ -
+

<%= link_to poll.title, proposal_poll_path(proposal, poll) %>

diff --git a/app/components/dashboard/poll_component.rb b/app/components/dashboard/poll_component.rb new file mode 100644 index 000000000..8990576f2 --- /dev/null +++ b/app/components/dashboard/poll_component.rb @@ -0,0 +1,13 @@ +class Dashboard::PollComponent < ApplicationComponent + attr_reader :poll + + def initialize(poll) + @poll = poll + end + + private + + def proposal + poll.related + end +end diff --git a/app/views/dashboard/polls/index.html.erb b/app/views/dashboard/polls/index.html.erb index fb7eebae8..ad362dd84 100644 --- a/app/views/dashboard/polls/index.html.erb +++ b/app/views/dashboard/polls/index.html.erb @@ -5,7 +5,9 @@ <% if @polls.any? %>
- <%= render @polls %> + <% @polls.each do |poll| %> + <%= render Dashboard::PollComponent.new(poll) %> + <% end %>
<% end %>
diff --git a/spec/components/dashboard/poll_component_spec.rb b/spec/components/dashboard/poll_component_spec.rb new file mode 100644 index 000000000..101615e39 --- /dev/null +++ b/spec/components/dashboard/poll_component_spec.rb @@ -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 diff --git a/spec/system/dashboard/polls_spec.rb b/spec/system/dashboard/polls_spec.rb index cb9ed5821..2ef729541 100644 --- a/spec/system/dashboard/polls_spec.rb +++ b/spec/system/dashboard/polls_spec.rb @@ -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