Merge pull request #2654 from wairbut-m2c/backport/budgets-map-fixes
Budgets homepage map fixes
This commit is contained in:
@@ -9,9 +9,10 @@ App.Map =
|
||||
|
||||
$('.js-toggle-map').on
|
||||
click: ->
|
||||
App.Map.toogleMap()
|
||||
App.Map.toggleMap()
|
||||
|
||||
initializeMap: (element) ->
|
||||
App.Map.cleanInvestmentCoordinates(element)
|
||||
|
||||
mapCenterLatitude = $(element).data('map-center-latitude')
|
||||
mapCenterLongitude = $(element).data('map-center-longitude')
|
||||
@@ -103,6 +104,18 @@ App.Map =
|
||||
|
||||
marker.on 'click', openMarkerPopup
|
||||
|
||||
toogleMap: ->
|
||||
toggleMap: ->
|
||||
$('.map').toggle()
|
||||
$('.js-location-map-remove-marker').toggle()
|
||||
|
||||
cleanInvestmentCoordinates: (element) ->
|
||||
markers = $(element).attr('data-marker-investments-coordinates')
|
||||
if markers?
|
||||
clean_markers = markers.replace(/-?(\*+)/g, null)
|
||||
$(element).attr('data-marker-investments-coordinates', clean_markers)
|
||||
|
||||
validCoordinates: (coordinates) ->
|
||||
App.Map.isNumeric(coordinates.lat) && App.Map.isNumeric(coordinates.long)
|
||||
|
||||
isNumeric: (n) ->
|
||||
!isNaN(parseFloat(n)) && isFinite(n)
|
||||
|
||||
@@ -2,8 +2,8 @@ require 'rails_helper'
|
||||
|
||||
feature 'Budgets' do
|
||||
|
||||
let(:budget) { create(:budget) }
|
||||
let(:level_two_user) { create(:user, :level_two) }
|
||||
let(:budget) { create(:budget) }
|
||||
let(:level_two_user) { create(:user, :level_two) }
|
||||
let(:allowed_phase_list) { ['balloting', 'reviewing_ballots', 'finished'] }
|
||||
|
||||
context 'Index' do
|
||||
@@ -191,6 +191,61 @@ feature 'Budgets' do
|
||||
expect(page).to have_css(".phase.active", count: 1)
|
||||
end
|
||||
|
||||
context "Index map" do
|
||||
|
||||
let(:group) { create(:budget_group, budget: budget) }
|
||||
let(:heading) { create(:budget_heading, group: group) }
|
||||
|
||||
background do
|
||||
Setting['feature.map'] = true
|
||||
end
|
||||
|
||||
scenario "Display investment's map location markers", :js do
|
||||
investment1 = create(:budget_investment, heading: heading)
|
||||
investment2 = create(:budget_investment, heading: heading)
|
||||
investment3 = create(:budget_investment, heading: heading)
|
||||
|
||||
create(:map_location, longitude: 40.1234, latitude: -3.634, investment: investment1)
|
||||
create(:map_location, longitude: 40.1235, latitude: -3.635, investment: investment2)
|
||||
create(:map_location, longitude: 40.1236, latitude: -3.636, investment: investment3)
|
||||
|
||||
visit budgets_path
|
||||
|
||||
within ".map_location" do
|
||||
expect(page).to have_css(".map-icon", count: 3, visible: false)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Skip invalid map markers", :js do
|
||||
map_locations = []
|
||||
|
||||
investment = create(:budget_investment, heading: heading)
|
||||
|
||||
map_locations << { longitude: 40.123456789, latitude: 3.12345678 }
|
||||
map_locations << { longitude: 40.123456789, latitude: "********" }
|
||||
map_locations << { longitude: "**********", latitude: 3.12345678 }
|
||||
|
||||
budget_map_locations = map_locations.map do |map_location|
|
||||
{
|
||||
lat: map_location[:latitude],
|
||||
long: map_location[:longitude],
|
||||
investment_title: investment.title,
|
||||
investment_id: investment.id,
|
||||
budget_id: budget.id
|
||||
}
|
||||
end
|
||||
|
||||
allow_any_instance_of(BudgetsHelper).
|
||||
to receive(:current_budget_map_locations).and_return(budget_map_locations)
|
||||
|
||||
visit budgets_path
|
||||
|
||||
within ".map_location" do
|
||||
expect(page).to have_css(".map-icon", count: 1, visible: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'Show' do
|
||||
|
||||
scenario "List all groups" do
|
||||
|
||||
Reference in New Issue
Block a user