-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add specs releated to the backport scopes management
- Loading branch information
Showing
1 changed file
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |