Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin tests #39

Merged
merged 9 commits into from
Jun 27, 2023
Merged
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: "[CI] Test"

on:
push:
branches:
- main
pull_request:

env:
Expand Down
26 changes: 26 additions & 0 deletions spec/shared/system_admin_homepage_examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

shared_examples "increase number of content blocks" do |text|
it "increases the number of active content blocks" do
content_block = find("ul.js-list-availables li", text: text)
active_blocks_list = find("ul.js-list-actives")
content_block.drag_to(active_blocks_list)
sleep(2)
expect(Decidim::ContentBlock.count).to eq 1
end
end

shared_examples "updates the content block" do |manifest_name|
it "updates the settings of the content block" do
visit decidim_admin.edit_organization_homepage_content_block_path(manifest_name.to_sym)

fill_in(
:content_block_settings_title_en,
with: "Custom #{manifest_name} title text!"
)

click_button "Update"
visit decidim.root_path
expect(page).to have_content(/Custom #{manifest_name} title text!/i)
end
end
40 changes: 40 additions & 0 deletions spec/shared/system_admin_process_group_landing_examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

shared_examples "updates the content block extra title" do
it "updates the settings of the content block" do
visit "/admin/participatory_process_groups/#{participatory_process_group.id}/landing_page/content_blocks/extra_title/edit"

fill_in(
:content_block_settings_link_text_1_en,
with: "Custom extra title link text!"
)
# rubocop:disable Naming/VariableNumber
fill_in(
:content_block_settings_link_url_1,
with: "https://google.es"
)
# rubocop:enable Naming/VariableNumber
click_button "Update"
visit decidim_participatory_processes.participatory_process_group_path(participatory_process_group)
expect(page).to have_content(/Custom extra title link text!/i)
end
end

shared_examples "updates the content block extra information" do
it "updates the settings of the content block" do
visit "/admin/participatory_process_groups/#{participatory_process_group.id}/landing_page/content_blocks/extra_information/edit"

editor = find(".ql-editor")
editor.set("Custom extra information body text!")

fill_in(
:content_block_settings_columns,
with: 2
)

click_button "Update"
visit decidim_participatory_processes.participatory_process_group_path(participatory_process_group)
expect(page).to have_content(/Custom extra information body text!/i)
expect(page).to have_css(".columns.large-2")
end
end
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
require "decidim/dev"

require "simplecov"
SimpleCov.start "rails"
SimpleCov.start "rails" do
add_filter "lib/decidim/alternative_landing/version.rb"
add_filter "lib/tasks"
end
if ENV["CODECOV"]
require "codecov"
SimpleCov.formatter = SimpleCov::Formatter::Codecov
Expand Down
81 changes: 81 additions & 0 deletions spec/system/admin_homepage_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# frozen_string_literal: true

require "spec_helper"
require "shared/system_admin_homepage_examples"

describe "Admin visits homepage settings", type: :system do
include ActionView::Helpers::SanitizeHelper

let(:organization) { create(:organization) }
let(:user) { create(:user, :admin, :confirmed, organization: organization) }
let!(:meeting) { create :meeting }
let!(:post) { create(:post) }

before do
switch_to_host(organization.host)
login_as user, scope: :user
end

context "when visiting homepage settings" do
before do
visit decidim_admin.edit_organization_homepage_path
end

it "renders active and inactive content blocks headers" do
expect(page).to have_content("Active content blocks")
expect(page).to have_content("Inactive content blocks")
end

it "renders all alternative landing content blocks" do
expect(page).to have_content("Upcoming meetings (Alternative)")
expect(page).to have_content("Stack of 3 custom items (Horizontal)")
expect(page).to have_content("Stack of 3 custom items (Vertical)")
expect(page).to have_content("Latest blog posts")
expect(page).to have_content("Cover (Full screen)")
expect(page).to have_content("Cover (Half screen)")
expect(page).to have_content("Tiles")
end

it "has initial active content blocks equal to 0" do
expect(Decidim::ContentBlock.count).to eq 0
end

context "when dragging the content block from inactive to active panel" do
it_behaves_like "increase number of content blocks", "Upcoming meetings (Alternative)"
it_behaves_like "increase number of content blocks", "Stack of 3 custom items (Horizontal)"
it_behaves_like "increase number of content blocks", "Stack of 3 custom items (Vertical)"
it_behaves_like "increase number of content blocks", "Latest blog posts"
it_behaves_like "increase number of content blocks", "Cover (Full screen)"
it_behaves_like "increase number of content blocks", "Cover (Half screen)"
it_behaves_like "increase number of content blocks", "Tiles"
end

context "when editing a persisted content block" do
let!(:alternative_upcoming_meetings_block) { create :alternative_upcoming_meetings_block, organization: organization, scope_name: :homepage }
let!(:cover_full_block) { create :content_block, organization: organization, manifest_name: "cover_full", scope_name: :homepage }
let!(:cover_half_block) { create :cover_half_block, organization: organization, scope_name: :homepage }
let!(:latest_blog_posts_block) { create :latest_blog_posts_block, organization: organization, scope_name: :homepage }
let!(:stack_horizontal_block) { create :stack_horizontal_block, organization: organization, scope_name: :homepage }
let!(:stack_vertical_block) { create :stack_vertical_block, organization: organization, scope_name: :homepage }
let!(:tiles_block) { create :tiles_block, organization: organization, scope_name: :homepage }

it_behaves_like "updates the content block", "alternative_upcoming_meetings"
it_behaves_like "updates the content block", "cover_full"
it_behaves_like "updates the content block", "cover_half"
it_behaves_like "updates the content block", "latest_blog_posts"
it_behaves_like "updates the content block", "stack_horizontal"
it_behaves_like "updates the content block", "stack_vertical"
it_behaves_like "updates the content block", "tiles"

it "updates the images of the content block" do
visit decidim_admin.edit_organization_homepage_content_block_path(:cover_full)

dynamically_attach_file(:content_block_images_background_image, Decidim::Dev.asset("city2.jpeg"))

click_button "Update"
visit decidim.root_path
expect(page.html).to include("city2.jpeg")
end
end
end
end
7 changes: 7 additions & 0 deletions spec/system/process_group_landing_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

require "spec_helper"
require "shared/system_admin_process_group_landing_examples"

describe "Visit a process group's landing page", type: :system, perform_enqueued: true do
let!(:organization) { create :organization, available_locales: [:en] }
let(:user) { create(:user, :admin, :confirmed, organization: organization) }
let!(:participatory_process_group) { create :participatory_process_group, :with_participatory_processes, organization: organization }
let!(:processes) { participatory_process_group.participatory_processes }

Expand All @@ -16,6 +18,7 @@

before do
switch_to_host(organization.host)
login_as user, scope: :user
visit decidim_participatory_processes.participatory_process_group_path(participatory_process_group)
end

Expand All @@ -31,6 +34,8 @@
expect(page).to have_selector(".icon--instagram")
end
end

it_behaves_like "updates the content block extra title", "extra_title"
end

describe "extra information block" do
Expand All @@ -39,6 +44,8 @@
expect(page).to have_i18n_content(extra_information_block.settings.body)
end
end

it_behaves_like "updates the content block extra information", "extra_information"
end

describe "calendar block" do
Expand Down