Skip to content

Commit

Permalink
Fix specs / Fix modal
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Jan 10, 2025
1 parent ed53a69 commit 4a26abc
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app/views/decidim/budgets/line_items/_error_modal.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= decidim_modal id:"order-update-error", role:"dialog" do %>
<%= decidim_modal id:"order-update-error-modal" do %>
<div data-dialog-container>
<h3 id="order-update-error-label"><%= t(".title") %></h3>

Expand Down
12 changes: 5 additions & 7 deletions app/views/decidim/budgets/line_items/update_budget_error.js.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import Dialog from "a11y-dialog-component";

var $modal = $("#order-update-error");
let $modal = $("#order-update-error");

if ($modal.length < 1) {
$modal = $('<%= j(render partial: "error_modal").strip.html_safe %>');
$("body").append($modal);

let dialog = new Dialog($modal);
let dialog = new window.Decidim.Dialogs("#order-update-error-modal");
$modal.data("budgetErrorDialog", dialog);

var dialogInstance = dialog;
}

$(".error-message", $modal).html('<%= j(render partial: "error_message").strip.html_safe %>')
$(".error-details", $modal).html('<%= j(render partial: "error_details").strip.html_safe %>');

let dialogInstance = $modal.data("budgetErrorDialog");

dialogInstance.show();
dialogInstance.open();

var $project = $("[data-project-id='<%= project.id %>']");
if ($project.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<h3 class="attributes__item__name"><%= t(".attributes.created_at") %></h3>
<div class="attributes__item__value"><%= l(project.created_at.to_date, format: :decidim_short) %></div>
</div>
<% if false && component_settings.geocoding_enabled? && project.address.present? %>
<% if component_settings.geocoding_enabled? && project.address.present? %>
<div class="attributes__item">
<h3 class="attributes__item__name"><%= t(".attributes.address") %></h3>
<div class="attributes__item__value"><%= project.address %></div>
Expand Down
29 changes: 19 additions & 10 deletions app/views/decidim/budgets/results/_vote_finished_modal.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
<div class="reveal reveal--vote-finished" id="vote-finished-modal" data-reveal role="dialog" aria-modal="true" aria-labelledby="vote-finished-modal-label" data-close-on-click="false" data-close-on-esc="false">
<div class="reveal__header">
<h2 id="vote-finished-modal-label" class="reveal__title"><%= t(".title") %></h2>
</div>
<div class="reveal__content" id="vote-finished-modal-content" aria-live="assertive">
<%= decidim_modal id:"vote-finished-modal" do %>
<div data-dialog-container>
<h2 id="vote-finished-modal-label"><%= t(".title") %></h2>

<%= render partial: "decidim/budgets/votes/finished_content" %>
</div>

<div class="buttons buttons-row">
<%= link_to t(".sign_out"), decidim.destroy_user_session_path, method: :delete, class: "sign-out-link button", role: "button" %>
</div>

<div data-dialog-actions>
<button type="button" class="button hollow" data-close>
<%= t(".continue") %>
</button>
</div>
</div>
<% end %>

<% content_for(:js_content) do %>
<script>
$(document).ready(function() {
var $modal = $("#vote-finished-modal");
$modal.foundation("open");
let $modal = $("#vote-finished-modal");

if ($modal.length < 1) {
$modal = $('<%= j(render partial: "decidim/budgets/votes/finished_modal") %>');
$("body").append($modal);

let dialog = new window.Decidim.Dialogs("#vote-finished-modal");
$modal.data("voteFinishedDialog", dialog);
var dialogInstance = $modal.data("voteFinishedDialog");
}

dialogInstance.open();
});
</script>
<% end %>
1 change: 0 additions & 1 deletion app/views/decidim/budgets/votes/_identify_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<h2 class="h4"><%= t(".title") %></h2>
<%== translated_attribute component_settings.vote_identify_page_content %>
</div>

<div class="voting-identity">
<% if user_signed_in? %>
<% if user_authorizations(:pending).any? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/decidim/budgets/votes/_projects_list.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ show_categories = params[:order] == "category"
<p><%= translated_attribute(summary) %></p>
<% end %>
<p class="h5"><%= t(".description") %></p>
<%== translated_attribute(project.description) %>
<%== decidim_sanitize(translated_attribute(project.description)) %>
<%= render partial: "project_linked_resources", locals: { resource: project, type: :plans, link_name: "included_plans" } %>
</div>
Expand Down
29 changes: 12 additions & 17 deletions spec/system/explore_projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,32 @@

it "can filter based on keywords" do
within "form.new_filter" do
find(%(input[aria-label="Keyword"])).set(translated(budget1_projects.first.title))
find(%(input[name="filter[search_text_cont]"])).set(translated(budget1_projects.first.title))
click_button "Search"
end

expect(page).to have_content("FOUND 1 PROPOSAL")
expect(page).to have_content("Found 1 proposal")
end

it "can filter based on the area" do
within "form.new_filter" do
find(%(select[aria-label="Area"])).find(%(option[value="#{budget1.id}"])).select_option
find(%(select[name="filter[decidim_budgets_budget_id_eq]"])).find(%(option[value="#{budget1.id}"])).select_option
click_button "Search"
end

expect(page).to have_content("FOUND 10 PROPOSALS")
expect(page).to have_content("Found 10 proposals")
end

it "can filter based on the budget" do
within "form.new_filter" do
click_button "Show more search criteria"
scroll_to find("#additional_search")

find(%(input[aria-label="Minimum budget"])).set(16_000)
find(%(input[aria-label="Maximum budget"])).set(20_000)
click_button "Search"
end

expect(page).to have_content("FOUND 20 PROPOSALS")
find("#additional_search").find("input[name='filter[budget_amount_lteq]']").set(16_000)
find("#additional_search").find("input[name='filter[budget_amount_lteq]']").set(20_000)
click_button "Search"
expect(page).to have_content("Found 20 proposals")
end
end
end
Expand All @@ -59,9 +58,7 @@
end

it "shows the project details" do
scroll_to find(".resource-details")

expect(page).to have_content("##{project.id}")
expect(page).to have_content("#{project.id}")
expect(page).to have_content(translated(project.budget.title))
expect(page).to have_content(project.address)
expect(page).to have_content(translated(project.title))
Expand All @@ -75,16 +72,14 @@
let!(:project) { create(:budgeting_pipeline_project, budget: budget1, category: category) }

it "displays the category and its parent category" do
scroll_to find(".resource-details")

expect(page).to have_content(translated(parent_category.name))
expect(page).to have_content(translated(category.name))
end
end

context "when voting finished" do
before do
component.step_settings = { component.participatory_space.active_step.id => { votes: "finished", show_votes: true } }
component.step_settings = { component.participatory_space.active_step.id => { votes: "finished", show_votes: true, show_selected_status: true } }
component.save
budget1_projects.first.update(selected_at: Time.current)
end
Expand All @@ -98,8 +93,8 @@
within "form.new_filter" do
click_button "Search"
end
within "#project_#{project.id}" do
expect(page).to have_content("Proceeds to implementation")
within "#project-#{project.id}-item" do
expect(page).to have_css(".card__text--status", text: "Selected")
end
end
end
Expand Down
31 changes: 15 additions & 16 deletions spec/system/voting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

context "when not authorized" do
let!(:authorization) { nil }
let(:authorizations) { [:foo] }

it "displays the authorization options" do
visit_voting
Expand All @@ -50,7 +51,7 @@
it "redirects to the budgets selection and allows selecting a budget" do
visit_voting

expect(page).to have_content("Select voting area")
expect(page).to have_content("Select the area where you want to vote")
end
end
end
Expand All @@ -62,28 +63,29 @@
it "lists all available budgets" do
visit_voting

page.scroll_to find("h2", text: "Select voting area")
page.scroll_to find("h2", text: "Select the area where you want to vote")

within "form#new_budget_select_" do
budgets.each do |budget|
expect(find("label", text: translated(budget.title))).not_to be_nil
end
budgets.each do |budget|
expect(find("h2", text: translated(budget.title))).not_to be_nil
end
end
end

describe "start" do
before { login_as user, scope: :user }

let(:project1) { budget1.projects.first }

it "allows selecting a budget" do
visit_voting

page.scroll_to find("h2", text: "Select voting area")
page.scroll_to find("h2", text: "Select the area where you want to vote")

find("label", text: translated(budget1.title)).click
click_button "Select proposals"
find("h2", text: translated(budget1.title)).click
find("input[name='filter[selected]']").click
find("label[for=project_selector_#{project1.id}]").click

expect(find("h2", text: "Select proposals")).not_to be_nil
expect(find("div#project-#{project1.id}-order-summary")).to have_content(translated(project1.title))
end
end

Expand All @@ -94,14 +96,11 @@
login_as user, scope: :user

visit_voting
find("label", text: translated(budget.title)).click
click_button "Select proposals"

page.scroll_to find("h2", text: "Select proposals")
find("h2", text: translated(budget.title)).click
end

it "lists the projects for the selected budget" do
expect(page).to have_content("FOUND 10 PROPOSALS")
expect(page).to have_content("Found 10 proposals")
end

it "allows selecting projects" do
Expand Down Expand Up @@ -185,7 +184,7 @@

it "can cast the vote" do
click_button "Vote"

click_on "See my vote"
within "#vote-finished-modal" do
expect(page).to have_content("Thank you for your vote!")
end
Expand Down

0 comments on commit 4a26abc

Please sign in to comment.