-
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.
fix: Fix the issue of the single initiative not retrieving infos and …
…add tests
- Loading branch information
Showing
3 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
app/views/decidim/initiatives/admin/initiatives/_form.html.erb
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,133 @@ | ||
<div class="card"> | ||
<div class="card-divider"> | ||
<h2 class="card-title"><%= t ".title" %></h2> | ||
</div> | ||
|
||
<div class="card-section"> | ||
<div class="row column"> | ||
<%= form.translated :text_field, :title, autofocus: true, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> | ||
</div> | ||
|
||
<div class="row column"> | ||
<%= form.translated :editor, :description, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> | ||
</div> | ||
|
||
<div class="row column"> | ||
<div class="columns xlarge-6"> | ||
<%= form.text_field :hashtag, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="card"> | ||
<div class="card-divider"> | ||
<h2 class="card-title"><%= t ".settings" %></h2> | ||
</div> | ||
|
||
<div class="card-section"> | ||
<div class="row"> | ||
<div class="columns xlarge-6"> | ||
<%= form.select :state, | ||
Decidim::Initiative.states.keys.map { |state| [I18n.t(state, scope: "decidim.initiatives.admin_states"), state] }, | ||
{}, | ||
{ disabled: !@form.state_updatable? } %> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="columns xlarge-6"> | ||
<% unless single_initiative_type? %> | ||
<%= form.select :type_id, | ||
initiative_type_options, | ||
{}, | ||
{ | ||
disabled: !@form.signature_type_updatable?, | ||
"data-scope-selector": "initiative_decidim_scope_id", | ||
"data-scope-id": form.object.decidim_scope_id.to_s, | ||
"data-scope-search-url": decidim_initiatives.initiative_type_scopes_search_url, | ||
"data-signature-types-selector": "initiative_signature_type", | ||
"data-signature-type": current_initiative.signature_type, | ||
"data-signature-types-search-url": decidim_initiatives.initiative_type_signature_types_search_url | ||
} %> | ||
</div> | ||
<% else %> | ||
<%= form.hidden_field :type_id, | ||
{ | ||
disabled: !@form.signature_type_updatable?, | ||
"data-scope-selector": "initiative_decidim_scope_id", | ||
"data-scope-id": form.object.decidim_scope_id.to_s, | ||
"data-scope-search-url": decidim_initiatives.initiative_type_scopes_search_url, | ||
"data-signature-types-selector": "initiative_signature_type", | ||
"data-signature-type": current_initiative.signature_type, | ||
"data-signature-types-search-url": decidim_initiatives.initiative_type_signature_types_search_url | ||
} %> | ||
<% end %> | ||
<div class="columns xlarge-6"> | ||
<%= form.select :decidim_scope_id, [], {}, { disabled: !@form.signature_type_updatable? } %> | ||
</div> | ||
</div> | ||
|
||
<% if current_initiative.published? && current_user.admin? %> | ||
<div class="row"> | ||
<div class="columns xlarge-6"> | ||
<%= form.date_field :signature_start_date %> | ||
</div> | ||
|
||
<div class="columns xlarge-6"> | ||
<%= form.date_field :signature_end_date %> | ||
</div> | ||
</div> | ||
<% end %> | ||
|
||
<% if can_edit_custom_signature_end_date?(current_initiative) %> | ||
<div class="row column"> | ||
<%= form.date_field :signature_end_date, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> | ||
</div> | ||
<% end %> | ||
|
||
<% if current_initiative.area_enabled? %> | ||
<div class="field"> | ||
<%= form.areas_select :area_id, | ||
areas_for_select(current_organization), | ||
{ | ||
selected: current_initiative.decidim_area_id, | ||
include_blank: current_initiative.decidim_area_id.blank? || current_initiative.created? | ||
}, | ||
disabled: !@form.area_updatable? %> | ||
</div> | ||
<% end %> | ||
|
||
<div class="row"> | ||
<div class="columns xlarge-6"> | ||
<%= form.select :signature_type, [], {}, { disabled: !@form.signature_type_updatable? } %> | ||
</div> | ||
</div> | ||
|
||
<% if current_initiative.accepts_offline_votes? && current_user.admin? %> | ||
<div class="row"> | ||
<div class="columns xlarge-6"> | ||
<% @form.offline_votes.each do |scope_id, (votes, scope_name)| %> | ||
<%= label_tag "initiative_offline_votes_#{scope_id}", t("activemodel.attributes.initiative.offline_votes_for_scope", scope_name: translated_attribute(scope_name)) %> | ||
<%= number_field_tag "initiative[offline_votes][#{scope_id}]", votes, min: 0, id: "initiative_offline_votes_#{scope_id}" %> | ||
<% end %> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="card"> | ||
<div class="card-divider"> | ||
<h2 class="card-title"><%= t ".attachments" %></h2> | ||
</div> | ||
|
||
<div class="card-section"> | ||
<div class="row"> | ||
<% if allowed_to?(:read, :attachment, initiative: current_participatory_space) %> | ||
<%= render partial: "initiative_attachments", locals: { current_initiative: current_initiative, current_participatory_space: current_participatory_space } %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<%= javascript_pack_tag "decidim_initiatives_admin" %> |
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
shared_context "when admins initiative" do | ||
let(:organization) { create(:organization) } | ||
let(:user) { create(:user, :admin, :confirmed, organization: organization) } | ||
let(:author) { create(:user, :confirmed, organization: organization) } | ||
let(:other_initiatives_type) { create(:initiatives_type, organization: organization, signature_type: "any") } | ||
let!(:other_initiatives_type_scope) { create(:initiatives_type_scope, type: other_initiatives_type) } | ||
|
||
let(:initiative_type) { create(:initiatives_type, organization: organization) } | ||
let(:initiative_scope) { create(:initiatives_type_scope, type: initiative_type) } | ||
let!(:initiative) { create(:initiative, organization: organization, scoped_type: initiative_scope, author: author) } | ||
|
||
let(:image1_filename) { "city.jpeg" } | ||
let(:image1_path) { Decidim::Dev.asset(image1_filename) } | ||
let(:image2_filename) { "city2.jpeg" } | ||
let(:image2_path) { Decidim::Dev.asset(image2_filename) } | ||
let(:image3_filename) { "city3.jpeg" } | ||
let(:image3_path) { Decidim::Dev.asset(image3_filename) } | ||
end |
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,124 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe "User prints the initiative", type: :system do | ||
include_context "when admins initiative" | ||
|
||
def submit_and_validate | ||
find("*[type=submit]").click | ||
|
||
within ".callout-wrapper" do | ||
expect(page).to have_content("successfully") | ||
end | ||
end | ||
|
||
context "when initiative update" do | ||
context "and user is admin" do | ||
before do | ||
switch_to_host(organization.host) | ||
login_as user, scope: :user | ||
visit decidim_admin_initiatives.initiatives_path | ||
end | ||
|
||
it "Updates published initiative data" do | ||
page.find(".action-icon--edit").click | ||
within ".edit_initiative" do | ||
fill_in :initiative_hashtag, with: "#hashtag" | ||
end | ||
submit_and_validate | ||
end | ||
|
||
context "when initiative is in created state" do | ||
before do | ||
initiative.created! | ||
end | ||
|
||
it "updates type, scope and signature type" do | ||
page.find(".action-icon--edit").click | ||
within ".edit_initiative" do | ||
select translated(other_initiatives_type.title), from: "initiative_type_id" | ||
select translated(other_initiatives_type_scope.scope.name), from: "initiative_decidim_scope_id" | ||
select "In-person", from: "initiative_signature_type" | ||
end | ||
submit_and_validate | ||
end | ||
|
||
it "displays initiative attachments" do | ||
page.find(".action-icon--edit").click | ||
expect(page).to have_link("Edit") | ||
expect(page).to have_link("New") | ||
end | ||
end | ||
|
||
context "when initiative is in validating state" do | ||
before do | ||
initiative.validating! | ||
end | ||
|
||
it "updates type, scope and signature type" do | ||
page.find(".action-icon--edit").click | ||
within ".edit_initiative" do | ||
select translated(other_initiatives_type.title), from: "initiative_type_id" | ||
select translated(other_initiatives_type_scope.scope.name), from: "initiative_decidim_scope_id" | ||
select "In-person", from: "initiative_signature_type" | ||
end | ||
submit_and_validate | ||
end | ||
|
||
it "displays initiative attachments" do | ||
page.find(".action-icon--edit").click | ||
expect(page).to have_link("Edit") | ||
expect(page).to have_link("New") | ||
end | ||
end | ||
|
||
context "when initiative is in accepted state" do | ||
before do | ||
initiative.accepted! | ||
end | ||
|
||
it "update of type, scope and signature type are disabled" do | ||
page.find(".action-icon--edit").click | ||
|
||
within ".edit_initiative" do | ||
expect(page).to have_css("#initiative_type_id[disabled]") | ||
expect(page).to have_css("#initiative_decidim_scope_id[disabled]") | ||
expect(page).to have_css("#initiative_signature_type[disabled]") | ||
end | ||
end | ||
|
||
it "displays initiative attachments" do | ||
page.find(".action-icon--edit").click | ||
expect(page).to have_link("Edit") | ||
expect(page).to have_link("New") | ||
end | ||
end | ||
|
||
context "when there is a single initiative type" do | ||
let!(:other_initiatives_type) { nil } | ||
let!(:other_initiatives_type_scope) { nil } | ||
|
||
before do | ||
initiative.created! | ||
end | ||
|
||
it "update of type, scope and signature type are disabled" do | ||
page.find(".action-icon--edit").click | ||
|
||
within ".edit_initiative" do | ||
expect(page).not_to have_css("label[for='initiative_type_id']") | ||
expect(page).not_to have_css("#initiative_type_id") | ||
|
||
expect(page).to have_css("label[for='initiative_decidim_scope_id']") | ||
expect(page).to have_css("#initiative_decidim_scope_id") | ||
expect(page).to have_css("option[value='#{initiative_scope.id}'][selected='selected']") | ||
expect(page).to have_css("label[for='initiative_signature_type']") | ||
expect(page).to have_css("#initiative_signature_type") | ||
expect(page).to have_css("option[value='#{initiative.signature_type}'][selected='selected']") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |