Skip to content

Commit

Permalink
Fix specs / Fix views
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Dec 12, 2024
1 parent d06d2db commit 6310e91
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 59 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GIT

GIT
remote: https://github.com/mainio/decidim-module-plans.git
revision: c561ec3143786bb9e6a9484c17efdb38b0ccb70a
revision: e9419b7fab6f24755cb856550f9082629fd44fd8
specs:
decidim-plans (0.28.0)
decidim-core (~> 0.28.0)
Expand Down Expand Up @@ -359,7 +359,7 @@ GEM
nokogiri (>= 1.13.2, < 1.17.0)
rubyzip (~> 2.3.0)
docile (1.4.1)
doorkeeper (5.8.0)
doorkeeper (5.8.1)
railties (>= 5)
doorkeeper-i18n (4.0.1)
erb_lint (0.4.0)
Expand All @@ -383,7 +383,7 @@ GEM
railties (>= 5.0.0)
faker (3.2.3)
i18n (>= 1.8.11, < 2)
faraday (2.12.1)
faraday (2.12.2)
faraday-net_http (>= 2.0, < 3.5)
json
logger
Expand Down
47 changes: 30 additions & 17 deletions app/cells/decidim/ideas/highlighted_ideas_for_component/show.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
<section class="section row collapse highlighted_ideas">
<h3 class="section-heading">
<%= translated_attribute(model.name) %> <a href="<%= main_component_path(model) %>" class="text-small"><%= t("decidim.participatory_spaces.highlighted_ideas.see_all", count: ideas_count) %></a>
</h3>
<div class="content-block__title">
<h2 class="h2 decorator">
<%= single_component? ? decidim_escape_translated(model.name) : t("decidim.components.ideas.name") %>
</h2>
<div class="label text-lg"><%= ideas_count %></div>
<% if single_component? %>
<%= link_to decidim_ideas.root_path, class: "button button__sm button__text-secondary" do %>
<span><%= t("decidim.participatory_spaces.highlighted_ideas.see_all") %></span>
<%= icon "arrow-right-line" %>
<% end %>
<% end %>
</div>

<%= cell(
"decidim/collapsible_list",
ideas_to_render,
cell_options: {},
list_class: "row small-up-1 medium-up-2 card-grid",
size: ideas_count
) %>
<div class="flex items-start justify-between">
<div class="grow space-y-6">
<span class="content-block__span">
<%= t("decidim.participatory_spaces.highlighted_ideas.last") %>
</span>

<% ideas_to_render.each do |p| %>
<%= card_for p, link_whole_card: true, title_tag: :h3, **options.slice(:show_space) %>
<% end %>
</div>

<% if single_component? %>
<%= link_to decidim_ideas.new_idea_path, class: "button button__sm md:button__lg button__secondary" do %>
<span><%= t("decidim.ideas.actions.new") %></span>
<%= icon "add-line" %>
<% end %>
<% end %>
</div>

<%= link_to(
t("decidim.participatory_spaces.highlighted_ideas.see_all", count: ideas_count),
main_component_path(model),
class: "button button--sc light secondary button--right"
) %>
</section>
17 changes: 16 additions & 1 deletion app/cells/decidim/ideas/highlighted_ideas_for_component_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ module Ideas
# view hook.
class HighlightedIdeasForComponentCell < Decidim::ViewModel
include Decidim::ComponentPathHelper
include Decidim::CardHelper

def show
render unless ideas_count.zero?
render unless items_blank?
end

def items_blank?
ideas_count.zero?
end

private
Expand All @@ -22,6 +27,16 @@ def ideas
.order_randomly((rand * 2) - 1)
end

def single_component?
@single_component ||= model.is_a?(Decidim::Component)
end

def decidim_ideas
return unless single_component?

Decidim::EngineRouter.main_proxy(model)
end

def ideas_to_render
@ideas_to_render ||= ideas.includes(
[:amendable, :category, :component, :area_scope]
Expand Down
9 changes: 1 addition & 8 deletions app/cells/decidim/ideas/idea_activity_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ module Ideas
# A cell to display when a idea has been published.
class IdeaActivityCell < ActivityCell
def title
key =
if action == "update"
"decidim.ideas.last_activity.idea_updated_html"
else
"decidim.ideas.last_activity.new_idea_at_html"
end

I18n.t(key, link: participatory_space_link)
action == "update" ? I18n.t("decidim.ideas.last_activity.idea_updated_html") : I18n.t("decidim.ideas.last_activity.new_idea_at_html")
end

def resource_link_text
Expand Down
6 changes: 6 additions & 0 deletions app/cells/decidim/ideas/idea_g/data.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
</div>
<% end %>

<% if show_space? %>
<div class="card__info__item">
<%= decidim_html_escape(translated_attribute(participatory_space.title)) %>
</div>
<% end %>

<div class="card__info__item">
#<%= model.id %>
</div>
Expand Down
12 changes: 11 additions & 1 deletion app/cells/decidim/ideas/idea_g_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,22 @@ def title
decidim_html_escape(present(model).title)
end

def show_space?
(context[:show_space].presence || options[:show_space].presence) && resource.respond_to?(:participatory_space) && resource.participatory_space.present?
end

def participatory_space
return unless show_space?

@participatory_space ||= resource.participatory_space
end

def body
decidim_sanitize(present(model).body)
end

def category
decidim_sanitize translated_attribute(model.category.name) if has_category?
decidim_sanitize(translated_attribute(model.category.name)) if has_category?
end

def full_category
Expand Down
2 changes: 1 addition & 1 deletion app/cells/decidim/ideas/ideas_picker_inline_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def show
unless snippets.any?(:idea_picker_inline)
snippets.add(
:idea_picker_inline,
javascript_pack_tag("decidim_ideas_idea_picker_inline")
append_javascript_pack_tag("decidim_ideas_idea_picker_inline")
)
snippets.add(
:idea_picker_inline,
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/decidim/ideas/ideas_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def idea_form_map(map_html_options = {})
# e.g. the markercluser would not be available when the ideas map is
# loaded.
unless snippets.any?(:ideas_map_scripts)
snippets.add(:ideas_map_scripts, javascript_pack_tag("decidim_ideas_map"))
snippets.add(:ideas_map_scripts, append_javascript_pack_tag("decidim_ideas_map"))
snippets.add(:foot, snippets.for(:ideas_map_scripts))
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/decidim/ideas/ideas_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def ideas_map(geocoded_ideas, **options)
dynamic_map_for(map_options.merge(options)) do
# These snippets need to be added AFTER the other map scripts have
# been added which is why they cannot be within the block. Otherwise
# e.g. the markercluser would not be available when the idas map is
# e.g. the markercluster would not be available when the ideas map is
# loaded.
unless snippets.any?(:ideas_map_scripts)
snippets.add(:ideas_map_scripts, javascript_pack_tag("decidim_ideas_map"))
snippets.add(:ideas_map_scripts, append_javascript_pack_tag("decidim_ideas_map"))
snippets.add(:foot, snippets.for(:ideas_map_scripts))
end

Expand Down
4 changes: 3 additions & 1 deletion app/packs/stylesheets/decidim/ideas/ideas/_map.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.map-container{
position: relative;
[data-decidim-map]{
@apply my-4 aspect-[4/3];
}
}
2 changes: 1 addition & 1 deletion app/views/decidim/ideas/ideas/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</div>

<% if component_settings.geocoding_enabled? %>
<div class="tabs-panel" id="ideas-map">
<div class="tabs-panel map-container" id="ideas-map">
<%= ideas_map ideas_data_for_map(@geocoded_ideas) do %>
<%= render partial: "map_template" %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@

# Register the main application's stylesheet include statement
# Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/ideas/ideas")
Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/ideas/ideas/_map")
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ en:
ideas_count: Ideas
participatory_spaces:
highlighted_ideas:
last: Last ideas
see_all: See all (%{count})
plans:
section_types:
Expand Down
2 changes: 1 addition & 1 deletion spec/cells/decidim/ideas/highlighted_ideas_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
let!(:external_idea) { create(:idea, component: another_component) }

it "renders the ideas from components under the same space" do
expect(subject).to have_css(".card.card--idea", count: 2)
expect(subject).to have_css(".card__content", count: 2)
expect(subject).to have_content(translated(idea1.title))
expect(subject).to have_content(translated(idea2.title))
expect(subject).not_to have_content(translated(external_idea.title))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
let!(:hidden_idea) { create(:idea, :hidden, component: component) }

it "renders only the visible ideas" do
expect(subject).to have_css(".card.card--idea", count: 2)
expect(subject).to have_css(".card__content", count: 2)
expect(subject).to have_content(translated(idea1.title))
expect(subject).to have_content(translated(idea2.title))
expect(subject).not_to have_content(translated(unpublished_idea.title))
Expand All @@ -30,7 +30,7 @@
let!(:rest_of_ideas) { create_list(:idea, 10, component: component) }

it "shows the configured amount of ideas" do
expect(subject).to have_css(".card.card--idea", count: 4)
expect(subject).to have_css(".card__content", count: 4)
end

context "when the configuration is changed to a custom amount" do
Expand All @@ -41,7 +41,7 @@
end

it "shows the configured amount of ideas" do
expect(subject).to have_css(".card.card--idea", count: amount)
expect(subject).to have_css(".card__content", count: amount)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/cells/decidim/ideas/idea_activity_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

context "when rendering" do
it "renders the card" do
expect(subject).to have_css("#action-#{action_log.id}")
expect(subject).to have_css("[data-activity]")
end

context "when action is update" do
let(:action) { :update }

it "renders the correct title" do
expect(subject).to have_css("#action-#{action_log.id}")
expect(subject).to have_css("[data-activity]")
expect(subject).to have_content("Idea updated")
end
end
Expand All @@ -39,14 +39,14 @@
let(:action) { :create }

it "renders the correct title" do
expect(subject).to have_css("#action-#{action_log.id}")
expect(subject).to have_css("[data-activity]")
expect(subject).to have_content("New idea")
end
end

context "when action is publish" do
it "renders the correct title" do
expect(subject).to have_css("#action-#{action_log.id}")
expect(subject).to have_css("[data-activity]")
expect(subject).to have_content("New idea")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/cells/decidim/ideas/idea_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
let(:model) { idea }

it "renders the card" do
expect(subject).to have_css(".card--idea")
expect(subject).to have_css(".card__content")
end
end
end
5 changes: 3 additions & 2 deletions spec/cells/decidim/ideas/idea_g_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Decidim::Ideas

subject { cell_html }

let(:my_cell) { cell("decidim/ideas/idea_g", idea, context: { show_space: show_space }) }
let(:my_cell) { cell("decidim/ideas/idea_g", idea, context: { show_space: }) }
let(:cell_html) { my_cell.call }
let(:created_at) { 1.month.ago }
let(:published_at) { Time.current }
Expand All @@ -33,7 +33,8 @@ module Decidim::Ideas
let(:show_space) { false }

it "renders the card" do
expect(subject).to have_css(".card--idea")
puts subject
expect(subject).to have_css(".card__content")
end

it "renders the published_at date" do
Expand Down
4 changes: 2 additions & 2 deletions spec/system/create_idea_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def visit_component

it "withdraw" do
click_link "Discard this draft"
click_link "OK"
click_on "OK"
expect(page).to have_content("Draft destroyed successfully")
end
end
Expand All @@ -139,7 +139,7 @@ def visit_component

context "when uploading a file", processing_uploads_for: Decidim::Ideas::AttachmentUploader do
it "creates a new idea with image" do
dynamically_attach_file(:idea_images, Decidim::Dev.asset("avatar.jpg"), title: "Foo bar")
dynamically_attach_file(:idea_images, Decidim::Dev.asset("avatar.jpg"), title: "Foo bar", front_interface: true, remove_before: true)
click_button "Continue"
click_button "Publish"
expect(page).to have_content("Idea successfully published")
Expand Down
8 changes: 4 additions & 4 deletions spec/system/edit_idea_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@

it "remove image" do
click_button "Change image"
within ".reveal.upload-modal" do
click_button "× Remove"
within ".upload-modal" do
click_button "Remove"
click_button "Save"
end
expect { click_button "Save" }.to change(idea2.attachments, :count).by(-1)
Expand Down Expand Up @@ -139,8 +139,8 @@

it "removes attached pdf" do
click_button "Change attachment"
within ".reveal.upload-modal" do
click_button "× Remove"
within ".upload-modal" do
click_button "Remove"
click_button "Save"
end
expect { click_button "Save" }.to change(idea3.attachments, :count).by(-1)
Expand Down
6 changes: 3 additions & 3 deletions spec/system/filter_and_sort_ideas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def visit_component

before do
visit current_path
within all(".filters__control.area_scope_id_filter").last do
within all(".filters__control.area_scope_id_filter").first do
fill_in "filter[search_text_cont]", with: title
end
perform_search
Expand Down Expand Up @@ -195,11 +195,11 @@ def visit_component
before do
visit current_path
within ".order-by" do
expect(page).to have_selector("ul[data-dropdown-menu$=dropdown-menu]", text: "Recent")
expect(page).to have_selector("a[data-order='recent']", text: "Recent")
page.find("a", text: "Recent").click
click_link(selected_option, match: :first)
end
within ".order-by__dropdown .dropdown.menu li.is-dropdown-submenu-parent a" do
within ".order-by" do
expect(page).to have_content(selected_option)
end
expect(page).to have_content("Browse ideas", wait: 1)
Expand Down
9 changes: 6 additions & 3 deletions spec/system/global_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
end

it "finds idea" do
fill_in :term, with: idea.title
click_button "Search"
expect(page).to have_content("1 RESULTS FOR THE SEARCH")
within ".main-bar__search" do
fill_in :term, with: idea.title
end

find("input#input-search").native.send_keys :enter
expect(page).to have_content("1 Results for the search")
expect(page).to have_content(idea_title)
expect(page).not_to have_content(idea2_title)
end
Expand Down

0 comments on commit 6310e91

Please sign in to comment.