diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 894d977..236ae6f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,8 +2,6 @@ name: "[CI] Test" on: push: - branches: - - main pull_request: env: diff --git a/spec/shared/system_admin_homepage_examples.rb b/spec/shared/system_admin_homepage_examples.rb new file mode 100644 index 0000000..824b159 --- /dev/null +++ b/spec/shared/system_admin_homepage_examples.rb @@ -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 diff --git a/spec/shared/system_admin_process_group_landing_examples.rb b/spec/shared/system_admin_process_group_landing_examples.rb new file mode 100644 index 0000000..764937a --- /dev/null +++ b/spec/shared/system_admin_process_group_landing_examples.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e74c150..2883ffc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/system/admin_homepage_spec.rb b/spec/system/admin_homepage_spec.rb new file mode 100644 index 0000000..f20c6cc --- /dev/null +++ b/spec/system/admin_homepage_spec.rb @@ -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 diff --git a/spec/system/process_group_landing_spec.rb b/spec/system/process_group_landing_spec.rb index 833e576..ac01257 100644 --- a/spec/system/process_group_landing_spec.rb +++ b/spec/system/process_group_landing_spec.rb @@ -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 } @@ -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 @@ -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 @@ -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