Skip to content

Commit

Permalink
Include ephemeral participation specs in the CI and fix them
Browse files Browse the repository at this point in the history
  • Loading branch information
fblupi committed Mar 15, 2024
1 parent b7d777a commit 300a4ae
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 91 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ jobs:
run: |
npm install
bundle exec rake assets:precompile
- run: bundle exec rspec
- run: |
bundle exec rspec
bundle exec rspec decidim-ephemeral_participation/spec/**/*.rb
name: Run specs
5 changes: 5 additions & 0 deletions app/packs/stylesheets/decidim/decidim_application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@

// @import "stylesheets/barcelona";
// @import "stylesheets/global_accountability";

// Fix for the confirm modal showing behind the modal who generates it
#confirm-modal {
z-index: 100;
}
4 changes: 2 additions & 2 deletions app/views/layouts/decidim/mailer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
<table>
<tr>
<th>
<% if @organization.official_img_header.attached? %>
<% if @organization.official_img_footer.attached? %>
<%= link_to @organization.official_url do %>
<%= image_tag @organization.attached_uploader(:official_img_header).url(host: @organization.host), alt: "", style: "max-height: 50px", class: "float-right" %>
<%= image_tag @organization.attached_uploader(:official_img_footer).url(host: @organization.host), alt: "", style: "max-height: 50px", class: "float-right" %>
<% end %>
<% end %>
</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def validate_ephemeral_participation_permissions_settings
permissions.values.each do |permission_form|
next if valid_permission_form?(permission_form)

permission_form.errors.add(:base, :invalid_ephemeral_participation_permissions, i18n_options)
permission_form.errors.add(:base, I18n.t("activemodel.errors.models.permission.attributes.base.invalid_ephemeral_participation_permissions", **i18n_options))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module ComponentOverride
included do
def ephemeral_participation_enabled?
organization.try(:ephemeral_participation_authorization) && settings.try(:ephemeral_participation_enabled) == true
# @todo: Remove this line
true
end

# Given organization.ephemeral_participation_authorization == "valid_auth"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def answering_public_survey?

def ephemeral_participation_permission_action?
Decidim::EphemeralParticipation::EphemeralPermissionActionsDictionary.for(component)
.any? do |_, permission_action_attributes|
permission_action_attributes.any? do |action:, scope:, subject:|
permission_action.matches?(scope, action, subject)
.any? do |_, ephemeral_permission_actions|
ephemeral_permission_actions.any? do |ephemeral_permission_action|
permission_action.matches?(ephemeral_permission_action[:scope], ephemeral_permission_action[:action], ephemeral_permission_action[:subject])
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if controller.respond_to?(:current_component) && current_component.ephemeral_participation_enabled? && current_component.ephemeral_participation_permissions.any? %>
<div class="form__wrapper">
<div class="form__wrapper" id="ephemeral-participation-login-form">
<div class="row">
<div class="columns medium-8 medium-centered">
<div class="text-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ def create_ephemeral_participant
let(:document_number) { "123456789X" }

def click_ephemeral_participation_button(selector = ephemeral_participation_action_button_selector)
click_ephemeral_parcipation_action_button(selector)
accept_confirm { click_on("I want to participate without registering") }
click_ephemeral_participation_action_button(selector)
accept_confirm { click_ephemeral_participation_login_button }
end

def click_ephemeral_parcipation_action_button(_selector = ephemeral_participation_action_button_selector)
def click_ephemeral_participation_login_button
# Modals takes too long rendering. We wait for the buttons to be visible and enabled.
sleep(0.2)
click_on("I want to participate without registering")
sleep(0.2)
end

def click_ephemeral_participation_action_button(_selector = ephemeral_participation_action_button_selector)
page.find(ephemeral_participation_action_button_selector).click
end

Expand All @@ -94,10 +101,10 @@ def submit_unverifiable_form
let(:email) { "[email protected]" }

def register_workflows
[
"decidim-generators/lib/decidim/generators/app_templates/dummy_authorization_handler.rb",
"decidim-generators/lib/decidim/generators/app_templates/another_dummy_authorization_handler.rb"
].each { |file_path| require "#{Gem::Specification.find_by_name("decidim").gem_dir}/#{file_path}" }
%w(lib/decidim/generators/app_templates/dummy_authorization_handler.rb
lib/decidim/generators/app_templates/another_dummy_authorization_handler.rb).each do |file_path|
require "#{Gem::Specification.find_by_name("decidim-generators").gem_dir}/#{file_path}"
end

Decidim::Verifications.register_workflow(:dummy_authorization_handler) do |workflow|
workflow.form = "DummyAuthorizationHandler"
Expand Down
2 changes: 1 addition & 1 deletion decidim-ephemeral_participation/spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "../../spec/rails_helper"
require_relative "../../spec/rails_helper"
56 changes: 28 additions & 28 deletions decidim-ephemeral_participation/spec/system/admin/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
es: "Alerta!"
)

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end
end

Expand All @@ -73,9 +73,9 @@
es: "Alerta!"
)

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.alert")
expect(page).to have_css("div.callout-wrapper .flash.alert")
end
end
end
Expand All @@ -102,26 +102,26 @@
it "updates permissions when selecting ephemeral authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end

it "updates permissions when selecting regular authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_another_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end

it "fails to update permissions when selecting more than one authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_dummy_authorization_handler")
check("component_permissions_permissions_vote_authorization_handlers_another_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.alert")
expect(page).to have_css("div.callout-wrapper .flash.alert")
end
end

Expand All @@ -133,26 +133,26 @@
it "updates permissions when selecting ephemeral authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end

it "updates permissions when selecting regular authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_another_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end

it "updates permissions when selecting more than one authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_dummy_authorization_handler")
check("component_permissions_permissions_vote_authorization_handlers_another_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end
end
end
Expand All @@ -173,26 +173,26 @@
it "updates permissions when selecting ephemeral authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end

it "updates permissions when selecting regular authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_another_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end

it "updates permissions when selecting more than one authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_dummy_authorization_handler")
check("component_permissions_permissions_vote_authorization_handlers_another_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end
end

Expand All @@ -204,26 +204,26 @@
it "updates permissions when selecting ephemeral authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end

it "updates permissions when selecting regular authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_another_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end

it "updates permissions when selecting more than one authorization for a given action" do
check("component_permissions_permissions_vote_authorization_handlers_dummy_authorization_handler")
check("component_permissions_permissions_vote_authorization_handlers_another_dummy_authorization_handler")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.callout.success")
expect(page).to have_css("div.callout-wrapper .flash.success")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

shared_examples "fails to transfer the users" do
it "fails to transfer the users" do
within(".callout") do
within(".callout-wrapper") do
expect(page).to have_content("There was a problem transfering the current participant to managed participant.")
end

Expand All @@ -46,7 +46,7 @@

context "when transfering the user" do
before do
click_on(href: "/admin/conflicts/#{conflict.id}/edit")
find(:xpath, "//a[@href='/admin/conflicts/#{conflict.id}/edit']").click
end

context "and submitting a registered email" do
Expand Down Expand Up @@ -78,7 +78,7 @@

context "when transfering the user" do
before do
click_on(href: "/admin/conflicts/#{conflict.id}/edit")
find(:xpath, "//a[@href='/admin/conflicts/#{conflict.id}/edit']").click
end

context "and submitting a registered email" do
Expand All @@ -101,7 +101,7 @@
end

it "transfers the users successfuly" do
within(".callout") do
within(".callout-wrapper") do
expect(page).to have_content("The current transfer has been successfully completed.")
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

choose("organization_available_authorizations_dummy_authorization_handler_allow_ephemeral_participation")

find("*[type=submit]").click
find("*[type=submit][name=commit]").click

expect(page).to have_css("div.flash.success")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

describe "User menu" do
describe "Complete registration" do
include_context "with ephemerable participation"

let!(:project) { create(:project, budget:) }
Expand All @@ -19,21 +19,15 @@
end

context "when the user clicks the ephemeral participation button and toggles the user menu" do
let(:toggle_user_menu) do
within(".topbar__user__logged") do
click_on(current_user.name)
end
end
let(:current_user) { Decidim::User.last }

before do
click_ephemeral_participation_button
toggle_user_menu
end

context "when the user clicks the complete registration link" do
before do
within(".topbar__user__logged") do
within(".main-footer__top") do
click_on("Finish your registration")
end
end
Expand All @@ -46,7 +40,7 @@
fill_in("ephemeral_participant_email", with: email)
fill_in("ephemeral_participant_password", with: password)
fill_in("ephemeral_participant_password_confirmation", with: password)
find("*[type=submit]").click
find("*[type=submit][name=commit]").click
end
end
let(:name) { "New name" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
end

it "renders the confirmation modal" do
click_on("I want to participate without registering")
click_ephemeral_participation_login_button

within(".confirm-modal-content") do
within("#confirm-modal-content") do
expect(page).to have_content("Are you sure?")
end
end
Expand All @@ -50,7 +50,7 @@
end

it "renders the verification form directly" do
click_on("I want to participate without registering")
click_ephemeral_participation_login_button

within_flash_messages do
expect(page).to have_content("en.decidim.ephemeral_participation.ephemeral_participants.create")
Expand Down
Loading

0 comments on commit 300a4ae

Please sign in to comment.