From 6310e9167e78b96a6aa20c23054d0d7d61f4a757 Mon Sep 17 00:00:00 2001 From: Joonas Date: Thu, 12 Dec 2024 08:09:20 +0200 Subject: [PATCH] Fix specs / Fix views --- Gemfile.lock | 6 +-- .../highlighted_ideas_for_component/show.erb | 47 ++++++++++++------- .../highlighted_ideas_for_component_cell.rb | 17 ++++++- app/cells/decidim/ideas/idea_activity_cell.rb | 9 +--- app/cells/decidim/ideas/idea_g/data.erb | 6 +++ app/cells/decidim/ideas/idea_g_cell.rb | 12 ++++- .../decidim/ideas/ideas_picker_inline_cell.rb | 2 +- .../decidim/ideas/ideas_form_helper.rb | 2 +- app/helpers/decidim/ideas/ideas_helper.rb | 4 +- .../stylesheets/decidim/ideas/ideas/_map.scss | 4 +- app/views/decidim/ideas/ideas/index.html.erb | 2 +- config/assets.rb | 1 + config/locales/en.yml | 1 + .../ideas/highlighted_ideas_cell_spec.rb | 2 +- ...ghlighted_ideas_for_component_cell_spec.rb | 6 +-- .../decidim/ideas/idea_activity_cell_spec.rb | 8 ++-- spec/cells/decidim/ideas/idea_cell_spec.rb | 2 +- spec/cells/decidim/ideas/idea_g_cell_spec.rb | 5 +- spec/system/create_idea_spec.rb | 4 +- spec/system/edit_idea_spec.rb | 8 ++-- spec/system/filter_and_sort_ideas_spec.rb | 6 +-- spec/system/global_search_spec.rb | 9 ++-- 22 files changed, 104 insertions(+), 59 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5bca07f..c0da7d1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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 diff --git a/app/cells/decidim/ideas/highlighted_ideas_for_component/show.erb b/app/cells/decidim/ideas/highlighted_ideas_for_component/show.erb index 575563f..6ddd0a2 100644 --- a/app/cells/decidim/ideas/highlighted_ideas_for_component/show.erb +++ b/app/cells/decidim/ideas/highlighted_ideas_for_component/show.erb @@ -1,19 +1,32 @@ -
-

- <%= translated_attribute(model.name) %> <%= t("decidim.participatory_spaces.highlighted_ideas.see_all", count: ideas_count) %> -

+
+

+ <%= single_component? ? decidim_escape_translated(model.name) : t("decidim.components.ideas.name") %> +

+
<%= ideas_count %>
+ <% if single_component? %> + <%= link_to decidim_ideas.root_path, class: "button button__sm button__text-secondary" do %> + <%= t("decidim.participatory_spaces.highlighted_ideas.see_all") %> + <%= icon "arrow-right-line" %> + <% end %> + <% end %> +
- <%= cell( - "decidim/collapsible_list", - ideas_to_render, - cell_options: {}, - list_class: "row small-up-1 medium-up-2 card-grid", - size: ideas_count - ) %> +
+
+ + <%= t("decidim.participatory_spaces.highlighted_ideas.last") %> + + + <% ideas_to_render.each do |p| %> + <%= card_for p, link_whole_card: true, title_tag: :h3, **options.slice(:show_space) %> + <% end %> +
+ + <% if single_component? %> + <%= link_to decidim_ideas.new_idea_path, class: "button button__sm md:button__lg button__secondary" do %> + <%= t("decidim.ideas.actions.new") %> + <%= icon "add-line" %> + <% end %> + <% end %> +
- <%= 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" - ) %> -
diff --git a/app/cells/decidim/ideas/highlighted_ideas_for_component_cell.rb b/app/cells/decidim/ideas/highlighted_ideas_for_component_cell.rb index 008c609..d7a5b62 100644 --- a/app/cells/decidim/ideas/highlighted_ideas_for_component_cell.rb +++ b/app/cells/decidim/ideas/highlighted_ideas_for_component_cell.rb @@ -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 @@ -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] diff --git a/app/cells/decidim/ideas/idea_activity_cell.rb b/app/cells/decidim/ideas/idea_activity_cell.rb index e66bdb9..1d0dec6 100644 --- a/app/cells/decidim/ideas/idea_activity_cell.rb +++ b/app/cells/decidim/ideas/idea_activity_cell.rb @@ -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 diff --git a/app/cells/decidim/ideas/idea_g/data.erb b/app/cells/decidim/ideas/idea_g/data.erb index 4add7e2..8dda48c 100644 --- a/app/cells/decidim/ideas/idea_g/data.erb +++ b/app/cells/decidim/ideas/idea_g/data.erb @@ -5,6 +5,12 @@ <% end %> + <% if show_space? %> +
+ <%= decidim_html_escape(translated_attribute(participatory_space.title)) %> +
+ <% end %> +
#<%= model.id %>
diff --git a/app/cells/decidim/ideas/idea_g_cell.rb b/app/cells/decidim/ideas/idea_g_cell.rb index 18c89ec..f3e2f36 100644 --- a/app/cells/decidim/ideas/idea_g_cell.rb +++ b/app/cells/decidim/ideas/idea_g_cell.rb @@ -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 diff --git a/app/cells/decidim/ideas/ideas_picker_inline_cell.rb b/app/cells/decidim/ideas/ideas_picker_inline_cell.rb index b109fd2..6c5b070 100644 --- a/app/cells/decidim/ideas/ideas_picker_inline_cell.rb +++ b/app/cells/decidim/ideas/ideas_picker_inline_cell.rb @@ -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, diff --git a/app/helpers/decidim/ideas/ideas_form_helper.rb b/app/helpers/decidim/ideas/ideas_form_helper.rb index 725ed53..449df2a 100644 --- a/app/helpers/decidim/ideas/ideas_form_helper.rb +++ b/app/helpers/decidim/ideas/ideas_form_helper.rb @@ -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 diff --git a/app/helpers/decidim/ideas/ideas_helper.rb b/app/helpers/decidim/ideas/ideas_helper.rb index 8896c90..de1bc53 100644 --- a/app/helpers/decidim/ideas/ideas_helper.rb +++ b/app/helpers/decidim/ideas/ideas_helper.rb @@ -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 diff --git a/app/packs/stylesheets/decidim/ideas/ideas/_map.scss b/app/packs/stylesheets/decidim/ideas/ideas/_map.scss index ea5e86c..cd5010d 100644 --- a/app/packs/stylesheets/decidim/ideas/ideas/_map.scss +++ b/app/packs/stylesheets/decidim/ideas/ideas/_map.scss @@ -1,3 +1,5 @@ .map-container{ - position: relative; + [data-decidim-map]{ + @apply my-4 aspect-[4/3]; + } } diff --git a/app/views/decidim/ideas/ideas/index.html.erb b/app/views/decidim/ideas/ideas/index.html.erb index 06d7915..f5fe5b4 100644 --- a/app/views/decidim/ideas/ideas/index.html.erb +++ b/app/views/decidim/ideas/ideas/index.html.erb @@ -87,7 +87,7 @@ <% if component_settings.geocoding_enabled? %> -
+
<%= ideas_map ideas_data_for_map(@geocoded_ideas) do %> <%= render partial: "map_template" %> <% end %> diff --git a/config/assets.rb b/config/assets.rb index e6208ca..4a1f206 100644 --- a/config/assets.rb +++ b/config/assets.rb @@ -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") diff --git a/config/locales/en.yml b/config/locales/en.yml index 5281cbe..895a2cf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -662,6 +662,7 @@ en: ideas_count: Ideas participatory_spaces: highlighted_ideas: + last: Last ideas see_all: See all (%{count}) plans: section_types: diff --git a/spec/cells/decidim/ideas/highlighted_ideas_cell_spec.rb b/spec/cells/decidim/ideas/highlighted_ideas_cell_spec.rb index 0e85631..4cb1596 100644 --- a/spec/cells/decidim/ideas/highlighted_ideas_cell_spec.rb +++ b/spec/cells/decidim/ideas/highlighted_ideas_cell_spec.rb @@ -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)) diff --git a/spec/cells/decidim/ideas/highlighted_ideas_for_component_cell_spec.rb b/spec/cells/decidim/ideas/highlighted_ideas_for_component_cell_spec.rb index 6397ec1..43de06b 100644 --- a/spec/cells/decidim/ideas/highlighted_ideas_for_component_cell_spec.rb +++ b/spec/cells/decidim/ideas/highlighted_ideas_for_component_cell_spec.rb @@ -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)) @@ -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 @@ -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 diff --git a/spec/cells/decidim/ideas/idea_activity_cell_spec.rb b/spec/cells/decidim/ideas/idea_activity_cell_spec.rb index 03e3b3f..0bf75b4 100644 --- a/spec/cells/decidim/ideas/idea_activity_cell_spec.rb +++ b/spec/cells/decidim/ideas/idea_activity_cell_spec.rb @@ -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 @@ -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 diff --git a/spec/cells/decidim/ideas/idea_cell_spec.rb b/spec/cells/decidim/ideas/idea_cell_spec.rb index 74eeb3b..2aa7c53 100644 --- a/spec/cells/decidim/ideas/idea_cell_spec.rb +++ b/spec/cells/decidim/ideas/idea_cell_spec.rb @@ -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 diff --git a/spec/cells/decidim/ideas/idea_g_cell_spec.rb b/spec/cells/decidim/ideas/idea_g_cell_spec.rb index 97ca461..0b5da4b 100644 --- a/spec/cells/decidim/ideas/idea_g_cell_spec.rb +++ b/spec/cells/decidim/ideas/idea_g_cell_spec.rb @@ -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 } @@ -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 diff --git a/spec/system/create_idea_spec.rb b/spec/system/create_idea_spec.rb index dde4185..7c3c29c 100644 --- a/spec/system/create_idea_spec.rb +++ b/spec/system/create_idea_spec.rb @@ -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 @@ -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") diff --git a/spec/system/edit_idea_spec.rb b/spec/system/edit_idea_spec.rb index 846e400..88744bb 100644 --- a/spec/system/edit_idea_spec.rb +++ b/spec/system/edit_idea_spec.rb @@ -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) @@ -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) diff --git a/spec/system/filter_and_sort_ideas_spec.rb b/spec/system/filter_and_sort_ideas_spec.rb index 444515e..557d1da 100644 --- a/spec/system/filter_and_sort_ideas_spec.rb +++ b/spec/system/filter_and_sort_ideas_spec.rb @@ -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 @@ -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) diff --git a/spec/system/global_search_spec.rb b/spec/system/global_search_spec.rb index 3e4be06..1d4b0a7 100644 --- a/spec/system/global_search_spec.rb +++ b/spec/system/global_search_spec.rb @@ -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