From 5e79b8fbf86624368c87f927c7ea0ea3d4fbd8cf Mon Sep 17 00:00:00 2001 From: Joonas Date: Tue, 17 Sep 2024 09:49:35 +0300 Subject: [PATCH] Fix specs --- app/cells/decidim/plans/plan_cell.rb | 2 +- app/cells/decidim/plans/plan_g/data.erb | 2 +- app/cells/decidim/plans/plan_g/state.erb | 2 +- app/cells/decidim/plans/plan_g_cell.rb | 24 +++++++----- app/cells/decidim/plans/plan_l/data.erb | 2 +- app/cells/decidim/plans/plan_view/show.erb | 2 +- .../decidim/plans/plan_cells_helper.rb | 13 ------- .../decidim/plans/plans/preview.html.erb | 3 ++ .../plans/collapsible_authors_cell_spec.rb | 21 ++--------- ...lan_m_cell_spec.rb => plan_g_cell_spec.rb} | 4 +- .../decidim/plans/plan_cells_helper_spec.rb | 37 ------------------- spec/system/explore_plans_spec.rb | 2 +- 12 files changed, 28 insertions(+), 86 deletions(-) rename spec/cells/decidim/plans/{plan_m_cell_spec.rb => plan_g_cell_spec.rb} (92%) diff --git a/app/cells/decidim/plans/plan_cell.rb b/app/cells/decidim/plans/plan_cell.rb index 0423f374..8b4e2ec2 100644 --- a/app/cells/decidim/plans/plan_cell.rb +++ b/app/cells/decidim/plans/plan_cell.rb @@ -24,7 +24,7 @@ def current_user end def card_size - "decidim/plans/plan_m" + "decidim/plans/plan_g" end def resource_path diff --git a/app/cells/decidim/plans/plan_g/data.erb b/app/cells/decidim/plans/plan_g/data.erb index 62909022..502ba574 100644 --- a/app/cells/decidim/plans/plan_g/data.erb +++ b/app/cells/decidim/plans/plan_g/data.erb @@ -12,7 +12,7 @@
- + <%= creation_date_status %>
<% if has_category? %> diff --git a/app/cells/decidim/plans/plan_g/state.erb b/app/cells/decidim/plans/plan_g/state.erb index d8074563..90b492a2 100644 --- a/app/cells/decidim/plans/plan_g/state.erb +++ b/app/cells/decidim/plans/plan_g/state.erb @@ -1 +1 @@ -"><%= badge_name %> +<%= badge_name %> diff --git a/app/cells/decidim/plans/plan_g_cell.rb b/app/cells/decidim/plans/plan_g_cell.rb index 6df64e09..bfe60c32 100644 --- a/app/cells/decidim/plans/plan_g_cell.rb +++ b/app/cells/decidim/plans/plan_g_cell.rb @@ -11,7 +11,7 @@ class PlanGCell < Decidim::CardGCell alias plan model - def badge + def state render if has_badge? end @@ -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 @@ -94,12 +98,6 @@ 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? @@ -107,13 +105,19 @@ def statuses [: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) diff --git a/app/cells/decidim/plans/plan_l/data.erb b/app/cells/decidim/plans/plan_l/data.erb index f41c1e7c..00e9f51a 100644 --- a/app/cells/decidim/plans/plan_l/data.erb +++ b/app/cells/decidim/plans/plan_l/data.erb @@ -10,7 +10,7 @@
- <%# <%= creation_date_status %> + <%= creation_date_status %>
<% if has_category? %> diff --git a/app/cells/decidim/plans/plan_view/show.erb b/app/cells/decidim/plans/plan_view/show.erb index d62e16b8..9e4a48ea 100644 --- a/app/cells/decidim/plans/plan_view/show.erb +++ b/app/cells/decidim/plans/plan_view/show.erb @@ -47,7 +47,7 @@
- <%== 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"] }) %>
diff --git a/app/helpers/decidim/plans/plan_cells_helper.rb b/app/helpers/decidim/plans/plan_cells_helper.rb index 6d3340d1..d4cc97c6 100644 --- a/app/helpers/decidim/plans/plan_cells_helper.rb +++ b/app/helpers/decidim/plans/plan_cells_helper.rb @@ -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 diff --git a/app/views/decidim/plans/plans/preview.html.erb b/app/views/decidim/plans/plans/preview.html.erb index b8e402b5..68dcb58a 100644 --- a/app/views/decidim/plans/plans/preview.html.erb +++ b/app/views/decidim/plans/plans/preview.html.erb @@ -19,6 +19,9 @@
+ <%= 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" %>
diff --git a/spec/cells/decidim/plans/collapsible_authors_cell_spec.rb b/spec/cells/decidim/plans/collapsible_authors_cell_spec.rb index 6723fb0d..873e4cd4 100644 --- a/spec/cells/decidim/plans/collapsible_authors_cell_spec.rb +++ b/spec/cells/decidim/plans/collapsible_authors_cell_spec.rb @@ -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 diff --git a/spec/cells/decidim/plans/plan_m_cell_spec.rb b/spec/cells/decidim/plans/plan_g_cell_spec.rb similarity index 92% rename from spec/cells/decidim/plans/plan_m_cell_spec.rb rename to spec/cells/decidim/plans/plan_g_cell_spec.rb index 8c63b169..16084bb1 100644 --- a/spec/cells/decidim/plans/plan_m_cell_spec.rb +++ b/spec/cells/decidim/plans/plan_g_cell_spec.rb @@ -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 } diff --git a/spec/helpers/decidim/plans/plan_cells_helper_spec.rb b/spec/helpers/decidim/plans/plan_cells_helper_spec.rb index 9a809857..e00cef3d 100644 --- a/spec/helpers/decidim/plans/plan_cells_helper_spec.rb +++ b/spec/helpers/decidim/plans/plan_cells_helper_spec.rb @@ -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 diff --git a/spec/system/explore_plans_spec.rb b/spec/system/explore_plans_spec.rb index be15cebf..88bc80ac 100644 --- a/spec/system/explore_plans_spec.rb +++ b/spec/system/explore_plans_spec.rb @@ -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")