- <%= f.hidden_field :header, value: @card.header? %>
+ <%= f.hidden_field :header, value: card.header? %>
<%= f.submit(
- t("admin.homepage.#{admin_submit_action(@card)}.#{@card.header? ? "submit_header" : "submit_card"}"),
+ t("admin.homepage.#{admin_submit_action(card)}.#{card.header? ? "submit_header" : "submit_card"}"),
class: "button success"
) %>
diff --git a/app/views/admin/widget/cards/edit.html.erb b/app/views/admin/widget/cards/edit.html.erb
index f4f751fd1..c95b6fb7d 100644
--- a/app/views/admin/widget/cards/edit.html.erb
+++ b/app/views/admin/widget/cards/edit.html.erb
@@ -1,11 +1 @@
-<%= back_link_to index_path %>
-
-
- <% if @card.header? %>
- <%= t("admin.homepage.edit.header_title") %>
- <% else %>
- <%= t("admin.homepage.edit.card_title") %>
- <% end %>
-
-
-<%= render "admin/widget/cards/form" %>
+<%= render Admin::Widget::Cards::EditComponent.new(@card, index_path: index_path) %>
diff --git a/app/views/admin/widget/cards/new.html.erb b/app/views/admin/widget/cards/new.html.erb
index f15f0172e..d25857cef 100644
--- a/app/views/admin/widget/cards/new.html.erb
+++ b/app/views/admin/widget/cards/new.html.erb
@@ -1,11 +1 @@
-<%= back_link_to index_path %>
-
-
- <% if @card.header? %>
- <%= t("admin.homepage.new.header_title") %>
- <% else %>
- <%= t("admin.homepage.new.card_title") %>
- <% end %>
-
-
-<%= render "admin/widget/cards/form" %>
+<%= render Admin::Widget::Cards::NewComponent.new(@card, index_path: index_path) %>
diff --git a/app/views/sdg_management/homepage/show.html.erb b/app/views/sdg_management/homepage/show.html.erb
new file mode 100644
index 000000000..f76456364
--- /dev/null
+++ b/app/views/sdg_management/homepage/show.html.erb
@@ -0,0 +1 @@
+<%= render SDGManagement::Homepage::ShowComponent.new(@phases) %>
diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb
index fd096a64a..9b5cded6f 100644
--- a/config/initializers/routes_hierarchy.rb
+++ b/config/initializers/routes_hierarchy.rb
@@ -16,14 +16,23 @@ module ActionDispatch::Routing::UrlFor
end
def admin_polymorphic_path(resource, options = {})
+ namespaced_polymorphic_path(:admin, resource, options)
+ end
+
+ def sdg_management_polymorphic_path(resource, options = {})
+ namespaced_polymorphic_path(:sdg_management, resource, options)
+ end
+
+ def namespaced_polymorphic_path(namespace, resource, options = {})
if %w[Budget::Group Budget::Heading Poll::Booth Poll::BoothAssignment Poll::Officer
- Poll::Question Poll::Question::Answer::Video Poll::Shift].include?(resource.class.name)
+ Poll::Question Poll::Question::Answer::Video Poll::Shift
+ SDG::LocalTarget].include?(resource.class.name)
resolve = resolve_for(resource)
resolve_options = resolve.pop
- polymorphic_path([:admin, *resolve], options.merge(resolve_options))
+ polymorphic_path([namespace, *resolve], options.merge(resolve_options))
else
- polymorphic_path([:admin, *resource_hierarchy_for(resource)], options)
+ polymorphic_path([namespace, *resource_hierarchy_for(resource)], options)
end
end
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml
index 84264fbce..eae5e99a0 100644
--- a/config/locales/en/activerecord.yml
+++ b/config/locales/en/activerecord.yml
@@ -336,6 +336,10 @@ en:
sdg/local_target/translation:
title: "Title"
description: "Description"
+ sdg/phase/kind:
+ sensitization: "Sensitization"
+ planning: "Planning"
+ monitoring: "Monitoring"
sdg/target:
code: "Code"
title: "Title"
diff --git a/config/locales/en/sdg_management.yml b/config/locales/en/sdg_management.yml
index bacc84bbb..f4736fe8e 100644
--- a/config/locales/en/sdg_management.yml
+++ b/config/locales/en/sdg_management.yml
@@ -4,6 +4,10 @@ en:
edit: "Manage goals and targets"
header:
title: "SDG content"
+ homepage:
+ title: "Homepage configuration"
+ create_card: "Create %{phase} card"
+ no_cards: "There are no cards for this phase"
menu:
budget_investments: "Participatory budgets"
debates: "Debates"
@@ -11,6 +15,7 @@ en:
polls: "Polls"
proposals: "Proposals"
sdg_content: "Goals and Targets"
+ sdg_homepage: "SDG homepage"
local_targets:
create:
notice: "Local target created successfully"
diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml
index d59c643c4..788576928 100644
--- a/config/locales/es/activerecord.yml
+++ b/config/locales/es/activerecord.yml
@@ -331,6 +331,10 @@ es:
sdg/local_target/translation:
title: "Título"
description: "Descripción"
+ sdg/phase/kind:
+ sensitization: "Sensibilización"
+ planning: "Planificación"
+ monitoring: "Seguimiento"
sdg/target:
code: "Código"
title: "Título"
diff --git a/config/locales/es/sdg_management.yml b/config/locales/es/sdg_management.yml
index 23c10bd4a..488599bc5 100644
--- a/config/locales/es/sdg_management.yml
+++ b/config/locales/es/sdg_management.yml
@@ -4,6 +4,10 @@ es:
edit: "Asignar objetivos y metas"
header:
title: "Contenido ODS"
+ homepage:
+ title: "Configuración de la página de inicio"
+ create_card: "Crear tarjeta de %{phase}"
+ no_cards: "No hay tarjetas para esta fase"
menu:
budget_investments: "Presupuestos participativos"
debates: "Debates"
@@ -11,6 +15,7 @@ es:
polls: "Votaciones"
proposals: "Propuestas"
sdg_content: "Objetivos y Metas"
+ sdg_homepage: "Página de inicio ODS"
local_targets:
create:
notice: "Meta localizada creada correctamente"
diff --git a/config/routes/admin.rb b/config/routes/admin.rb
index 4bc1f098f..197707c97 100644
--- a/config/routes/admin.rb
+++ b/config/routes/admin.rb
@@ -271,7 +271,7 @@ resolve "Audit" do |audit|
end
resolve "Widget::Card" do |card, options|
- [*resource_hierarchy_for(card.page), card]
+ [*resource_hierarchy_for(card.cardable), card]
end
resolve "Budget::Group" do |group, options|
diff --git a/config/routes/sdg_management.rb b/config/routes/sdg_management.rb
index 6f303b45c..c8816ad56 100644
--- a/config/routes/sdg_management.rb
+++ b/config/routes/sdg_management.rb
@@ -4,6 +4,11 @@ namespace :sdg_management do
resources :goals, only: [:index]
resources :targets, only: [:index]
resources :local_targets, except: [:show]
+ resource :homepage, controller: :homepage, only: [:show]
+
+ resources :phases, only: [], as: :sdg_phases do
+ resources :cards, except: [:index, :show], as: :widget_cards
+ end
types = SDG::Related::RELATABLE_TYPES.map(&:tableize)
types_constraint = /#{types.join("|")}/
@@ -17,3 +22,7 @@ namespace :sdg_management do
get "#{type}/:id/edit", to: "relations#edit", as: "edit_#{type.singularize}"
end
end
+
+resolve "SDG::LocalTarget" do |target, options|
+ [:local_target, options.merge(id: target)]
+end
diff --git a/db/dev_seeds/sdg.rb b/db/dev_seeds/sdg.rb
index 055f64e41..f7fe40a3a 100644
--- a/db/dev_seeds/sdg.rb
+++ b/db/dev_seeds/sdg.rb
@@ -30,3 +30,9 @@ section "Creating Sustainable Development Goals" do
end
end
end
+
+section "Creating SDG homepage cards" do
+ SDG::Phase.all.each do |phase|
+ Widget::Card.create!(cardable: phase, title: "#{phase.title} card")
+ end
+end
diff --git a/db/migrate/20210106132909_make_cards_polymorphic.rb b/db/migrate/20210106132909_make_cards_polymorphic.rb
new file mode 100644
index 000000000..fe49baa92
--- /dev/null
+++ b/db/migrate/20210106132909_make_cards_polymorphic.rb
@@ -0,0 +1,8 @@
+class MakeCardsPolymorphic < ActiveRecord::Migration[5.2]
+ def change
+ change_table :widget_cards do |t|
+ t.rename :site_customization_page_id, :cardable_id
+ t.string :cardable_type, default: "SiteCustomization::Page"
+ end
+ end
+end
diff --git a/db/migrate/20210107125458_create_sdg_phases.rb b/db/migrate/20210107125458_create_sdg_phases.rb
new file mode 100644
index 000000000..7b4e19b89
--- /dev/null
+++ b/db/migrate/20210107125458_create_sdg_phases.rb
@@ -0,0 +1,9 @@
+class CreateSDGPhases < ActiveRecord::Migration[5.2]
+ def change
+ create_table :sdg_phases do |t|
+ t.integer :kind, null: false
+ t.index :kind, unique: true
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 6a67f083f..94cfb14ca 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2020_12_16_132642) do
+ActiveRecord::Schema.define(version: 2021_01_07_125458) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@@ -1333,6 +1333,13 @@ ActiveRecord::Schema.define(version: 2020_12_16_132642) do
t.index ["user_id"], name: "index_sdg_managers_on_user_id", unique: true
end
+ create_table "sdg_phases", force: :cascade do |t|
+ t.integer "kind", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["kind"], name: "index_sdg_phases_on_kind", unique: true
+ end
+
create_table "sdg_relations", force: :cascade do |t|
t.string "related_sdg_type"
t.bigint "related_sdg_id"
@@ -1647,9 +1654,10 @@ ActiveRecord::Schema.define(version: 2020_12_16_132642) do
t.boolean "header", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.integer "site_customization_page_id"
+ t.integer "cardable_id"
t.integer "columns", default: 4
- t.index ["site_customization_page_id"], name: "index_widget_cards_on_site_customization_page_id"
+ t.string "cardable_type", default: "SiteCustomization::Page"
+ t.index ["cardable_id"], name: "index_widget_cards_on_cardable_id"
end
create_table "widget_feeds", id: :serial, force: :cascade do |t|
diff --git a/db/sdg.rb b/db/sdg.rb
index f81741e77..a7cef491c 100644
--- a/db/sdg.rb
+++ b/db/sdg.rb
@@ -23,3 +23,5 @@ end
].each do |code|
SDG::Target.where(code: code, goal: SDG::Goal.find_by!(code: code.split(".").first)).first_or_create!
end
+
+SDG::Phase.kinds.values.each { |kind| SDG::Phase.where(kind: kind).first_or_create! }
diff --git a/spec/components/admin/budgets/table_actions_component_spec.rb b/spec/components/admin/budgets/table_actions_component_spec.rb
index 05312853c..36aeea537 100644
--- a/spec/components/admin/budgets/table_actions_component_spec.rb
+++ b/spec/components/admin/budgets/table_actions_component_spec.rb
@@ -4,6 +4,10 @@ describe Admin::Budgets::TableActionsComponent, type: :component do
let(:budget) { create(:budget) }
let(:component) { Admin::Budgets::TableActionsComponent.new(budget) }
+ before do
+ allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BaseController")
+ end
+
it "renders links to edit budget, manage investments and edit groups and manage ballots" do
render_inline component
diff --git a/spec/components/admin/poll/officers/officers_component_spec.rb b/spec/components/admin/poll/officers/officers_component_spec.rb
index f80fbb026..dab2dd04e 100644
--- a/spec/components/admin/poll/officers/officers_component_spec.rb
+++ b/spec/components/admin/poll/officers/officers_component_spec.rb
@@ -6,6 +6,10 @@ describe Admin::Poll::Officers::OfficersComponent, type: :component do
let(:officers) { [existing_officer, new_officer] }
let(:component) { Admin::Poll::Officers::OfficersComponent.new(officers) }
+ before do
+ allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BaseController")
+ end
+
it "renders as many rows as officers" do
render_inline component
diff --git a/spec/components/admin/roles/table_actions_component_spec.rb b/spec/components/admin/roles/table_actions_component_spec.rb
index 42382cf8b..a5bb0cd91 100644
--- a/spec/components/admin/roles/table_actions_component_spec.rb
+++ b/spec/components/admin/roles/table_actions_component_spec.rb
@@ -3,6 +3,10 @@ require "rails_helper"
describe Admin::Roles::TableActionsComponent, type: :component do
let(:user) { create(:user) }
+ before do
+ allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BaseController")
+ end
+
it "renders link to add the role for new records" do
render_inline Admin::Roles::TableActionsComponent.new(user.build_manager)
diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb
index c4630c645..a643a6da1 100644
--- a/spec/components/admin/table_actions_component_spec.rb
+++ b/spec/components/admin/table_actions_component_spec.rb
@@ -3,6 +3,10 @@ require "rails_helper"
describe Admin::TableActionsComponent, type: :component do
let(:record) { create(:banner) }
+ before do
+ allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BaseController")
+ end
+
it "renders links to edit and destroy a record by default" do
render_inline Admin::TableActionsComponent.new(record)
@@ -65,4 +69,18 @@ describe Admin::TableActionsComponent, type: :component do
expect(page).to have_link "Edit"
expect(page).to have_link "Delete"
end
+
+ context "different namespace" do
+ before do
+ allow(ViewComponent::Base).to receive(:test_controller).and_return("SDGManagement::BaseController")
+ end
+
+ it "generates links to different namespaces" do
+ render_inline Admin::TableActionsComponent.new(create(:sdg_local_target))
+
+ expect(page).to have_css "a", count: 2
+ expect(page).to have_css "a[href^='/sdg_management/'][href*='edit']", text: "Edit"
+ expect(page).to have_css "a[href^='/sdg_management/'][data-method='delete']", text: "Delete"
+ end
+ end
end
diff --git a/spec/components/sdg_management/menu_component_spec.rb b/spec/components/sdg_management/menu_component_spec.rb
index 707f892ab..4d29fe677 100644
--- a/spec/components/sdg_management/menu_component_spec.rb
+++ b/spec/components/sdg_management/menu_component_spec.rb
@@ -17,6 +17,7 @@ describe SDGManagement::MenuComponent, type: :component do
render_inline component
expect(page).to have_link "Goals and Targets"
+ expect(page).to have_link "SDG homepage"
expect(page).to have_link "Participatory budgets"
expect(page).to have_link "Debates"
expect(page).to have_link "Collaborative legislation"
@@ -37,8 +38,9 @@ describe SDGManagement::MenuComponent, type: :component do
it "does not generate links to any processes" do
render_inline component
- expect(page).to have_css "a", count: 1
+ expect(page).to have_css "a", count: 2
expect(page).to have_link "Goals and Targets"
+ expect(page).to have_link "SDG homepage"
end
end
@@ -54,8 +56,9 @@ describe SDGManagement::MenuComponent, type: :component do
it "does not generate links to any processes" do
render_inline component
- expect(page).to have_css "a", count: 1
+ expect(page).to have_css "a", count: 2
expect(page).to have_link "Goals and Targets"
+ expect(page).to have_link "SDG homepage"
end
end
@@ -66,6 +69,7 @@ describe SDGManagement::MenuComponent, type: :component do
render_inline component
expect(page).to have_link "Goals and Targets"
+ expect(page).to have_link "SDG homepage"
expect(page).to have_link "Participatory budgets"
expect(page).to have_link "Collaborative legislation"
expect(page).to have_link "Polls"
@@ -82,6 +86,7 @@ describe SDGManagement::MenuComponent, type: :component do
render_inline component
expect(page).to have_link "Goals and Targets"
+ expect(page).to have_link "SDG homepage"
expect(page).to have_link "Debates"
expect(page).to have_link "Participatory budgets"
expect(page).to have_link "Polls"
diff --git a/spec/factories/sdg.rb b/spec/factories/sdg.rb
index 9495a4114..a9dc94e4e 100644
--- a/spec/factories/sdg.rb
+++ b/spec/factories/sdg.rb
@@ -14,4 +14,8 @@ FactoryBot.define do
target { SDG::Target[code.rpartition(".").first] }
end
+
+ factory :sdg_phase, class: "SDG::Phase" do
+ kind { :sensitization }
+ end
end
diff --git a/spec/lib/tasks/db_spec.rb b/spec/lib/tasks/db_spec.rb
index b556b41b4..31448853c 100644
--- a/spec/lib/tasks/db_spec.rb
+++ b/spec/lib/tasks/db_spec.rb
@@ -9,27 +9,33 @@ describe "rake db:load_sdg" do
it "populates empty databases and assigns targets correctly" do
SDG::Goal.destroy_all
+ SDG::Phase.destroy_all
run_rake_task
expect(SDG::Goal.count).to eq 17
expect(SDG::Target.count).to eq 169
expect(SDG::Target["17.1"].goal.code).to eq 17
+ expect(SDG::Phase.count).to eq 3
end
it "does not create additional records on populated databases" do
expect(SDG::Goal.count).to eq 17
expect(SDG::Target.count).to eq 169
+ expect(SDG::Phase.count).to eq 3
goal_id = SDG::Goal.last.id
target_id = SDG::Target.last.id
+ phase_id = SDG::Phase.last.id
run_rake_task
expect(SDG::Goal.count).to eq 17
expect(SDG::Target.count).to eq 169
+ expect(SDG::Phase.count).to eq 3
expect(SDG::Goal.last.id).to eq goal_id
expect(SDG::Target.last.id).to eq target_id
+ expect(SDG::Phase.last.id).to eq phase_id
end
end
diff --git a/spec/models/abilities/everyone_spec.rb b/spec/models/abilities/everyone_spec.rb
index 81b82dcd5..7aaa1e1c5 100644
--- a/spec/models/abilities/everyone_spec.rb
+++ b/spec/models/abilities/everyone_spec.rb
@@ -55,6 +55,7 @@ describe Abilities::Everyone do
it { should be_able_to(:read, SDG::Goal) }
it { should_not be_able_to(:read, SDG::Target) }
+ it { should be_able_to(:read, SDG::Phase) }
it { should_not be_able_to(:read, SDG::Manager) }
it { should_not be_able_to(:create, SDG::Manager) }
diff --git a/spec/models/abilities/sdg/manager_spec.rb b/spec/models/abilities/sdg/manager_spec.rb
index 11800ca04..fa4febb16 100644
--- a/spec/models/abilities/sdg/manager_spec.rb
+++ b/spec/models/abilities/sdg/manager_spec.rb
@@ -13,4 +13,9 @@ describe "Abilities::SDG::Manager" do
it { should_not be_able_to(:read, SDG::Manager) }
it { should_not be_able_to(:create, SDG::Manager) }
it { should_not be_able_to(:delete, SDG::Manager) }
+
+ it { should_not be_able_to(:update, create(:widget_card)) }
+ it { should be_able_to(:update, create(:widget_card, cardable: SDG::Phase.sample)) }
+ it { should_not be_able_to(:create, build(:widget_card)) }
+ it { should be_able_to(:create, build(:widget_card, cardable: SDG::Phase.sample)) }
end
diff --git a/spec/models/sdg/phase_spec.rb b/spec/models/sdg/phase_spec.rb
new file mode 100644
index 000000000..160d09c25
--- /dev/null
+++ b/spec/models/sdg/phase_spec.rb
@@ -0,0 +1,44 @@
+require "rails_helper"
+
+describe SDG::Phase do
+ let(:phase) { build(:sdg_phase) }
+ before { SDG::Phase["sensitization"].destroy }
+
+ it "is valid with a valid kind" do
+ phase.kind = "sensitization"
+
+ expect(phase).to be_valid
+ end
+
+ it "is not valid without a kind" do
+ phase.kind = nil
+
+ expect(phase).not_to be_valid
+ end
+
+ it "is not valid with a duplicate kind" do
+ phase.kind = "planning"
+
+ expect(phase).not_to be_valid
+ end
+
+ it "is not valid with a custom kind" do
+ expect { phase.kind = "improvement" }.to raise_exception(ArgumentError)
+ end
+
+ describe ".[]" do
+ it "finds existing phases by kind" do
+ expect(SDG::Phase["monitoring"].kind).to eq "monitoring"
+ end
+
+ it "raises an exception on empty databases" do
+ SDG::Phase["monitoring"].destroy!
+
+ expect { SDG::Phase["monitoring"] }.to raise_exception ActiveRecord::RecordNotFound
+ end
+
+ it "raises an exception for non-existing kinds" do
+ expect { SDG::Phase["improvement"] }.to raise_exception ActiveRecord::StatementInvalid
+ end
+ end
+end
diff --git a/spec/models/widget/card_spec.rb b/spec/models/widget/card_spec.rb
index e7b01ddfe..70bb3eb93 100644
--- a/spec/models/widget/card_spec.rb
+++ b/spec/models/widget/card_spec.rb
@@ -34,7 +34,7 @@ describe Widget::Card do
header = create(:widget_card, header: true)
card1 = create(:widget_card, header: false)
card2 = create(:widget_card, header: false)
- page_card = create(:widget_card, header: false, page: create(:site_customization_page))
+ page_card = create(:widget_card, header: false, cardable: create(:site_customization_page))
expect(Widget::Card.body).to match_array [card1, card2]
expect(Widget::Card.body).not_to include(header)
diff --git a/spec/routing/polymorphic_routes_spec.rb b/spec/routing/polymorphic_routes_spec.rb
index 729e16d66..814e67b01 100644
--- a/spec/routing/polymorphic_routes_spec.rb
+++ b/spec/routing/polymorphic_routes_spec.rb
@@ -172,7 +172,7 @@ describe "Polymorphic routes" do
it "routes site customization page widget cards" do
page = create(:site_customization_page)
- card = create(:widget_card, page: page)
+ card = create(:widget_card, cardable: page)
expect(admin_polymorphic_path(card)).to eq admin_site_customization_page_widget_card_path(page, card)
end
@@ -186,6 +186,25 @@ describe "Polymorphic routes" do
)
end
end
+
+ describe "sdg_management_polymorphic_path" do
+ include ActionDispatch::Routing::UrlFor
+
+ it "routes local targets" do
+ target = create(:sdg_local_target)
+
+ expect(sdg_management_polymorphic_path(target)).to eq sdg_management_local_target_path(target)
+ end
+
+ it "routes SDG phases widget cards" do
+ phase = SDG::Phase.sample
+ card = create(:widget_card, cardable: phase)
+
+ expect(sdg_management_polymorphic_path(card)).to eq(
+ sdg_management_sdg_phase_widget_card_path(phase, card)
+ )
+ end
+ end
end
def polymorphic_path(record, options = {})
diff --git a/spec/system/admin/widgets/cards_spec.rb b/spec/system/admin/widgets/cards_spec.rb
index 444968b7d..03ea2c2be 100644
--- a/spec/system/admin/widgets/cards_spec.rb
+++ b/spec/system/admin/widgets/cards_spec.rb
@@ -175,9 +175,9 @@ describe "Cards", :admin do
end
scenario "Show" do
- card_1 = create(:widget_card, page: custom_page, title: "Card large", columns: 8)
- card_2 = create(:widget_card, page: custom_page, title: "Card medium", columns: 4)
- card_3 = create(:widget_card, page: custom_page, title: "Card small", columns: 2)
+ card_1 = create(:widget_card, cardable: custom_page, title: "Card large", columns: 8)
+ card_2 = create(:widget_card, cardable: custom_page, title: "Card medium", columns: 4)
+ card_3 = create(:widget_card, cardable: custom_page, title: "Card small", columns: 2)
visit custom_page.url
@@ -189,8 +189,8 @@ describe "Cards", :admin do
end
scenario "Show label only if it is present" do
- card_1 = create(:widget_card, page: custom_page, title: "Card one", label: "My label")
- card_2 = create(:widget_card, page: custom_page, title: "Card two")
+ card_1 = create(:widget_card, cardable: custom_page, title: "Card one", label: "My label")
+ card_2 = create(:widget_card, cardable: custom_page, title: "Card two")
visit custom_page.url
@@ -204,7 +204,7 @@ describe "Cards", :admin do
end
scenario "Edit", :js do
- create(:widget_card, page: custom_page, title: "Original title")
+ create(:widget_card, cardable: custom_page, title: "Original title")
visit admin_site_customization_page_widget_cards_path(custom_page)
@@ -227,7 +227,7 @@ describe "Cards", :admin do
end
scenario "Destroy", :js do
- create(:widget_card, page: custom_page, title: "Card title")
+ create(:widget_card, cardable: custom_page, title: "Card title")
visit admin_site_customization_page_widget_cards_path(custom_page)
diff --git a/spec/system/sdg_management/homepage_spec.rb b/spec/system/sdg_management/homepage_spec.rb
new file mode 100644
index 000000000..598066adc
--- /dev/null
+++ b/spec/system/sdg_management/homepage_spec.rb
@@ -0,0 +1,52 @@
+require "rails_helper"
+
+describe "SDG homepage configuration", :js do
+ before do
+ Setting["feature.sdg"] = true
+ login_as(create(:sdg_manager).user)
+ end
+
+ describe "Show" do
+ scenario "Visit the index" do
+ visit sdg_management_root_path
+
+ within("#side_menu") do
+ click_link "SDG homepage"
+ end
+
+ expect(page).to have_title "SDG content - Homepage configuration"
+ end
+
+ scenario "Create card" do
+ visit sdg_management_homepage_path
+ click_link "Create planning card"
+
+ within(".translatable-fields") { fill_in "Title", with: "My planning card" }
+ click_button "Create card"
+
+ within(".planning-cards") do
+ expect(page).to have_content "My planning card"
+ end
+
+ within(".sensitization-cards") do
+ expect(page).to have_content "There are no cards for this phase"
+ end
+ end
+
+ scenario "Update card" do
+ create(:widget_card, cardable: SDG::Phase["monitoring"], title: "My monitoring card")
+
+ visit sdg_management_homepage_path
+ within(".monitoring-cards") { click_link "Edit" }
+
+ within(".translatable-fields") { fill_in "Title", with: "Updated monitoring card" }
+ click_button "Save card"
+
+ within(".monitoring-cards") do
+ expect(page).to have_css "tbody tr", count: 1
+ expect(page).to have_content "Updated monitoring card"
+ expect(page).not_to have_content "My monitoring card"
+ end
+ end
+ end
+end
diff --git a/spec/system/site_customization/custom_pages_spec.rb b/spec/system/site_customization/custom_pages_spec.rb
index a54c50b37..68a1745cf 100644
--- a/spec/system/site_customization/custom_pages_spec.rb
+++ b/spec/system/site_customization/custom_pages_spec.rb
@@ -104,7 +104,7 @@ describe "Custom Pages" do
scenario "Show widget cards for that page" do
custom_page = create(:site_customization_page, :published)
- create(:widget_card, page: custom_page, title: "Card Highlights")
+ create(:widget_card, cardable: custom_page, title: "Card Highlights")
visit custom_page.url