Move dashboard system tests to resources component specs
We're making the `new_actions_since_last_login` parameter optional in order to simplify the tests.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class Dashboard::ResourcesComponent < ApplicationComponent
|
||||
attr_reader :proposal, :new_actions_since_last_login
|
||||
|
||||
def initialize(proposal, new_actions_since_last_login)
|
||||
def initialize(proposal, new_actions_since_last_login = [])
|
||||
@proposal = proposal
|
||||
@new_actions_since_last_login = new_actions_since_last_login
|
||||
end
|
||||
|
||||
130
spec/components/dashboard/resources_component_spec.rb
Normal file
130
spec/components/dashboard/resources_component_spec.rb
Normal file
@@ -0,0 +1,130 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Dashboard::ResourcesComponent do
|
||||
let(:proposal) { create(:proposal, :draft) }
|
||||
before { sign_in(proposal.author) }
|
||||
|
||||
describe "Available resources section" do
|
||||
let!(:available) { create(:dashboard_action, :resource, :active) }
|
||||
let(:requested) { create(:dashboard_action, :resource, :admin_request, :active) }
|
||||
let(:executed_action) do
|
||||
create(
|
||||
:dashboard_executed_action,
|
||||
action: requested,
|
||||
proposal: proposal,
|
||||
executed_at: Time.current
|
||||
)
|
||||
end
|
||||
let(:solved) { create(:dashboard_action, :resource, :admin_request, :active) }
|
||||
let(:executed_solved_action) do
|
||||
create(
|
||||
:dashboard_executed_action,
|
||||
action: solved,
|
||||
proposal: proposal,
|
||||
executed_at: Time.current
|
||||
)
|
||||
end
|
||||
let!(:unavailable) do
|
||||
create(
|
||||
:dashboard_action,
|
||||
:resource,
|
||||
:active,
|
||||
required_supports: proposal.votes_for.size + 1_000
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
create(:dashboard_administrator_task, :pending, source: executed_action)
|
||||
create(:dashboard_administrator_task, :done, source: executed_solved_action)
|
||||
end
|
||||
|
||||
it "shows available resources for proposal drafts" do
|
||||
render_inline Dashboard::ResourcesComponent.new(proposal)
|
||||
|
||||
expect(page).to have_content "Polls"
|
||||
expect(page).to have_content "E-mail"
|
||||
expect(page).to have_content "Poster"
|
||||
expect(page).to have_content available.title
|
||||
expect(page).to have_content unavailable.title
|
||||
expect(page).to have_content requested.title
|
||||
expect(page).to have_content solved.title
|
||||
|
||||
page.find("div#dashboard_action_#{available.id}") do |dashboard_action_available|
|
||||
expect(dashboard_action_available).to have_link "See resource"
|
||||
end
|
||||
|
||||
page.find("div#dashboard_action_#{requested.id}") do |dashboard_action_requested|
|
||||
expect(dashboard_action_requested).to have_content "Resource already requested"
|
||||
end
|
||||
|
||||
page.find("div#dashboard_action_#{unavailable.id}") do |dashboard_action_unavailable|
|
||||
expect(dashboard_action_unavailable).to have_content "1.000 supports required"
|
||||
end
|
||||
|
||||
page.find("div#dashboard_action_#{solved.id}") do |dashboard_action_solved|
|
||||
expect(dashboard_action_solved).to have_link "See resource"
|
||||
end
|
||||
end
|
||||
|
||||
it "shows available resources for published proposals" do
|
||||
proposal.update!(published_at: Date.current)
|
||||
|
||||
render_inline Dashboard::ResourcesComponent.new(proposal)
|
||||
|
||||
expect(page).to have_content "Polls"
|
||||
expect(page).to have_content "E-mail"
|
||||
expect(page).to have_content "Poster"
|
||||
expect(page).to have_content available.title
|
||||
expect(page).to have_content unavailable.title
|
||||
expect(page).to have_content requested.title
|
||||
expect(page).to have_content solved.title
|
||||
|
||||
page.find("div#dashboard_action_#{available.id}") do |dashboard_action_available|
|
||||
expect(dashboard_action_available).to have_link "See resource"
|
||||
end
|
||||
|
||||
page.find("div#dashboard_action_#{requested.id}") do |dashboard_action_requested|
|
||||
expect(dashboard_action_requested).to have_content "Resource already requested"
|
||||
end
|
||||
|
||||
page.find("div#dashboard_action_#{unavailable.id}") do |dashboard_action_unavailable|
|
||||
expect(dashboard_action_unavailable).to have_content "1.000 supports required"
|
||||
end
|
||||
|
||||
page.find("div#dashboard_action_#{solved.id}") do |dashboard_action_solved|
|
||||
expect(dashboard_action_solved).to have_link "See resource"
|
||||
end
|
||||
end
|
||||
|
||||
it "does not show resources with published_proposal: true" do
|
||||
available.update!(published_proposal: true)
|
||||
unavailable.update!(published_proposal: true)
|
||||
|
||||
render_inline Dashboard::ResourcesComponent.new(proposal)
|
||||
|
||||
expect(page).to have_content "Polls"
|
||||
expect(page).to have_content "E-mail"
|
||||
expect(page).to have_content "Poster"
|
||||
expect(page).not_to have_content available.title
|
||||
expect(page).not_to have_content unavailable.title
|
||||
end
|
||||
end
|
||||
|
||||
describe "Tags for new actions" do
|
||||
it "displays tag 'new' only when resource is detected like new action" do
|
||||
new_resource = create(:dashboard_action, :resource, :active)
|
||||
old_resource = create(:dashboard_action, :resource, :active)
|
||||
new_actions_since_last_login = [new_resource.id]
|
||||
|
||||
render_inline Dashboard::ResourcesComponent.new(proposal, new_actions_since_last_login)
|
||||
|
||||
page.find("div#dashboard_action_#{new_resource.id}") do |dashboard_action_new_resource|
|
||||
expect(dashboard_action_new_resource).to have_content "New"
|
||||
end
|
||||
|
||||
page.find("div#dashboard_action_#{old_resource.id}") do |dashboard_action_old_resource|
|
||||
expect(dashboard_action_old_resource).not_to have_content "New"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -138,116 +138,6 @@ describe "Proposal's dashboard" do
|
||||
expect(page).not_to have_content(action.title)
|
||||
end
|
||||
|
||||
scenario "Dashboard progress show available resources for proposal draft" do
|
||||
available = create(:dashboard_action, :resource, :active)
|
||||
|
||||
requested = create(:dashboard_action, :resource, :admin_request, :active)
|
||||
executed_action = create(:dashboard_executed_action, action: requested,
|
||||
proposal: proposal,
|
||||
executed_at: Time.current)
|
||||
_task = create(:dashboard_administrator_task, :pending, source: executed_action)
|
||||
|
||||
solved = create(:dashboard_action, :resource, :admin_request, :active)
|
||||
executed_solved_action = create(:dashboard_executed_action, action: solved,
|
||||
proposal: proposal,
|
||||
executed_at: Time.current)
|
||||
_solved_task = create(:dashboard_administrator_task, :done, source: executed_solved_action)
|
||||
|
||||
unavailable = create(:dashboard_action, :resource, :active,
|
||||
required_supports: proposal.votes_for.size + 1_000)
|
||||
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
within ".dashboard-resources" do
|
||||
expect(page).to have_content("Polls")
|
||||
expect(page).to have_content("E-mail")
|
||||
expect(page).to have_content("Poster")
|
||||
expect(page).to have_content(available.title)
|
||||
expect(page).to have_content(unavailable.title)
|
||||
expect(page).to have_content(requested.title)
|
||||
expect(page).to have_content(solved.title)
|
||||
|
||||
within "div#dashboard_action_#{available.id}" do
|
||||
expect(page).to have_link "See resource"
|
||||
end
|
||||
|
||||
within "div#dashboard_action_#{requested.id}" do
|
||||
expect(page).to have_content("Resource already requested")
|
||||
end
|
||||
|
||||
within "div#dashboard_action_#{unavailable.id}" do
|
||||
expect(page).to have_content("1.000 supports required")
|
||||
end
|
||||
|
||||
within "div#dashboard_action_#{solved.id}" do
|
||||
expect(page).to have_link("See resource")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Dashboard progress show available resources for published proposal" do
|
||||
proposal.update!(published_at: Date.current)
|
||||
available = create(:dashboard_action, :resource, :active)
|
||||
|
||||
requested = create(:dashboard_action, :resource, :admin_request, :active)
|
||||
executed_action = create(:dashboard_executed_action, action: requested,
|
||||
proposal: proposal,
|
||||
executed_at: Time.current)
|
||||
_task = create(:dashboard_administrator_task, :pending, source: executed_action)
|
||||
|
||||
solved = create(:dashboard_action, :resource, :admin_request, :active)
|
||||
executed_solved_action = create(:dashboard_executed_action, action: solved,
|
||||
proposal: proposal,
|
||||
executed_at: Time.current)
|
||||
_solved_task = create(:dashboard_administrator_task, :done, source: executed_solved_action)
|
||||
|
||||
unavailable = create(:dashboard_action, :resource, :active,
|
||||
required_supports: proposal.votes_for.size + 1_000)
|
||||
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
within ".dashboard-resources" do
|
||||
expect(page).to have_content("Polls")
|
||||
expect(page).to have_content("E-mail")
|
||||
expect(page).to have_content("Poster")
|
||||
expect(page).to have_content(available.title)
|
||||
expect(page).to have_content(unavailable.title)
|
||||
expect(page).to have_content(requested.title)
|
||||
expect(page).to have_content(solved.title)
|
||||
|
||||
within "div#dashboard_action_#{available.id}" do
|
||||
expect(page).to have_link "See resource"
|
||||
end
|
||||
|
||||
within "div#dashboard_action_#{requested.id}" do
|
||||
expect(page).to have_content("Resource already requested")
|
||||
end
|
||||
|
||||
within "div#dashboard_action_#{unavailable.id}" do
|
||||
expect(page).to have_content("1.000 supports required")
|
||||
end
|
||||
|
||||
within "div#dashboard_action_#{solved.id}" do
|
||||
expect(page).to have_link("See resource")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Dashboard progress dont show resources with published_proposal: true" do
|
||||
available = create(:dashboard_action, :resource, :active, published_proposal: true)
|
||||
unavailable = create(:dashboard_action, :resource, :active,
|
||||
required_supports: proposal.votes_for.size + 1_000,
|
||||
published_proposal: true)
|
||||
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
|
||||
within ".dashboard-resources" do
|
||||
expect(page).to have_content("Polls")
|
||||
expect(page).to have_content("E-mail")
|
||||
expect(page).to have_content("Poster")
|
||||
expect(page).not_to have_content(available.title)
|
||||
expect(page).not_to have_content(unavailable.title)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Dashboard has a link to resources on main menu" do
|
||||
feature = create(:dashboard_action, :resource, :active)
|
||||
|
||||
@@ -480,29 +370,6 @@ describe "Proposal's dashboard" do
|
||||
describe "detect_new_actions_after_last_login" do
|
||||
before { proposal.author.update!(current_sign_in_at: 1.day.ago) }
|
||||
|
||||
scenario "Display tag 'new' on resouce when it is new for author since last login" do
|
||||
resource = create(:dashboard_action, :resource, :active, day_offset: 0,
|
||||
published_proposal: false)
|
||||
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
|
||||
within "#dashboard_action_#{resource.id}" do
|
||||
expect(page).to have_content("New")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Not display tag 'new' on resouce when there is not new resources since last login" do
|
||||
resource = create(:dashboard_action, :resource, :active, day_offset: 0,
|
||||
published_proposal: false)
|
||||
proposal.author.update!(current_sign_in_at: Date.current)
|
||||
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
|
||||
within "#dashboard_action_#{resource.id}" do
|
||||
expect(page).not_to have_content("New")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Display tag 'new' on proposed_action when it is new for author since last login" do
|
||||
proposed_action = create(:dashboard_action, :proposed_action, :active, day_offset: 0,
|
||||
published_proposal: false)
|
||||
|
||||
Reference in New Issue
Block a user