Skip to content

Commit

Permalink
Backport 'User's group endorsement no longer disappears after persona…
Browse files Browse the repository at this point in the history
…l endorsement removed' to v0.26 (decidim#10311)

* User's group endorsement no longer disappears after personal endorsement removed

* Fixed group endorsement removal when personal endorsement removed & tests

* test-fixes

* Improve the spec to wait the endorsement has happened

---------

Co-authored-by: JoonasAapro <[email protected]>
Co-authored-by: Antti Hukkanen <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2023
1 parent 97c17c5 commit a94516d
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 1 deletion.
113 changes: 113 additions & 0 deletions decidim-blogs/spec/system/endorse_posts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# frozen_string_literal: true

require "spec_helper"

describe "endorse posts", type: :system do
include_context "with a component"
let(:manifest_name) { "blogs" }
let(:organization) { create(:organization) }
let(:author) { create(:user, :confirmed, name: "Tester", organization: organization) }
let!(:post) { create(:post, component: component, title: { en: "Blog post title" }) }

before do
sign_in author
visit_component
click_link "Blog post title"
end

context "when endorsing the post without belonging to a user group" do
it "endorses the post" do
click_button("Endorse")
expect(page).to have_content("ENDORSED")
end
end

context "when endorsing the post while being a part of a group" do
let!(:user_group) do
create(
:user_group,
:verified,
name: "Tester's Organization",
nickname: "test_org",
email: "[email protected]",
users: [author],
organization: organization
)
end

it "opens a modal where you select identity as a user or a group" do
visit page.current_path
click_button("Endorse")
expect(page).to have_content("SELECT IDENTITY")
expect(page).to have_content("Tester's Organization")
expect(page).to have_content("Tester")
end

def add_endorsements
click_button "Endorse"
within "#user-identities" do
find("li", text: /\ATester's Organization\z/).click
find("li", text: /\ATester\z/).click
expect(page).to have_css(".selected", count: 2)
click_button "Done"
end
visit current_path
click_button "Endorse"
end

context "when both identities picked" do
it "endorses the post as a group and a user" do
visit page.current_path

add_endorsements

within "#user-identities" do
expect(page).to have_css(".selected", count: 2)
end
end
end

context "when endorsement cancelled as a user" do
it "doesn't cancel group endorsement" do
visit page.current_path

add_endorsements
within "#user-identities" do
find(".selected", match: :first).click
expect(page).to have_css(".selected", count: 1)
click_button "Done"
end
visit current_path
click_button "Endorse"

within "#user-identities" do
expect(page).to have_css(".selected", count: 1)
within ".selected" do
expect(page).to have_text("Tester's Organization", exact: true)
end
end
end
end

context "when endorsement cancelled as a group" do
it "doesn't cancel user endorsement" do
visit page.current_path

add_endorsements
within "#user-identities" do
page.all(".selected")[1].click
click_button "Done"
end
visit current_path
click_button "Endorse"

within "#user-identities" do
expect(page).to have_css(".selected", count: 1)
within ".selected" do
expect(page).to have_text("Tester", exact: true)
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion decidim-core/app/commands/decidim/unendorse_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def destroy_resource_endorsement
query = if @current_group.present?
@resource.endorsements.where(decidim_user_group_id: @current_group&.id)
else
@resource.endorsements.where(author: @current_user)
@resource.endorsements.where(author: @current_user, decidim_user_group_id: nil)
end
query.destroy_all
end
Expand Down

0 comments on commit a94516d

Please sign in to comment.