Skip to content

Commit

Permalink
Add specs for missing map configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Apr 11, 2024
1 parent c160de0 commit c61946c
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@
<% end %>
</div>

<%= javascript_pack_tag "decidim_forms_admin", defer: false %>

<% if questionnaire.questions_editable? %>
<script>
window.Decidim.createEditableForm()
</script>
<% end %>

<% if Decidim::Map.autocomplete(organization: current_organization).present? %>
<div id="answer-option-map-selector" data-reveal class="reveal answer_option_map">
<%= cell(
Expand All @@ -141,3 +133,11 @@
) %>
</div>
<% end %>

<%= javascript_pack_tag "decidim_forms_admin", defer: false %>

<% if questionnaire.questions_editable? %>
<script>
window.Decidim.createEditableForm()
</script>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -19,96 +19,113 @@
let!(:survey) { create :survey, questionnaire: questionnaire, component: component }
let!(:question) { create :questionnaire_question, questionnaire: questionnaire }

before do
utility = Decidim::Map.autocomplete(organization: organization)
allow(Decidim::Map).to receive(:autocomplete).with(organization: organization).and_return(utility)
allow(utility).to receive(:builder_options).and_return(
api_key: "key1234"
)

switch_to_host(organization.host)
login_as user, scope: :user
visit questionnaire_edit_path
end
context "when map is provided" do
before do
switch_to_host(organization.host)
login_as user, scope: :user
visit questionnaire_edit_path
end

context "when question type map_locations" do
context "when question added with \"multiple\" -map configuration to survey" do
it "allows creation of survey" do
find(".question--collapse", match: :first).click
check "Mandatory"
select("Map", from: "Type").select_option
expect(page).to have_field("Map config", with: "multiple")
fill_in "Default latitude", with: "11"
fill_in "Default longitude", with: "13"
click_button "Save"

expect(page).to have_content("Survey successfully saved.")
context "when question type map_locations" do
context "when question added with \"multiple\" -map configuration to survey" do
it "allows creation of survey" do
find(".question--collapse", match: :first).click
check "Mandatory"
select("Map", from: "Type").select_option
expect(page).to have_field("Map config", with: "multiple")
fill_in "Default latitude", with: "11"
fill_in "Default longitude", with: "13"
click_button "Save"

expect(page).to have_content("Survey successfully saved.")
end
end
end

context "when question added with \"single\" -map configuration to survey" do
it "allows creation of survey" do
find(".question--collapse", match: :first).click
check "Mandatory"
select("Map", from: "Type").select_option
select("Single", from: "Map config")
expect(page).to have_field("Map config", with: "single")
fill_in "Default latitude", with: "11"
fill_in "Default longitude", with: "13"
click_button "Save"

expect(page).to have_content("Survey successfully saved.")
context "when question added with \"single\" -map configuration to survey" do
it "allows creation of survey" do
find(".question--collapse", match: :first).click
check "Mandatory"
select("Map", from: "Type").select_option
select("Single", from: "Map config")
expect(page).to have_field("Map config", with: "single")
fill_in "Default latitude", with: "11"
fill_in "Default longitude", with: "13"
click_button "Save"

expect(page).to have_content("Survey successfully saved.")
end
end
end
end

context "when question type select_locations" do
context "when question added with 2 answer options" do
it "allows creation of survey" do
find(".question--collapse", match: :first).click
select("Select locations", from: "Type").select_option
expect(page).to have_content("Answer option")
answer_options = all(".questionnaire-question-location-option")

answer_options.each do |option|
within(option) do
fill_in find("input", match: :first)["name"], with: "Lauttasaari"
fill_in "Geojson", match: :first, with: '{"type":"Feature","geometry":{"type":"Point","coordinates":[12,5]}}'
context "when question type select_locations" do
context "when question added with 2 answer options" do
it "allows creation of survey" do
find(".question--collapse", match: :first).click
select("Select locations", from: "Type").select_option
scroll_to(:bottom)
expect(page).to have_content("Add answer option")
expect(page).to have_content("Answer option")
answer_options = all(".questionnaire-question-location-option")

answer_options.each do |option|
within(option) do
fill_in find("input", match: :first)["name"], with: "Lauttasaari"
fill_in "Geojson", match: :first, with: '{"type":"Feature","geometry":{"type":"Point","coordinates":[12,5]}}'
end
end
end

click_button "Save"
click_button "Save"

expect(page).to have_content("Survey successfully saved.")
expect(Decidim::Forms::Question.first.answer_options.count).to eq(2)
expect(Decidim::Forms::Question.first.answer_options.first.geojson).to eq(
'{"type":"Feature","geometry":{"type":"Point","coordinates":[12,5]}}'
)
expect(page).to have_content("Survey successfully saved.")
expect(Decidim::Forms::Question.first.answer_options.count).to eq(2)
expect(Decidim::Forms::Question.first.answer_options.first.geojson).to eq(
'{"type":"Feature","geometry":{"type":"Point","coordinates":[12,5]}}'
)
end
end
end

context "when question added with 3 answer options" do
it "allows creation of survey" do
find(".question--collapse", match: :first).click
select("Select locations", from: "Type").select_option
expect(page).to have_content("Answer option")
click_button "Add answer option"
answer_options = all(".questionnaire-question-location-option")

answer_options.each do |option|
within(option) do
fill_in find("input", match: :first)["name"], with: "Lauttasaari"
fill_in "Geojson", match: :first, with: '{"type":"Feature","geometry":{"type":"Point","coordinates":[12,5]}}'
context "when question added with 3 answer options" do
it "allows creation of survey" do
find(".question--collapse", match: :first).click
select("Select locations", from: "Type").select_option
expect(page).to have_content("Answer option")
click_button "Add answer option"
answer_options = all(".questionnaire-question-location-option")

answer_options.each do |option|
within(option) do
fill_in find("input", match: :first)["name"], with: "Lauttasaari"
fill_in "Geojson", match: :first, with: '{"type":"Feature","geometry":{"type":"Point","coordinates":[12,5]}}'
end
end

click_button "Save"

expect(page).to have_content("Survey successfully saved.")
expect(Decidim::Forms::Question.first.answer_options.count).to eq(3)
expect(Decidim::Forms::Question.first.answer_options.first.geojson).to eq(
'{"type":"Feature","geometry":{"type":"Point","coordinates":[12,5]}}'
)
end
end
end
end

click_button "Save"
context "when map is not provided" do
before do
allow(Decidim::Map).to receive(:autocomplete)

expect(page).to have_content("Survey successfully saved.")
expect(Decidim::Forms::Question.first.answer_options.count).to eq(3)
expect(Decidim::Forms::Question.first.answer_options.first.geojson).to eq(
'{"type":"Feature","geometry":{"type":"Point","coordinates":[12,5]}}'
)
switch_to_host(organization.host)
login_as user, scope: :user
visit questionnaire_edit_path
end

context "when selecting a question type" do
it "doesn't allow picking 'Map locations' or 'Select locations'" do
find(".question--collapse", match: :first).click
select_element = find("#questionnaire_questions_#{question.id}_question_type")
expect(select_element).to have_selector("option[value='select_locations'][disabled]")
expect(select_element).to have_selector("option[value='map_locations'][disabled]")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,46 @@
before do
switch_to_host(organization.host)
login_as user, scope: :user
visit decidim.root_path
find("nav.topbar__dropmenu").click
click_link "Admin dashboard"
click_link "Processes"
find(".action-icon--new").click
click_link "Meetings"
click_link "New meeting"
end

context "when creating a meeting" do
it "allows adding locations with a map" do
context "when map provided" do
context "when creating a meeting" do
it "allows adding locations with a map" do
expect(page).to have_selector("[data-decidim-map]", visible: :hidden)
find("#meeting_type_of_meeting").find("option[value='in_person']").click
expect(page).to have_selector("[data-decidim-map]")
end
end
end

context "when map not provided" do
before do
allow(Decidim::Map).to receive(:autocomplete)

switch_to_host(organization.host)
login_as user, scope: :user
visit decidim.root_path
find("nav.topbar__dropmenu").click
click_link "Admin dashboard"
click_link "Processes"
find(".action-icon--new").click
click_link "Meetings"
click_link "New meeting"
expect(page).to have_selector("[data-decidim-map]", visible: :hidden)
find("#meeting_type_of_meeting").find("option[value='in_person']").click
expect(page).to have_selector("[data-decidim-map]")
end

context "when creating a meeting" do
it "renders an address field instead of a map" do
find("#meeting_type_of_meeting").find("option[value='in_person']").click
expect(page).not_to have_selector("[data-decidim-map]")
expect(page).to have_selector("#meeting_address")
end
end
end
end
36 changes: 31 additions & 5 deletions decidim-module-meetings_locations/spec/system/map_render_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,44 @@
before do
switch_to_host(organization.host)
login_as user, scope: :user

visit decidim.root_path
click_link "Processes"
find(".card__link").click
click_link "Meetings"
click_link "New meeting"
end

context "when map provided" do
context "when creating a meeting" do
it "allows adding locations with a map" do
expect(page).to have_selector("[data-decidim-map]", visible: :hidden)
find("#meeting_type_of_meeting").find("option[value='in_person']").click
expect(page).to have_selector("[data-decidim-map]")
end
end
end

context "when creating a meeting" do
it "allows adding locations with a map" do
context "when map not provided" do
before do
allow(Decidim::Map).to receive(:autocomplete)

switch_to_host(organization.host)
login_as user, scope: :user

visit decidim.root_path
click_link "Processes"
find(".card__link").click
click_link "Meetings"
click_link "New meeting"
expect(page).to have_selector("[data-decidim-map]", visible: :hidden)
find("#meeting_type_of_meeting").find("option[value='in_person']").click
expect(page).to have_selector("[data-decidim-map]")
end

context "when creating a meeting" do
it "renders an address field instead of a map" do
find("#meeting_type_of_meeting").find("option[value='in_person']").click
expect(page).not_to have_selector("[data-decidim-map]")
expect(page).to have_selector("#meeting_address")
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,19 @@

<% if @form.geocoding_enabled? %>
<div class="row column">
<%= cell("decidim/locations/locations", @proposal, form: form, coords: [current_component.settings.default_latitude, current_component.settings.default_longitude], checkbox: true) %>
<% if Decidim::Map.autocomplete(organization: current_organization).present? %>
<%= cell("decidim/locations/locations",
@proposal,
form: form,
coords: [
current_component.settings.default_latitude,
current_component.settings.default_longitude
],
checkbox: true
) %>
<% else %>
<%= form.geocoding_field :address %>
<% end %>
</div>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@
<% end %>

<% if @form.geocoding_enabled? %>
<%= cell("decidim/locations/locations", @proposal, form: form, coords: [current_component.settings.default_latitude, current_component.settings.default_longitude], checkbox: true) %>
<% if Decidim::Map.autocomplete(organization: current_organization).present? %>
<%= cell("decidim/locations/locations",
@proposal,
form: form,
coords: [
current_component.settings.default_latitude,
current_component.settings.default_longitude
],
checkbox: true
) %>
<% else %>
<%= form.check_box :has_address, checked: form_has_address? %>
<% end %>
<% end %>

<% if @form.categories&.any? %>
Expand Down
Loading

0 comments on commit c61946c

Please sign in to comment.