Apply PrettierJS to tests files

Command: `make pretty filepath="umap/static/umap/test/*"`
This commit is contained in:
David Larlet 2023-05-26 13:25:21 -04:00
parent 7f85684d52
commit 06a354730b
12 changed files with 2790 additions and 2331 deletions

View file

@ -1,50 +1,48 @@
describe('L.Utorage.Controls', function () { describe('L.Utorage.Controls', function () {
before(function () { before(function () {
this.server = sinon.fakeServer.create(); this.server = sinon.fakeServer.create()
this.server.respondWith('/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET)); this.server.respondWith('/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET))
this.map = initMap({umap_id: 99}); this.map = initMap({ umap_id: 99 })
this.server.respond(); this.server.respond()
this.datalayer = this.map.getDataLayerByUmapId(62); this.datalayer = this.map.getDataLayerByUmapId(62)
}); })
after(function () { after(function () {
this.server.restore(); this.server.restore()
resetMap(); resetMap()
}); })
describe('#databrowser()', function () { describe('#databrowser()', function () {
it('should be opened at datalayer button click', function () { it('should be opened at datalayer button click', function () {
var button = qs('.umap-browse-actions .umap-browse-link'); var button = qs('.umap-browse-actions .umap-browse-link')
assert.ok(button); assert.ok(button)
happen.click(button); happen.click(button)
assert.ok(qs('#umap-ui-container .umap-browse-data')); assert.ok(qs('#umap-ui-container .umap-browse-data'))
}); })
it('should contain datalayer section', function () { it('should contain datalayer section', function () {
assert.ok(qs('#browse_data_datalayer_62')); assert.ok(qs('#browse_data_datalayer_62'))
}); })
it('should contain datalayer\'s features list', function() { it("should contain datalayer's features list", function () {
assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 3); assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 3)
}); })
it('should redraw datalayer\'s features list at feature delete', function() { it("should redraw datalayer's features list at feature delete", function () {
var oldConfirm = window.confirm; var oldConfirm = window.confirm
window.confirm = function () {return true;}; window.confirm = function () {
enableEdit(); return true
happen.once(qs('path[fill="DarkBlue"]'), {type: 'contextmenu'}); }
happen.click(qs('.leaflet-contextmenu .umap-delete')); enableEdit()
assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 2); happen.once(qs('path[fill="DarkBlue"]'), { type: 'contextmenu' })
window.confirm = oldConfirm; happen.click(qs('.leaflet-contextmenu .umap-delete'))
}); assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 2)
window.confirm = oldConfirm
})
it('should redraw datalayer\'s features list on edit cancel', function() { it("should redraw datalayer's features list on edit cancel", function () {
clickCancel(); clickCancel()
happen.click(qs('.umap-browse-actions .umap-browse-link')); happen.click(qs('.umap-browse-actions .umap-browse-link'))
assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 3); assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 3)
}); })
})
}); })
});

View file

@ -1,334 +1,377 @@
describe('L.U.DataLayer', function () { describe('L.U.DataLayer', function () {
var path = '/map/99/datalayer/edit/62/'; var path = '/map/99/datalayer/edit/62/'
before(function () { before(function () {
this.server = sinon.fakeServer.create(); this.server = sinon.fakeServer.create()
this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET)); this.server.respondWith(
this.map = initMap({umap_id: 99}); 'GET',
this.datalayer = this.map.getDataLayerByUmapId(62); '/datalayer/62/',
this.server.respond(); JSON.stringify(RESPONSES.datalayer62_GET)
enableEdit(); )
}); this.map = initMap({ umap_id: 99 })
this.datalayer = this.map.getDataLayerByUmapId(62)
this.server.respond()
enableEdit()
})
after(function () { after(function () {
this.server.restore(); this.server.restore()
resetMap(); resetMap()
}); })
describe('#init()', function () { describe('#init()', function () {
it('should be added in datalayers index', function () { it('should be added in datalayers index', function () {
assert.notEqual(this.map.datalayers_index.indexOf(this.datalayer), -1); assert.notEqual(this.map.datalayers_index.indexOf(this.datalayer), -1)
}); })
})
});
describe('#edit()', function () { describe('#edit()', function () {
var editButton, form, input, forceButton; var editButton, form, input, forceButton
it('row in control should be active', function () { it('row in control should be active', function () {
assert.notOk(qs('.leaflet-control-browse #browse_data_toggle_' + L.stamp(this.datalayer) + '.off')); assert.notOk(
}); qs(
'.leaflet-control-browse #browse_data_toggle_' +
L.stamp(this.datalayer) +
'.off'
)
)
})
it('should have edit button', function () { it('should have edit button', function () {
editButton = qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit'); editButton = qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
assert.ok(editButton); assert.ok(editButton)
}); })
it('should have toggle visibility element', function () { it('should have toggle visibility element', function () {
assert.ok(qs('.leaflet-control-browse i.layer-toggle')); assert.ok(qs('.leaflet-control-browse i.layer-toggle'))
}); })
it('should exist only one datalayer', function () { it('should exist only one datalayer', function () {
assert.equal(qsa('.leaflet-control-browse i.layer-toggle').length, 1); assert.equal(qsa('.leaflet-control-browse i.layer-toggle').length, 1)
}); })
it('should build a form on edit button click', function () { it('should build a form on edit button click', function () {
happen.click(editButton); happen.click(editButton)
form = qs('form.umap-form'); form = qs('form.umap-form')
input = qs('form.umap-form input[name="name"]'); input = qs('form.umap-form input[name="name"]')
assert.ok(form); assert.ok(form)
assert.ok(input); assert.ok(input)
}); })
it('should update name on input change', function () { it('should update name on input change', function () {
var new_name = 'This is a new name'; var new_name = 'This is a new name'
input.value = new_name; input.value = new_name
happen.once(input, {type: 'input'}); happen.once(input, { type: 'input' })
assert.equal(this.datalayer.options.name, new_name); assert.equal(this.datalayer.options.name, new_name)
}); })
it('should have made datalayer dirty', function () { it('should have made datalayer dirty', function () {
assert.ok(this.datalayer.isDirty); assert.ok(this.datalayer.isDirty)
assert.notEqual(this.map.dirty_datalayers.indexOf(this.datalayer), -1); assert.notEqual(this.map.dirty_datalayers.indexOf(this.datalayer), -1)
}); })
it('should have made Map dirty', function () { it('should have made Map dirty', function () {
assert.ok(this.map.isDirty); assert.ok(this.map.isDirty)
}); })
it('should call datalayer.save on save button click', function (done) { it('should call datalayer.save on save button click', function (done) {
sinon.spy(this.datalayer, 'save'); sinon.spy(this.datalayer, 'save')
this.server.flush(); this.server.flush()
this.server.respondWith('POST', '/map/99/update/settings/', JSON.stringify({id: 99})); this.server.respondWith(
this.server.respondWith('POST', '/map/99/datalayer/update/62/', JSON.stringify(defaultDatalayerData())); 'POST',
clickSave(); '/map/99/update/settings/',
this.server.respond(); JSON.stringify({ id: 99 })
this.server.respond(); )
assert(this.datalayer.save.calledOnce); this.server.respondWith(
this.datalayer.save.restore(); 'POST',
done(); '/map/99/datalayer/update/62/',
}); JSON.stringify(defaultDatalayerData())
)
clickSave()
this.server.respond()
this.server.respond()
assert(this.datalayer.save.calledOnce)
this.datalayer.save.restore()
done()
})
it('should show alert if server respond 412', function () { it('should show alert if server respond 412', function () {
cleanAlert(); cleanAlert()
this.server.flush(); this.server.flush()
this.server.respondWith('POST', '/map/99/update/settings/', JSON.stringify({id: 99})); this.server.respondWith(
this.server.respondWith('POST', '/map/99/datalayer/update/62/', [412, {}, '']); 'POST',
happen.click(editButton); '/map/99/update/settings/',
input = qs('form.umap-form input[name="name"]'); JSON.stringify({ id: 99 })
input.value = 'a new name'; )
happen.once(input, {type: 'input'}); this.server.respondWith('POST', '/map/99/datalayer/update/62/', [412, {}, ''])
clickSave(); happen.click(editButton)
this.server.respond(); input = qs('form.umap-form input[name="name"]')
this.server.respond(); input.value = 'a new name'
assert(L.DomUtil.hasClass(this.map._container, 'umap-alert')); happen.once(input, { type: 'input' })
assert.notEqual(this.map.dirty_datalayers.indexOf(this.datalayer), -1); clickSave()
forceButton = qs('#umap-alert-container .umap-action'); this.server.respond()
assert.ok(forceButton); this.server.respond()
}); assert(L.DomUtil.hasClass(this.map._container, 'umap-alert'))
assert.notEqual(this.map.dirty_datalayers.indexOf(this.datalayer), -1)
forceButton = qs('#umap-alert-container .umap-action')
assert.ok(forceButton)
})
it('should save anyway on force save button click', function () { it('should save anyway on force save button click', function () {
sinon.spy(this.map, 'continueSaving'); sinon.spy(this.map, 'continueSaving')
happen.click(forceButton); happen.click(forceButton)
this.server.flush(); this.server.flush()
this.server.respond('POST', '/map/99/datalayer/update/62/', JSON.stringify(defaultDatalayerData())); this.server.respond(
assert.notOk(qs('#umap-alert-container .umap-action')); 'POST',
assert(this.map.continueSaving.calledOnce); '/map/99/datalayer/update/62/',
this.map.continueSaving.restore(); JSON.stringify(defaultDatalayerData())
assert.equal(this.map.dirty_datalayers.indexOf(this.datalayer), -1); )
}); assert.notOk(qs('#umap-alert-container .umap-action'))
assert(this.map.continueSaving.calledOnce)
}); this.map.continueSaving.restore()
assert.equal(this.map.dirty_datalayers.indexOf(this.datalayer), -1)
})
})
describe('#save() new', function () { describe('#save() new', function () {
var newLayerButton, form, input, newDatalayer, editButton, manageButton; var newLayerButton, form, input, newDatalayer, editButton, manageButton
it('should have a manage datalayers action', function () { it('should have a manage datalayers action', function () {
enableEdit(); enableEdit()
manageButton = qs('.manage-datalayers'); manageButton = qs('.manage-datalayers')
assert.ok(manageButton); assert.ok(manageButton)
happen.click(manageButton); happen.click(manageButton)
}); })
it('should have a new layer button', function () { it('should have a new layer button', function () {
newLayerButton = qs('#umap-ui-container .add-datalayer'); newLayerButton = qs('#umap-ui-container .add-datalayer')
assert.ok(newLayerButton); assert.ok(newLayerButton)
}); })
it('should build a form on new layer button click', function () { it('should build a form on new layer button click', function () {
happen.click(newLayerButton); happen.click(newLayerButton)
form = qs('form.umap-form'); form = qs('form.umap-form')
input = qs('form.umap-form input[name="name"]'); input = qs('form.umap-form input[name="name"]')
assert.ok(form); assert.ok(form)
assert.ok(input); assert.ok(input)
}); })
it('should have an empty name', function () { it('should have an empty name', function () {
assert.notOk(input.value); assert.notOk(input.value)
}); })
it('should have created a new datalayer', function () { it('should have created a new datalayer', function () {
assert.equal(this.map.datalayers_index.length, 2); assert.equal(this.map.datalayers_index.length, 2)
newDatalayer = this.map.datalayers_index[1]; newDatalayer = this.map.datalayers_index[1]
}); })
it('should have made Map dirty', function () { it('should have made Map dirty', function () {
assert.ok(this.map.isDirty); assert.ok(this.map.isDirty)
}); })
it('should update name on input change', function () { it('should update name on input change', function () {
var new_name = 'This is a new name'; var new_name = 'This is a new name'
input.value = new_name; input.value = new_name
happen.once(input, {type: 'input'}); happen.once(input, { type: 'input' })
assert.equal(newDatalayer.options.name, new_name); assert.equal(newDatalayer.options.name, new_name)
}); })
it('should set umap_id on save callback', function () { it('should set umap_id on save callback', function () {
assert.notOk(newDatalayer.umap_id); assert.notOk(newDatalayer.umap_id)
this.server.flush(); this.server.flush()
this.server.respondWith('POST', '/map/99/update/settings/', JSON.stringify({id: 99})); this.server.respondWith(
this.server.respondWith('POST', '/map/99/datalayer/create/', JSON.stringify(defaultDatalayerData({id: 63}))); 'POST',
clickSave(); '/map/99/update/settings/',
this.server.respond(); JSON.stringify({ id: 99 })
this.server.respond(); // First respond will then trigger another Xhr request (continueSaving) )
assert.equal(newDatalayer.umap_id, 63); this.server.respondWith(
}); 'POST',
'/map/99/datalayer/create/',
JSON.stringify(defaultDatalayerData({ id: 63 }))
)
clickSave()
this.server.respond()
this.server.respond() // First respond will then trigger another Xhr request (continueSaving)
assert.equal(newDatalayer.umap_id, 63)
})
it('should have unset map dirty', function () { it('should have unset map dirty', function () {
assert.notOk(this.map.isDirty); assert.notOk(this.map.isDirty)
}); })
it('should have edit button', function () { it('should have edit button', function () {
editButton = qs('#browse_data_toggle_' + L.stamp(newDatalayer) + ' .layer-edit'); editButton = qs('#browse_data_toggle_' + L.stamp(newDatalayer) + ' .layer-edit')
assert.ok(editButton); assert.ok(editButton)
}); })
it('should call update if we edit again', function () { it('should call update if we edit again', function () {
happen.click(editButton); happen.click(editButton)
assert.notOk(this.map.isDirty); assert.notOk(this.map.isDirty)
input = qs('form.umap-form input[name="name"]'); input = qs('form.umap-form input[name="name"]')
input.value = 'a new name again but we don\'t care which'; input.value = "a new name again but we don't care which"
happen.once(input, {type: 'input'}); happen.once(input, { type: 'input' })
assert.ok(this.map.isDirty); assert.ok(this.map.isDirty)
var response = function (request) { var response = function (request) {
return request.respond(200, {}, JSON.stringify(defaultDatalayerData({pk: 63}))); return request.respond(
}; 200,
var spy = sinon.spy(response); {},
this.server.flush(); JSON.stringify(defaultDatalayerData({ pk: 63 }))
this.server.respondWith('POST', '/map/99/update/settings/', JSON.stringify({id: 99})); )
this.server.respondWith('POST', '/map/99/datalayer/update/63/', spy); }
clickSave(); var spy = sinon.spy(response)
this.server.respond(); this.server.flush()
this.server.respond(); this.server.respondWith(
assert.ok(spy.calledOnce); 'POST',
}); '/map/99/update/settings/',
JSON.stringify({ id: 99 })
}); )
this.server.respondWith('POST', '/map/99/datalayer/update/63/', spy)
clickSave()
this.server.respond()
this.server.respond()
assert.ok(spy.calledOnce)
})
})
describe('#iconClassChange()', function () { describe('#iconClassChange()', function () {
it('should change icon class', function () { it('should change icon class', function () {
happen.click(qs('[data-id="' + this.datalayer._leaflet_id +'"] .layer-edit')); happen.click(qs('[data-id="' + this.datalayer._leaflet_id + '"] .layer-edit'))
changeSelectValue(qs('form#datalayer-advanced-properties select[name=iconClass]'), 'Circle'); changeSelectValue(
assert.notOk(qs('div.umap-div-icon')); qs('form#datalayer-advanced-properties select[name=iconClass]'),
assert.ok(qs('div.umap-circle-icon')); 'Circle'
happen.click(qs('form#datalayer-advanced-properties .umap-field-iconClass .undefine')); )
assert.notOk(qs('div.umap-circle-icon')); assert.notOk(qs('div.umap-div-icon'))
assert.ok(qs('div.umap-div-icon')); assert.ok(qs('div.umap-circle-icon'))
clickCancel(); happen.click(
}); qs('form#datalayer-advanced-properties .umap-field-iconClass .undefine')
)
}); assert.notOk(qs('div.umap-circle-icon'))
assert.ok(qs('div.umap-div-icon'))
clickCancel()
})
})
describe('#show/hide', function () { describe('#show/hide', function () {
it('should hide features on hide', function () { it('should hide features on hide', function () {
assert.ok(qs('div.umap-div-icon')); assert.ok(qs('div.umap-div-icon'))
assert.ok(qs('path[fill="none"]')); assert.ok(qs('path[fill="none"]'))
this.datalayer.hide(); this.datalayer.hide()
assert.notOk(qs('div.umap-div-icon')); assert.notOk(qs('div.umap-div-icon'))
assert.notOk(qs('path[fill="none"]')); assert.notOk(qs('path[fill="none"]'))
}); })
it('should show features on show', function () { it('should show features on show', function () {
assert.notOk(qs('div.umap-div-icon')); assert.notOk(qs('div.umap-div-icon'))
assert.notOk(qs('path[fill="none"]')); assert.notOk(qs('path[fill="none"]'))
this.datalayer.show(); this.datalayer.show()
assert.ok(qs('div.umap-div-icon')); assert.ok(qs('div.umap-div-icon'))
assert.ok(qs('path[fill="none"]')); assert.ok(qs('path[fill="none"]'))
}); })
})
});
describe('#clone()', function () { describe('#clone()', function () {
it('should clone everything but the id and the name', function () { it('should clone everything but the id and the name', function () {
enableEdit(); enableEdit()
var clone = this.datalayer.clone(); var clone = this.datalayer.clone()
assert.notOk(clone.umap_id); assert.notOk(clone.umap_id)
assert.notEqual(clone.options.name, this.datalayer.name); assert.notEqual(clone.options.name, this.datalayer.name)
assert.ok(clone.options.name); assert.ok(clone.options.name)
assert.equal(clone.options.color, this.datalayer.options.color); assert.equal(clone.options.color, this.datalayer.options.color)
assert.equal(clone.options.stroke, this.datalayer.options.stroke); assert.equal(clone.options.stroke, this.datalayer.options.stroke)
clone._delete(); clone._delete()
clickSave(); clickSave()
}); })
})
});
describe('#restore()', function () { describe('#restore()', function () {
var oldConfirm, var oldConfirm,
newConfirm = function () { newConfirm = function () {
return true; return true
}; }
before(function () { before(function () {
oldConfirm = window.confirm; oldConfirm = window.confirm
window.confirm = newConfirm; window.confirm = newConfirm
}); })
after(function () { after(function () {
window.confirm = oldConfirm; window.confirm = oldConfirm
}); })
it('should restore everything', function () { it('should restore everything', function () {
enableEdit(); enableEdit()
var geojson = L.Util.CopyJSON(RESPONSES.datalayer62_GET); var geojson = L.Util.CopyJSON(RESPONSES.datalayer62_GET)
geojson.features.push({ geojson.features.push({
'geometry': { geometry: {
'type': 'Point', type: 'Point',
'coordinates': [-1.274658203125, 50.57634993749885] coordinates: [-1.274658203125, 50.57634993749885],
}, },
'type': 'Feature', type: 'Feature',
'id': 1807, id: 1807,
'properties': {_umap_options: {}, name: 'new point from restore'} properties: { _umap_options: {}, name: 'new point from restore' },
}); })
geojson._umap_options.color = 'Chocolate'; geojson._umap_options.color = 'Chocolate'
this.server.respondWith('GET', '/datalayer/62/olderversion.geojson', JSON.stringify(geojson)); this.server.respondWith(
sinon.spy(window, 'confirm'); 'GET',
this.datalayer.restore('olderversion.geojson'); '/datalayer/62/olderversion.geojson',
this.server.respond(); JSON.stringify(geojson)
assert(window.confirm.calledOnce); )
window.confirm.restore(); sinon.spy(window, 'confirm')
assert.equal(this.datalayer.umap_id, 62); this.datalayer.restore('olderversion.geojson')
assert.ok(this.datalayer.isDirty); this.server.respond()
assert.equal(this.datalayer._index.length, 4); assert(window.confirm.calledOnce)
assert.ok(qs('path[fill="Chocolate"]')); window.confirm.restore()
}); assert.equal(this.datalayer.umap_id, 62)
assert.ok(this.datalayer.isDirty)
assert.equal(this.datalayer._index.length, 4)
assert.ok(qs('path[fill="Chocolate"]'))
})
it('should revert anything on cancel click', function () { it('should revert anything on cancel click', function () {
clickCancel(); clickCancel()
assert.equal(this.datalayer._index.length, 3); assert.equal(this.datalayer._index.length, 3)
assert.notOk(qs('path[fill="Chocolate"]')); assert.notOk(qs('path[fill="Chocolate"]'))
}); })
})
});
describe('#delete()', function () { describe('#delete()', function () {
var deleteLink, deletePath = '/map/99/datalayer/delete/62/'; var deleteLink,
deletePath = '/map/99/datalayer/delete/62/'
it('should have a delete link in update form', function () { it('should have a delete link in update form', function () {
enableEdit(); enableEdit()
happen.click(qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')); happen.click(
deleteLink = qs('a.delete_datalayer_button'); qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
assert.ok(deleteLink); )
}); deleteLink = qs('a.delete_datalayer_button')
assert.ok(deleteLink)
})
it('should delete features on datalayer delete', function () { it('should delete features on datalayer delete', function () {
happen.click(deleteLink); happen.click(deleteLink)
assert.notOk(qs('div.icon_container')); assert.notOk(qs('div.icon_container'))
}); })
it('should have set map dirty', function () { it('should have set map dirty', function () {
assert.ok(this.map.isDirty); assert.ok(this.map.isDirty)
}); })
it('should delete layer control row on delete', function () { it('should delete layer control row on delete', function () {
assert.notOk(qs('.leaflet-control-browse #browse_data_toggle_' + L.stamp(this.datalayer))); assert.notOk(
}); qs('.leaflet-control-browse #browse_data_toggle_' + L.stamp(this.datalayer))
)
})
it('should be removed from map.datalayers_index', function () { it('should be removed from map.datalayers_index', function () {
assert.equal(this.map.datalayers_index.indexOf(this.datalayer), -1); assert.equal(this.map.datalayers_index.indexOf(this.datalayer), -1)
}); })
it('should be removed from map.datalayers', function () { it('should be removed from map.datalayers', function () {
assert.notOk(this.map.datalayers[L.stamp(this.datalayer)]); assert.notOk(this.map.datalayers[L.stamp(this.datalayer)])
}); })
it('should be visible again on edit cancel', function () { it('should be visible again on edit cancel', function () {
clickCancel(); clickCancel()
assert.ok(qs('div.icon_container')); assert.ok(qs('div.icon_container'))
}); })
})
}); })
});

View file

@ -1,245 +1,285 @@
describe('L.U.FeatureMixin', function () { describe('L.U.FeatureMixin', function () {
before(function () { before(function () {
this.server = sinon.fakeServer.create(); this.server = sinon.fakeServer.create()
this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET)); this.server.respondWith(
this.map = initMap({umap_id: 99}); 'GET',
this.datalayer = this.map.getDataLayerByUmapId(62); '/datalayer/62/',
this.server.respond(); JSON.stringify(RESPONSES.datalayer62_GET)
}); )
this.map = initMap({ umap_id: 99 })
this.datalayer = this.map.getDataLayerByUmapId(62)
this.server.respond()
})
after(function () { after(function () {
this.server.restore(); this.server.restore()
resetMap(); resetMap()
}); })
describe('#edit()', function () { describe('#edit()', function () {
var link; var link
it('should have datalayer features created', function () { it('should have datalayer features created', function () {
assert.equal(document.querySelectorAll('#map > .leaflet-map-pane > .leaflet-overlay-pane path.leaflet-interactive').length, 2); assert.equal(
assert.ok(qs('path[fill="none"]')); // Polyline document.querySelectorAll(
assert.ok(qs('path[fill="DarkBlue"]')); // Polygon '#map > .leaflet-map-pane > .leaflet-overlay-pane path.leaflet-interactive'
}); ).length,
2
)
assert.ok(qs('path[fill="none"]')) // Polyline
assert.ok(qs('path[fill="DarkBlue"]')) // Polygon
})
it('should take into account styles changes made in the datalayer', function () { it('should take into account styles changes made in the datalayer', function () {
enableEdit(); enableEdit()
happen.click(qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')); happen.click(
var colorInput = qs('form#datalayer-advanced-properties input[name=color]'); qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
changeInputValue(colorInput, 'DarkRed'); )
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged var colorInput = qs('form#datalayer-advanced-properties input[name=color]')
assert.notOk(qs('path[fill="DarkBlue"]')); changeInputValue(colorInput, 'DarkRed')
assert.ok(qs('path[fill="DarkRed"]')); assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
}); assert.notOk(qs('path[fill="DarkBlue"]'))
assert.ok(qs('path[fill="DarkRed"]'))
})
it('should open a popup toolbar on feature click', function () { it('should open a popup toolbar on feature click', function () {
enableEdit(); enableEdit()
happen.click(qs('path[fill="DarkRed"]')); happen.click(qs('path[fill="DarkRed"]'))
var toolbar = qs('ul.leaflet-inplace-toolbar'); var toolbar = qs('ul.leaflet-inplace-toolbar')
assert.ok(toolbar); assert.ok(toolbar)
link = qs('a.umap-toggle-edit', toolbar); link = qs('a.umap-toggle-edit', toolbar)
assert.ok(link); assert.ok(link)
}); })
it('should open a form on popup toolbar toggle edit click', function () { it('should open a form on popup toolbar toggle edit click', function () {
happen.click(link); happen.click(link)
var form = qs('form#umap-feature-properties'); var form = qs('form#umap-feature-properties')
var input = qs('form#umap-feature-properties input[name="name"]'); var input = qs('form#umap-feature-properties input[name="name"]')
assert.ok(form); assert.ok(form)
assert.ok(input); assert.ok(input)
}); })
it('should not handle _umap_options has normal property', function () { it('should not handle _umap_options has normal property', function () {
assert.notOk(qs('form#umap-feature-properties input[name="_umap_options"]')); assert.notOk(qs('form#umap-feature-properties input[name="_umap_options"]'))
}); })
it('should give precedence to feature style over datalayer styles', function () { it('should give precedence to feature style over datalayer styles', function () {
var input = qs('#umap-ui-container form input[name="color"]'); var input = qs('#umap-ui-container form input[name="color"]')
assert.ok(input); assert.ok(input)
changeInputValue(input, 'DarkGreen'); changeInputValue(input, 'DarkGreen')
assert.notOk(qs('path[fill="DarkRed"]')); assert.notOk(qs('path[fill="DarkRed"]'))
assert.notOk(qs('path[fill="DarkBlue"]')); assert.notOk(qs('path[fill="DarkBlue"]'))
assert.ok(qs('path[fill="DarkGreen"]')); assert.ok(qs('path[fill="DarkGreen"]'))
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
}); })
it('should remove stroke if set to no', function () { it('should remove stroke if set to no', function () {
assert.notOk(qs('path[stroke="none"]')); assert.notOk(qs('path[stroke="none"]'))
var defineButton = qs('#umap-feature-shape-properties .formbox:nth-child(4) .define'); var defineButton = qs(
happen.click(defineButton); '#umap-feature-shape-properties .formbox:nth-child(4) .define'
var input = qs('#umap-feature-shape-properties input[name="stroke"]'); )
assert.ok(input); happen.click(defineButton)
input.checked = false; var input = qs('#umap-feature-shape-properties input[name="stroke"]')
happen.once(input, {type: 'change'}); assert.ok(input)
assert.ok(qs('path[stroke="none"]')); input.checked = false
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged happen.once(input, { type: 'change' })
}); assert.ok(qs('path[stroke="none"]'))
assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
})
it('should not override already set style on features', function () { it('should not override already set style on features', function () {
happen.click(qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')); happen.click(
changeInputValue(qs('#umap-ui-container form input[name=color]'), 'Chocolate'); qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
assert.notOk(qs('path[fill="DarkBlue"]')); )
assert.notOk(qs('path[fill="DarkRed"]')); changeInputValue(qs('#umap-ui-container form input[name=color]'), 'Chocolate')
assert.notOk(qs('path[fill="Chocolate"]')); assert.notOk(qs('path[fill="DarkBlue"]'))
assert.ok(qs('path[fill="DarkGreen"]')); assert.notOk(qs('path[fill="DarkRed"]'))
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged assert.notOk(qs('path[fill="Chocolate"]'))
}); assert.ok(qs('path[fill="DarkGreen"]'))
assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
})
it('should reset style on cancel click', function () { it('should reset style on cancel click', function () {
clickCancel(); clickCancel()
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
assert.ok(qs('path[fill="DarkBlue"]')); assert.ok(qs('path[fill="DarkBlue"]'))
assert.notOk(qs('path[fill="DarkRed"]')); assert.notOk(qs('path[fill="DarkRed"]'))
}); })
it('should set map.editedFeature on edit', function () { it('should set map.editedFeature on edit', function () {
enableEdit(); enableEdit()
assert.notOk(this.map.editedFeature); assert.notOk(this.map.editedFeature)
happen.click(qs('path[fill="DarkBlue"]')); happen.click(qs('path[fill="DarkBlue"]'))
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
assert.ok(this.map.editedFeature); assert.ok(this.map.editedFeature)
disableEdit(); disableEdit()
}); })
it('should reset map.editedFeature on panel open', function (done) { it('should reset map.editedFeature on panel open', function (done) {
enableEdit(); enableEdit()
assert.notOk(this.map.editedFeature); assert.notOk(this.map.editedFeature)
happen.click(qs('path[fill="DarkBlue"]')); happen.click(qs('path[fill="DarkBlue"]'))
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
assert.ok(this.map.editedFeature); assert.ok(this.map.editedFeature)
this.map.displayCaption(); this.map.displayCaption()
window.setTimeout(function () { window.setTimeout(function () {
assert.notOk(this.map.editedFeature); assert.notOk(this.map.editedFeature)
disableEdit(); disableEdit()
done(); done()
}, 1001); // CSS transition time. }, 1001) // CSS transition time.
}); })
})
});
describe('#utils()', function () { describe('#utils()', function () {
var poly, marker; var poly, marker
function setFeatures(datalayer) { function setFeatures(datalayer) {
datalayer.eachLayer(function (layer) { datalayer.eachLayer(function (layer) {
if (!poly && layer instanceof L.Polygon) { if (!poly && layer instanceof L.Polygon) {
poly = layer; poly = layer
} }
if (!marker && layer instanceof L.Marker) { if (!marker && layer instanceof L.Marker) {
marker = layer; marker = layer
} }
}); })
} }
it('should generate a valid geojson', function () { it('should generate a valid geojson', function () {
setFeatures(this.datalayer); setFeatures(this.datalayer)
assert.ok(poly); assert.ok(poly)
assert.deepEqual(poly.toGeoJSON().geometry, {'type': 'Polygon', 'coordinates': [[[11.25, 53.585984], [10.151367, 52.975108], [12.689209, 52.167194], [14.084473, 53.199452], [12.634277, 53.618579], [11.25, 53.585984], [11.25, 53.585984]]]}); assert.deepEqual(poly.toGeoJSON().geometry, {
type: 'Polygon',
coordinates: [
[
[11.25, 53.585984],
[10.151367, 52.975108],
[12.689209, 52.167194],
[14.084473, 53.199452],
[12.634277, 53.618579],
[11.25, 53.585984],
[11.25, 53.585984],
],
],
})
// Ensure original latlngs has not been modified // Ensure original latlngs has not been modified
assert.equal(poly.getLatLngs()[0].length, 6); assert.equal(poly.getLatLngs()[0].length, 6)
}); })
it('should remove empty _umap_options from exported geojson', function () { it('should remove empty _umap_options from exported geojson', function () {
setFeatures(this.datalayer); setFeatures(this.datalayer)
assert.ok(poly); assert.ok(poly)
assert.deepEqual(poly.toGeoJSON().properties, {name: 'name poly'}); assert.deepEqual(poly.toGeoJSON().properties, { name: 'name poly' })
assert.ok(marker); assert.ok(marker)
assert.deepEqual(marker.toGeoJSON().properties, {_umap_options: {color: 'OliveDrab'}, name: 'test'}); assert.deepEqual(marker.toGeoJSON().properties, {
}); _umap_options: { color: 'OliveDrab' },
name: 'test',
}); })
})
})
describe('#changeDataLayer()', function () { describe('#changeDataLayer()', function () {
it('should change style on datalayer select change', function () { it('should change style on datalayer select change', function () {
enableEdit(); enableEdit()
happen.click(qs('.manage-datalayers')); happen.click(qs('.manage-datalayers'))
happen.click(qs('#umap-ui-container .add-datalayer')); happen.click(qs('#umap-ui-container .add-datalayer'))
changeInputValue(qs('form.umap-form input[name="name"]'), 'New layer'); changeInputValue(qs('form.umap-form input[name="name"]'), 'New layer')
changeInputValue(qs('form#datalayer-advanced-properties input[name=color]'), 'MediumAquaMarine'); changeInputValue(
happen.click(qs('path[fill="DarkBlue"]')); qs('form#datalayer-advanced-properties input[name=color]'),
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); 'MediumAquaMarine'
var select = qs('select[name=datalayer]'); )
select.selectedIndex = 0; happen.click(qs('path[fill="DarkBlue"]'))
happen.once(select, {type: 'change'}); happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged var select = qs('select[name=datalayer]')
assert.notOk(qs('path[fill="DarkBlue"]')); select.selectedIndex = 0
assert.ok(qs('path[fill="MediumAquaMarine"]')); happen.once(select, { type: 'change' })
clickCancel(); assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
}); assert.notOk(qs('path[fill="DarkBlue"]'))
assert.ok(qs('path[fill="MediumAquaMarine"]'))
}); clickCancel()
})
})
describe('#openPopup()', function () { describe('#openPopup()', function () {
it('should open a popup on click', function () { it('should open a popup on click', function () {
assert.notOk(qs('.leaflet-popup-content')); assert.notOk(qs('.leaflet-popup-content'))
happen.click(qs('path[fill="DarkBlue"]')); happen.click(qs('path[fill="DarkBlue"]'))
var title = qs('.leaflet-popup-content'); var title = qs('.leaflet-popup-content')
assert.ok(title); assert.ok(title)
assert.ok(title.innerHTML.indexOf('name poly')); assert.ok(title.innerHTML.indexOf('name poly'))
}); })
})
});
describe('#tooltip', function () { describe('#tooltip', function () {
it('should have a tooltip when active and allow variables', function () { it('should have a tooltip when active and allow variables', function () {
this.map.options.showLabel = true; this.map.options.showLabel = true
this.map.options.labelKey = "Foo {name}"; this.map.options.labelKey = 'Foo {name}'
this.datalayer.redraw(); this.datalayer.redraw()
assert.equal(qs('.leaflet-tooltip-pane .leaflet-tooltip').textContent, "Foo name poly"); assert.equal(
}); qs('.leaflet-tooltip-pane .leaflet-tooltip').textContent,
'Foo name poly'
}); )
})
})
describe('#properties()', function () { describe('#properties()', function () {
it('should rename property', function () { it('should rename property', function () {
var poly = this.datalayer._lineToLayer({}, [[0, 0], [0, 1], [0, 2]]); var poly = this.datalayer._lineToLayer({}, [
poly.properties.prop1 = 'xxx'; [0, 0],
poly.renameProperty('prop1', 'prop2'); [0, 1],
assert.equal(poly.properties.prop2, 'xxx'); [0, 2],
assert.ok(typeof poly.properties.prop1 === 'undefined'); ])
}); poly.properties.prop1 = 'xxx'
poly.renameProperty('prop1', 'prop2')
assert.equal(poly.properties.prop2, 'xxx')
assert.ok(typeof poly.properties.prop1 === 'undefined')
})
it('should not create property when renaming', function () { it('should not create property when renaming', function () {
var poly = this.datalayer._lineToLayer({}, [[0, 0], [0, 1], [0, 2]]); var poly = this.datalayer._lineToLayer({}, [
delete poly.properties.prop2; // Make sure it doesn't exist [0, 0],
poly.renameProperty('prop1', 'prop2'); [0, 1],
assert.ok(typeof poly.properties.prop2 === 'undefined'); [0, 2],
}); ])
delete poly.properties.prop2 // Make sure it doesn't exist
poly.renameProperty('prop1', 'prop2')
assert.ok(typeof poly.properties.prop2 === 'undefined')
})
it('should delete property', function () { it('should delete property', function () {
var poly = this.datalayer._lineToLayer({}, [[0, 0], [0, 1], [0, 2]]); var poly = this.datalayer._lineToLayer({}, [
poly.properties.prop = 'xxx'; [0, 0],
assert.equal(poly.properties.prop, 'xxx'); [0, 1],
poly.deleteProperty('prop'); [0, 2],
assert.ok(typeof poly.properties.prop === 'undefined'); ])
}); poly.properties.prop = 'xxx'
assert.equal(poly.properties.prop, 'xxx')
}); poly.deleteProperty('prop')
assert.ok(typeof poly.properties.prop === 'undefined')
})
})
describe('#matchFilter()', function () { describe('#matchFilter()', function () {
var poly; var poly
it('should filter on properties', function () { it('should filter on properties', function () {
poly = this.datalayer._lineToLayer({}, [[0, 0], [0, 1], [0, 2]]); poly = this.datalayer._lineToLayer({}, [
poly.properties.name = 'mooring'; [0, 0],
assert.ok(poly.matchFilter('moo', ['name'])); [0, 1],
assert.notOk(poly.matchFilter('foo', ['name'])); [0, 2],
}); ])
poly.properties.name = 'mooring'
assert.ok(poly.matchFilter('moo', ['name']))
assert.notOk(poly.matchFilter('foo', ['name']))
})
it('should be case unsensitive', function () { it('should be case unsensitive', function () {
assert.ok(poly.matchFilter('Moo', ['name'])); assert.ok(poly.matchFilter('Moo', ['name']))
}); })
it('should match also in the middle of a string', function () { it('should match also in the middle of a string', function () {
assert.ok(poly.matchFilter('oor', ['name'])); assert.ok(poly.matchFilter('oor', ['name']))
}); })
it('should handle multiproperties', function () { it('should handle multiproperties', function () {
poly.properties.city = 'Teulada'; poly.properties.city = 'Teulada'
assert.ok(poly.matchFilter('eul', ['name', 'city', 'foo'])); assert.ok(poly.matchFilter('eul', ['name', 'city', 'foo']))
}); })
})
}); })
});

View file

@ -1,316 +1,327 @@
describe('L.U.Map', function () { describe('L.U.Map', function () {
before(function () { before(function () {
this.server = sinon.fakeServer.create(); this.server = sinon.fakeServer.create()
this.server.respondWith('/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET)); this.server.respondWith('/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET))
this.options = { this.options = {
umap_id: 99 umap_id: 99,
}; }
this.map = initMap({umap_id: 99}); this.map = initMap({ umap_id: 99 })
this.server.respond(); this.server.respond()
this.datalayer = this.map.getDataLayerByUmapId(62); this.datalayer = this.map.getDataLayerByUmapId(62)
}); })
after(function () { after(function () {
this.server.restore(); this.server.restore()
clickCancel(); clickCancel()
resetMap(); resetMap()
}); })
describe('#init()', function () { describe('#init()', function () {
it('should be initialized', function () { it('should be initialized', function () {
assert.equal(this.map.options.umap_id, 99); assert.equal(this.map.options.umap_id, 99)
}); })
it('should have created the edit button', function () { it('should have created the edit button', function () {
assert.ok(qs('div.leaflet-control-edit-enable')); assert.ok(qs('div.leaflet-control-edit-enable'))
}); })
it('should have datalayer control div', function () { it('should have datalayer control div', function () {
assert.ok(qs('div.leaflet-control-browse')); assert.ok(qs('div.leaflet-control-browse'))
}); })
it('should have datalayer actions div', function () { it('should have datalayer actions div', function () {
assert.ok(qs('div.umap-browse-actions')); assert.ok(qs('div.umap-browse-actions'))
}); })
it('should have icon container div', function () { it('should have icon container div', function () {
assert.ok(qs('div.icon_container')); assert.ok(qs('div.icon_container'))
}); })
it('should hide icon container div when hiding datalayer', function () { it('should hide icon container div when hiding datalayer', function () {
var el = qs('.leaflet-control-browse #browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-toggle'); var el = qs(
happen.click(el); '.leaflet-control-browse #browse_data_toggle_' +
assert.notOk(qs('div.icon_container')); L.stamp(this.datalayer) +
}); ' .layer-toggle'
)
happen.click(el)
assert.notOk(qs('div.icon_container'))
})
it('enable edit on click on toggle button', function () { it('enable edit on click on toggle button', function () {
var el = qs('div.leaflet-control-edit-enable a'); var el = qs('div.leaflet-control-edit-enable a')
happen.click(el); happen.click(el)
assert.isTrue(L.DomUtil.hasClass(document.body, 'umap-edit-enabled')); assert.isTrue(L.DomUtil.hasClass(document.body, 'umap-edit-enabled'))
}); })
it('should have only one datalayer in its index', function () { it('should have only one datalayer in its index', function () {
assert.equal(this.map.datalayers_index.length, 1); assert.equal(this.map.datalayers_index.length, 1)
}); })
}); })
describe('#editMetadata()', function () { describe('#editMetadata()', function () {
var form, input; var form, input
it('should build a form on editMetadata control click', function (done) { it('should build a form on editMetadata control click', function (done) {
var button = qs('a.update-map-settings'); var button = qs('a.update-map-settings')
assert.ok(button); assert.ok(button)
happen.click(button); happen.click(button)
form = qs('form.umap-form'); form = qs('form.umap-form')
input = qs('form[class="umap-form"] input[name="name"]'); input = qs('form[class="umap-form"] input[name="name"]')
assert.ok(form); assert.ok(form)
assert.ok(input); assert.ok(input)
done(); done()
}); })
it('should update map name on input change', function () { it('should update map name on input change', function () {
var new_name = 'This is a new name'; var new_name = 'This is a new name'
input.value = new_name; input.value = new_name
happen.once(input, {type: 'input'}); happen.once(input, { type: 'input' })
assert.equal(this.map.options.name, new_name); assert.equal(this.map.options.name, new_name)
}); })
it('should have made Map dirty', function () { it('should have made Map dirty', function () {
assert.ok(this.map.isDirty); assert.ok(this.map.isDirty)
}); })
it('should have added dirty class on map container', function () { it('should have added dirty class on map container', function () {
assert.ok(L.DomUtil.hasClass(this.map._container, 'umap-is-dirty')); assert.ok(L.DomUtil.hasClass(this.map._container, 'umap-is-dirty'))
}); })
})
});
describe('#delete()', function () { describe('#delete()', function () {
var path = '/map/99/delete/', var path = '/map/99/delete/',
oldConfirm, oldConfirm,
newConfirm = function () { newConfirm = function () {
return true; return true
}; }
before(function () { before(function () {
oldConfirm = window.confirm; oldConfirm = window.confirm
window.confirm = newConfirm; window.confirm = newConfirm
}); })
after(function () { after(function () {
window.confirm = oldConfirm; window.confirm = oldConfirm
}); })
it('should ask for confirmation on delete link click', function (done) { it('should ask for confirmation on delete link click', function (done) {
var button = qs('a.update-map-settings'); var button = qs('a.update-map-settings')
assert.ok(button, 'update map info button exists'); assert.ok(button, 'update map info button exists')
happen.click(button); happen.click(button)
var deleteLink = qs('a.umap-delete'); var deleteLink = qs('a.umap-delete')
assert.ok(deleteLink, 'delete map button exists'); assert.ok(deleteLink, 'delete map button exists')
sinon.spy(window, 'confirm'); sinon.spy(window, 'confirm')
this.server.respondWith('POST', path, JSON.stringify({redirect: '#'})); this.server.respondWith('POST', path, JSON.stringify({ redirect: '#' }))
happen.click(deleteLink); happen.click(deleteLink)
this.server.respond(); this.server.respond()
assert(window.confirm.calledOnce); assert(window.confirm.calledOnce)
window.confirm.restore(); window.confirm.restore()
done(); done()
}); })
})
});
describe('#importData()', function () { describe('#importData()', function () {
var fileInput, textarea, submit, formatSelect, layerSelect, clearFlag; var fileInput, textarea, submit, formatSelect, layerSelect, clearFlag
it('should build a form on click', function () { it('should build a form on click', function () {
happen.click(qs('a.upload-data')); happen.click(qs('a.upload-data'))
fileInput = qs('.umap-upload input[type="file"]'); fileInput = qs('.umap-upload input[type="file"]')
textarea = qs('.umap-upload textarea'); textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]'); submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]'); formatSelect = qs('.umap-upload select[name="format"]')
layerSelect = qs('.umap-upload select[name="datalayer"]'); layerSelect = qs('.umap-upload select[name="datalayer"]')
assert.ok(fileInput); assert.ok(fileInput)
assert.ok(submit); assert.ok(submit)
assert.ok(textarea); assert.ok(textarea)
assert.ok(formatSelect); assert.ok(formatSelect)
assert.ok(layerSelect); assert.ok(layerSelect)
}); })
it('should import geojson from textarea', function () { it('should import geojson from textarea', function () {
this.datalayer.empty() this.datalayer.empty()
assert.equal(this.datalayer._index.length, 0); assert.equal(this.datalayer._index.length, 0)
textarea.value = '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [6.922931671142578, 47.481161607175736]}, "type": "Feature", "properties": {"color": "", "name": "Chez R\u00e9my", "description": ""}}, {"geometry": {"type": "LineString", "coordinates": [[2.4609375, 48.88639177703194], [2.48291015625, 48.76343113791796], [2.164306640625, 48.719961222646276]]}, "type": "Feature", "properties": {"color": "", "name": "P\u00e9rif", "description": ""}}]}'; textarea.value =
changeSelectValue(formatSelect, 'geojson'); '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [6.922931671142578, 47.481161607175736]}, "type": "Feature", "properties": {"color": "", "name": "Chez R\u00e9my", "description": ""}}, {"geometry": {"type": "LineString", "coordinates": [[2.4609375, 48.88639177703194], [2.48291015625, 48.76343113791796], [2.164306640625, 48.719961222646276]]}, "type": "Feature", "properties": {"color": "", "name": "P\u00e9rif", "description": ""}}]}'
happen.click(submit); changeSelectValue(formatSelect, 'geojson')
assert.equal(this.datalayer._index.length, 2); happen.click(submit)
}); assert.equal(this.datalayer._index.length, 2)
})
it('should import osm from textarea', function () { it('should import osm from textarea', function () {
this.datalayer.empty() this.datalayer.empty()
happen.click(qs('a.upload-data')); happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea'); textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]'); submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]'); formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0); assert.equal(this.datalayer._index.length, 0)
textarea.value = '{"version": 0.6,"generator": "Overpass API 0.7.55.4 3079d8ea","osm3s": {"timestamp_osm_base": "2018-09-22T05:26:02Z","copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."},"elements": [{"type": "node","id": 3619112991,"lat": 48.9352995,"lon": 2.3570684,"tags": {"information": "map","map_size": "city","map_type": "scheme","tourism": "information"}},{"type": "node","id": 3682500756,"lat": 48.9804426,"lon": 2.2719725,"tags": {"information": "map","level": "0","tourism": "information"}}]}'; textarea.value =
changeSelectValue(formatSelect, 'osm'); '{"version": 0.6,"generator": "Overpass API 0.7.55.4 3079d8ea","osm3s": {"timestamp_osm_base": "2018-09-22T05:26:02Z","copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."},"elements": [{"type": "node","id": 3619112991,"lat": 48.9352995,"lon": 2.3570684,"tags": {"information": "map","map_size": "city","map_type": "scheme","tourism": "information"}},{"type": "node","id": 3682500756,"lat": 48.9804426,"lon": 2.2719725,"tags": {"information": "map","level": "0","tourism": "information"}}]}'
happen.click(submit); changeSelectValue(formatSelect, 'osm')
assert.equal(this.datalayer._index.length, 2); happen.click(submit)
assert.equal(this.datalayer._layers[this.datalayer._index[0]].properties.tourism, 'information'); assert.equal(this.datalayer._index.length, 2)
}); assert.equal(
this.datalayer._layers[this.datalayer._index[0]].properties.tourism,
'information'
)
})
it('should import kml from textarea', function () { it('should import kml from textarea', function () {
this.datalayer.empty() this.datalayer.empty()
happen.click(qs('a.upload-data')); happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea'); textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]'); submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]'); formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0); assert.equal(this.datalayer._index.length, 0)
textarea.value = kml_example; textarea.value = kml_example
changeSelectValue(formatSelect, 'kml'); changeSelectValue(formatSelect, 'kml')
happen.click(submit); happen.click(submit)
assert.equal(this.datalayer._index.length, 3); assert.equal(this.datalayer._index.length, 3)
}); })
it('should import gpx from textarea', function () { it('should import gpx from textarea', function () {
this.datalayer.empty() this.datalayer.empty()
happen.click(qs('a.upload-data')); happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea'); textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]'); submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]'); formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0); assert.equal(this.datalayer._index.length, 0)
textarea.value = gpx_example; textarea.value = gpx_example
changeSelectValue(formatSelect, 'gpx'); changeSelectValue(formatSelect, 'gpx')
happen.click(submit); happen.click(submit)
assert.equal(this.datalayer._index.length, 2); assert.equal(this.datalayer._index.length, 2)
}); })
it('should import csv from textarea', function () { it('should import csv from textarea', function () {
this.datalayer.empty() this.datalayer.empty()
happen.click(qs('a.upload-data')); happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea'); textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]'); submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]'); formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0); assert.equal(this.datalayer._index.length, 0)
textarea.value = csv_example; textarea.value = csv_example
changeSelectValue(formatSelect, 'csv'); changeSelectValue(formatSelect, 'csv')
happen.click(submit); happen.click(submit)
assert.equal(this.datalayer._index.length, 1); assert.equal(this.datalayer._index.length, 1)
}); })
it('should replace content if asked so', function () { it('should replace content if asked so', function () {
happen.click(qs('a.upload-data')); happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea'); textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]'); submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]'); formatSelect = qs('.umap-upload select[name="format"]')
clearFlag = qs('.umap-upload input[name="clear"]'); clearFlag = qs('.umap-upload input[name="clear"]')
clearFlag.checked = true; clearFlag.checked = true
assert.equal(this.datalayer._index.length, 1); assert.equal(this.datalayer._index.length, 1)
textarea.value = csv_example; textarea.value = csv_example
changeSelectValue(formatSelect, 'csv'); changeSelectValue(formatSelect, 'csv')
happen.click(submit); happen.click(submit)
assert.equal(this.datalayer._index.length, 1); assert.equal(this.datalayer._index.length, 1)
}); })
it('should import GeometryCollection from textarea', function () { it('should import GeometryCollection from textarea', function () {
this.datalayer.empty() this.datalayer.empty()
textarea.value = '{"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-80.66080570220947,35.04939206472683]},{"type": "Polygon","coordinates": [[[-80.66458225250244,35.04496519190309],[-80.66344499588013,35.04603679820616],[-80.66258668899536,35.045580049697556],[-80.66387414932251,35.044280059194946],[-80.66458225250244,35.04496519190309]]]},{"type": "LineString","coordinates": [[-80.66237211227417,35.05950973022538],[-80.66269397735596,35.0592638296087],[-80.66284418106079,35.05893010615862],[-80.66308021545409,35.05833291342246],[-80.66359519958496,35.057753281001425],[-80.66387414932251,35.05740198662245],[-80.66441059112549,35.05703312589789],[-80.66486120223999,35.056787217822475],[-80.66541910171509,35.05650617911516],[-80.66563367843628,35.05631296444281],[-80.66601991653441,35.055891403570705],[-80.66619157791138,35.05545227534804],[-80.66619157791138,35.05517123204622],[-80.66625595092773,35.05489018777713],[-80.6662130355835,35.054222703761525],[-80.6662130355835,35.05392409072499],[-80.66595554351807,35.05290528508858],[-80.66569805145262,35.052044560077285],[-80.66550493240356,35.0514824490509],[-80.665762424469,35.05048117920187],[-80.66617012023926,35.04972582715769],[-80.66651344299316,35.049286665781096],[-80.66692113876343,35.0485313026898],[-80.66700696945189,35.048215102112344],[-80.66707134246826,35.04777593261294],[-80.66704988479614,35.04738946150025],[-80.66696405410767,35.04698542156371],[-80.66681385040283,35.046353007216055],[-80.66659927368164,35.04596652937105],[-80.66640615463257,35.04561518428889],[-80.6659984588623,35.045193568195565],[-80.66552639007568,35.044877354697526],[-80.6649899482727,35.04454357245502],[-80.66449642181396,35.04417465365292],[-80.66385269165039,35.04387600387859],[-80.66303730010986,35.043717894732545]]}]}'; textarea.value =
formatSelect = qs('.umap-upload select[name="format"]'); '{"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-80.66080570220947,35.04939206472683]},{"type": "Polygon","coordinates": [[[-80.66458225250244,35.04496519190309],[-80.66344499588013,35.04603679820616],[-80.66258668899536,35.045580049697556],[-80.66387414932251,35.044280059194946],[-80.66458225250244,35.04496519190309]]]},{"type": "LineString","coordinates": [[-80.66237211227417,35.05950973022538],[-80.66269397735596,35.0592638296087],[-80.66284418106079,35.05893010615862],[-80.66308021545409,35.05833291342246],[-80.66359519958496,35.057753281001425],[-80.66387414932251,35.05740198662245],[-80.66441059112549,35.05703312589789],[-80.66486120223999,35.056787217822475],[-80.66541910171509,35.05650617911516],[-80.66563367843628,35.05631296444281],[-80.66601991653441,35.055891403570705],[-80.66619157791138,35.05545227534804],[-80.66619157791138,35.05517123204622],[-80.66625595092773,35.05489018777713],[-80.6662130355835,35.054222703761525],[-80.6662130355835,35.05392409072499],[-80.66595554351807,35.05290528508858],[-80.66569805145262,35.052044560077285],[-80.66550493240356,35.0514824490509],[-80.665762424469,35.05048117920187],[-80.66617012023926,35.04972582715769],[-80.66651344299316,35.049286665781096],[-80.66692113876343,35.0485313026898],[-80.66700696945189,35.048215102112344],[-80.66707134246826,35.04777593261294],[-80.66704988479614,35.04738946150025],[-80.66696405410767,35.04698542156371],[-80.66681385040283,35.046353007216055],[-80.66659927368164,35.04596652937105],[-80.66640615463257,35.04561518428889],[-80.6659984588623,35.045193568195565],[-80.66552639007568,35.044877354697526],[-80.6649899482727,35.04454357245502],[-80.66449642181396,35.04417465365292],[-80.66385269165039,35.04387600387859],[-80.66303730010986,35.043717894732545]]}]}'
changeSelectValue(formatSelect, 'geojson'); formatSelect = qs('.umap-upload select[name="format"]')
happen.click(submit); changeSelectValue(formatSelect, 'geojson')
assert.equal(this.datalayer._index.length, 3); happen.click(submit)
}); assert.equal(this.datalayer._index.length, 3)
})
it('should import multipolygon', function () { it('should import multipolygon', function () {
this.datalayer.empty() this.datalayer.empty()
textarea.value = '{"type": "Feature", "properties": { "name": "Some states" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-109, 36], [-109, 40], [-102, 37], [-109, 36]], [[-108, 39], [-107, 37], [-104, 37], [-108, 39]]], [[[-119, 42], [-120, 39], [-114, 41], [-119, 42]]]] }}'; textarea.value =
changeSelectValue(formatSelect, 'geojson'); '{"type": "Feature", "properties": { "name": "Some states" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-109, 36], [-109, 40], [-102, 37], [-109, 36]], [[-108, 39], [-107, 37], [-104, 37], [-108, 39]]], [[[-119, 42], [-120, 39], [-114, 41], [-119, 42]]]] }}'
happen.click(submit); changeSelectValue(formatSelect, 'geojson')
assert.equal(this.datalayer._index.length, 1); happen.click(submit)
var layer = this.datalayer.getFeatureByIndex(0); assert.equal(this.datalayer._index.length, 1)
assert.equal(layer._latlngs.length, 2); // Two shapes. var layer = this.datalayer.getFeatureByIndex(0)
assert.equal(layer._latlngs[0].length, 2); // Hole. assert.equal(layer._latlngs.length, 2) // Two shapes.
}); assert.equal(layer._latlngs[0].length, 2) // Hole.
})
it('should import multipolyline', function () { it('should import multipolyline', function () {
this.datalayer.empty() this.datalayer.empty()
textarea.value = '{"type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "MultiLineString", "coordinates": [[[-108, 46], [-113, 43]], [[-112, 45], [-115, 44]]] } }]}'; textarea.value =
changeSelectValue(formatSelect, 'geojson'); '{"type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "MultiLineString", "coordinates": [[[-108, 46], [-113, 43]], [[-112, 45], [-115, 44]]] } }]}'
happen.click(submit); changeSelectValue(formatSelect, 'geojson')
assert.equal(this.datalayer._index.length, 1); happen.click(submit)
var layer = this.datalayer.getFeatureByIndex(0); assert.equal(this.datalayer._index.length, 1)
assert.equal(layer._latlngs.length, 2); // Two shapes. var layer = this.datalayer.getFeatureByIndex(0)
}); assert.equal(layer._latlngs.length, 2) // Two shapes.
})
it('should import raw umap data from textarea', function () { it('should import raw umap data from textarea', function () {
//Right now, the import function will try to save and reload. Stop this from happening. //Right now, the import function will try to save and reload. Stop this from happening.
var disabledSaveFunction = this.map.save; var disabledSaveFunction = this.map.save
this.map.save = function(){}; this.map.save = function () {}
happen.click(qs('a.upload-data')); happen.click(qs('a.upload-data'))
var initialLayerCount = Object.keys(this.map.datalayers).length; var initialLayerCount = Object.keys(this.map.datalayers).length
formatSelect = qs('.umap-upload select[name="format"]'); formatSelect = qs('.umap-upload select[name="format"]')
textarea = qs('.umap-upload textarea'); textarea = qs('.umap-upload textarea')
textarea.value = '{ "type": "umap", "geometry": { "type": "Point", "coordinates": [3.0528, 50.6269] }, "properties": { "umap_id": 666, "longCredit": "the illustrious mapmaker", "shortCredit": "the mapmaker", "slideshow": {}, "captionBar": true, "dashArray": "5,5", "fillOpacity": "0.5", "fillColor": "Crimson", "fill": true, "weight": "2", "opacity": "0.9", "smoothFactor": "1", "iconClass": "Drop", "color": "Red", "limitBounds": {}, "tilelayer": { "maxZoom": 18, "url_template": "http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg", "minZoom": 0, "attribution": "Map tiles by [[http://stamen.com|Stamen Design]], under [[http://creativecommons.org/licenses/by/3.0|CC BY 3.0]]. Data by [[http://openstreetmap.org|OpenStreetMap]], under [[http://creativecommons.org/licenses/by-sa/3.0|CC BY SA]].", "name": "Watercolor" }, "licence": { "url": "", "name": "No licence set" }, "description": "Map description", "name": "Imported map", "tilelayersControl": true, "onLoadPanel": "caption", "displayPopupFooter": true, "miniMap": true, "moreControl": true, "scaleControl": true, "zoomControl": true, "scrollWheelZoom": true, "datalayersControl": true, "zoom": 6 }, "layers": [{ "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [4.2939, 50.8893], [4.2441, 50.8196], [4.3869, 50.7642], [4.4813, 50.7929], [4.413, 50.9119], [4.2939, 50.8893] ] ] }, "properties": { "name": "Bruxelles", "description": "polygon" } }, { "type": "Feature", "geometry": { "type": "Point", "coordinates": [3.0528, 50.6269] }, "properties": { "_umap_options": { "color": "Orange" }, "name": "Lille", "description": "une ville" } }], "_umap_options": { "displayOnLoad": true, "name": "Cities", "id": 108, "remoteData": {}, "description": "A layer with some cities", "color": "Navy", "iconClass": "Drop", "smoothFactor": "1", "dashArray": "5,1", "fillOpacity": "0.5", "fillColor": "Blue", "fill": true } }, { "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "LineString", "coordinates": [ [1.7715, 50.9255], [1.6589, 50.9696], [1.4941, 51.0128], [1.4199, 51.0638], [1.2881, 51.1104] ] }, "properties": { "_umap_options": { "weight": "4" }, "name": "tunnel sous la Manche" } }], "_umap_options": { "displayOnLoad": true, "name": "Tunnels", "id": 109, "remoteData": {} } }]}'; textarea.value =
formatSelect.value = 'umap'; '{ "type": "umap", "geometry": { "type": "Point", "coordinates": [3.0528, 50.6269] }, "properties": { "umap_id": 666, "longCredit": "the illustrious mapmaker", "shortCredit": "the mapmaker", "slideshow": {}, "captionBar": true, "dashArray": "5,5", "fillOpacity": "0.5", "fillColor": "Crimson", "fill": true, "weight": "2", "opacity": "0.9", "smoothFactor": "1", "iconClass": "Drop", "color": "Red", "limitBounds": {}, "tilelayer": { "maxZoom": 18, "url_template": "http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg", "minZoom": 0, "attribution": "Map tiles by [[http://stamen.com|Stamen Design]], under [[http://creativecommons.org/licenses/by/3.0|CC BY 3.0]]. Data by [[http://openstreetmap.org|OpenStreetMap]], under [[http://creativecommons.org/licenses/by-sa/3.0|CC BY SA]].", "name": "Watercolor" }, "licence": { "url": "", "name": "No licence set" }, "description": "Map description", "name": "Imported map", "tilelayersControl": true, "onLoadPanel": "caption", "displayPopupFooter": true, "miniMap": true, "moreControl": true, "scaleControl": true, "zoomControl": true, "scrollWheelZoom": true, "datalayersControl": true, "zoom": 6 }, "layers": [{ "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [4.2939, 50.8893], [4.2441, 50.8196], [4.3869, 50.7642], [4.4813, 50.7929], [4.413, 50.9119], [4.2939, 50.8893] ] ] }, "properties": { "name": "Bruxelles", "description": "polygon" } }, { "type": "Feature", "geometry": { "type": "Point", "coordinates": [3.0528, 50.6269] }, "properties": { "_umap_options": { "color": "Orange" }, "name": "Lille", "description": "une ville" } }], "_umap_options": { "displayOnLoad": true, "name": "Cities", "id": 108, "remoteData": {}, "description": "A layer with some cities", "color": "Navy", "iconClass": "Drop", "smoothFactor": "1", "dashArray": "5,1", "fillOpacity": "0.5", "fillColor": "Blue", "fill": true } }, { "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "LineString", "coordinates": [ [1.7715, 50.9255], [1.6589, 50.9696], [1.4941, 51.0128], [1.4199, 51.0638], [1.2881, 51.1104] ] }, "properties": { "_umap_options": { "weight": "4" }, "name": "tunnel sous la Manche" } }], "_umap_options": { "displayOnLoad": true, "name": "Tunnels", "id": 109, "remoteData": {} } }]}'
submit = qs('.umap-upload input[type="button"]'); formatSelect.value = 'umap'
happen.click(submit); submit = qs('.umap-upload input[type="button"]')
assert.equal(Object.keys(this.map.datalayers).length, initialLayerCount + 2); happen.click(submit)
assert.equal(this.map.options.name, "Imported map"); assert.equal(Object.keys(this.map.datalayers).length, initialLayerCount + 2)
var foundFirstLayer = false; assert.equal(this.map.options.name, 'Imported map')
var foundSecondLayer = false; var foundFirstLayer = false
var foundSecondLayer = false
for (var idx in this.map.datalayers) { for (var idx in this.map.datalayers) {
var datalayer = this.map.datalayers[idx]; var datalayer = this.map.datalayers[idx]
if (datalayer.options.name === "Cities") { if (datalayer.options.name === 'Cities') {
foundFirstLayer = true; foundFirstLayer = true
assert.equal(datalayer._index.length, 2); assert.equal(datalayer._index.length, 2)
} }
if (datalayer.options.name === "Tunnels") { if (datalayer.options.name === 'Tunnels') {
foundSecondLayer = true; foundSecondLayer = true
assert.equal(datalayer._index.length, 1); assert.equal(datalayer._index.length, 1)
} }
} }
assert.equal(foundFirstLayer, true); assert.equal(foundFirstLayer, true)
assert.equal(foundSecondLayer, true); assert.equal(foundSecondLayer, true)
})
});
it('should only import options on the whitelist (umap format import)', function () { it('should only import options on the whitelist (umap format import)', function () {
assert.equal(this.map.options.umap_id, 99); assert.equal(this.map.options.umap_id, 99)
}); })
it('should update title bar (umap format import)', function () { it('should update title bar (umap format import)', function () {
var title = qs("#map div.umap-main-edit-toolbox h3 a.umap-click-to-edit"); var title = qs('#map div.umap-main-edit-toolbox h3 a.umap-click-to-edit')
assert.equal(title.innerHTML, "Imported map"); assert.equal(title.innerHTML, 'Imported map')
}); })
it('should reinitialize controls (umap format import)', function () { it('should reinitialize controls (umap format import)', function () {
var minimap = qs("#map div.leaflet-control-container div.leaflet-control-minimap"); var minimap = qs('#map div.leaflet-control-container div.leaflet-control-minimap')
assert.ok(minimap); assert.ok(minimap)
}); })
it('should update the tilelayer switcher control (umap format import)', function () { it('should update the tilelayer switcher control (umap format import)', function () {
//The tilelayer in the imported data isn't in the tilelayer list (set in _pre.js), there should be no selection on the tilelayer switcher //The tilelayer in the imported data isn't in the tilelayer list (set in _pre.js), there should be no selection on the tilelayer switcher
var selectedLayer = qs(".umap-tilelayer-switcher-container li.selected"); var selectedLayer = qs('.umap-tilelayer-switcher-container li.selected')
assert.equal(selectedLayer, null); assert.equal(selectedLayer, null)
}); })
it('should set the tilelayer (umap format import)', function () { it('should set the tilelayer (umap format import)', function () {
assert.equal(this.map.selected_tilelayer._url, "http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg"); assert.equal(
}); this.map.selected_tilelayer._url,
'http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg'
}); )
})
})
describe('#localizeUrl()', function () { describe('#localizeUrl()', function () {
it('should replace known variables', function () { it('should replace known variables', function () {
assert.equal(this.map.localizeUrl('http://example.org/{zoom}'), 'http://example.org/' + this.map.getZoom()); assert.equal(
}); this.map.localizeUrl('http://example.org/{zoom}'),
'http://example.org/' + this.map.getZoom()
)
})
it('should keep unknown variables', function () { it('should keep unknown variables', function () {
assert.equal(this.map.localizeUrl('http://example.org/{unkown}'), 'http://example.org/{unkown}'); assert.equal(
}); this.map.localizeUrl('http://example.org/{unkown}'),
'http://example.org/{unkown}'
}); )
})
})
}); })

View file

@ -1,82 +1,98 @@
describe('L.U.Marker', function () { describe('L.U.Marker', function () {
before(function () { before(function () {
this.server = sinon.fakeServer.create(); this.server = sinon.fakeServer.create()
var datalayer_response = JSON.parse(JSON.stringify(RESPONSES.datalayer62_GET)); // Copy. var datalayer_response = JSON.parse(JSON.stringify(RESPONSES.datalayer62_GET)) // Copy.
datalayer_response._umap_options.iconClass = 'Drop'; datalayer_response._umap_options.iconClass = 'Drop'
this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(datalayer_response)); this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(datalayer_response))
this.map = initMap({umap_id: 99}); this.map = initMap({ umap_id: 99 })
this.datalayer = this.map.getDataLayerByUmapId(62); this.datalayer = this.map.getDataLayerByUmapId(62)
this.server.respond(); this.server.respond()
}); })
after(function () { after(function () {
this.server.restore(); this.server.restore()
resetMap(); resetMap()
}); })
describe('#iconClassChange()', function () { describe('#iconClassChange()', function () {
it('should change icon class', function () { it('should change icon class', function () {
enableEdit(); enableEdit()
happen.click(qs('div.umap-drop-icon')); happen.click(qs('div.umap-drop-icon'))
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
changeSelectValue(qs('form#umap-feature-shape-properties .umap-field-iconClass select[name=iconClass]'), 'Circle'); changeSelectValue(
assert.notOk(qs('div.umap-drop-icon')); qs(
assert.ok(qs('div.umap-circle-icon')); 'form#umap-feature-shape-properties .umap-field-iconClass select[name=iconClass]'
happen.click(qs('form#umap-feature-shape-properties .umap-field-iconClass .undefine')); ),
assert.notOk(qs('div.umap-circle-icon')); 'Circle'
assert.ok(qs('div.umap-drop-icon')); )
clickCancel(); assert.notOk(qs('div.umap-drop-icon'))
}); assert.ok(qs('div.umap-circle-icon'))
happen.click(
}); qs('form#umap-feature-shape-properties .umap-field-iconClass .undefine')
)
assert.notOk(qs('div.umap-circle-icon'))
assert.ok(qs('div.umap-drop-icon'))
clickCancel()
})
})
describe('#iconSymbolChange()', function () { describe('#iconSymbolChange()', function () {
it('should change icon symbol', function () { it('should change icon symbol', function () {
enableEdit(); enableEdit()
happen.click(qs('div.umap-drop-icon')); happen.click(qs('div.umap-drop-icon'))
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
changeInputValue(qs('form#umap-feature-shape-properties .umap-field-iconUrl input[name=iconUrl]'), '1'); changeInputValue(
assert.equal(qs('div.umap-drop-icon span').textContent, '1'); qs(
changeInputValue(qs('form#umap-feature-shape-properties .umap-field-iconUrl input[name=iconUrl]'), '{name}'); 'form#umap-feature-shape-properties .umap-field-iconUrl input[name=iconUrl]'
assert.equal(qs('div.umap-drop-icon span').textContent, 'test'); ),
clickCancel(); '1'
}); )
assert.equal(qs('div.umap-drop-icon span').textContent, '1')
}); changeInputValue(
qs(
'form#umap-feature-shape-properties .umap-field-iconUrl input[name=iconUrl]'
),
'{name}'
)
assert.equal(qs('div.umap-drop-icon span').textContent, 'test')
clickCancel()
})
})
describe('#iconClassChange()', function () { describe('#iconClassChange()', function () {
it('should change icon class', function () { it('should change icon class', function () {
enableEdit(); enableEdit()
happen.click(qs('div.umap-drop-icon')); happen.click(qs('div.umap-drop-icon'))
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
changeSelectValue(qs('form#umap-feature-shape-properties .umap-field-iconClass select[name=iconClass]'), 'Circle'); changeSelectValue(
assert.notOk(qs('div.umap-drop-icon')); qs(
assert.ok(qs('div.umap-circle-icon')); 'form#umap-feature-shape-properties .umap-field-iconClass select[name=iconClass]'
happen.click(qs('form#umap-feature-shape-properties .umap-field-iconClass .undefine')); ),
assert.notOk(qs('div.umap-circle-icon')); 'Circle'
assert.ok(qs('div.umap-drop-icon')); )
clickCancel(); assert.notOk(qs('div.umap-drop-icon'))
}); assert.ok(qs('div.umap-circle-icon'))
happen.click(
}); qs('form#umap-feature-shape-properties .umap-field-iconClass .undefine')
)
assert.notOk(qs('div.umap-circle-icon'))
assert.ok(qs('div.umap-drop-icon'))
clickCancel()
})
})
describe('#clone', function () { describe('#clone', function () {
it('should clone marker', function () { it('should clone marker', function () {
var layer = new L.U.Marker(this.map, [10, 20], {datalayer: this.datalayer}).addTo(this.datalayer); var layer = new L.U.Marker(this.map, [10, 20], {
assert.equal(this.datalayer._index.length, 4); datalayer: this.datalayer,
other = layer.clone(); }).addTo(this.datalayer)
assert.ok(this.map.hasLayer(other)); assert.equal(this.datalayer._index.length, 4)
assert.equal(this.datalayer._index.length, 5); other = layer.clone()
assert.ok(this.map.hasLayer(other))
assert.equal(this.datalayer._index.length, 5)
// Must not be the same reference // Must not be the same reference
assert.notEqual(layer._latlng, other._latlng); assert.notEqual(layer._latlng, other._latlng)
assert.equal(L.Util.formatNum(layer._latlng.lat), other._latlng.lat); assert.equal(L.Util.formatNum(layer._latlng.lat), other._latlng.lat)
assert.equal(L.Util.formatNum(layer._latlng.lng), other._latlng.lng); assert.equal(L.Util.formatNum(layer._latlng.lng), other._latlng.lng)
}); })
})
}); })
});

View file

@ -1,77 +1,76 @@
describe('L.Permissions', function () { describe('L.Permissions', function () {
var path = '/map/99/datalayer/edit/62/'; var path = '/map/99/datalayer/edit/62/'
before(function () { before(function () {
this.server = sinon.fakeServer.create(); this.server = sinon.fakeServer.create()
this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET)); this.server.respondWith(
this.map = initMap({umap_id: 99}); 'GET',
this.datalayer = this.map.getDataLayerByUmapId(62); '/datalayer/62/',
this.server.respond(); JSON.stringify(RESPONSES.datalayer62_GET)
enableEdit(); )
}); this.map = initMap({ umap_id: 99 })
this.datalayer = this.map.getDataLayerByUmapId(62)
this.server.respond()
enableEdit()
})
after(function () { after(function () {
clickCancel(); clickCancel()
this.server.restore(); this.server.restore()
resetMap(); resetMap()
}); })
describe('#open()', function () { describe('#open()', function () {
var button; var button
it('should exist update permissions link', function () { it('should exist update permissions link', function () {
button = qs('a.update-map-permissions'); button = qs('a.update-map-permissions')
expect(button).to.be.ok; expect(button).to.be.ok
}); })
it('should open table button click', function () { it('should open table button click', function () {
happen.click(button); happen.click(button)
expect(qs('.permissions-panel')).to.be.ok; expect(qs('.permissions-panel')).to.be.ok
}); })
})
});
describe('#anonymous with cookie', function () { describe('#anonymous with cookie', function () {
var button; var button
it('should only allow edit_status', function () { it('should only allow edit_status', function () {
this.map.permissions.options.anonymous_edit_url = 'http://anonymous.url'; this.map.permissions.options.anonymous_edit_url = 'http://anonymous.url'
button = qs('a.update-map-permissions'); button = qs('a.update-map-permissions')
happen.click(button); happen.click(button)
expect(qs('select[name="edit_status"]')).to.be.ok; expect(qs('select[name="edit_status"]')).to.be.ok
expect(qs('select[name="share_status"]')).not.to.be.ok; expect(qs('select[name="share_status"]')).not.to.be.ok
expect(qs('input.edit-owner')).not.to.be.ok; expect(qs('input.edit-owner')).not.to.be.ok
}); })
})
});
describe('#editor', function () { describe('#editor', function () {
var button; var button
it('should only allow editors', function () { it('should only allow editors', function () {
this.map.permissions.options.owner = {id: 1, url: '/url', name: 'jojo'}; this.map.permissions.options.owner = { id: 1, url: '/url', name: 'jojo' }
button = qs('a.update-map-permissions'); button = qs('a.update-map-permissions')
happen.click(button); happen.click(button)
expect(qs('select[name="edit_status"]')).not.to.be.ok; expect(qs('select[name="edit_status"]')).not.to.be.ok
expect(qs('select[name="share_status"]')).not.to.be.ok; expect(qs('select[name="share_status"]')).not.to.be.ok
expect(qs('input.edit-owner')).not.to.be.ok; expect(qs('input.edit-owner')).not.to.be.ok
expect(qs('input.edit-editors')).to.be.ok; expect(qs('input.edit-editors')).to.be.ok
}); })
})
});
describe('#owner', function () { describe('#owner', function () {
var button; var button
it('should allow everything', function () { it('should allow everything', function () {
this.map.permissions.options.owner = {id: 1, url: '/url', name: 'jojo'}; this.map.permissions.options.owner = { id: 1, url: '/url', name: 'jojo' }
this.map.options.user = {id: 1, url: '/url', name: 'jojo'}; this.map.options.user = { id: 1, url: '/url', name: 'jojo' }
button = qs('a.update-map-permissions'); button = qs('a.update-map-permissions')
happen.click(button); happen.click(button)
expect(qs('select[name="edit_status"]')).to.be.ok; expect(qs('select[name="edit_status"]')).to.be.ok
expect(qs('select[name="share_status"]')).to.be.ok; expect(qs('select[name="share_status"]')).to.be.ok
expect(qs('input.edit-owner')).to.be.ok; expect(qs('input.edit-owner')).to.be.ok
expect(qs('input.edit-editors')).to.be.ok; expect(qs('input.edit-editors')).to.be.ok
}); })
})
}); })
});

View file

@ -1,288 +1,367 @@
describe('L.U.Polygon', function () { describe('L.U.Polygon', function () {
var p2ll, map; var p2ll, map
before(function () { before(function () {
this.map = map = initMap({umap_id: 99}); this.map = map = initMap({ umap_id: 99 })
enableEdit(); enableEdit()
p2ll = function (x, y) { p2ll = function (x, y) {
return map.containerPointToLatLng([x, y]); return map.containerPointToLatLng([x, y])
}; }
this.datalayer = this.map.createDataLayer(); this.datalayer = this.map.createDataLayer()
this.datalayer.connectToMap();; this.datalayer.connectToMap()
}); })
after(function () { after(function () {
clickCancel(); clickCancel()
resetMap(); resetMap()
}); })
afterEach(function () { afterEach(function () {
this.datalayer.empty(); this.datalayer.empty()
}); })
describe('#isMulti()', function () { describe('#isMulti()', function () {
it('should return false for basic Polygon', function () { it('should return false for basic Polygon', function () {
var layer = new L.U.Polygon(this.map, [[1, 2], [3, 4], [5, 6]], {datalayer: this.datalayer}); var layer = new L.U.Polygon(
this.map,
[
[1, 2],
[3, 4],
[5, 6],
],
{ datalayer: this.datalayer }
)
assert.notOk(layer.isMulti()) assert.notOk(layer.isMulti())
}); })
it('should return false for nested basic Polygon', function () { it('should return false for nested basic Polygon', function () {
var latlngs = [ var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]] layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer })
],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer});
assert.notOk(layer.isMulti()) assert.notOk(layer.isMulti())
}); })
it('should return false for simple Polygon with hole', function () { it('should return false for simple Polygon with hole', function () {
var layer = new L.U.Polygon(this.map, [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]], {datalayer: this.datalayer}); var layer = new L.U.Polygon(
this.map,
[
[
[1, 2],
[3, 4],
[5, 6],
],
[
[7, 8],
[9, 10],
[11, 12],
],
],
{ datalayer: this.datalayer }
)
assert.notOk(layer.isMulti()) assert.notOk(layer.isMulti())
}); })
it('should return true for multi Polygon', function () { it('should return true for multi Polygon', function () {
var latLngs = [ var latLngs = [
[ [
[[1, 2], [3, 4], [5, 6]] [
[1, 2],
[3, 4],
[5, 6],
],
], ],
[ [
[[7, 8], [9, 10], [11, 12]] [
[7, 8],
[9, 10],
[11, 12],
],
],
] ]
]; var layer = new L.U.Polygon(this.map, latLngs, { datalayer: this.datalayer })
var layer = new L.U.Polygon(this.map, latLngs, {datalayer: this.datalayer});
assert.ok(layer.isMulti()) assert.ok(layer.isMulti())
}); })
it('should return true for multi Polygon with hole', function () { it('should return true for multi Polygon with hole', function () {
var latLngs = [ var latLngs = [
[[[10, 20], [30, 40], [50, 60]]], [
[[[0, 10], [10, 10], [10, 0]], [[2, 3], [2, 4], [3, 4]]] [
]; [10, 20],
var layer = new L.U.Polygon(this.map, latLngs, {datalayer: this.datalayer}); [30, 40],
[50, 60],
],
],
[
[
[0, 10],
[10, 10],
[10, 0],
],
[
[2, 3],
[2, 4],
[3, 4],
],
],
]
var layer = new L.U.Polygon(this.map, latLngs, { datalayer: this.datalayer })
assert.ok(layer.isMulti()) assert.ok(layer.isMulti())
}); })
})
});
describe('#contextmenu', function () { describe('#contextmenu', function () {
afterEach(function () { afterEach(function () {
// Make sure contextmenu is hidden // Make sure contextmenu is hidden
happen.once(document, {type: 'keydown', keyCode: 27}); happen.once(document, { type: 'keydown', keyCode: 27 })
}); })
describe('#in edit mode', function () { describe('#in edit mode', function () {
it('should allow to remove shape when multi', function () { it('should allow to remove shape when multi', function () {
var latlngs = [ var latlngs = [
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]],
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]] [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polygon(this.map, latlngs, {
happen.once(layer._path, {type: 'contextmenu'}); datalayer: this.datalayer,
assert.equal(qst('Remove shape from the multi'), 1); }).addTo(this.datalayer)
}); happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Remove shape from the multi'), 1)
})
it('should not allow to remove shape when not multi', function () { it('should not allow to remove shape when not multi', function () {
var latlngs = [ var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]] layer = new L.U.Polygon(this.map, latlngs, {
], datalayer: this.datalayer,
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); }).addTo(this.datalayer)
happen.once(layer._path, {type: 'contextmenu'}); happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Remove shape from the multi')); assert.notOk(qst('Remove shape from the multi'))
}); })
it('should not allow to isolate shape when not multi', function () { it('should not allow to isolate shape when not multi', function () {
var latlngs = [ var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]] layer = new L.U.Polygon(this.map, latlngs, {
], datalayer: this.datalayer,
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); }).addTo(this.datalayer)
happen.once(layer._path, {type: 'contextmenu'}); happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Extract shape to separate feature')); assert.notOk(qst('Extract shape to separate feature'))
}); })
it('should allow to isolate shape when multi', function () { it('should allow to isolate shape when multi', function () {
var latlngs = [ var latlngs = [
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]],
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]] [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polygon(this.map, latlngs, {
happen.once(layer._path, {type: 'contextmenu'}); datalayer: this.datalayer,
assert.ok(qst('Extract shape to separate feature')); }).addTo(this.datalayer)
}); happen.once(layer._path, { type: 'contextmenu' })
assert.ok(qst('Extract shape to separate feature'))
})
it('should not allow to transform to lines when multi', function () { it('should not allow to transform to lines when multi', function () {
var latlngs = [ var latlngs = [
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]],
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]] [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polygon(this.map, latlngs, {
happen.once(layer._path, {type: 'contextmenu'}); datalayer: this.datalayer,
assert.notOk(qst('Transform to lines')); }).addTo(this.datalayer)
}); happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Transform to lines'))
})
it('should not allow to transform to lines when hole', function () { it('should not allow to transform to lines when hole', function () {
var latlngs = [ var latlngs = [
[ [
[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)], [p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)],
[p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)] [p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)],
]
], ],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); ],
happen.once(layer._path, {type: 'contextmenu'}); layer = new L.U.Polygon(this.map, latlngs, {
assert.notOk(qst('Transform to lines')); datalayer: this.datalayer,
}); }).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Transform to lines'))
})
it('should allow to transform to lines when not multi', function () { it('should allow to transform to lines when not multi', function () {
var latlngs = [ var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]]
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]] new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
]; this.datalayer
new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); )
happen.at('contextmenu', 150, 150); happen.at('contextmenu', 150, 150)
assert.equal(qst('Transform to lines'), 1); assert.equal(qst('Transform to lines'), 1)
}); })
it('should not allow to transfer shape when not editedFeature', function () { it('should not allow to transfer shape when not editedFeature', function () {
new L.U.Polygon(this.map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], {datalayer: this.datalayer}).addTo(this.datalayer); new L.U.Polygon(this.map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], {
happen.at('contextmenu', 110, 160); datalayer: this.datalayer,
assert.equal(qst('Delete this feature'), 1); // Make sure we have right clicked on the polygon. }).addTo(this.datalayer)
assert.notOk(qst('Transfer shape to edited feature')); happen.at('contextmenu', 110, 160)
}); assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon.
assert.notOk(qst('Transfer shape to edited feature'))
})
it('should not allow to transfer shape when editedFeature is not a polygon', function () { it('should not allow to transfer shape when editedFeature is not a polygon', function () {
var layer = new L.U.Polygon(this.map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], {datalayer: this.datalayer}).addTo(this.datalayer), var layer = new L.U.Polygon(
other = new L.U.Polyline(this.map, [p2ll(200, 250), p2ll(200, 300)], {datalayer: this.datalayer}).addTo(this.datalayer); this.map,
other.edit(); [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)],
happen.once(layer._path, {type: 'contextmenu'}); { datalayer: this.datalayer }
assert.equal(qst('Delete this feature'), 1); // Make sure we have right clicked on the polygon. ).addTo(this.datalayer),
assert.notOk(qst('Transfer shape to edited feature')); other = new L.U.Polyline(this.map, [p2ll(200, 250), p2ll(200, 300)], {
}); datalayer: this.datalayer,
}).addTo(this.datalayer)
other.edit()
happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon.
assert.notOk(qst('Transfer shape to edited feature'))
})
it('should allow to transfer shape when another polygon is edited', function (done) { it('should allow to transfer shape when another polygon is edited', function (done) {
this.datalayer.empty(); this.datalayer.empty()
var layer = new L.U.Polygon(this.map, [p2ll(200, 300), p2ll(300, 200), p2ll(200, 100)], {datalayer: this.datalayer}).addTo(this.datalayer); var layer = new L.U.Polygon(
layer.edit(); // This moves the map to put "other" at the center. this.map,
var other = new L.U.Polygon(this.map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], {datalayer: this.datalayer}).addTo(this.datalayer); [p2ll(200, 300), p2ll(300, 200), p2ll(200, 100)],
happen.once(other._path, {type: 'contextmenu'}); { datalayer: this.datalayer }
assert.equal(qst('Transfer shape to edited feature'), 1); ).addTo(this.datalayer)
done(); layer.edit() // This moves the map to put "other" at the center.
}); var other = new L.U.Polygon(
this.map,
}); [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)],
{ datalayer: this.datalayer }
}); ).addTo(this.datalayer)
happen.once(other._path, { type: 'contextmenu' })
assert.equal(qst('Transfer shape to edited feature'), 1)
done()
})
})
})
describe('#addShape', function () { describe('#addShape', function () {
it('"add shape" control should not be visible by default', function () { it('"add shape" control should not be visible by default', function () {
assert.notOk(qs('.umap-draw-polygon-multi')); assert.notOk(qs('.umap-draw-polygon-multi'))
}); })
it('"add shape" control should be visible when editing a Polygon', function () { it('"add shape" control should be visible when editing a Polygon', function () {
var layer = new L.U.Polygon(this.map, [p2ll(100, 100), p2ll(100, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); var layer = new L.U.Polygon(this.map, [p2ll(100, 100), p2ll(100, 200)], {
layer.edit(); datalayer: this.datalayer,
assert.ok(qs('.umap-draw-polygon-multi')); }).addTo(this.datalayer)
}); layer.edit()
assert.ok(qs('.umap-draw-polygon-multi'))
})
it('"add shape" control should extend the same multi', function () { it('"add shape" control should extend the same multi', function () {
var layer = new L.U.Polygon(this.map, [p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)], {datalayer: this.datalayer}).addTo(this.datalayer); var layer = new L.U.Polygon(
layer.edit(); this.map,
assert.notOk(layer.isMulti()); [p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)],
happen.click(qs('.umap-draw-polygon-multi')); { datalayer: this.datalayer }
happen.at('mousemove', 300, 300); ).addTo(this.datalayer)
happen.at('click', 300, 300); layer.edit()
happen.at('mousemove', 350, 300); assert.notOk(layer.isMulti())
happen.at('click', 350, 300); happen.click(qs('.umap-draw-polygon-multi'))
happen.at('click', 350, 300); happen.at('mousemove', 300, 300)
assert.ok(layer.isMulti()); happen.at('click', 300, 300)
assert.equal(this.datalayer._index.length, 1); happen.at('mousemove', 350, 300)
}); happen.at('click', 350, 300)
happen.at('click', 350, 300)
}); assert.ok(layer.isMulti())
assert.equal(this.datalayer._index.length, 1)
})
})
describe('#transferShape', function () { describe('#transferShape', function () {
it('should transfer simple polygon shape to another polygon', function () { it('should transfer simple polygon shape to another polygon', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer), layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
other = new L.U.Polygon(this.map, [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); this.datalayer
assert.ok(this.map.hasLayer(layer)); ),
layer.transferShape(p2ll(150, 150), other); other = new L.U.Polygon(
assert.equal(other._latlngs.length, 2); this.map,
assert.deepEqual(other._latlngs[1][0], latlngs); [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)],
assert.notOk(this.map.hasLayer(layer)); { datalayer: this.datalayer }
}); ).addTo(this.datalayer)
assert.ok(this.map.hasLayer(layer))
layer.transferShape(p2ll(150, 150), other)
assert.equal(other._latlngs.length, 2)
assert.deepEqual(other._latlngs[1][0], latlngs)
assert.notOk(this.map.hasLayer(layer))
})
it('should transfer multipolygon shape to another polygon', function () { it('should transfer multipolygon shape to another polygon', function () {
var latlngs = [ var latlngs = [
[ [
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)] [p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)],
], ],
[[p2ll(200, 300), p2ll(300, 200)]] [[p2ll(200, 300), p2ll(300, 200)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer), layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
other = new L.U.Polygon(this.map, [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); this.datalayer
assert.ok(this.map.hasLayer(layer)); ),
layer.transferShape(p2ll(150, 150), other); other = new L.U.Polygon(
assert.equal(other._latlngs.length, 2); this.map,
assert.deepEqual(other._latlngs[1][0], latlngs[0][0]); [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)],
assert.ok(this.map.hasLayer(layer)); { datalayer: this.datalayer }
assert.equal(layer._latlngs.length, 1); ).addTo(this.datalayer)
}); assert.ok(this.map.hasLayer(layer))
layer.transferShape(p2ll(150, 150), other)
}); assert.equal(other._latlngs.length, 2)
assert.deepEqual(other._latlngs[1][0], latlngs[0][0])
assert.ok(this.map.hasLayer(layer))
assert.equal(layer._latlngs.length, 1)
})
})
describe('#isolateShape', function () { describe('#isolateShape', function () {
it('should not allow to isolate simple polygon', function () { it('should not allow to isolate simple polygon', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
assert.equal(this.datalayer._index.length, 1); this.datalayer
assert.ok(this.map.hasLayer(layer)); )
layer.isolateShape(p2ll(150, 150)); assert.equal(this.datalayer._index.length, 1)
assert.equal(layer._latlngs[0].length, 3); assert.ok(this.map.hasLayer(layer))
assert.equal(this.datalayer._index.length, 1); layer.isolateShape(p2ll(150, 150))
}); assert.equal(layer._latlngs[0].length, 3)
assert.equal(this.datalayer._index.length, 1)
})
it('should isolate multipolygon shape', function () { it('should isolate multipolygon shape', function () {
var latlngs = [ var latlngs = [
[ [
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)] [p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)],
], ],
[[p2ll(200, 300), p2ll(300, 200)]] [[p2ll(200, 300), p2ll(300, 200)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
assert.equal(this.datalayer._index.length, 1); this.datalayer
assert.ok(this.map.hasLayer(layer)); )
var other = layer.isolateShape(p2ll(150, 150)); assert.equal(this.datalayer._index.length, 1)
assert.equal(this.datalayer._index.length, 2); assert.ok(this.map.hasLayer(layer))
assert.equal(other._latlngs.length, 2); var other = layer.isolateShape(p2ll(150, 150))
assert.deepEqual(other._latlngs[0], latlngs[0][0]); assert.equal(this.datalayer._index.length, 2)
assert.ok(this.map.hasLayer(layer)); assert.equal(other._latlngs.length, 2)
assert.ok(this.map.hasLayer(other)); assert.deepEqual(other._latlngs[0], latlngs[0][0])
assert.equal(layer._latlngs.length, 1); assert.ok(this.map.hasLayer(layer))
other.remove(); assert.ok(this.map.hasLayer(other))
}); assert.equal(layer._latlngs.length, 1)
other.remove()
}); })
})
describe('#clone', function () { describe('#clone', function () {
it('should clone polygon', function () { it('should clone polygon', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
assert.equal(this.datalayer._index.length, 1); this.datalayer
other = layer.clone(); )
assert.ok(this.map.hasLayer(other)); assert.equal(this.datalayer._index.length, 1)
assert.equal(this.datalayer._index.length, 2); other = layer.clone()
assert.ok(this.map.hasLayer(other))
assert.equal(this.datalayer._index.length, 2)
// Must not be the same reference // Must not be the same reference
assert.notEqual(layer._latlngs, other._latlngs); assert.notEqual(layer._latlngs, other._latlngs)
assert.equal(L.Util.formatNum(layer._latlngs[0][0].lat), other._latlngs[0][0].lat); assert.equal(L.Util.formatNum(layer._latlngs[0][0].lat), other._latlngs[0][0].lat)
assert.equal(L.Util.formatNum(layer._latlngs[0][0].lng), other._latlngs[0][0].lng); assert.equal(L.Util.formatNum(layer._latlngs[0][0].lng), other._latlngs[0][0].lng)
}); })
})
}); })
});

View file

@ -1,326 +1,400 @@
describe('L.Utorage.Polyline', function () { describe('L.Utorage.Polyline', function () {
var p2ll, map; var p2ll, map
before(function () { before(function () {
this.map = map = initMap({umap_id: 99}); this.map = map = initMap({ umap_id: 99 })
enableEdit(); enableEdit()
p2ll = function (x, y) { p2ll = function (x, y) {
return map.containerPointToLatLng([x, y]); return map.containerPointToLatLng([x, y])
}; }
this.datalayer = this.map.createDataLayer(); this.datalayer = this.map.createDataLayer()
this.datalayer.connectToMap();; this.datalayer.connectToMap()
}); })
after(function () { after(function () {
clickCancel(); clickCancel()
resetMap(); resetMap()
}); })
afterEach(function () { afterEach(function () {
this.datalayer.empty(); this.datalayer.empty()
}); })
describe('#isMulti()', function () { describe('#isMulti()', function () {
it('should return false for basic Polyline', function () { it('should return false for basic Polyline', function () {
var layer = new L.U.Polyline(this.map, [[1, 2], [3, 4], [5, 6]], {datalayer: this.datalayer}); var layer = new L.U.Polyline(
this.map,
[
[1, 2],
[3, 4],
[5, 6],
],
{ datalayer: this.datalayer }
)
assert.notOk(layer.isMulti()) assert.notOk(layer.isMulti())
}); })
it('should return false for nested basic Polyline', function () { it('should return false for nested basic Polyline', function () {
var layer = new L.U.Polyline(this.map, [[[1, 2], [3, 4], [5, 6]]], {datalayer: this.datalayer}); var layer = new L.U.Polyline(
this.map,
[
[
[1, 2],
[3, 4],
[5, 6],
],
],
{ datalayer: this.datalayer }
)
assert.notOk(layer.isMulti()) assert.notOk(layer.isMulti())
}); })
it('should return true for multi Polyline', function () { it('should return true for multi Polyline', function () {
var latLngs = [ var latLngs = [
[ [
[[1, 2], [3, 4], [5, 6]] [
[1, 2],
[3, 4],
[5, 6],
],
], ],
[ [
[[7, 8], [9, 10], [11, 12]] [
[7, 8],
[9, 10],
[11, 12],
],
],
] ]
]; var layer = new L.U.Polyline(this.map, latLngs, { datalayer: this.datalayer })
var layer = new L.U.Polyline(this.map, latLngs, {datalayer: this.datalayer});
assert.ok(layer.isMulti()) assert.ok(layer.isMulti())
}); })
})
});
describe('#contextmenu', function () { describe('#contextmenu', function () {
afterEach(function () { afterEach(function () {
// Make sure contextmenu is hidden. // Make sure contextmenu is hidden.
happen.once(document, {type: 'keydown', keyCode: 27}); happen.once(document, { type: 'keydown', keyCode: 27 })
}); })
describe('#in edit mode', function () { describe('#in edit mode', function () {
it('should allow to remove shape when multi', function () { it('should allow to remove shape when multi', function () {
var latlngs = [ var latlngs = [
[p2ll(100, 100), p2ll(100, 200)], [p2ll(100, 100), p2ll(100, 200)],
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] [p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)],
], ],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polyline(this.map, latlngs, {
datalayer: this.datalayer,
}).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Remove shape from the multi'), 1); assert.equal(qst('Remove shape from the multi'), 1)
}); })
it('should not allow to remove shape when not multi', function () { it('should not allow to remove shape when not multi', function () {
var latlngs = [ var latlngs = [[p2ll(100, 100), p2ll(100, 200)]],
[p2ll(100, 100), p2ll(100, 200)] layer = new L.U.Polyline(this.map, latlngs, {
], datalayer: this.datalayer,
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); }).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Remove shape from the multi')); assert.notOk(qst('Remove shape from the multi'))
}); })
it('should not allow to isolate shape when not multi', function () { it('should not allow to isolate shape when not multi', function () {
var latlngs = [ var latlngs = [[p2ll(100, 100), p2ll(100, 200)]],
[p2ll(100, 100), p2ll(100, 200)] layer = new L.U.Polyline(this.map, latlngs, {
], datalayer: this.datalayer,
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); }).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Extract shape to separate feature')); assert.notOk(qst('Extract shape to separate feature'))
}); })
it('should allow to isolate shape when multi', function () { it('should allow to isolate shape when multi', function () {
var latlngs = [ var latlngs = [
[p2ll(100, 150), p2ll(100, 200)], [p2ll(100, 150), p2ll(100, 200)],
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] [p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)],
], ],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polyline(this.map, latlngs, {
happen.once(layer._path, {type: 'contextmenu'}); datalayer: this.datalayer,
assert.ok(qst('Extract shape to separate feature')); }).addTo(this.datalayer)
}); happen.once(layer._path, { type: 'contextmenu' })
assert.ok(qst('Extract shape to separate feature'))
})
it('should not allow to transform to polygon when multi', function () { it('should not allow to transform to polygon when multi', function () {
var latlngs = [ var latlngs = [
[p2ll(100, 150), p2ll(100, 200)], [p2ll(100, 150), p2ll(100, 200)],
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] [p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)],
], ],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polyline(this.map, latlngs, {
happen.once(layer._path, {type: 'contextmenu'}); datalayer: this.datalayer,
assert.notOk(qst('Transform to polygon')); }).addTo(this.datalayer)
}); happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Transform to polygon'))
})
it('should allow to transform to polygon when not multi', function () { it('should allow to transform to polygon when not multi', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polyline(this.map, latlngs, {
happen.once(layer._path, {type: 'contextmenu'}); datalayer: this.datalayer,
assert.equal(qst('Transform to polygon'), 1); }).addTo(this.datalayer)
}); happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Transform to polygon'), 1)
})
it('should not allow to transfer shape when not editedFeature', function () { it('should not allow to transfer shape when not editedFeature', function () {
var layer = new L.U.Polyline(this.map, [p2ll(100, 150), p2ll(100, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); var layer = new L.U.Polyline(this.map, [p2ll(100, 150), p2ll(100, 200)], {
happen.once(layer._path, {type: 'contextmenu'}); datalayer: this.datalayer,
assert.notOk(qst('Transfer shape to edited feature')); }).addTo(this.datalayer)
}); happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Transfer shape to edited feature'))
})
it('should not allow to transfer shape when editedFeature is not a line', function () { it('should not allow to transfer shape when editedFeature is not a line', function () {
var layer = new L.U.Polyline(this.map, [p2ll(100, 150), p2ll(100, 200)], {datalayer: this.datalayer}).addTo(this.datalayer), var layer = new L.U.Polyline(this.map, [p2ll(100, 150), p2ll(100, 200)], {
other = new L.U.Polygon(this.map, [p2ll(200, 300), p2ll(300, 200), p2ll(200, 100)], {datalayer: this.datalayer}).addTo(this.datalayer); datalayer: this.datalayer,
other.edit(); }).addTo(this.datalayer),
happen.once(layer._path, {type: 'contextmenu'}); other = new L.U.Polygon(
assert.notOk(qst('Transfer shape to edited feature')); this.map,
}); [p2ll(200, 300), p2ll(300, 200), p2ll(200, 100)],
{ datalayer: this.datalayer }
).addTo(this.datalayer)
other.edit()
happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Transfer shape to edited feature'))
})
it('should allow to transfer shape when another line is edited', function () { it('should allow to transfer shape when another line is edited', function () {
var layer = new L.U.Polyline(this.map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], {datalayer: this.datalayer}).addTo(this.datalayer), var layer = new L.U.Polyline(
other = new L.U.Polyline(this.map, [p2ll(200, 300), p2ll(300, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); this.map,
other.edit(); [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
happen.once(layer._path, {type: 'contextmenu'}); { datalayer: this.datalayer }
assert.equal(qst('Transfer shape to edited feature'), 1); ).addTo(this.datalayer),
}); other = new L.U.Polyline(this.map, [p2ll(200, 300), p2ll(300, 200)], {
datalayer: this.datalayer,
}).addTo(this.datalayer)
other.edit()
happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Transfer shape to edited feature'), 1)
})
it('should allow to merge lines when multi', function () { it('should allow to merge lines when multi', function () {
var latlngs = [ var latlngs = [
[p2ll(100, 100), p2ll(100, 200)], [p2ll(100, 100), p2ll(100, 200)],
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] [p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)],
], ],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polyline(this.map, latlngs, {
datalayer: this.datalayer,
}).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Merge lines'), 1); assert.equal(qst('Merge lines'), 1)
}); })
it('should not allow to merge lines when not multi', function () { it('should not allow to merge lines when not multi', function () {
var latlngs = [ var latlngs = [[p2ll(100, 100), p2ll(100, 200)]],
[p2ll(100, 100), p2ll(100, 200)] layer = new L.U.Polyline(this.map, latlngs, {
], datalayer: this.datalayer,
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); }).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Merge lines')); assert.notOk(qst('Merge lines'))
}); })
it('should allow to split lines when clicking on vertex', function () { it('should allow to split lines when clicking on vertex', function () {
var latlngs = [ var latlngs = [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] layer = new L.U.Polyline(this.map, latlngs, {
], datalayer: this.datalayer,
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); }).addTo(this.datalayer)
layer.enableEdit(); layer.enableEdit()
happen.at('contextmenu', 350, 400); happen.at('contextmenu', 350, 400)
assert.equal(qst('Split line'), 1); assert.equal(qst('Split line'), 1)
}); })
it('should not allow to split lines when clicking on first vertex', function () { it('should not allow to split lines when clicking on first vertex', function () {
var latlngs = [ var latlngs = [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] layer = new L.U.Polyline(this.map, latlngs, {
], datalayer: this.datalayer,
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); }).addTo(this.datalayer)
layer.enableEdit(); layer.enableEdit()
happen.at('contextmenu', 300, 350); happen.at('contextmenu', 300, 350)
assert.equal(qst('Delete this feature'), 1); // Make sure we have clicked on the vertex. assert.equal(qst('Delete this feature'), 1) // Make sure we have clicked on the vertex.
assert.notOk(qst('Split line')); assert.notOk(qst('Split line'))
}); })
it('should not allow to split lines when clicking on last vertex', function () { it('should not allow to split lines when clicking on last vertex', function () {
var latlngs = [ var latlngs = [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] layer = new L.U.Polyline(this.map, latlngs, {
], datalayer: this.datalayer,
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); }).addTo(this.datalayer)
layer.enableEdit(); layer.enableEdit()
happen.at('contextmenu', 400, 300); happen.at('contextmenu', 400, 300)
assert.equal(qst('Delete this feature'), 1); // Make sure we have clicked on the vertex. assert.equal(qst('Delete this feature'), 1) // Make sure we have clicked on the vertex.
assert.notOk(qst('Split line')); assert.notOk(qst('Split line'))
}); })
})
}); })
});
describe('#addShape', function () { describe('#addShape', function () {
it('"add shape" control should not be visible by default', function () { it('"add shape" control should not be visible by default', function () {
assert.notOk(qs('.umap-draw-polyline-multi')); assert.notOk(qs('.umap-draw-polyline-multi'))
}); })
it('"add shape" control should be visible when editing a Polyline', function () { it('"add shape" control should be visible when editing a Polyline', function () {
var layer = new L.U.Polyline(this.map, [p2ll(100, 100), p2ll(100, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); var layer = new L.U.Polyline(this.map, [p2ll(100, 100), p2ll(100, 200)], {
layer.edit(); datalayer: this.datalayer,
assert.ok(qs('.umap-draw-polyline-multi')); }).addTo(this.datalayer)
}); layer.edit()
assert.ok(qs('.umap-draw-polyline-multi'))
})
it('"add shape" control should extend the same multi', function () { it('"add shape" control should extend the same multi', function () {
var layer = new L.U.Polyline(this.map, [p2ll(100, 100), p2ll(100, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); var layer = new L.U.Polyline(this.map, [p2ll(100, 100), p2ll(100, 200)], {
layer.edit(); datalayer: this.datalayer,
assert.notOk(layer.isMulti()); }).addTo(this.datalayer)
happen.click(qs('.umap-draw-polyline-multi')); layer.edit()
happen.at('mousemove', 300, 300); assert.notOk(layer.isMulti())
happen.at('click', 300, 300); happen.click(qs('.umap-draw-polyline-multi'))
happen.at('mousemove', 350, 300); happen.at('mousemove', 300, 300)
happen.at('click', 350, 300); happen.at('click', 300, 300)
happen.at('click', 350, 300); happen.at('mousemove', 350, 300)
assert.ok(layer.isMulti()); happen.at('click', 350, 300)
assert.equal(this.datalayer._index.length, 1); happen.at('click', 350, 300)
}); assert.ok(layer.isMulti())
assert.equal(this.datalayer._index.length, 1)
}); })
})
describe('#transferShape', function () { describe('#transferShape', function () {
it('should transfer simple line shape to another line', function () { it('should transfer simple line shape to another line', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer), layer = new L.U.Polyline(this.map, latlngs, {
other = new L.U.Polyline(this.map, [p2ll(200, 300), p2ll(300, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); datalayer: this.datalayer,
assert.ok(this.map.hasLayer(layer)); }).addTo(this.datalayer),
layer.transferShape(p2ll(150, 150), other); other = new L.U.Polyline(this.map, [p2ll(200, 300), p2ll(300, 200)], {
assert.equal(other._latlngs.length, 2); datalayer: this.datalayer,
assert.deepEqual(other._latlngs[1], latlngs); }).addTo(this.datalayer)
assert.notOk(this.map.hasLayer(layer)); assert.ok(this.map.hasLayer(layer))
}); layer.transferShape(p2ll(150, 150), other)
assert.equal(other._latlngs.length, 2)
assert.deepEqual(other._latlngs[1], latlngs)
assert.notOk(this.map.hasLayer(layer))
})
it('should transfer multi line shape to another line', function () { it('should transfer multi line shape to another line', function () {
var latlngs = [ var latlngs = [
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[p2ll(200, 300), p2ll(300, 200)] [p2ll(200, 300), p2ll(300, 200)],
], ],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer), layer = new L.U.Polyline(this.map, latlngs, {
other = new L.U.Polyline(this.map, [p2ll(250, 300), p2ll(350, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); datalayer: this.datalayer,
assert.ok(this.map.hasLayer(layer)); }).addTo(this.datalayer),
layer.transferShape(p2ll(150, 150), other); other = new L.U.Polyline(this.map, [p2ll(250, 300), p2ll(350, 200)], {
assert.equal(other._latlngs.length, 2); datalayer: this.datalayer,
assert.deepEqual(other._latlngs[1], latlngs[0]); }).addTo(this.datalayer)
assert.ok(this.map.hasLayer(layer)); assert.ok(this.map.hasLayer(layer))
assert.equal(layer._latlngs.length, 1); layer.transferShape(p2ll(150, 150), other)
}); assert.equal(other._latlngs.length, 2)
assert.deepEqual(other._latlngs[1], latlngs[0])
}); assert.ok(this.map.hasLayer(layer))
assert.equal(layer._latlngs.length, 1)
})
})
describe('#mergeShapes', function () { describe('#mergeShapes', function () {
it('should remove duplicated join point when merging', function () { it('should remove duplicated join point when merging', function () {
var latlngs = [ var latlngs = [
[[0, 0], [0, 1]], [
[[0, 1], [0, 2]], [0, 0],
[0, 1],
], ],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); [
layer.mergeShapes(); [0, 1],
layer.disableEdit(); // Remove vertex from latlngs to compare them. [0, 2],
assert.deepEqual(layer.getLatLngs(), [L.latLng([0, 0]), L.latLng([0, 1]), L.latLng([0, 2])]); ],
assert(this.map.isDirty); ],
}); layer = new L.U.Polyline(this.map, latlngs, {
datalayer: this.datalayer,
}).addTo(this.datalayer)
layer.mergeShapes()
layer.disableEdit() // Remove vertex from latlngs to compare them.
assert.deepEqual(layer.getLatLngs(), [
L.latLng([0, 0]),
L.latLng([0, 1]),
L.latLng([0, 2]),
])
assert(this.map.isDirty)
})
it('should revert candidate if first point is closer', function () { it('should revert candidate if first point is closer', function () {
var latlngs = [ var latlngs = [
[[0, 0], [0, 1]], [
[[0, 2], [0, 1]], [0, 0],
[0, 1],
], ],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); [
layer.mergeShapes(); [0, 2],
layer.disableEdit(); [0, 1],
assert.deepEqual(layer.getLatLngs(), [L.latLng([0, 0]), L.latLng([0, 1]), L.latLng([0, 2])]); ],
}); ],
layer = new L.U.Polyline(this.map, latlngs, {
}); datalayer: this.datalayer,
}).addTo(this.datalayer)
layer.mergeShapes()
layer.disableEdit()
assert.deepEqual(layer.getLatLngs(), [
L.latLng([0, 0]),
L.latLng([0, 1]),
L.latLng([0, 2]),
])
})
})
describe('#isolateShape', function () { describe('#isolateShape', function () {
it('should not allow to isolate simple line', function () { it('should not allow to isolate simple line', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polyline(this.map, latlngs, {
assert.equal(this.datalayer._index.length, 1); datalayer: this.datalayer,
assert.ok(this.map.hasLayer(layer)); }).addTo(this.datalayer)
layer.isolateShape(p2ll(150, 150)); assert.equal(this.datalayer._index.length, 1)
assert.equal(layer._latlngs.length, 3); assert.ok(this.map.hasLayer(layer))
assert.equal(this.datalayer._index.length, 1); layer.isolateShape(p2ll(150, 150))
}); assert.equal(layer._latlngs.length, 3)
assert.equal(this.datalayer._index.length, 1)
})
it('should isolate multipolyline shape', function () { it('should isolate multipolyline shape', function () {
var latlngs = [ var latlngs = [
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[[p2ll(200, 300), p2ll(300, 200)]] [[p2ll(200, 300), p2ll(300, 200)]],
], ],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polyline(this.map, latlngs, {
assert.equal(this.datalayer._index.length, 1); datalayer: this.datalayer,
assert.ok(this.map.hasLayer(layer)); }).addTo(this.datalayer)
var other = layer.isolateShape(p2ll(150, 150)); assert.equal(this.datalayer._index.length, 1)
assert.equal(this.datalayer._index.length, 2); assert.ok(this.map.hasLayer(layer))
assert.equal(other._latlngs.length, 3); var other = layer.isolateShape(p2ll(150, 150))
assert.deepEqual(other._latlngs, latlngs[0]); assert.equal(this.datalayer._index.length, 2)
assert.ok(this.map.hasLayer(layer)); assert.equal(other._latlngs.length, 3)
assert.ok(this.map.hasLayer(other)); assert.deepEqual(other._latlngs, latlngs[0])
assert.equal(layer._latlngs.length, 1); assert.ok(this.map.hasLayer(layer))
other.remove(); assert.ok(this.map.hasLayer(other))
}); assert.equal(layer._latlngs.length, 1)
other.remove()
}); })
})
describe('#clone', function () { describe('#clone', function () {
it('should clone polyline', function () { it('should clone polyline', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer = new L.U.Polyline(this.map, latlngs, {
assert.equal(this.datalayer._index.length, 1); datalayer: this.datalayer,
other = layer.clone(); }).addTo(this.datalayer)
assert.ok(this.map.hasLayer(other)); assert.equal(this.datalayer._index.length, 1)
assert.equal(this.datalayer._index.length, 2); other = layer.clone()
assert.ok(this.map.hasLayer(other))
assert.equal(this.datalayer._index.length, 2)
// Must not be the same reference // Must not be the same reference
assert.notEqual(layer._latlngs, other._latlngs); assert.notEqual(layer._latlngs, other._latlngs)
assert.equal(L.Util.formatNum(layer._latlngs[0].lat), other._latlngs[0].lat); assert.equal(L.Util.formatNum(layer._latlngs[0].lat), other._latlngs[0].lat)
assert.equal(L.Util.formatNum(layer._latlngs[0].lng), other._latlngs[0].lng); assert.equal(L.Util.formatNum(layer._latlngs[0].lng), other._latlngs[0].lng)
}); })
})
}); })
});

View file

@ -1,94 +1,101 @@
describe('L.TableEditor', function () { describe('L.TableEditor', function () {
var path = '/map/99/datalayer/edit/62/'; var path = '/map/99/datalayer/edit/62/'
before(function () { before(function () {
this.server = sinon.fakeServer.create(); this.server = sinon.fakeServer.create()
this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET)); this.server.respondWith(
this.map = initMap({umap_id: 99}); 'GET',
this.datalayer = this.map.getDataLayerByUmapId(62); '/datalayer/62/',
this.server.respond(); JSON.stringify(RESPONSES.datalayer62_GET)
enableEdit(); )
}); this.map = initMap({ umap_id: 99 })
this.datalayer = this.map.getDataLayerByUmapId(62)
this.server.respond()
enableEdit()
})
after(function () { after(function () {
clickCancel(); clickCancel()
this.server.restore(); this.server.restore()
resetMap(); resetMap()
}); })
describe('#open()', function () { describe('#open()', function () {
var button; var button
it('should exist table click on edit mode', function () { it('should exist table click on edit mode', function () {
button = qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-table-edit'); button = qs(
expect(button).to.be.ok; '#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-table-edit'
}); )
expect(button).to.be.ok
})
it('should open table button click', function () { it('should open table button click', function () {
happen.click(button); happen.click(button)
expect(qs('#umap-ui-container div.table')).to.be.ok; expect(qs('#umap-ui-container div.table')).to.be.ok
expect(qsa('#umap-ui-container div.table form').length).to.eql(3); // One per feature. expect(qsa('#umap-ui-container div.table form').length).to.eql(3) // One per feature.
expect(qsa('#umap-ui-container div.table input').length).to.eql(3); // One per feature and per property. expect(qsa('#umap-ui-container div.table input').length).to.eql(3) // One per feature and per property.
}); })
})
});
describe('#properties()', function () { describe('#properties()', function () {
var feature; var feature
before(function () { before(function () {
var firstIndex = this.datalayer._index[0]; var firstIndex = this.datalayer._index[0]
feature = this.datalayer._layers[firstIndex]; feature = this.datalayer._layers[firstIndex]
}); })
it('should create new property column', function () { it('should create new property column', function () {
var newPrompt = function () { var newPrompt = function () {
return 'newprop'; return 'newprop'
}; }
var oldPrompt = window.prompt; var oldPrompt = window.prompt
window.prompt = newPrompt; window.prompt = newPrompt
var button = qs('#umap-ui-container .add-property'); var button = qs('#umap-ui-container .add-property')
expect(button).to.be.ok; expect(button).to.be.ok
happen.click(button); happen.click(button)
expect(qsa('#umap-ui-container div.table input').length).to.eql(6); // One per feature and per property. expect(qsa('#umap-ui-container div.table input').length).to.eql(6) // One per feature and per property.
window.prompt = oldPrompt; window.prompt = oldPrompt
}); })
it('should populate feature property on fill', function () { it('should populate feature property on fill', function () {
var input = qs('form#umap-feature-properties_' + L.stamp(feature) + ' input[name=newprop]'); var input = qs(
changeInputValue(input, 'the value'); 'form#umap-feature-properties_' + L.stamp(feature) + ' input[name=newprop]'
expect(feature.properties.newprop).to.eql('the value'); )
}); changeInputValue(input, 'the value')
expect(feature.properties.newprop).to.eql('the value')
})
it('should update property name on update click', function () { it('should update property name on update click', function () {
var newPrompt = function () { var newPrompt = function () {
return 'newname'; return 'newname'
}; }
var oldPrompt = window.prompt; var oldPrompt = window.prompt
window.prompt = newPrompt; window.prompt = newPrompt
var button = qs('#umap-ui-container div.thead div.tcell:last-of-type .umap-edit'); var button = qs('#umap-ui-container div.thead div.tcell:last-of-type .umap-edit')
expect(button).to.be.ok; expect(button).to.be.ok
happen.click(button); happen.click(button)
expect(qsa('#umap-ui-container div.table input').length).to.eql(6); expect(qsa('#umap-ui-container div.table input').length).to.eql(6)
expect(feature.properties.newprop).to.be.undefined; expect(feature.properties.newprop).to.be.undefined
expect(feature.properties.newname).to.eql('the value'); expect(feature.properties.newname).to.eql('the value')
window.prompt = oldPrompt; window.prompt = oldPrompt
}); })
it('should update property on delete click', function () { it('should update property on delete click', function () {
var oldConfirm, var oldConfirm,
newConfirm = function () { newConfirm = function () {
return true; return true
}; }
oldConfirm = window.confirm; oldConfirm = window.confirm
window.confirm = newConfirm; window.confirm = newConfirm
var button = qs('#umap-ui-container div.thead div.tcell:last-of-type .umap-delete'); var button = qs(
expect(button).to.be.ok; '#umap-ui-container div.thead div.tcell:last-of-type .umap-delete'
happen.click(button); )
FEATURE = feature; expect(button).to.be.ok
expect(qsa('#umap-ui-container div.table input').length).to.eql(3); happen.click(button)
expect(feature.properties.newname).to.be.undefined; FEATURE = feature
window.confirm = oldConfirm; expect(qsa('#umap-ui-container div.table input').length).to.eql(3)
}); expect(feature.properties.newname).to.be.undefined
window.confirm = oldConfirm
}); })
})
}); })

View file

@ -1,285 +1,435 @@
describe('L.Util', function () { describe('L.Util', function () {
describe('#toHTML()', function () { describe('#toHTML()', function () {
it('should handle title', function () { it('should handle title', function () {
assert.equal(L.Util.toHTML('# A title'), '<h3>A title</h3>'); assert.equal(L.Util.toHTML('# A title'), '<h3>A title</h3>')
}); })
it('should handle title in the middle of the content', function () { it('should handle title in the middle of the content', function () {
assert.equal(L.Util.toHTML('A phrase\n## A title'), 'A phrase<br>\n<h4>A title</h4>'); assert.equal(
}); L.Util.toHTML('A phrase\n## A title'),
'A phrase<br>\n<h4>A title</h4>'
)
})
it('should handle hr', function () { it('should handle hr', function () {
assert.equal(L.Util.toHTML('---'), '<hr>'); assert.equal(L.Util.toHTML('---'), '<hr>')
}); })
it('should handle bold', function () { it('should handle bold', function () {
assert.equal(L.Util.toHTML('Some **bold**'), 'Some <strong>bold</strong>'); assert.equal(L.Util.toHTML('Some **bold**'), 'Some <strong>bold</strong>')
}); })
it('should handle italic', function () { it('should handle italic', function () {
assert.equal(L.Util.toHTML('Some *italic*'), 'Some <em>italic</em>'); assert.equal(L.Util.toHTML('Some *italic*'), 'Some <em>italic</em>')
}); })
it('should handle newlines', function () { it('should handle newlines', function () {
assert.equal(L.Util.toHTML('two\nlines'), 'two<br>\nlines'); assert.equal(L.Util.toHTML('two\nlines'), 'two<br>\nlines')
}); })
it('should not change last newline', function () { it('should not change last newline', function () {
assert.equal(L.Util.toHTML('two\nlines\n'), 'two<br>\nlines\n'); assert.equal(L.Util.toHTML('two\nlines\n'), 'two<br>\nlines\n')
}); })
it('should handle two successive newlines', function () { it('should handle two successive newlines', function () {
assert.equal(L.Util.toHTML('two\n\nlines\n'), 'two<br>\n<br>\nlines\n'); assert.equal(L.Util.toHTML('two\n\nlines\n'), 'two<br>\n<br>\nlines\n')
}); })
it('should handle links without formatting', function () { it('should handle links without formatting', function () {
assert.equal(L.Util.toHTML('A simple http://osm.org link'), 'A simple <a target="_blank" href="http://osm.org">http://osm.org</a> link'); assert.equal(
}); L.Util.toHTML('A simple http://osm.org link'),
'A simple <a target="_blank" href="http://osm.org">http://osm.org</a> link'
)
})
it('should handle simple link in title', function () { it('should handle simple link in title', function () {
assert.equal(L.Util.toHTML('# http://osm.org'), '<h3><a target="_blank" href="http://osm.org">http://osm.org</a></h3>'); assert.equal(
}); L.Util.toHTML('# http://osm.org'),
'<h3><a target="_blank" href="http://osm.org">http://osm.org</a></h3>'
)
})
it('should handle links with url parameter', function () { it('should handle links with url parameter', function () {
assert.equal(L.Util.toHTML('A simple https://osm.org/?url=https%3A//anotherurl.com link'), 'A simple <a target="_blank" href="https://osm.org/?url=https%3A//anotherurl.com">https://osm.org/?url=https%3A//anotherurl.com</a> link'); assert.equal(
}); L.Util.toHTML('A simple https://osm.org/?url=https%3A//anotherurl.com link'),
'A simple <a target="_blank" href="https://osm.org/?url=https%3A//anotherurl.com">https://osm.org/?url=https%3A//anotherurl.com</a> link'
)
})
it('should handle simple link inside parenthesis', function () { it('should handle simple link inside parenthesis', function () {
assert.equal(L.Util.toHTML('A simple link (http://osm.org)'), 'A simple link (<a target="_blank" href="http://osm.org">http://osm.org</a>)'); assert.equal(
}); L.Util.toHTML('A simple link (http://osm.org)'),
'A simple link (<a target="_blank" href="http://osm.org">http://osm.org</a>)'
)
})
it('should handle simple link with formatting', function () { it('should handle simple link with formatting', function () {
assert.equal(L.Util.toHTML('A simple [[http://osm.org]] link'), 'A simple <a target="_blank" href="http://osm.org">http://osm.org</a> link'); assert.equal(
}); L.Util.toHTML('A simple [[http://osm.org]] link'),
'A simple <a target="_blank" href="http://osm.org">http://osm.org</a> link'
)
})
it('should handle simple link with formatting and content', function () { it('should handle simple link with formatting and content', function () {
assert.equal(L.Util.toHTML('A simple [[http://osm.org|link]]'), 'A simple <a target="_blank" href="http://osm.org">link</a>'); assert.equal(
}); L.Util.toHTML('A simple [[http://osm.org|link]]'),
'A simple <a target="_blank" href="http://osm.org">link</a>'
)
})
it('should handle simple link followed by a carriage return', function () { it('should handle simple link followed by a carriage return', function () {
assert.equal(L.Util.toHTML('A simple link http://osm.org\nAnother line'), 'A simple link <a target="_blank" href="http://osm.org">http://osm.org</a><br>\nAnother line'); assert.equal(
}); L.Util.toHTML('A simple link http://osm.org\nAnother line'),
'A simple link <a target="_blank" href="http://osm.org">http://osm.org</a><br>\nAnother line'
)
})
it('should handle image', function () { it('should handle image', function () {
assert.equal(L.Util.toHTML('A simple image: {{http://osm.org/pouet.png}}'), 'A simple image: <img src="http://osm.org/pouet.png">'); assert.equal(
}); L.Util.toHTML('A simple image: {{http://osm.org/pouet.png}}'),
'A simple image: <img src="http://osm.org/pouet.png">'
)
})
it('should handle image without text', function () { it('should handle image without text', function () {
assert.equal(L.Util.toHTML('{{http://osm.org/pouet.png}}'), '<img src="http://osm.org/pouet.png">'); assert.equal(
}); L.Util.toHTML('{{http://osm.org/pouet.png}}'),
'<img src="http://osm.org/pouet.png">'
)
})
it('should handle image with width', function () { it('should handle image with width', function () {
assert.equal(L.Util.toHTML('A simple image: {{http://osm.org/pouet.png|100}}'), 'A simple image: <img src="http://osm.org/pouet.png" width="100">'); assert.equal(
}); L.Util.toHTML('A simple image: {{http://osm.org/pouet.png|100}}'),
'A simple image: <img src="http://osm.org/pouet.png" width="100">'
)
})
it('should handle iframe', function () { it('should handle iframe', function () {
assert.equal(L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html}}}'), 'A simple iframe: <div><iframe frameborder="0" src="http://osm.org/pouet.html" width="100%" height="300px"></iframe></div>'); assert.equal(
}); L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html}}}'),
'A simple iframe: <div><iframe frameborder="0" src="http://osm.org/pouet.html" width="100%" height="300px"></iframe></div>'
)
})
it('should handle iframe with height', function () { it('should handle iframe with height', function () {
assert.equal(L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html|200}}}'), 'A simple iframe: <div><iframe frameborder="0" src="http://osm.org/pouet.html" width="100%" height="200px"></iframe></div>'); assert.equal(
}); L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html|200}}}'),
'A simple iframe: <div><iframe frameborder="0" src="http://osm.org/pouet.html" width="100%" height="200px"></iframe></div>'
)
})
it('should handle iframe with height and width', function () { it('should handle iframe with height and width', function () {
assert.equal(L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html|200*400}}}'), 'A simple iframe: <div><iframe frameborder="0" src="http://osm.org/pouet.html" width="400px" height="200px"></iframe></div>'); assert.equal(
}); L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html|200*400}}}'),
'A simple iframe: <div><iframe frameborder="0" src="http://osm.org/pouet.html" width="400px" height="200px"></iframe></div>'
)
})
it('should handle iframe with height with px', function () { it('should handle iframe with height with px', function () {
assert.equal(L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html|200px}}}'), 'A simple iframe: <div><iframe frameborder="0" src="http://osm.org/pouet.html" width="100%" height="200px"></iframe></div>'); assert.equal(
}); L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html|200px}}}'),
'A simple iframe: <div><iframe frameborder="0" src="http://osm.org/pouet.html" width="100%" height="200px"></iframe></div>'
)
})
it('should handle iframe with url parameter', function () { it('should handle iframe with url parameter', function () {
assert.equal(L.Util.toHTML('A simple iframe: {{{https://osm.org/?url=https%3A//anotherurl.com}}}'), 'A simple iframe: <div><iframe frameborder="0" src="https://osm.org/?url=https%3A//anotherurl.com" width="100%" height="300px"></iframe></div>'); assert.equal(
}); L.Util.toHTML(
'A simple iframe: {{{https://osm.org/?url=https%3A//anotherurl.com}}}'
),
'A simple iframe: <div><iframe frameborder="0" src="https://osm.org/?url=https%3A//anotherurl.com" width="100%" height="300px"></iframe></div>'
)
})
it('should handle iframe with height with px', function () { it('should handle iframe with height with px', function () {
assert.equal(L.Util.toHTML('A double iframe: {{{https://osm.org/pouet}}}{{{https://osm.org/boudin}}}'), 'A double iframe: <div><iframe frameborder="0" src="https://osm.org/pouet" width="100%" height="300px"></iframe></div><div><iframe frameborder="0" src="https://osm.org/boudin" width="100%" height="300px"></iframe></div>'); assert.equal(
}); L.Util.toHTML(
'A double iframe: {{{https://osm.org/pouet}}}{{{https://osm.org/boudin}}}'
),
'A double iframe: <div><iframe frameborder="0" src="https://osm.org/pouet" width="100%" height="300px"></iframe></div><div><iframe frameborder="0" src="https://osm.org/boudin" width="100%" height="300px"></iframe></div>'
)
})
it('http link with http link as parameter as variable', function () { it('http link with http link as parameter as variable', function () {
assert.equal(L.Util.toHTML('A phrase with a [[http://iframeurl.com?to=http://another.com]].'), 'A phrase with a <a target="_blank" href="http://iframeurl.com?to=http://another.com">http://iframeurl.com?to=http://another.com</a>.'); assert.equal(
}); L.Util.toHTML(
'A phrase with a [[http://iframeurl.com?to=http://another.com]].'
}); ),
'A phrase with a <a target="_blank" href="http://iframeurl.com?to=http://another.com">http://iframeurl.com?to=http://another.com</a>.'
)
})
})
describe('#escapeHTML', function () { describe('#escapeHTML', function () {
it('should escape HTML tags', function () { it('should escape HTML tags', function () {
assert.equal(L.Util.escapeHTML('<a href="pouet">'), '&lt;a href="pouet">'); assert.equal(L.Util.escapeHTML('<a href="pouet">'), '&lt;a href="pouet">')
}); })
it('should not fail with int value', function () { it('should not fail with int value', function () {
assert.equal(L.Util.escapeHTML(25), '25'); assert.equal(L.Util.escapeHTML(25), '25')
}); })
it('should not fail with null value', function () { it('should not fail with null value', function () {
assert.equal(L.Util.escapeHTML(null), ''); assert.equal(L.Util.escapeHTML(null), '')
}); })
})
});
describe('#greedyTemplate', function () { describe('#greedyTemplate', function () {
it('should replace simple props', function () { it('should replace simple props', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {variable}.', {variable: 'thing'}), 'A phrase with a thing.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {variable}.', { variable: 'thing' }),
'A phrase with a thing.'
)
})
it('should not fail when missing key', function () { it('should not fail when missing key', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {missing}', {}), 'A phrase with a '); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {missing}', {}),
'A phrase with a '
)
})
it('should process brakets in brakets', function () { it('should process brakets in brakets', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {{{variable}}}.', {variable: 'value'}), 'A phrase with a {{value}}.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {{{variable}}}.', { variable: 'value' }),
'A phrase with a {{value}}.'
)
})
it('should not process http links', function () { it('should not process http links', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {{{http://iframeurl.com}}}.', {'http://iframeurl.com': 'value'}), 'A phrase with a {{{http://iframeurl.com}}}.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {{{http://iframeurl.com}}}.', {
'http://iframeurl.com': 'value',
}),
'A phrase with a {{{http://iframeurl.com}}}.'
)
})
it('should not accept dash', function () { it('should not accept dash', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {var-iable}.', {'var-iable': 'value'}), 'A phrase with a {var-iable}.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {var-iable}.', { 'var-iable': 'value' }),
'A phrase with a {var-iable}.'
)
})
it('should accept colon', function () { it('should accept colon', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {variable:fr}.', {'variable:fr': 'value'}), 'A phrase with a value.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {variable:fr}.', {
'variable:fr': 'value',
}),
'A phrase with a value.'
)
})
it('should replace even with ignore if key is found', function () { it('should replace even with ignore if key is found', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {variable:fr}.', {'variable:fr': 'value'}, true), 'A phrase with a value.'); assert.equal(
}); L.Util.greedyTemplate(
'A phrase with a {variable:fr}.',
{ 'variable:fr': 'value' },
true
),
'A phrase with a value.'
)
})
it('should keep string when using ignore if key is not found', function () { it('should keep string when using ignore if key is not found', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {variable:fr}.', {}, true), 'A phrase with a {variable:fr}.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {variable:fr}.', {}, true),
'A phrase with a {variable:fr}.'
)
})
it('should replace nested variables', function () { it('should replace nested variables', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var}.', {fr: {var: 'value'}}), 'A phrase with a value.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {fr.var}.', { fr: { var: 'value' } }),
'A phrase with a value.'
)
})
it('should not fail if nested variable is missing', function () { it('should not fail if nested variable is missing', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.foo}.', {fr: {var: 'value'}}), 'A phrase with a .'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {fr.var.foo}.', {
fr: { var: 'value' },
}),
'A phrase with a .'
)
})
it('should not fail with nested variables and no data', function () { it('should not fail with nested variables and no data', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.foo}.', {}), 'A phrase with a .'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {fr.var.foo}.', {}),
'A phrase with a .'
)
})
it('should handle fallback value if any', function () { it('should handle fallback value if any', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|"default"}.', {}), 'A phrase with a default.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {fr.var.bar|"default"}.', {}),
'A phrase with a default.'
)
})
it('should handle fallback var if any', function () { it('should handle fallback var if any', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|fallback}.', {fallback: "default"}), 'A phrase with a default.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {fr.var.bar|fallback}.', {
fallback: 'default',
}),
'A phrase with a default.'
)
})
it('should handle multiple fallbacks', function () { it('should handle multiple fallbacks', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {}), 'A phrase with a default.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {}),
'A phrase with a default.'
)
})
it('should use the first defined value', function () { it('should use the first defined value', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {try: { again: 'please'}}), 'A phrase with a please.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {
try: { again: 'please' },
}),
'A phrase with a please.'
)
})
it('should use the first defined value', function () { it('should use the first defined value', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {try: { again: 'again'}, fr: {var: {bar: 'value'}}}), 'A phrase with a value.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {
try: { again: 'again' },
fr: { var: { bar: 'value' } },
}),
'A phrase with a value.'
)
})
it('should support the first example from #820 when translated to final syntax', function () { it('should support the first example from #820 when translated to final syntax', function () {
assert.equal(L.Util.greedyTemplate('# {name} ({ele|"-"} m ü. M.)', {name: 'Portalet'}), '# Portalet (- m ü. M.)'); assert.equal(
}); L.Util.greedyTemplate('# {name} ({ele|"-"} m ü. M.)', { name: 'Portalet' }),
'# Portalet (- m ü. M.)'
)
})
it('should support the first example from #820 when translated to final syntax when no fallback required', function () { it('should support the first example from #820 when translated to final syntax when no fallback required', function () {
assert.equal(L.Util.greedyTemplate('# {name} ({ele|"-"} m ü. M.)', {name: 'Portalet', ele: 3344}), '# Portalet (3344 m ü. M.)'); assert.equal(
}); L.Util.greedyTemplate('# {name} ({ele|"-"} m ü. M.)', {
name: 'Portalet',
ele: 3344,
}),
'# Portalet (3344 m ü. M.)'
)
})
it('should support white space in fallback', function () { it('should support white space in fallback', function () {
assert.equal(L.Util.greedyTemplate('A phrase with {var|"white space in the fallback."}', {}), 'A phrase with white space in the fallback.'); assert.equal(
}); L.Util.greedyTemplate('A phrase with {var|"white space in the fallback."}', {}),
'A phrase with white space in the fallback.'
)
})
it('should support empty string as fallback', function () { it('should support empty string as fallback', function () {
assert.equal(L.Util.greedyTemplate('A phrase with empty string ("{var|""}") in the fallback.', {}), 'A phrase with empty string ("") in the fallback.'); assert.equal(
}); L.Util.greedyTemplate(
'A phrase with empty string ("{var|""}") in the fallback.',
{}
),
'A phrase with empty string ("") in the fallback.'
)
})
it('should support e.g. links as fallback', function () { it('should support e.g. links as fallback', function () {
assert.equal(L.Util.greedyTemplate('A phrase with {var|"[[https://osm.org|link]]"} as fallback.', {}), 'A phrase with [[https://osm.org|link]] as fallback.'); assert.equal(
}); L.Util.greedyTemplate(
}); 'A phrase with {var|"[[https://osm.org|link]]"} as fallback.',
{}
),
'A phrase with [[https://osm.org|link]] as fallback.'
)
})
})
describe('#TextColorFromBackgroundColor', function () { describe('#TextColorFromBackgroundColor', function () {
it('should output white for black', function () { it('should output white for black', function () {
document.body.style.backgroundColor = 'black'; document.body.style.backgroundColor = 'black'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#ffffff'); assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#ffffff')
}); })
it('should output white for brown', function () { it('should output white for brown', function () {
document.body.style.backgroundColor = 'brown'; document.body.style.backgroundColor = 'brown'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#ffffff'); assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#ffffff')
}); })
it('should output black for white', function () { it('should output black for white', function () {
document.body.style.backgroundColor = 'white'; document.body.style.backgroundColor = 'white'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000'); assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000')
}); })
it('should output black for tan', function () { it('should output black for tan', function () {
document.body.style.backgroundColor = 'tan'; document.body.style.backgroundColor = 'tan'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000'); assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000')
}); })
it('should output black by default', function () { it('should output black by default', function () {
document.body.style.backgroundColor = 'transparent'; document.body.style.backgroundColor = 'transparent'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000'); assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000')
}); })
})
});
describe('#flattenCoordinates()', function () { describe('#flattenCoordinates()', function () {
it('should not alter already flat coords', function () { it('should not alter already flat coords', function () {
var coords = [[1, 2], [3, 4]]; var coords = [
assert.deepEqual(L.Util.flattenCoordinates(coords), coords); [1, 2],
[3, 4],
]
assert.deepEqual(L.Util.flattenCoordinates(coords), coords)
}) })
it('should flatten nested coords', function () { it('should flatten nested coords', function () {
var coords = [[[1, 2], [3, 4]]]; var coords = [
assert.deepEqual(L.Util.flattenCoordinates(coords), coords[0]); [
coords = [[[[1, 2], [3, 4]]]]; [1, 2],
assert.deepEqual(L.Util.flattenCoordinates(coords), coords[0][0]); [3, 4],
],
]
assert.deepEqual(L.Util.flattenCoordinates(coords), coords[0])
coords = [
[
[
[1, 2],
[3, 4],
],
],
]
assert.deepEqual(L.Util.flattenCoordinates(coords), coords[0][0])
}) })
it('should not fail on empty coords', function () { it('should not fail on empty coords', function () {
var coords = []; var coords = []
assert.deepEqual(L.Util.flattenCoordinates(coords), coords); assert.deepEqual(L.Util.flattenCoordinates(coords), coords)
})
}) })
});
describe('#usableOption()', function () { describe('#usableOption()', function () {
it('should consider false', function () { it('should consider false', function () {
assert.ok(L.Util.usableOption({key: false}, 'key')); assert.ok(L.Util.usableOption({ key: false }, 'key'))
}) })
it('should consider 0', function () { it('should consider 0', function () {
assert.ok(L.Util.usableOption({key: 0}, 'key')); assert.ok(L.Util.usableOption({ key: 0 }, 'key'))
}) })
it('should not consider undefined', function () { it('should not consider undefined', function () {
assert.notOk(L.Util.usableOption({}, 'key')); assert.notOk(L.Util.usableOption({}, 'key'))
}) })
it('should not consider empty string', function () { it('should not consider empty string', function () {
assert.notOk(L.Util.usableOption({key: ''}, 'key')); assert.notOk(L.Util.usableOption({ key: '' }, 'key'))
}) })
it('should consider null', function () { it('should consider null', function () {
assert.ok(L.Util.usableOption({key: null}, 'key')); assert.ok(L.Util.usableOption({ key: null }, 'key'))
})
})
}) })
});
});

View file

@ -1,69 +1,87 @@
var qs = function (selector, element) {return (element || document).querySelector(selector);}; var qs = function (selector, element) {
var qsa = function (selector) {return document.querySelectorAll(selector);}; return (element || document).querySelector(selector)
}
var qsa = function (selector) {
return document.querySelectorAll(selector)
}
var qst = function (text, parent) { var qst = function (text, parent) {
// find element by its text content // find element by its text content
var r = document.evaluate("descendant::*[contains(text(),'" + text + "')]", parent || qs('#map'), null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null), count = 0; var r = document.evaluate(
while(r.iterateNext()) console.log(++count); "descendant::*[contains(text(),'" + text + "')]",
return count; parent || qs('#map'),
}; null,
XPathResult.UNORDERED_NODE_ITERATOR_TYPE,
null
),
count = 0
while (r.iterateNext()) console.log(++count)
return count
}
happen.at = function (what, x, y, props) { happen.at = function (what, x, y, props) {
this.once(document.elementFromPoint(x, y), L.Util.extend({ this.once(
document.elementFromPoint(x, y),
L.Util.extend(
{
type: what, type: what,
clientX: x, clientX: x,
clientY: y, clientY: y,
screenX: x, screenX: x,
screenY: y, screenY: y,
which: 1, which: 1,
button: 0 button: 0,
}, props || {})); },
}; props || {}
)
)
}
var resetMap = function () { var resetMap = function () {
var mapElement = qs('#map'); var mapElement = qs('#map')
mapElement.innerHTML = 'Done'; mapElement.innerHTML = 'Done'
delete mapElement._leaflet_id; delete mapElement._leaflet_id
document.body.className = ''; document.body.className = ''
}; }
var enableEdit = function () { var enableEdit = function () {
happen.click(qs('div.leaflet-control-edit-enable a')); happen.click(qs('div.leaflet-control-edit-enable a'))
}; }
var disableEdit = function () { var disableEdit = function () {
happen.click(qs('a.leaflet-control-edit-disable')); happen.click(qs('a.leaflet-control-edit-disable'))
}; }
var clickSave = function () { var clickSave = function () {
happen.click(qs('a.leaflet-control-edit-save')); happen.click(qs('a.leaflet-control-edit-save'))
}; }
var clickCancel = function () { var clickCancel = function () {
var _confirm = window.confirm; var _confirm = window.confirm
window.confirm = function (text) { window.confirm = function (text) {
return true; return true
}; }
happen.click(qs('a.leaflet-control-edit-cancel')); happen.click(qs('a.leaflet-control-edit-cancel'))
happen.once(document.body, {type: 'keypress', keyCode: 13}); happen.once(document.body, { type: 'keypress', keyCode: 13 })
window.confirm = _confirm; window.confirm = _confirm
}; }
var changeInputValue = function (input, value) { var changeInputValue = function (input, value) {
input.value = value; input.value = value
happen.once(input, {type: 'input'}); happen.once(input, { type: 'input' })
happen.once(input, {type: 'blur'}); happen.once(input, { type: 'blur' })
}; }
var changeSelectValue = function (path_or_select, value) { var changeSelectValue = function (path_or_select, value) {
if (typeof path_or_select === 'string') path_or_select = qs(path_or_select); if (typeof path_or_select === 'string') path_or_select = qs(path_or_select)
var found = false; var found = false
for (var i = 0; i < path_or_select.length; i++) { for (var i = 0; i < path_or_select.length; i++) {
if (path_or_select.options[i].value === value) { if (path_or_select.options[i].value === value) {
path_or_select.options[i].selected = true; path_or_select.options[i].selected = true
found = true; found = true
} }
} }
happen.once(path_or_select, {type: 'change'}); happen.once(path_or_select, { type: 'change' })
if (!found) throw new Error('Value ' + value + 'not found in select ' + path_or_select); if (!found)
return path_or_select; throw new Error('Value ' + value + 'not found in select ' + path_or_select)
return path_or_select
} }
var cleanAlert = function () { var cleanAlert = function () {
L.DomUtil.removeClass(qs('#map'), 'umap-alert'); L.DomUtil.removeClass(qs('#map'), 'umap-alert')
L.DomUtil.get('umap-alert-container').innerHTML = ''; L.DomUtil.get('umap-alert-container').innerHTML = ''
UI_ALERT_ID = null; // Prevent setTimeout to be called UI_ALERT_ID = null // Prevent setTimeout to be called
}; }
var defaultDatalayerData = function (custom) { var defaultDatalayerData = function (custom) {
var _default = { var _default = {
iconClass: 'Default', iconClass: 'Default',
@ -79,162 +97,183 @@ var defaultDatalayerData = function (custom) {
smoothFactor: null, smoothFactor: null,
dashArray: '', dashArray: '',
fillOpacity: null, fillOpacity: null,
fill: true fill: true,
}; }
return L.extend({}, _default, custom); return L.extend({}, _default, custom)
}; }
function initMap(options) { function initMap(options) {
default_options = { default_options = {
"geometry": { geometry: {
"type": "Point", type: 'Point',
"coordinates": [5.0592041015625, 52.05924589011585] coordinates: [5.0592041015625, 52.05924589011585],
}, },
"type": "Feature", type: 'Feature',
"properties": { properties: {
"umap_id": 42, umap_id: 42,
"datalayers": [], datalayers: [],
"urls": { urls: {
"map": "/map/{slug}_{pk}", map: '/map/{slug}_{pk}',
"datalayer_view": "/datalayer/{pk}/", datalayer_view: '/datalayer/{pk}/',
"map_update": "/map/{map_id}/update/settings/", map_update: '/map/{map_id}/update/settings/',
"map_old_url": "/map/{username}/{slug}/", map_old_url: '/map/{username}/{slug}/',
"map_clone": "/map/{map_id}/update/clone/", map_clone: '/map/{map_id}/update/clone/',
"map_short_url": "/m/{pk}/", map_short_url: '/m/{pk}/',
"map_anonymous_edit_url": "/map/anonymous-edit/{signature}", map_anonymous_edit_url: '/map/anonymous-edit/{signature}',
"map_new": "/map/new/", map_new: '/map/new/',
"datalayer_update": "/map/{map_id}/datalayer/update/{pk}/", datalayer_update: '/map/{map_id}/datalayer/update/{pk}/',
"map_delete": "/map/{map_id}/update/delete/", map_delete: '/map/{map_id}/update/delete/',
"map_create": "/map/create/", map_create: '/map/create/',
"logout": "/logout/", logout: '/logout/',
"datalayer_create": "/map/{map_id}/datalayer/create/", datalayer_create: '/map/{map_id}/datalayer/create/',
"login_popup_end": "/login/popupd/", login_popup_end: '/login/popupd/',
"login": "/login/", login: '/login/',
"datalayer_delete": "/map/{map_id}/datalayer/delete/{pk}/", datalayer_delete: '/map/{map_id}/datalayer/delete/{pk}/',
"datalayer_versions": "/map/{map_id}/datalayer/{pk}/versions/", datalayer_versions: '/map/{map_id}/datalayer/{pk}/versions/',
"datalayer_version": "/datalayer/{pk}/{name}", datalayer_version: '/datalayer/{pk}/{name}',
"pictogram_list_json": "/pictogram/json/", pictogram_list_json: '/pictogram/json/',
"map_update_permissions": "/map/{map_id}/update/permissions/" map_update_permissions: '/map/{map_id}/update/permissions/',
}, },
"default_iconUrl": "../src/img/marker.png", default_iconUrl: '../src/img/marker.png',
"zoom": 6, zoom: 6,
"tilelayers": [ tilelayers: [
{ {
"attribution": "\u00a9 OSM Contributors", attribution: '\u00a9 OSM Contributors',
"name": "OpenStreetMap", name: 'OpenStreetMap',
"url_template": "http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png", url_template: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
"minZoom": 0, minZoom: 0,
"maxZoom": 18, maxZoom: 18,
"id": 1, id: 1,
"selected": true selected: true,
}, },
{ {
"attribution": "HOT and friends", attribution: 'HOT and friends',
"name": "HOT OSM-fr server", name: 'HOT OSM-fr server',
"url_template": "http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png", url_template: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
"rank": 99, rank: 99,
"minZoom": 0, minZoom: 0,
"maxZoom": 20, maxZoom: 20,
"id": 2 id: 2,
}],
"tilelayer": {
"attribution": "HOT and friends",
"name": "HOT OSM-fr server",
"url_template": "http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png",
"rank": 99,
"minZoom": 0,
"maxZoom": 20,
"id": 2
}, },
"licences": { ],
"No licence set": { tilelayer: {
"url": "", attribution: 'HOT and friends',
"name": "No licence set" name: 'HOT OSM-fr server',
url_template: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
rank: 99,
minZoom: 0,
maxZoom: 20,
id: 2,
}, },
"Licence ouverte/Open Licence": { licences: {
"url": "http://www.data.gouv.fr/Licence-Ouverte-Open-Licence", 'No licence set': {
"name": "Licence ouverte/Open Licence" url: '',
name: 'No licence set',
}, },
"WTFPL": { 'Licence ouverte/Open Licence': {
"url": "http://www.wtfpl.net/", url: 'http://www.data.gouv.fr/Licence-Ouverte-Open-Licence',
"name": "WTFPL" name: 'Licence ouverte/Open Licence',
},
'WTFPL': {
url: 'http://www.wtfpl.net/',
name: 'WTFPL',
},
'ODbl': {
url: 'http://opendatacommons.org/licenses/odbl/',
name: 'ODbl',
},
},
name: 'name of the map',
description: 'The description of the map',
allowEdit: true,
moreControl: true,
scaleControl: true,
miniMap: true,
datalayersControl: true,
displayCaptionOnLoad: false,
displayPopupFooter: false,
displayDataBrowserOnLoad: false,
}, },
"ODbl": {
"url": "http://opendatacommons.org/licenses/odbl/",
"name": "ODbl"
} }
}, default_options.properties.datalayers.push(defaultDatalayerData())
"name": "name of the map", options.properties = L.extend({}, default_options.properties, options)
"description": "The description of the map", return new L.U.Map('map', options)
"allowEdit": true,
"moreControl": true,
"scaleControl": true,
"miniMap": true,
"datalayersControl": true,
"displayCaptionOnLoad": false,
"displayPopupFooter": false,
"displayDataBrowserOnLoad": false
}
};
default_options.properties.datalayers.push(defaultDatalayerData());
options.properties = L.extend({}, default_options.properties, options);
return new L.U.Map("map", options);
} }
var RESPONSES = { var RESPONSES = {
'datalayer62_GET': { datalayer62_GET: {
"crs": null, crs: null,
"type": "FeatureCollection", type: 'FeatureCollection',
"_umap_options": defaultDatalayerData(), _umap_options: defaultDatalayerData(),
"features": [{ features: [
"geometry": { {
"type": "Point", geometry: {
"coordinates": [-0.274658203125, 52.57634993749885] type: 'Point',
coordinates: [-0.274658203125, 52.57634993749885],
}, },
"type": "Feature", type: 'Feature',
"id": 1807, id: 1807,
"properties": {_umap_options: {color: "OliveDrab"}, name: "test"} properties: { _umap_options: { color: 'OliveDrab' }, name: 'test' },
}, },
{ {
"geometry": { geometry: {
"type": "LineString", type: 'LineString',
"coordinates": [[-0.5712890625, 54.47642158429295], [0.439453125, 54.610254981579146], [1.724853515625, 53.44880683542759], [4.163818359375, 53.98839506479995], [5.306396484375, 53.533778184257805], [6.591796875, 53.70971358510174], [7.042236328124999, 53.35055131839989]] coordinates: [
[-0.5712890625, 54.47642158429295],
[0.439453125, 54.610254981579146],
[1.724853515625, 53.44880683542759],
[4.163818359375, 53.98839506479995],
[5.306396484375, 53.533778184257805],
[6.591796875, 53.70971358510174],
[7.042236328124999, 53.35055131839989],
],
}, },
"type": "Feature", type: 'Feature',
"id": 20, "properties": {"_umap_options": {"fill": false}, "name": "test"} id: 20,
properties: { _umap_options: { fill: false }, name: 'test' },
}, },
{ {
"geometry": { geometry: {
"type": "Polygon", type: 'Polygon',
"coordinates": [[[11.25, 53.585983654559804], [10.1513671875, 52.9751081817353], [12.689208984375, 52.16719363541221], [14.084472656249998, 53.199451902831555], [12.63427734375, 53.61857936489517], [11.25, 53.585983654559804], [11.25, 53.585983654559804]]] coordinates: [
[
[11.25, 53.585983654559804],
[10.1513671875, 52.9751081817353],
[12.689208984375, 52.16719363541221],
[14.084472656249998, 53.199451902831555],
[12.63427734375, 53.61857936489517],
[11.25, 53.585983654559804],
[11.25, 53.585983654559804],
],
],
},
type: 'Feature',
id: 76,
properties: { name: 'name poly' },
},
],
}, },
"type": "Feature",
"id": 76,
"properties": {name: "name poly"}
}]
} }
};
sinon.fakeServer.getRequest = function (path, method) { sinon.fakeServer.getRequest = function (path, method) {
var request; var request
for (var i = 0, l = this.requests.length; i < l; i++) { for (var i = 0, l = this.requests.length; i < l; i++) {
request = this.requests[i]; request = this.requests[i]
// In case of a form submit, the request start with file:// // In case of a form submit, the request start with file://
if (request.url.indexOf(path) !== -1) { if (request.url.indexOf(path) !== -1) {
if (!method || request.method === method) { if (!method || request.method === method) {
return request; return request
}
} }
} }
} }
};
sinon.fakeServer.flush = function () { sinon.fakeServer.flush = function () {
this.responses = []; this.responses = []
}; }
var kml_example =
var kml_example = '<?xml version="1.0" encoding="UTF-8"?>' + '<?xml version="1.0" encoding="UTF-8"?>' +
'<kml xmlns="http://www.opengis.net/kml/2.2">' + '<kml xmlns="http://www.opengis.net/kml/2.2">' +
'<Placemark>' + '<Placemark>' +
'<name>Simple point</name>' + '<name>Simple point</name>' +
@ -266,9 +305,10 @@ var kml_example = '<?xml version="1.0" encoding="UTF-8"?>' +
'</outerBoundaryIs>' + '</outerBoundaryIs>' +
'</Polygon>' + '</Polygon>' +
'</Placemark>' + '</Placemark>' +
'</kml>'; '</kml>'
var gpx_example = '<gpx' + var gpx_example =
'<gpx' +
' version="1.1"' + ' version="1.1"' +
' creator="GPSBabel - http://www.gpsbabel.org"' + ' creator="GPSBabel - http://www.gpsbabel.org"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' + ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
@ -284,18 +324,19 @@ var gpx_example = '<gpx' +
' <trkpt lat="45.4425697" lon="-121.7279085"></trkpt>' + ' <trkpt lat="45.4425697" lon="-121.7279085"></trkpt>' +
' </trkseg>' + ' </trkseg>' +
' </trk>' + ' </trk>' +
'</gpx>'; '</gpx>'
var csv_example = 'Foo,Latitude,Longitude,title,description\n' + var csv_example =
'bar,41.34,122.86,a point somewhere,the description of this point'; 'Foo,Latitude,Longitude,title,description\n' +
'bar,41.34,122.86,a point somewhere,the description of this point'
// Make Sinon log readable // Make Sinon log readable
sinon.format = function (what) { sinon.format = function (what) {
if (typeof what === 'object') { if (typeof what === 'object') {
return JSON.stringify(what, null, 4); return JSON.stringify(what, null, 4)
} else if (typeof what === "undefined") { } else if (typeof what === 'undefined') {
return ''; return ''
} else { } else {
return what.toString(); return what.toString()
}
} }
};

View file

@ -1,7 +1,7 @@
<html> <html>
<head> <head>
<title>Umap front Tests</title> <title>Umap front Tests</title>
<meta charset="utf-8"> <meta charset="utf-8" />
<script src="../vendors/leaflet/leaflet-src.js"></script> <script src="../vendors/leaflet/leaflet-src.js"></script>
<script src="../vendors/editable/Path.Drag.js"></script> <script src="../vendors/editable/Path.Drag.js"></script>
<script src="../vendors/editable/Leaflet.Editable.js"></script> <script src="../vendors/editable/Leaflet.Editable.js"></script>
@ -44,12 +44,12 @@
<link rel="stylesheet" href="../vendors/contextmenu/leaflet.contextmenu.css" /> <link rel="stylesheet" href="../vendors/contextmenu/leaflet.contextmenu.css" />
<link rel="stylesheet" href="../vendors/toolbar/leaflet.toolbar.css" /> <link rel="stylesheet" href="../vendors/toolbar/leaflet.toolbar.css" />
<link rel="stylesheet" href="../vendors/measurable/Leaflet.Measurable.css" /> <link rel="stylesheet" href="../vendors/measurable/Leaflet.Measurable.css" />
<link rel="stylesheet" href="../../umap/font.css"> <link rel="stylesheet" href="../../umap/font.css" />
<link rel="stylesheet" href="../../umap/base.css"> <link rel="stylesheet" href="../../umap/base.css" />
<link rel="stylesheet" href="../../umap/content.css"> <link rel="stylesheet" href="../../umap/content.css" />
<link rel="stylesheet" href="../../umap/nav.css"> <link rel="stylesheet" href="../../umap/nav.css" />
<link rel="stylesheet" href="../../umap/map.css" /> <link rel="stylesheet" href="../../umap/map.css" />
<link rel="stylesheet" href="../../umap/theme.css"> <link rel="stylesheet" href="../../umap/theme.css" />
<script src="../../../../node_modules/sinon/pkg/sinon.js"></script> <script src="../../../../node_modules/sinon/pkg/sinon.js"></script>
<script src="../../../../node_modules/mocha/mocha.js"></script> <script src="../../../../node_modules/mocha/mocha.js"></script>
@ -59,12 +59,12 @@
<script type="text/javascript"> <script type="text/javascript">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
bail: (window.location.search.indexOf('failfast') !== -1), bail: window.location.search.indexOf('failfast') !== -1,
ignoreLeaks: true ignoreLeaks: true,
}); })
chai.config.includeStack = true; chai.config.includeStack = true
var assert = chai.assert; var assert = chai.assert
var expect = chai.expect; var expect = chai.expect
</script> </script>
<script src="./_pre.js"></script> <script src="./_pre.js"></script>
<script src="./Map.js"></script> <script src="./Map.js"></script>
@ -100,18 +100,19 @@
<div id="map"></div> <div id="map"></div>
<script> <script>
var runner = (window.mochaPhantomJS || window.mocha).run(function (failures) { var runner = (window.mochaPhantomJS || window.mocha).run(function (failures) {
if (window.location.search.indexOf('debug') === -1) qs('#mocha').style.display = 'block'; if (window.location.search.indexOf('debug') === -1)
console.log(failures); qs('#mocha').style.display = 'block'
}); console.log(failures)
})
if (window.location.search.indexOf('debug') !== -1) { if (window.location.search.indexOf('debug') !== -1) {
runner.on('fail', function (test, err) { runner.on('fail', function (test, err) {
console.log(test.title, test.err); console.log(test.title, test.err)
console.log(test.err.expected, test.err.actual); console.log(test.err.expected, test.err.actual)
console.log(test.err.stack); console.log(test.err.stack)
}); })
sinon.log = function (message) { sinon.log = function (message) {
console.log(message); console.log(message)
}; }
} }
</script> </script>
</body> </body>