decidim-skin 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.erb_lint.yml +44 -0
- data/.gitignore +12 -0
- data/.gitlab-ci.yml +137 -0
- data/.rspec +1 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -0
- data/.simplecov +24 -0
- data/Appraisals +28 -0
- data/CONTRIBUTING.md +77 -0
- data/Gemfile +46 -0
- data/Gemfile.lock +977 -0
- data/LICENSE.md +661 -0
- data/README.md +105 -0
- data/Rakefile +80 -0
- data/app/controllers/decidim/skin/homepage_controller.rb +25 -0
- data/app/overrides/add_component_dropdown_require.rb +21 -0
- data/app/overrides/admin_body_data_attributes.rb +27 -0
- data/app/overrides/admin_item_show_wrapper_data.rb +11 -0
- data/app/overrides/admin_static_page_space_help.rb +35 -0
- data/app/overrides/assemblies_form_processes_field.rb +12 -0
- data/app/overrides/breadcrumb_home_require.rb +55 -0
- data/app/overrides/conferences_form_related_spaces.rb +21 -0
- data/app/overrides/content_block_cell_space_require.rb +13 -0
- data/app/overrides/content_blocks_dropdown_space_require.rb +12 -0
- data/app/overrides/help_sections_space_require.rb +13 -0
- data/app/overrides/insert_hide_css.rb +19 -0
- data/app/overrides/public_body_data_attributes.rb +11 -0
- data/app/overrides/public_content_data.rb +11 -0
- data/app/overrides/search_filters_space_require.rb +14 -0
- data/app/overrides/search_resources_filter_block_space_require.rb +14 -0
- data/app/overrides/search_section_resource_type.rb +16 -0
- data/app/overrides/space_require_attributes.rb +106 -0
- data/app/overrides/statistic_require.rb +13 -0
- data/app/views/decidim/skin/deface_partials/_hide_css.html.erb +4 -0
- data/app/views/decidim/skin/deface_partials/_public_content.html.erb +10 -0
- data/bin/check +10 -0
- data/bin/ci-setup +65 -0
- data/bin/postversion +21 -0
- data/config/i18n-tasks.yml +17 -0
- data/config/locales/de.yml +45 -0
- data/config/locales/en.yml +45 -0
- data/config/locales/fr.yml +45 -0
- data/config/locales/it.yml +45 -0
- data/decidim-skin.gemspec +37 -0
- data/docker-compose.ci.yml +128 -0
- data/docker-compose.yml +53 -0
- data/gemfiles/.gitignore +1 -0
- data/gemfiles/decidim_0.29.gemfile +35 -0
- data/gemfiles/decidim_0.32.gemfile +35 -0
- data/lib/decidim/skin/admin/config_form.rb +135 -0
- data/lib/decidim/skin/body_data_attributes.rb +49 -0
- data/lib/decidim/skin/component_hide_css.rb +17 -0
- data/lib/decidim/skin/component_presence.rb +38 -0
- data/lib/decidim/skin/components.rb +114 -0
- data/lib/decidim/skin/disabled_state.rb +59 -0
- data/lib/decidim/skin/engine.rb +101 -0
- data/lib/decidim/skin/hide_css.rb +76 -0
- data/lib/decidim/skin/homepage_dispatcher.rb +64 -0
- data/lib/decidim/skin/homepage_options.rb +71 -0
- data/lib/decidim/skin/homepage_resolver.rb +67 -0
- data/lib/decidim/skin/layout_data_attributes.rb +48 -0
- data/lib/decidim/skin/migrate_from_space_page.rb +139 -0
- data/lib/decidim/skin/organization_extensions.rb +16 -0
- data/lib/decidim/skin/overrides/breadcrumb_helper.rb +36 -0
- data/lib/decidim/skin/overrides/layout_helper.rb +19 -0
- data/lib/decidim/skin/overrides/menu_item_presenter.rb +74 -0
- data/lib/decidim/skin/overrides/menu_presenter.rb +23 -0
- data/lib/decidim/skin/overrides/meta_tags_helper.rb +40 -0
- data/lib/decidim/skin/overrides/searches_controller.rb +36 -0
- data/lib/decidim/skin/participatory_spaces.rb +130 -0
- data/lib/decidim/skin/search_filters.rb +44 -0
- data/lib/decidim/skin/seeds.rb +363 -0
- data/lib/decidim/skin/settings_tab.rb +21 -0
- data/lib/decidim/skin/space_hide_css.rb +17 -0
- data/lib/decidim/skin/stored_config.rb +28 -0
- data/lib/decidim/skin/toggle_defaults.rb +36 -0
- data/lib/decidim/skin/ui_hides.rb +27 -0
- data/lib/decidim/skin/version.rb +14 -0
- data/lib/decidim/skin.rb +61 -0
- data/lib/tasks/decidim/skin/migrate_from_space_page.rake +14 -0
- data/package.json +23 -0
- data/requests/decidim/skin/homepage_controller_spec.rb +24 -0
- data/spec/decidim/skin/body_data_attributes_spec.rb +98 -0
- data/spec/decidim/skin/components_spec.rb +96 -0
- data/spec/decidim/skin/hide_css_spec.rb +110 -0
- data/spec/decidim/skin/homepage_dispatcher_spec.rb +34 -0
- data/spec/decidim/skin/homepage_options_spec.rb +42 -0
- data/spec/decidim/skin/homepage_resolver_spec.rb +73 -0
- data/spec/decidim/skin/layout_data_attributes_spec.rb +48 -0
- data/spec/decidim/skin/migrate_from_space_page_spec.rb +121 -0
- data/spec/decidim/skin/overrides/breadcrumb_helper_spec.rb +59 -0
- data/spec/decidim/skin/overrides/layout_helper_spec.rb +25 -0
- data/spec/decidim/skin/overrides/menu_item_presenter_spec.rb +77 -0
- data/spec/decidim/skin/overrides/menu_presenter_spec.rb +49 -0
- data/spec/decidim/skin/overrides/meta_tags_helper_spec.rb +108 -0
- data/spec/decidim/skin/participatory_spaces_spec.rb +83 -0
- data/spec/decidim/skin/search_filters_spec.rb +56 -0
- data/spec/decidim/skin/seeds_spec.rb +81 -0
- data/spec/decidim/skin/settings_tab_spec.rb +22 -0
- data/spec/decidim/skin.rb +3 -0
- data/spec/decidim_skin_overrides/space_require_spec.rb +25 -0
- data/spec/forms/decidim/skin/admin/config_form_spec.rb +160 -0
- data/spec/requests/decidim/skin/homepage_controller_spec.rb +33 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/system/decidim/skin/admin_add_component_require_attributes_spec.rb +28 -0
- data/spec/system/decidim/skin/admin_assembly_form_require_attributes_spec.rb +24 -0
- data/spec/system/decidim/skin/admin_help_sections_space_require_spec.rb +27 -0
- data/spec/system/decidim/skin/admin_layout_data_attributes_spec.rb +60 -0
- data/spec/system/decidim/skin/admin_organization_homepage_menu_spec.rb +39 -0
- data/spec/system/decidim/skin/public_breadcrumb_spec.rb +82 -0
- data/spec/system/decidim/skin/public_layout_data_attributes_spec.rb +131 -0
- data/system/decidim/skin/homepage_controller_spec.rb +24 -0
- data/views/decidim/skin/system/_homepage_tab.html.erb +15 -0
- metadata +246 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Skin::MigrateFromSpacePage do
|
|
6
|
+
subject(:result) { described_class.call(force:, dry_run:, rows:) }
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization) }
|
|
9
|
+
let(:force) { false }
|
|
10
|
+
let(:dry_run) { false }
|
|
11
|
+
let(:settings) { { "enabled" => true, "skin" => "Decidim::Assembly" } }
|
|
12
|
+
let(:rows) do
|
|
13
|
+
[{ "decidim_organization_id" => organization.id, "space_page_settings" => settings }]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def stored
|
|
17
|
+
Decidim::Skin::StoredConfig.hash_for(organization.reload, Decidim::Skin::MODULE_NAME)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "writes enabled and the first published assembly GID" do
|
|
21
|
+
assembly = create(:assembly, :published, organization:)
|
|
22
|
+
|
|
23
|
+
expect(result).to eq(migrated: 1, skipped: 0)
|
|
24
|
+
expect(stored["enabled"]).to be(true)
|
|
25
|
+
expect(stored["homepage"]).to eq(assembly.to_global_id.to_s)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "uses the organization homepage for vanilla skin" do
|
|
29
|
+
settings["skin"] = "Decidim::Organization"
|
|
30
|
+
|
|
31
|
+
expect(result[:migrated]).to eq(1)
|
|
32
|
+
expect(stored["homepage"]).to eq(Decidim::Skin::ORGANIZATION_HOMEPAGE)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "uses the first published process GID for process skin" do
|
|
36
|
+
settings["skin"] = "Decidim::ParticipatoryProcess"
|
|
37
|
+
process = create(:participatory_process, :published, organization:)
|
|
38
|
+
|
|
39
|
+
expect(result[:migrated]).to eq(1)
|
|
40
|
+
expect(stored["homepage"]).to eq(process.to_global_id.to_s)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "falls back to organization when the space is unpublished" do
|
|
44
|
+
create(:assembly, organization:, published_at: nil)
|
|
45
|
+
|
|
46
|
+
expect(result[:migrated]).to eq(1)
|
|
47
|
+
expect(stored["homepage"]).to eq(Decidim::Skin::ORGANIZATION_HOMEPAGE)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "does not use another organization's space" do
|
|
51
|
+
other = create(:organization)
|
|
52
|
+
create(:assembly, :published, organization: other)
|
|
53
|
+
|
|
54
|
+
expect(result[:migrated]).to eq(1)
|
|
55
|
+
expect(stored["homepage"]).to eq(Decidim::Skin::ORGANIZATION_HOMEPAGE)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "treats missing enabled as true" do
|
|
59
|
+
settings.delete("enabled")
|
|
60
|
+
settings["skin"] = "Decidim::Organization"
|
|
61
|
+
|
|
62
|
+
expect(result[:migrated]).to eq(1)
|
|
63
|
+
expect(stored["enabled"]).to be(true)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "preserves enabled false" do
|
|
67
|
+
settings["enabled"] = false
|
|
68
|
+
settings["skin"] = "Decidim::Organization"
|
|
69
|
+
|
|
70
|
+
expect(result[:migrated]).to eq(1)
|
|
71
|
+
expect(stored["enabled"]).to be(false)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "skips organizations that already have Skin config" do
|
|
75
|
+
Decidim::Toggle.save_config!(organization, Decidim::Skin::MODULE_NAME, { "enabled" => false })
|
|
76
|
+
|
|
77
|
+
expect(result).to eq(migrated: 0, skipped: 1)
|
|
78
|
+
expect(stored["enabled"]).to be(false)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "overwrites existing Skin config when force is true" do
|
|
82
|
+
Decidim::Toggle.save_config!(
|
|
83
|
+
organization,
|
|
84
|
+
Decidim::Skin::MODULE_NAME,
|
|
85
|
+
{ "enabled" => false, "homepage" => Decidim::Skin::ORGANIZATION_HOMEPAGE }
|
|
86
|
+
)
|
|
87
|
+
assembly = create(:assembly, :published, organization:)
|
|
88
|
+
|
|
89
|
+
expect(described_class.call(force: true, rows:)[:migrated]).to eq(1)
|
|
90
|
+
expect(stored["enabled"]).to be(true)
|
|
91
|
+
expect(stored["homepage"]).to eq(assembly.to_global_id.to_s)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "does not write when dry_run is true" do
|
|
95
|
+
create(:assembly, :published, organization:)
|
|
96
|
+
|
|
97
|
+
expect(described_class.call(dry_run: true, rows:)).to eq(migrated: 1, skipped: 0)
|
|
98
|
+
expect(stored).to eq({})
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "keeps each organization on its own row" do
|
|
102
|
+
other = create(:organization)
|
|
103
|
+
assembly = create(:assembly, :published, organization:)
|
|
104
|
+
other_rows = [
|
|
105
|
+
{ "decidim_organization_id" => organization.id, "space_page_settings" => settings },
|
|
106
|
+
{ "decidim_organization_id" => other.id, "space_page_settings" => { "skin" => "Decidim::Organization" } }
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
described_class.call(rows: other_rows)
|
|
110
|
+
expect(stored["homepage"]).to eq(assembly.to_global_id.to_s)
|
|
111
|
+
expect(Decidim::Skin::StoredConfig.hash_for(other, Decidim::Skin::MODULE_NAME)["homepage"])
|
|
112
|
+
.to eq(Decidim::Skin::ORGANIZATION_HOMEPAGE)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "returns missing_table when the source table is absent" do
|
|
116
|
+
allow(ActiveRecord::Base.connection).to receive(:table_exists?)
|
|
117
|
+
.with(described_class::TABLE).and_return(false)
|
|
118
|
+
|
|
119
|
+
expect(described_class.call).to eq(migrated: 0, skipped: 0, missing_table: true)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Skin::Overrides::BreadcrumbHelper, type: :helper do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:assembly) { create(:assembly, :published, organization:) }
|
|
8
|
+
let(:homepage) { assembly.to_global_id.to_s }
|
|
9
|
+
let(:request_path) { "/en" }
|
|
10
|
+
let(:space_item) { { label: "North District Council", url: "/en/assemblies/#{assembly.slug}" } }
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
helper.singleton_class.include(Decidim::BreadcrumbHelper) unless
|
|
14
|
+
helper.singleton_class.ancestors.include?(Decidim::BreadcrumbHelper)
|
|
15
|
+
Decidim::Skin::Engine.prepend_breadcrumb_stamps
|
|
16
|
+
helper.singleton_class.prepend(described_class) unless
|
|
17
|
+
helper.singleton_class.ancestors.first == described_class
|
|
18
|
+
allow(helper).to receive(:current_organization).and_return(organization)
|
|
19
|
+
allow(helper).to receive(:request).and_return(instance_double(ActionDispatch::Request, path: request_path))
|
|
20
|
+
allow(helper).to receive_messages(
|
|
21
|
+
context_breadcrumb_items: [space_item],
|
|
22
|
+
secondary_breadcrumb_menus: nil,
|
|
23
|
+
controller_breadcrumb_items: [],
|
|
24
|
+
active_breadcrumb_item: nil
|
|
25
|
+
)
|
|
26
|
+
Decidim::Toggle.save_config!(
|
|
27
|
+
organization,
|
|
28
|
+
Decidim::Skin::MODULE_NAME,
|
|
29
|
+
{ "enabled" => true, "homepage" => homepage },
|
|
30
|
+
merge: false
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
around do |example|
|
|
35
|
+
I18n.with_locale(:en, &example)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "when homepage is a published assembly" do
|
|
39
|
+
it "drops breadcrumb items on the locale root" do
|
|
40
|
+
expect(helper.breadcrumb_items).to eq([])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "when the path is a nested space page" do
|
|
44
|
+
let(:request_path) { "/en/assemblies/#{assembly.slug}" }
|
|
45
|
+
|
|
46
|
+
it "keeps the space trail" do
|
|
47
|
+
expect(helper.breadcrumb_items).to eq([space_item])
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "when homepage is organization" do
|
|
53
|
+
let(:homepage) { "organization" }
|
|
54
|
+
|
|
55
|
+
it "keeps the space trail on the locale root" do
|
|
56
|
+
expect(helper.breadcrumb_items).to eq([space_item])
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Decidim::Skin::Overrides::LayoutHelper", type: :helper do
|
|
6
|
+
before do
|
|
7
|
+
Decidim::Skin::Engine.prepend_layout_stamps
|
|
8
|
+
helper.singleton_class.include(Decidim::Skin::Overrides::LayoutHelper) unless
|
|
9
|
+
helper.singleton_class.ancestors.include?(Decidim::Skin::Overrides::LayoutHelper)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "returns admin wrapper data-content from controller and action" do
|
|
13
|
+
allow(helper).to receive(:controller_name).and_return("organization")
|
|
14
|
+
allow(helper).to receive(:action_name).and_return("edit")
|
|
15
|
+
|
|
16
|
+
expect(helper.skin_admin_wrapper_data).to eq("data-content" => "organization_edit")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "returns public content data without data-action on index" do
|
|
20
|
+
allow(helper).to receive(:controller_name).and_return("pages")
|
|
21
|
+
allow(helper).to receive(:action_name).and_return("index")
|
|
22
|
+
|
|
23
|
+
expect(helper.skin_public_content_data).to eq("data-controller" => "pages")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Skin::Overrides::MenuItemPresenter do
|
|
6
|
+
let(:view) { ActionController::Base.new.view_context }
|
|
7
|
+
let(:menu_item) do
|
|
8
|
+
Decidim::MenuItem.new("Assemblies", "/assemblies", :assemblies)
|
|
9
|
+
end
|
|
10
|
+
let(:presenter) { Decidim::MenuItemPresenter.new(menu_item, view) }
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
Decidim::MenuItemPresenter.prepend(described_class) unless
|
|
14
|
+
Decidim::MenuItemPresenter.ancestors.first == described_class
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "stamps data-require on the li from the menu identifier" do
|
|
18
|
+
html = presenter.content_tag(:li, class: "nav-item") { "Assemblies" }
|
|
19
|
+
|
|
20
|
+
expect(html).to include('data-require-assemblies="true"')
|
|
21
|
+
expect(html).to match(/<li[^>]*data-require-assemblies="true"/)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "when the identifier is edit_organization_homepage" do
|
|
25
|
+
let(:menu_item) do
|
|
26
|
+
Decidim::MenuItem.new("Homepage", "/admin/organization/homepage", :edit_organization_homepage)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "stamps data-require-organization-homepage on the li" do
|
|
30
|
+
html = presenter.content_tag(:li, class: "nav-item") { "Homepage" }
|
|
31
|
+
|
|
32
|
+
expect(html).to include('data-require-organization-homepage="true"')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "when Skin is disabled for the current organization" do
|
|
37
|
+
let(:organization) { create(:organization) }
|
|
38
|
+
|
|
39
|
+
before do
|
|
40
|
+
Decidim::Toggle.save_config!(
|
|
41
|
+
organization,
|
|
42
|
+
Decidim::Skin::MODULE_NAME,
|
|
43
|
+
{ "enabled" => false, "assemblies_enabled" => false },
|
|
44
|
+
merge: false
|
|
45
|
+
)
|
|
46
|
+
allow(view).to receive(:current_organization).and_return(organization)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "does not stamp data-require" do
|
|
50
|
+
html = presenter.content_tag(:li, class: "nav-item") { "Assemblies" }
|
|
51
|
+
|
|
52
|
+
expect(html).not_to include("data-require-assemblies")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context "when the menu is admin_menu" do
|
|
57
|
+
let(:presenter) { Decidim::MenuItemPresenter.new(menu_item, view, { menu_name: :admin_menu }) }
|
|
58
|
+
let(:menu_item) { Decidim::MenuItem.new("Global moderations", "/en/admin/moderations", :moderations) }
|
|
59
|
+
|
|
60
|
+
it "stamps data-navbar on the li" do
|
|
61
|
+
html = presenter.content_tag(:li, class: "nav-item") { "Global moderations" }
|
|
62
|
+
|
|
63
|
+
expect(html).to include('data-navbar="moderations"')
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context "when the menu is another admin menu" do
|
|
68
|
+
let(:presenter) { Decidim::MenuItemPresenter.new(menu_item, view, { menu_name: :admin_settings_menu }) }
|
|
69
|
+
let(:menu_item) { Decidim::MenuItem.new("Taxonomies", "/en/admin/taxonomies", :taxonomies) }
|
|
70
|
+
|
|
71
|
+
it "stamps data-sidebar on the li" do
|
|
72
|
+
html = presenter.content_tag(:li, class: "nav-item") { "Taxonomies" }
|
|
73
|
+
|
|
74
|
+
expect(html).to include('data-sidebar="taxonomies"')
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Skin::Overrides::MenuPresenter, type: :helper do
|
|
6
|
+
let(:presenter) { Decidim::MenuPresenter.new(menu_name, helper) }
|
|
7
|
+
let(:menu_item) { Decidim::MenuItem.new("Label", url, identifier) }
|
|
8
|
+
let(:url) { "/en/admin/moderations" }
|
|
9
|
+
let(:identifier) { :moderations }
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
Decidim::MenuPresenter.prepend(described_class) unless
|
|
13
|
+
Decidim::MenuPresenter.ancestors.first == described_class
|
|
14
|
+
Decidim::MenuItemPresenter.prepend(Decidim::Skin::Overrides::MenuItemPresenter) unless
|
|
15
|
+
Decidim::MenuItemPresenter.ancestors.first == Decidim::Skin::Overrides::MenuItemPresenter
|
|
16
|
+
allow(presenter).to receive(:items).and_return([menu_item])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def li_html
|
|
20
|
+
presenter.presented_items.first.content_tag(:li, class: "nav-item") { "Label" }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "when the menu is admin_menu" do
|
|
24
|
+
let(:menu_name) { :admin_menu }
|
|
25
|
+
|
|
26
|
+
it "stamps data-navbar on the li from the identifier" do
|
|
27
|
+
expect(li_html).to include('data-navbar="moderations"')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "when the menu is another admin menu" do
|
|
32
|
+
let(:menu_name) { :admin_settings_menu }
|
|
33
|
+
let(:identifier) { :taxonomies }
|
|
34
|
+
let(:url) { "/en/admin/taxonomies" }
|
|
35
|
+
|
|
36
|
+
it "stamps data-sidebar on the li from the identifier" do
|
|
37
|
+
expect(li_html).to include('data-sidebar="taxonomies"')
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "when the identifier is blank" do
|
|
42
|
+
let(:menu_name) { :admin_menu }
|
|
43
|
+
let(:identifier) { "" }
|
|
44
|
+
|
|
45
|
+
it "stamps data-navbar from the URL basename" do
|
|
46
|
+
expect(li_html).to include('data-navbar="moderations"')
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Decidim::Skin::Overrides::MetaTagsHelper", type: :helper do
|
|
6
|
+
subject { helper }
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization, name: Decidim.available_locales.index_with { org_name }) }
|
|
9
|
+
let(:org_name) { "NCA" }
|
|
10
|
+
let(:space_title) { "NCA" }
|
|
11
|
+
let(:process) do
|
|
12
|
+
create(:participatory_process, :published, organization:, title: Decidim.available_locales.index_with { space_title })
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
before do
|
|
16
|
+
Decidim::Skin::Engine.prepend_title_root
|
|
17
|
+
helper.singleton_class.include(Decidim::MetaTagsHelper) unless helper.singleton_class.ancestors.include?(Decidim::MetaTagsHelper)
|
|
18
|
+
helper.singleton_class.include(Decidim::OrganizationHelper) unless helper.respond_to?(:current_organization_name)
|
|
19
|
+
helper.singleton_class.include(Decidim::TranslatableAttributes) unless helper.respond_to?(:translated_attribute)
|
|
20
|
+
allow(controller.class).to receive(:name).and_return("Decidim::PagesController")
|
|
21
|
+
allow(helper).to receive(:current_organization).and_return(organization)
|
|
22
|
+
Decidim::Toggle.save_config!(
|
|
23
|
+
organization,
|
|
24
|
+
Decidim::Skin::MODULE_NAME,
|
|
25
|
+
{ "enabled" => true, "homepage" => process.to_global_id.to_s },
|
|
26
|
+
merge: false
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
around do |example|
|
|
31
|
+
I18n.with_locale(:en, &example)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def title_after(*segments)
|
|
35
|
+
helper.instance_variable_set(:@decidim_page_title, nil)
|
|
36
|
+
segments.each { |segment| helper.add_decidim_page_title(segment) }
|
|
37
|
+
helper.add_decidim_page_title(helper.current_organization_name)
|
|
38
|
+
helper.decidim_page_title
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "when org name equals the homepage space title" do
|
|
42
|
+
it "emits a single NCA segment on the homepage" do
|
|
43
|
+
expect(title_after(space_title)).to eq("NCA")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "uses the space title when only the organization name is added" do
|
|
47
|
+
expect(title_after).to eq("NCA")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "when org name differs from the homepage space title" do
|
|
52
|
+
let(:space_title) { "City Lab" }
|
|
53
|
+
|
|
54
|
+
it "uses the space title as root without the organization name" do
|
|
55
|
+
expect(title_after(space_title)).to eq("City Lab")
|
|
56
|
+
expect(title_after(space_title)).not_to include(org_name)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "replaces a layout-only organization name with the space title" do
|
|
60
|
+
expect(title_after).to eq("City Lab")
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "when on a nested page" do
|
|
65
|
+
let(:space_title) { "City Lab" }
|
|
66
|
+
|
|
67
|
+
it "keeps the page crumb under the space-title root" do
|
|
68
|
+
expect(title_after("Members", space_title)).to eq("Members - City Lab")
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "with another organization's homepage space" do
|
|
73
|
+
let(:space_title) { "City Lab" }
|
|
74
|
+
let(:other_org) { create(:organization, name: Decidim.available_locales.index_with { "Other" }) }
|
|
75
|
+
let!(:other_process) do
|
|
76
|
+
create(:participatory_process, :published, organization: other_org,
|
|
77
|
+
title: Decidim.available_locales.index_with { "Other Home" })
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
before do
|
|
81
|
+
Decidim::Toggle.save_config!(
|
|
82
|
+
other_org,
|
|
83
|
+
Decidim::Skin::MODULE_NAME,
|
|
84
|
+
{ "enabled" => true, "homepage" => other_process.to_global_id.to_s },
|
|
85
|
+
merge: false
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "does not use another organization's homepage title" do
|
|
90
|
+
expect(title_after("Members", space_title)).to eq("Members - City Lab")
|
|
91
|
+
expect(title_after("Members", space_title)).not_to include("Other Home")
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context "when current_organization is unavailable" do
|
|
96
|
+
before do
|
|
97
|
+
allow(helper).to receive(:respond_to?).and_call_original
|
|
98
|
+
allow(helper).to receive(:respond_to?).with(:current_organization).and_return(false)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "does not call current_organization" do
|
|
102
|
+
expect(helper).not_to receive(:current_organization)
|
|
103
|
+
helper.instance_variable_set(:@decidim_page_title, nil)
|
|
104
|
+
helper.add_decidim_page_title("Api clients")
|
|
105
|
+
expect(helper.decidim_page_title).to eq("Api clients")
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Skin::ParticipatorySpaces do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
|
|
8
|
+
describe ".enabled?" do
|
|
9
|
+
it "defaults participatory processes to enabled" do
|
|
10
|
+
expect(described_class.enabled?(organization, "participatory_processes")).to be(true)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "defaults initiatives to disabled" do
|
|
14
|
+
expect(described_class.enabled?(organization, "initiatives")).to be(false)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "reads the Skin module config" do
|
|
18
|
+
Decidim::Toggle.save_config!(
|
|
19
|
+
organization,
|
|
20
|
+
Decidim::Skin::MODULE_NAME,
|
|
21
|
+
{ "initiatives_enabled" => true }
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
expect(described_class.enabled?(organization, "initiatives")).to be(true)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "falls back to legacy spaces module config" do
|
|
28
|
+
Decidim::Toggle.save_config!(
|
|
29
|
+
organization,
|
|
30
|
+
"spaces",
|
|
31
|
+
{ "assemblies_enabled" => false }
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
expect(described_class.enabled?(organization, "assemblies")).to be(false)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "returns false when the organization is nil" do
|
|
38
|
+
expect(described_class.enabled?(nil, "assemblies")).to be(false)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "enables every space when Skin is disabled" do
|
|
42
|
+
Decidim::Toggle.save_config!(
|
|
43
|
+
organization,
|
|
44
|
+
Decidim::Skin::MODULE_NAME,
|
|
45
|
+
{ "enabled" => false, "assemblies_enabled" => false },
|
|
46
|
+
merge: false
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
expect(described_class.enabled?(organization, "assemblies")).to be(true)
|
|
50
|
+
expect(described_class.enabled?(organization, "initiatives")).to be(true)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe ".kebab" do
|
|
55
|
+
it "uses hyphens" do
|
|
56
|
+
expect(described_class.kebab("participatory_processes")).to eq("participatory-processes")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe ".require_data" do
|
|
61
|
+
it "stamps known space identifiers" do
|
|
62
|
+
expect(described_class.require_data(:assemblies)).to eq(
|
|
63
|
+
"data-require-assemblies" => "true"
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "skips unknown identifiers" do
|
|
68
|
+
expect(described_class.require_data(:proposals)).to eq({})
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe ".existing?" do
|
|
73
|
+
it "is true when the organization has an assembly" do
|
|
74
|
+
create(:assembly, organization:, published_at: nil)
|
|
75
|
+
|
|
76
|
+
expect(described_class.existing?(organization, "assemblies")).to be(true)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "is false when the organization has no assembly" do
|
|
80
|
+
expect(described_class.existing?(organization, "assemblies")).to be(false)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Skin::SearchFilters do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:results) do
|
|
8
|
+
{
|
|
9
|
+
"Decidim::User" => { count: 1, results: [] },
|
|
10
|
+
"Decidim::ParticipatoryProcess" => { count: 0, results: [] },
|
|
11
|
+
"Decidim::Assembly" => { count: 0, results: [] },
|
|
12
|
+
"Decidim::Proposals::Proposal" => { count: 0, results: [] },
|
|
13
|
+
"Decidim::Meetings::Meeting" => { count: 0, results: [] }
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe ".filter_results" do
|
|
18
|
+
it "removes disabled participatory space and component resource types" do
|
|
19
|
+
Decidim::Toggle.save_config!(
|
|
20
|
+
organization,
|
|
21
|
+
Decidim::Skin::MODULE_NAME,
|
|
22
|
+
{
|
|
23
|
+
"participatory_processes_enabled" => false,
|
|
24
|
+
"proposals_enabled" => false,
|
|
25
|
+
"meetings_enabled" => true,
|
|
26
|
+
"assemblies_enabled" => true
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
filtered = described_class.filter_results(results, organization)
|
|
31
|
+
|
|
32
|
+
expect(filtered.keys).to contain_exactly(
|
|
33
|
+
"Decidim::User",
|
|
34
|
+
"Decidim::Assembly",
|
|
35
|
+
"Decidim::Meetings::Meeting"
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "keeps every resource type when Skin is disabled" do
|
|
40
|
+
Decidim::Toggle.save_config!(
|
|
41
|
+
organization,
|
|
42
|
+
Decidim::Skin::MODULE_NAME,
|
|
43
|
+
{
|
|
44
|
+
"enabled" => false,
|
|
45
|
+
"participatory_processes_enabled" => false,
|
|
46
|
+
"proposals_enabled" => false,
|
|
47
|
+
"meetings_enabled" => false,
|
|
48
|
+
"assemblies_enabled" => false
|
|
49
|
+
},
|
|
50
|
+
merge: false
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
expect(described_class.filter_results(results, organization).keys).to match_array(results.keys)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Skin::Seeds do
|
|
6
|
+
subject(:seeds) { described_class.new }
|
|
7
|
+
|
|
8
|
+
let(:hosts) { described_class::TENANTS.map { |tenant| tenant[:host] } }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
described_class::COMPONENT_SEEDS.each do |config|
|
|
12
|
+
require "#{config[:gem].tr("-", "/")}/seeds"
|
|
13
|
+
klass = config[:class_name].constantize
|
|
14
|
+
allow(klass).to receive(:new).and_return(instance_double(klass, call: true))
|
|
15
|
+
rescue LoadError
|
|
16
|
+
next
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "is prepended on Decidim.seed!" do
|
|
21
|
+
expect(Decidim.singleton_class.ancestors).to include(Decidim::Skin::SeedHook)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "creates three extra organizations with space homepages" do
|
|
25
|
+
seeds.call
|
|
26
|
+
|
|
27
|
+
expect(Decidim::Organization.where(host: hosts).count).to eq(3)
|
|
28
|
+
|
|
29
|
+
described_class::TENANTS.each do |tenant|
|
|
30
|
+
organization = Decidim::Organization.find_by!(host: tenant[:host])
|
|
31
|
+
result = Decidim::Skin::HomepageResolver.call(organization)
|
|
32
|
+
|
|
33
|
+
expect(result).to be_space
|
|
34
|
+
expect(Decidim::Skin::ParticipatorySpaces.enabled?(organization, tenant[:space])).to be(true)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "creates a terms-of-service page for every seeded organization" do
|
|
39
|
+
seeds.call
|
|
40
|
+
|
|
41
|
+
described_class::TENANTS.each do |tenant|
|
|
42
|
+
organization = Decidim::Organization.find_by!(host: tenant[:host])
|
|
43
|
+
page = Decidim::StaticPage.find_by(slug: "terms-of-service", organization:)
|
|
44
|
+
|
|
45
|
+
expect(page).to be_present
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "does not duplicate organizations when run twice" do
|
|
50
|
+
2.times { seeds.call }
|
|
51
|
+
|
|
52
|
+
expect(Decidim::Organization.where(host: hosts).count).to eq(3)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "seeds meetings, blogs, and proposals on the process tenant" do
|
|
56
|
+
seeds.call
|
|
57
|
+
organization = Decidim::Organization.find_by!(host: "process-skin.localhost")
|
|
58
|
+
space = Decidim::ParticipatoryProcess.find_by!(organization:)
|
|
59
|
+
|
|
60
|
+
described_class::COMPONENT_SEEDS.each do |config|
|
|
61
|
+
klass = config[:class_name].constantize
|
|
62
|
+
allow(klass).to receive(:new).and_call_original
|
|
63
|
+
described_class.new.send(:seed_component!, config, space)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
expect(space.components.pluck(:manifest_name)).to include("meetings", "blogs", "proposals")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "creates a verified user group with members on each tenant when user groups exist" do
|
|
70
|
+
skip "user groups removed in Decidim 0.31+" unless Gem.loaded_specs["decidim-core"].version < Gem::Version.new("0.31")
|
|
71
|
+
|
|
72
|
+
seeds.call
|
|
73
|
+
|
|
74
|
+
described_class::TENANTS.each do |tenant|
|
|
75
|
+
organization = Decidim::Organization.find_by!(host: tenant[:host])
|
|
76
|
+
group = Decidim::UserGroup.where(decidim_organization_id: organization.id).verified.first
|
|
77
|
+
expect(group).to be_present
|
|
78
|
+
expect(group.users).to be_present
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Skin::SettingsTab do
|
|
6
|
+
it "registers the Skin organization settings tab" do
|
|
7
|
+
tabs = double("tabs")
|
|
8
|
+
allow(Decidim::Toggle).to receive(:settings_tabs).with(:organization_settings).and_yield(tabs)
|
|
9
|
+
expect(tabs).to receive(:add_tab).with(
|
|
10
|
+
:decidim_skin,
|
|
11
|
+
kind_of(String),
|
|
12
|
+
hash_including(
|
|
13
|
+
form: Decidim::Skin::Admin::ConfigForm,
|
|
14
|
+
command: Decidim::Toggle::UpdateModuleConfigCommand,
|
|
15
|
+
module_name: Decidim::Skin::MODULE_NAME,
|
|
16
|
+
form_layout_partial: "decidim/skin/system/homepage_tab"
|
|
17
|
+
)
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
described_class.register!
|
|
21
|
+
end
|
|
22
|
+
end
|