Initialize only visible maps when page is loaded
Its known that initializing a map when it is inside a hidden element wont work when hidden element is shown, so its makes sense to avoid initialization of hidden maps. When a map lives within a hidden layer we need to initialize the map after the event of showing that hidden layer, in our case when admin settings tab is shown.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
App.Map = {
|
App.Map = {
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
$("*[data-map]").each(function() {
|
$("*[data-map]:visible").each(function() {
|
||||||
App.Map.initializeMap(this);
|
App.Map.initializeMap(this);
|
||||||
});
|
});
|
||||||
$(".js-toggle-map").on({
|
$(".js-toggle-map").on({
|
||||||
|
|||||||
@@ -30,6 +30,30 @@ describe "Admin settings" do
|
|||||||
expect(page).to have_content "Value updated"
|
expect(page).to have_content "Value updated"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Map settings initialization", :js do
|
||||||
|
before do
|
||||||
|
Setting["feature.map"] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "When `Map settings` tab content is hidden map should not be initialized" do
|
||||||
|
admin = create(:administrator).user
|
||||||
|
login_as(admin)
|
||||||
|
visit admin_settings_path
|
||||||
|
|
||||||
|
expect(page).not_to have_css("#admin-map.leaflet-container", visible: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "When `Map settings` tab content is shown map should be initialized" do
|
||||||
|
admin = create(:administrator).user
|
||||||
|
login_as(admin)
|
||||||
|
visit admin_settings_path
|
||||||
|
|
||||||
|
find("#map-tab").click
|
||||||
|
|
||||||
|
expect(page).to have_css("#admin-map.leaflet-container", visible: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "Update map" do
|
describe "Update map" do
|
||||||
scenario "Should not be able when map feature deactivated" do
|
scenario "Should not be able when map feature deactivated" do
|
||||||
Setting["feature.map"] = false
|
Setting["feature.map"] = false
|
||||||
|
|||||||
Reference in New Issue
Block a user