Skip to content

Commit

Permalink
test: Add specs releated to the backport scopes management
Browse files Browse the repository at this point in the history
  • Loading branch information
AyakorK committed Nov 18, 2024
1 parent 70f61e8 commit 30fd48d
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions spec/system/admin_manages_organization_scopes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# frozen_string_literal: true

require "spec_helper"

describe "Organization scopes", type: :system do
include Decidim::SanitizeHelper

let(:organization) { create :organization, default_locale: :en, available_locales: [:en, :es, :ca, :fr] }
let(:admin) { create :user, :admin, :confirmed, organization: organization }
let!(:attributes) { attributes_for(:scope) }

before do
switch_to_host(organization.host)
end

describe "Managing scopes" do
let!(:scope_type) { create(:scope_type, organization: admin.organization) }

before do
login_as admin, scope: :user
visit decidim_admin.root_path
click_link "Settings"
click_link "Scopes"
end

it "can create new scopes" do
click_link "Add"

within ".new_scope" do
fill_in_i18n :scope_name, "#scope-name-tabs", **attributes[:name].except("machine_translations")
fill_in "Code", with: "MY-DISTRICT"
select scope_type.name["en"], from: :scope_scope_type_id

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

expect(page).to have_admin_callout("successfully")

within ".draggable-list" do
expect(page).to have_content(translated(attributes[:name]))
end

visit decidim_admin.root_path
expect(page).to have_content("created the #{translated(attributes[:name])} scope")
end

context "with existing scopes" do
let!(:scope) { create(:scope, organization: organization) }

before do
visit current_path
end

it "can edit them" do
within find(".draggable-content", text: translated(scope.name)) do
click_link "Edit"
end

within ".edit_scope" do
fill_in_i18n :scope_name, "#scope-name-tabs", **attributes[:name].except("machine_translations")
find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

within ".draggable-list" do
expect(page).to have_content(translated(attributes[:name]))
end

visit decidim_admin.root_path
expect(page).to have_content("updated the #{translated(attributes[:name])} scope")
end

it "can delete them" do
within find(".draggable-content", text: translated(scope.name)) do
accept_confirm { click_link "Destroy" }
end

expect(page).to have_admin_callout("successfully")

within ".card-section" do
expect(page).to have_no_content(translated(scope.name))
end
end

it "can create a new subcope" do
within find(".draggable-content", text: translated(scope.name)) do
find("a", text: translated(scope.name)).click
end

click_link "Add"

within ".new_scope" do
fill_in_i18n :scope_name, "#scope-name-tabs", en: "My nice subdistrict",
es: "Mi lindo subdistrito",
ca: "El meu bonic subbarri"
fill_in "Code", with: "MY-SUBDISTRICT"
select scope_type.name["en"], from: :scope_scope_type_id

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

expect(page).to have_admin_callout("successfully")

within ".draggable-list" do
expect(page).to have_content("My nice subdistrict")
end
end
end
end
end

0 comments on commit 30fd48d

Please sign in to comment.