Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Sep 17, 2024
1 parent ca2243a commit 5e79b8f
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 86 deletions.
2 changes: 1 addition & 1 deletion app/cells/decidim/plans/plan_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def current_user
end

def card_size
"decidim/plans/plan_m"
"decidim/plans/plan_g"
end

def resource_path
Expand Down
2 changes: 1 addition & 1 deletion app/cells/decidim/plans/plan_g/data.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div class="card__info">
<div class="card__info__item">

<%= creation_date_status %>
</div>

<% if has_category? %>
Expand Down
2 changes: 1 addition & 1 deletion app/cells/decidim/plans/plan_g/state.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<span class="label <%= state_classes.join(" ") %>"><%= badge_name %></span>
<span class="label <%= state_class %>"><%= badge_name %></span>
24 changes: 14 additions & 10 deletions app/cells/decidim/plans/plan_g_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PlanGCell < Decidim::CardGCell

alias plan model

def badge
def state
render if has_badge?
end

Expand Down Expand Up @@ -86,6 +86,10 @@ def has_badge?
closed? || answered? || withdrawn?
end

def badge_name
model.state.capitalize
end

def has_link_to_resource?
model.published?
end
Expand All @@ -94,26 +98,26 @@ def has_footer?
true
end

def badge_classes
return super unless options[:full_badge]

state_classes.push(["label", "idea-status"]).join(" ")
end

def statuses
return [] if preview?
return [:comments_count] if model.draft?

[:comments_count, :favoriting_count]
end

def state_class
return "success" if model.accepted?
return "warning" if model.evaluating?
return "alert" if model.answered? || model.rejected? || model.withdrawn?
end

def comments_count_status
render_comments_count
end

# def creation_date_status
# l(model.published_at.to_date, format: :decidim_short)
# end
def creation_date_status
l(model.published_at.to_date, format: :decidim_short)
end

def favoriting_count_status
cell("decidim/favorites/favoriting_count", model)
Expand Down
2 changes: 1 addition & 1 deletion app/cells/decidim/plans/plan_l/data.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>

<div class="card__info__item">
<%# <%= creation_date_status %>
<%= creation_date_status %>
</div>

<% if has_category? %>
Expand Down
2 changes: 1 addition & 1 deletion app/cells/decidim/plans/plan_view/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<div class="row">
<div class="columns medium-8">
<div class="section">
<%== cell("decidim/plans/plan_g", plan, full_badge: true) %>
<%== cell("decidim/plans/plan_g", plan, full_badge: true).state %>
<%= contents %>
<%= cell("decidim/plans/tags", plan, context: { extra_classes: ["tags--plan"] }) %>
</div>
Expand Down
13 changes: 0 additions & 13 deletions app/helpers/decidim/plans/plan_cells_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,6 @@ def from_context
def badge_name
humanize_plan_state state
end

def state_classes
case state
when "accepted"
["success"]
when "rejected", "withdrawn"
["alert"]
when "evaluating"
["warning"]
else
["muted"]
end
end
end
end
end
3 changes: 3 additions & 0 deletions app/views/decidim/plans/plans/preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<div class="resource__main">
<div class="actions">
<div class="flex--sbc">
<%= action_authorized_link_to :withdraw, withdraw_plan_path, method: :put, class: "title-action__action button small hollow", title: t("withdraw_btn_hint", scope: "decidim.plans.plans.show"), data: { confirm: t("withdraw_confirmation", scope: "decidim.plans.plans.show") } do %>
<%= t("withdraw_btn", scope: "decidim.plans.plans.show") %>
<% end %>
<%= link_to t(".modify"), edit_plan_path(@plan) %>
<%= button_to t(".publish"), publish_plan_path(@plan), method: :post, class: "button" %>
</div>
Expand Down
21 changes: 3 additions & 18 deletions spec/cells/decidim/plans/collapsible_authors_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,15 @@
let(:my_cell) do
cell(
"decidim/plans/collapsible_authors",
model.authors,
has_actions: true
authors_presenters
)
end
let(:model) { create(:plan) }
let(:authors_presenters) { model.authors.map { |author| Decidim::UserPresenter.new(author) } }

controller Decidim::Plans::PlansController

it "renders collapsible list" do
subject
end

context "when actionable" do
let(:author_cell) { double }

it "renders the actions" do
allow(my_cell).to receive(:actionable?).and_return(true)
allow(my_cell).to receive(:cell)
.with("decidim/author", any_args)
.and_return(author_cell)
expect(author_cell).to receive(:call).with(:date)
expect(author_cell).to receive(:call).with(:flag)
expect(author_cell).to receive(:call).with(:withdraw)
expect(subject).to have_css(".author-data__extra")
end
expect(subject).to have_css(".author > .author__container")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
require "spec_helper"

module Decidim::Plans
describe PlanMCell, type: :cell do
describe PlanGCell, type: :cell do
controller Decidim::Plans::PlansController

subject { cell_html }

let(:my_cell) { cell("decidim/plans/plan_m", plan, context: { show_space: }) }
let(:my_cell) { cell("decidim/plans/plan_g", plan, context: { show_space: }) }
let(:cell_html) { my_cell.call }
let(:created_at) { 1.month.ago }
let(:published_at) { Time.current }
Expand Down
37 changes: 0 additions & 37 deletions spec/helpers/decidim/plans/plan_cells_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,41 +90,4 @@
expect(helper.badge_name).to be(name)
end
end

describe "#state_classes" do
context "when accepted" do
it "returns correct classes" do
allow(helper).to receive(:state).and_return("accepted")
expect(helper.state_classes).to contain_exactly("success")
end
end

context "when rejected" do
it "returns correct classes" do
allow(helper).to receive(:state).and_return("rejected")
expect(helper.state_classes).to contain_exactly("alert")
end
end

context "when evaluating" do
it "returns correct classes" do
allow(helper).to receive(:state).and_return("evaluating")
expect(helper.state_classes).to contain_exactly("warning")
end
end

context "when withdrawn" do
it "returns correct classes" do
allow(helper).to receive(:state).and_return("withdrawn")
expect(helper.state_classes).to contain_exactly("alert")
end
end

context "when something else" do
it "returns correct classes" do
allow(helper).to receive(:state).and_return("something")
expect(helper.state_classes).to contain_exactly("muted")
end
end
end
end
2 changes: 1 addition & 1 deletion spec/system/explore_plans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
click_on "OK"
expect(page).to have_content("Item withdrawn successfully.")
expect(page).to have_current_path(decidim_plan.plan_path(plan.id))
within "span.alert.label.idea-status" do
within "span.alert" do
expect(page).to have_content("Withdrawn")
end
expect(page).to have_no_link("Withdraw proposal")
Expand Down

0 comments on commit 5e79b8f

Please sign in to comment.