Skip to content

Commit

Permalink
add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Oct 29, 2024
1 parent 1f544db commit 64cdc79
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,17 @@ default: &default
- **key**: the identifier for the menu and URL path. For instance, if it is `general_assemblies` we will have a new menu entry for the url `<host>/general_assemblies` and the name specified in the I18n key `decidim.participatory_processes.scoped_participatory_process_slug_prefixes.general_assemblies`.
- **position_in_menu**: Where to place the item in the main menu, the usual "PROCESSES" item have the value `2.0`, lower this number will put it before and vice-versa.
- **slug_prefixes**: and array of prefixes for the slug of the participatory process. All participatory processes that have an slug starting with this word will be listed here and not in the normal "PROCESSES" menu.

#### Extra menu items for participatory processes & assemblies

Extra menu items in a participatory process (or an assembly) can defined in addition to the ones generated by the components.

Works exclusively using ENV vars following this scheme:

1. Add an ENV var like `EXTRA_PROCESS_MENU_***` where `***` is the slug of a participatory process.
2. Set the value of that ENV var to a pair of a model and a slug of a participatory space, separated by a slash `/`, for instance: `Decidim::Assembly/some-assembly` or `Decidim::ParticipatoryProcess/some_process`
3. A new menu item will appear to link the referenced participatory space
4. Also works for assemblies, examples:
`EXTRA_ASSEMBLY_MENU_MY_ASSEMBLY=Decidim::ParticipatoryProcess/my_process`
`EXTRA_PROCESS_MENU_MY_PROCESS=Decidim::Assembly/my_assembly`
`EXTRA_PROCESS_MENU_MY_PROCESS=Decidim::ParticipatoryProcess/my_process`
4 changes: 1 addition & 3 deletions app/views/layouts/decidim/_assembly_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

model, slug = ENV.fetch("EXTRA_ASSEMBLY_MENU_#{current_participatory_space.slug.upcase}", "").split("/")
klass = model.safe_constantize
klass = model&.safe_constantize
if klass
space = klass.find_by(slug: slug)
if space
Expand All @@ -21,9 +21,7 @@
}
end
end
console
%>

<%=
extended_navigation_bar(([
{
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/decidim/_process_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
end

model, slug = ENV.fetch("EXTRA_PROCESS_MENU_#{current_participatory_space.slug.upcase}", "").split("/")
klass = model.safe_constantize
klass = model&.safe_constantize
if klass
space = klass.find_by(slug: slug)
if space
Expand All @@ -29,5 +29,4 @@
active: is_active_link?(decidim_participatory_processes.participatory_process_path(participatory_space), :exclusive) ||
is_active_link?(decidim_participatory_processes.all_metrics_participatory_process_path(participatory_space), :exclusive)
}] + items)

%>
27 changes: 27 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,30 @@
require "decidim/decidim_awesome/test/factories"
require "decidim/consultations/test/factories"
require "decidim/initiatives/test/factories"

shared_examples "a participatory space with extra menu" do |prefix|
let!(:linked_space) { create(:participatory_process, organization: organization) }

before do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with("#{prefix}#{participatory_space.slug.upcase}", "").and_return("Decidim::ParticipatoryProcess/#{linked_space.slug}")
visit visit_path
end

it "shows the extra menu" do
within "#process-nav-content" do
expect(page).to have_link(href: "/processes/#{linked_space.slug}")
end
end

context "when visiting another space" do
let!(:another_space) { create(:participatory_process, organization: organization) }
let(:visit_path) { decidim_participatory_processes.participatory_process_path(another_space.slug) }

it "does not show the extra menu" do
within "#process-nav-content" do
expect(page).not_to have_link(href: "/processes/#{linked_space.slug}")
end
end
end
end
6 changes: 4 additions & 2 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
{
package: "decidim-assemblies",
files: {
"/app/views/decidim/assemblies/_filter_by_type.html.erb" => "c6ddcc8dd42702031f8027bb56b69687"
"/app/views/decidim/assemblies/_filter_by_type.html.erb" => "c6ddcc8dd42702031f8027bb56b69687",
"/app/views/layouts/decidim/_assembly_navigation.html.erb" => "159f168bf1634937183cf5ca56b03a9d"
}
},
{
package: "decidim-participatory_processes",
files: {
"/app/cells/decidim/participatory_processes/process_filters_cell.rb" => "cd83acfcd8865c5fe1dbcf8deb5bf319"
"/app/cells/decidim/participatory_processes/process_filters_cell.rb" => "cd83acfcd8865c5fe1dbcf8deb5bf319",
"/app/views/layouts/decidim/_process_navigation.html.erb" => "e4d2322544d80ef4452aa61425034aa3"
}
},
{
Expand Down
5 changes: 5 additions & 0 deletions spec/system/participatory_processes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,9 @@
expect(page).to have_content("MORE INFO")
end
end

it_behaves_like "a participatory space with extra menu", "EXTRA_PROCESS_MENU_" do
let(:participatory_space) { normal_process }
let(:visit_path) { decidim_participatory_processes.participatory_process_path(normal_process.slug) }
end
end
5 changes: 5 additions & 0 deletions spec/system/tech_assembly_menu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@
it_behaves_like "shows menu"
end
end

it_behaves_like "a participatory space with extra menu", "EXTRA_ASSEMBLY_MENU_" do
let(:participatory_space) { assembly }
let(:visit_path) { decidim_assemblies.assembly_path(assembly.slug) }
end
end

0 comments on commit 64cdc79

Please sign in to comment.