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

View file

@ -1,245 +1,285 @@
describe('L.U.FeatureMixin', function () { describe('L.U.FeatureMixin', function () {
before(function () {
this.server = sinon.fakeServer.create()
this.server.respondWith(
'GET',
'/datalayer/62/',
JSON.stringify(RESPONSES.datalayer62_GET)
)
this.map = initMap({ umap_id: 99 })
this.datalayer = this.map.getDataLayerByUmapId(62)
this.server.respond()
})
after(function () {
this.server.restore()
resetMap()
})
before(function () { describe('#edit()', function () {
this.server = sinon.fakeServer.create(); var link
this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET));
this.map = initMap({umap_id: 99});
this.datalayer = this.map.getDataLayerByUmapId(62);
this.server.respond();
});
after(function () {
this.server.restore();
resetMap();
});
describe('#edit()', function () { it('should have datalayer features created', function () {
var link; assert.equal(
document.querySelectorAll(
'#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 have datalayer features created', function () { it('should take into account styles changes made in the datalayer', function () {
assert.equal(document.querySelectorAll('#map > .leaflet-map-pane > .leaflet-overlay-pane path.leaflet-interactive').length, 2); enableEdit()
assert.ok(qs('path[fill="none"]')); // Polyline happen.click(
assert.ok(qs('path[fill="DarkBlue"]')); // Polygon qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
}); )
var colorInput = qs('form#datalayer-advanced-properties input[name=color]')
changeInputValue(colorInput, '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 take into account styles changes made in the datalayer', function () { it('should open a popup toolbar on feature click', function () {
enableEdit(); enableEdit()
happen.click(qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')); happen.click(qs('path[fill="DarkRed"]'))
var colorInput = qs('form#datalayer-advanced-properties input[name=color]'); var toolbar = qs('ul.leaflet-inplace-toolbar')
changeInputValue(colorInput, 'DarkRed'); assert.ok(toolbar)
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged link = qs('a.umap-toggle-edit', toolbar)
assert.notOk(qs('path[fill="DarkBlue"]')); assert.ok(link)
assert.ok(qs('path[fill="DarkRed"]')); })
});
it('should open a popup toolbar on feature click', function () { it('should open a form on popup toolbar toggle edit click', function () {
enableEdit(); happen.click(link)
happen.click(qs('path[fill="DarkRed"]')); var form = qs('form#umap-feature-properties')
var toolbar = qs('ul.leaflet-inplace-toolbar'); var input = qs('form#umap-feature-properties input[name="name"]')
assert.ok(toolbar); assert.ok(form)
link = qs('a.umap-toggle-edit', toolbar); assert.ok(input)
assert.ok(link); })
});
it('should open a form on popup toolbar toggle edit click', function () { it('should not handle _umap_options has normal property', function () {
happen.click(link); assert.notOk(qs('form#umap-feature-properties input[name="_umap_options"]'))
var form = qs('form#umap-feature-properties'); })
var input = qs('form#umap-feature-properties input[name="name"]');
assert.ok(form);
assert.ok(input);
});
it('should not handle _umap_options has normal property', function () { it('should give precedence to feature style over datalayer styles', function () {
assert.notOk(qs('form#umap-feature-properties input[name="_umap_options"]')); var input = qs('#umap-ui-container form input[name="color"]')
}); assert.ok(input)
changeInputValue(input, 'DarkGreen')
assert.notOk(qs('path[fill="DarkRed"]'))
assert.notOk(qs('path[fill="DarkBlue"]'))
assert.ok(qs('path[fill="DarkGreen"]'))
assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
})
it('should give precedence to feature style over datalayer styles', function () { it('should remove stroke if set to no', function () {
var input = qs('#umap-ui-container form input[name="color"]'); assert.notOk(qs('path[stroke="none"]'))
assert.ok(input); var defineButton = qs(
changeInputValue(input, 'DarkGreen'); '#umap-feature-shape-properties .formbox:nth-child(4) .define'
assert.notOk(qs('path[fill="DarkRed"]')); )
assert.notOk(qs('path[fill="DarkBlue"]')); happen.click(defineButton)
assert.ok(qs('path[fill="DarkGreen"]')); var input = qs('#umap-feature-shape-properties input[name="stroke"]')
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged assert.ok(input)
}); input.checked = false
happen.once(input, { type: 'change' })
assert.ok(qs('path[stroke="none"]'))
assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
})
it('should remove stroke if set to no', function () { it('should not override already set style on features', function () {
assert.notOk(qs('path[stroke="none"]')); happen.click(
var defineButton = qs('#umap-feature-shape-properties .formbox:nth-child(4) .define'); qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
happen.click(defineButton); )
var input = qs('#umap-feature-shape-properties input[name="stroke"]'); changeInputValue(qs('#umap-ui-container form input[name=color]'), 'Chocolate')
assert.ok(input); assert.notOk(qs('path[fill="DarkBlue"]'))
input.checked = false; assert.notOk(qs('path[fill="DarkRed"]'))
happen.once(input, {type: 'change'}); assert.notOk(qs('path[fill="Chocolate"]'))
assert.ok(qs('path[stroke="none"]')); 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 not override already set style on features', function () { it('should reset style on cancel click', function () {
happen.click(qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')); clickCancel()
changeInputValue(qs('#umap-ui-container form input[name=color]'), 'Chocolate'); assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
assert.notOk(qs('path[fill="DarkBlue"]')); assert.ok(qs('path[fill="DarkBlue"]'))
assert.notOk(qs('path[fill="DarkRed"]')); assert.notOk(qs('path[fill="DarkRed"]'))
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 set map.editedFeature on edit', function () {
clickCancel(); enableEdit()
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged assert.notOk(this.map.editedFeature)
assert.ok(qs('path[fill="DarkBlue"]')); happen.click(qs('path[fill="DarkBlue"]'))
assert.notOk(qs('path[fill="DarkRed"]')); happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
}); assert.ok(this.map.editedFeature)
disableEdit()
})
it('should set map.editedFeature on edit', function () { 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)
disableEdit(); this.map.displayCaption()
}); window.setTimeout(function () {
assert.notOk(this.map.editedFeature)
disableEdit()
done()
}, 1001) // CSS transition time.
})
})
it('should reset map.editedFeature on panel open', function (done) { describe('#utils()', function () {
enableEdit(); var poly, marker
assert.notOk(this.map.editedFeature); function setFeatures(datalayer) {
happen.click(qs('path[fill="DarkBlue"]')); datalayer.eachLayer(function (layer) {
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); if (!poly && layer instanceof L.Polygon) {
assert.ok(this.map.editedFeature); poly = layer
this.map.displayCaption();
window.setTimeout(function () {
assert.notOk(this.map.editedFeature);
disableEdit();
done();
}, 1001); // CSS transition time.
});
});
describe('#utils()', function () {
var poly, marker;
function setFeatures (datalayer) {
datalayer.eachLayer(function (layer) {
if (!poly && layer instanceof L.Polygon) {
poly = layer;
}
if (!marker && layer instanceof L.Marker) {
marker = layer;
}
});
} }
it('should generate a valid geojson', function () { if (!marker && layer instanceof L.Marker) {
setFeatures(this.datalayer); marker = layer
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]]]}); })
// Ensure original latlngs has not been modified }
assert.equal(poly.getLatLngs()[0].length, 6); it('should generate a valid geojson', function () {
}); setFeatures(this.datalayer)
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],
],
],
})
// Ensure original latlngs has not been modified
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 () {
it('should change style on datalayer select change', function () {
enableEdit()
happen.click(qs('.manage-datalayers'))
happen.click(qs('#umap-ui-container .add-datalayer'))
changeInputValue(qs('form.umap-form input[name="name"]'), 'New layer')
changeInputValue(
qs('form#datalayer-advanced-properties input[name=color]'),
'MediumAquaMarine'
)
happen.click(qs('path[fill="DarkBlue"]'))
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
var select = qs('select[name=datalayer]')
select.selectedIndex = 0
happen.once(select, { type: 'change' })
assert.ok(qs('path[fill="none"]')) // Polyline fill is unchanged
assert.notOk(qs('path[fill="DarkBlue"]'))
assert.ok(qs('path[fill="MediumAquaMarine"]'))
clickCancel()
})
})
describe('#changeDataLayer()', function () { describe('#openPopup()', function () {
it('should open a popup on click', function () {
assert.notOk(qs('.leaflet-popup-content'))
happen.click(qs('path[fill="DarkBlue"]'))
var title = qs('.leaflet-popup-content')
assert.ok(title)
assert.ok(title.innerHTML.indexOf('name poly'))
})
})
it('should change style on datalayer select change', function () { describe('#tooltip', function () {
enableEdit(); it('should have a tooltip when active and allow variables', function () {
happen.click(qs('.manage-datalayers')); this.map.options.showLabel = true
happen.click(qs('#umap-ui-container .add-datalayer')); this.map.options.labelKey = 'Foo {name}'
changeInputValue(qs('form.umap-form input[name="name"]'), 'New layer'); this.datalayer.redraw()
changeInputValue(qs('form#datalayer-advanced-properties input[name=color]'), 'MediumAquaMarine'); assert.equal(
happen.click(qs('path[fill="DarkBlue"]')); qs('.leaflet-tooltip-pane .leaflet-tooltip').textContent,
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); 'Foo name poly'
var select = qs('select[name=datalayer]'); )
select.selectedIndex = 0; })
happen.once(select, {type: 'change'}); })
assert.ok(qs('path[fill="none"]')); // Polyline fill is unchanged
assert.notOk(qs('path[fill="DarkBlue"]'));
assert.ok(qs('path[fill="MediumAquaMarine"]'));
clickCancel();
});
}); describe('#properties()', function () {
it('should rename property', function () {
var poly = this.datalayer._lineToLayer({}, [
[0, 0],
[0, 1],
[0, 2],
])
poly.properties.prop1 = 'xxx'
poly.renameProperty('prop1', 'prop2')
assert.equal(poly.properties.prop2, 'xxx')
assert.ok(typeof poly.properties.prop1 === 'undefined')
})
describe('#openPopup()', function () { it('should not create property when renaming', function () {
var poly = this.datalayer._lineToLayer({}, [
[0, 0],
[0, 1],
[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 open a popup on click', function () { it('should delete property', function () {
assert.notOk(qs('.leaflet-popup-content')); var poly = this.datalayer._lineToLayer({}, [
happen.click(qs('path[fill="DarkBlue"]')); [0, 0],
var title = qs('.leaflet-popup-content'); [0, 1],
assert.ok(title); [0, 2],
assert.ok(title.innerHTML.indexOf('name poly')); ])
}); poly.properties.prop = 'xxx'
assert.equal(poly.properties.prop, 'xxx')
poly.deleteProperty('prop')
assert.ok(typeof poly.properties.prop === 'undefined')
})
})
}); describe('#matchFilter()', function () {
var poly
describe('#tooltip', function () { it('should filter on properties', function () {
poly = this.datalayer._lineToLayer({}, [
[0, 0],
[0, 1],
[0, 2],
])
poly.properties.name = 'mooring'
assert.ok(poly.matchFilter('moo', ['name']))
assert.notOk(poly.matchFilter('foo', ['name']))
})
it('should have a tooltip when active and allow variables', function () { it('should be case unsensitive', function () {
this.map.options.showLabel = true; assert.ok(poly.matchFilter('Moo', ['name']))
this.map.options.labelKey = "Foo {name}"; })
this.datalayer.redraw();
assert.equal(qs('.leaflet-tooltip-pane .leaflet-tooltip').textContent, "Foo name poly");
});
}); it('should match also in the middle of a string', function () {
assert.ok(poly.matchFilter('oor', ['name']))
})
describe('#properties()', function () { it('should handle multiproperties', function () {
poly.properties.city = 'Teulada'
it('should rename property', function () { assert.ok(poly.matchFilter('eul', ['name', 'city', 'foo']))
var poly = this.datalayer._lineToLayer({}, [[0, 0], [0, 1], [0, 2]]); })
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 () {
var poly = this.datalayer._lineToLayer({}, [[0, 0], [0, 1], [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 () {
var poly = this.datalayer._lineToLayer({}, [[0, 0], [0, 1], [0, 2]]);
poly.properties.prop = 'xxx';
assert.equal(poly.properties.prop, 'xxx');
poly.deleteProperty('prop');
assert.ok(typeof poly.properties.prop === 'undefined');
});
});
describe('#matchFilter()', function () {
var poly;
it('should filter on properties', function () {
poly = this.datalayer._lineToLayer({}, [[0, 0], [0, 1], [0, 2]]);
poly.properties.name = 'mooring';
assert.ok(poly.matchFilter('moo', ['name']));
assert.notOk(poly.matchFilter('foo', ['name']));
});
it('should be case unsensitive', function () {
assert.ok(poly.matchFilter('Moo', ['name']));
});
it('should match also in the middle of a string', function () {
assert.ok(poly.matchFilter('oor', ['name']));
});
it('should handle multiproperties', function () {
poly.properties.city = 'Teulada';
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 () {
this.server = sinon.fakeServer.create()
this.server.respondWith('/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET))
this.options = {
umap_id: 99,
}
this.map = initMap({ umap_id: 99 })
this.server.respond()
this.datalayer = this.map.getDataLayerByUmapId(62)
})
after(function () {
this.server.restore()
clickCancel()
resetMap()
})
describe('#init()', function () {
it('should be initialized', function () {
assert.equal(this.map.options.umap_id, 99)
})
it('should have created the edit button', function () {
assert.ok(qs('div.leaflet-control-edit-enable'))
})
it('should have datalayer control div', function () {
assert.ok(qs('div.leaflet-control-browse'))
})
it('should have datalayer actions div', function () {
assert.ok(qs('div.umap-browse-actions'))
})
it('should have icon container div', function () {
assert.ok(qs('div.icon_container'))
})
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'
)
happen.click(el)
assert.notOk(qs('div.icon_container'))
})
it('enable edit on click on toggle button', function () {
var el = qs('div.leaflet-control-edit-enable a')
happen.click(el)
assert.isTrue(L.DomUtil.hasClass(document.body, 'umap-edit-enabled'))
})
it('should have only one datalayer in its index', function () {
assert.equal(this.map.datalayers_index.length, 1)
})
})
describe('#editMetadata()', function () {
var form, input
it('should build a form on editMetadata control click', function (done) {
var button = qs('a.update-map-settings')
assert.ok(button)
happen.click(button)
form = qs('form.umap-form')
input = qs('form[class="umap-form"] input[name="name"]')
assert.ok(form)
assert.ok(input)
done()
})
it('should update map name on input change', function () {
var new_name = 'This is a new name'
input.value = new_name
happen.once(input, { type: 'input' })
assert.equal(this.map.options.name, new_name)
})
it('should have made Map dirty', function () {
assert.ok(this.map.isDirty)
})
it('should have added dirty class on map container', function () {
assert.ok(L.DomUtil.hasClass(this.map._container, 'umap-is-dirty'))
})
})
describe('#delete()', function () {
var path = '/map/99/delete/',
oldConfirm,
newConfirm = function () {
return true
}
before(function () { before(function () {
this.server = sinon.fakeServer.create(); oldConfirm = window.confirm
this.server.respondWith('/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET)); window.confirm = newConfirm
this.options = { })
umap_id: 99
};
this.map = initMap({umap_id: 99});
this.server.respond();
this.datalayer = this.map.getDataLayerByUmapId(62);
});
after(function () { after(function () {
this.server.restore(); window.confirm = oldConfirm
clickCancel(); })
resetMap();
});
describe('#init()', function(){ it('should ask for confirmation on delete link click', function (done) {
var button = qs('a.update-map-settings')
assert.ok(button, 'update map info button exists')
happen.click(button)
var deleteLink = qs('a.umap-delete')
assert.ok(deleteLink, 'delete map button exists')
sinon.spy(window, 'confirm')
this.server.respondWith('POST', path, JSON.stringify({ redirect: '#' }))
happen.click(deleteLink)
this.server.respond()
assert(window.confirm.calledOnce)
window.confirm.restore()
done()
})
})
it('should be initialized', function(){ describe('#importData()', function () {
assert.equal(this.map.options.umap_id, 99); var fileInput, textarea, submit, formatSelect, layerSelect, clearFlag
});
it('should have created the edit button', function(){ it('should build a form on click', function () {
assert.ok(qs('div.leaflet-control-edit-enable')); happen.click(qs('a.upload-data'))
}); fileInput = qs('.umap-upload input[type="file"]')
textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]')
layerSelect = qs('.umap-upload select[name="datalayer"]')
assert.ok(fileInput)
assert.ok(submit)
assert.ok(textarea)
assert.ok(formatSelect)
assert.ok(layerSelect)
})
it('should have datalayer control div', function(){ it('should import geojson from textarea', function () {
assert.ok(qs('div.leaflet-control-browse')); this.datalayer.empty()
}); 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": ""}}]}'
changeSelectValue(formatSelect, 'geojson')
happen.click(submit)
assert.equal(this.datalayer._index.length, 2)
})
it('should have datalayer actions div', function(){ it('should import osm from textarea', function () {
assert.ok(qs('div.umap-browse-actions')); this.datalayer.empty()
}); happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]')
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"}}]}'
changeSelectValue(formatSelect, 'osm')
happen.click(submit)
assert.equal(this.datalayer._index.length, 2)
assert.equal(
this.datalayer._layers[this.datalayer._index[0]].properties.tourism,
'information'
)
})
it('should have icon container div', function(){ it('should import kml from textarea', function () {
assert.ok(qs('div.icon_container')); this.datalayer.empty()
}); happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0)
textarea.value = kml_example
changeSelectValue(formatSelect, 'kml')
happen.click(submit)
assert.equal(this.datalayer._index.length, 3)
})
it('should hide icon container div when hiding datalayer', function() { it('should import gpx from textarea', function () {
var el = qs('.leaflet-control-browse #browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-toggle'); this.datalayer.empty()
happen.click(el); happen.click(qs('a.upload-data'))
assert.notOk(qs('div.icon_container')); textarea = qs('.umap-upload textarea')
}); submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0)
textarea.value = gpx_example
changeSelectValue(formatSelect, 'gpx')
happen.click(submit)
assert.equal(this.datalayer._index.length, 2)
})
it('enable edit on click on toggle button', function () { it('should import csv from textarea', function () {
var el = qs('div.leaflet-control-edit-enable a'); this.datalayer.empty()
happen.click(el); happen.click(qs('a.upload-data'))
assert.isTrue(L.DomUtil.hasClass(document.body, 'umap-edit-enabled')); textarea = qs('.umap-upload textarea')
}); submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0)
textarea.value = csv_example
changeSelectValue(formatSelect, 'csv')
happen.click(submit)
assert.equal(this.datalayer._index.length, 1)
})
it('should have only one datalayer in its index', function () { it('should replace content if asked so', function () {
assert.equal(this.map.datalayers_index.length, 1); happen.click(qs('a.upload-data'))
}); textarea = qs('.umap-upload textarea')
}); submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]')
clearFlag = qs('.umap-upload input[name="clear"]')
clearFlag.checked = true
assert.equal(this.datalayer._index.length, 1)
textarea.value = csv_example
changeSelectValue(formatSelect, 'csv')
happen.click(submit)
assert.equal(this.datalayer._index.length, 1)
})
describe('#editMetadata()', function () { it('should import GeometryCollection from textarea', function () {
var form, input; 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]]}]}'
formatSelect = qs('.umap-upload select[name="format"]')
changeSelectValue(formatSelect, 'geojson')
happen.click(submit)
assert.equal(this.datalayer._index.length, 3)
})
it('should build a form on editMetadata control click', function (done) { it('should import multipolygon', function () {
var button = qs('a.update-map-settings'); this.datalayer.empty()
assert.ok(button); textarea.value =
happen.click(button); '{"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]]]] }}'
form = qs('form.umap-form'); changeSelectValue(formatSelect, 'geojson')
input = qs('form[class="umap-form"] input[name="name"]'); happen.click(submit)
assert.ok(form); assert.equal(this.datalayer._index.length, 1)
assert.ok(input); var layer = this.datalayer.getFeatureByIndex(0)
done(); assert.equal(layer._latlngs.length, 2) // Two shapes.
}); assert.equal(layer._latlngs[0].length, 2) // Hole.
})
it('should update map name on input change', function () { it('should import multipolyline', function () {
var new_name = 'This is a new name'; this.datalayer.empty()
input.value = new_name; textarea.value =
happen.once(input, {type: 'input'}); '{"type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "MultiLineString", "coordinates": [[[-108, 46], [-113, 43]], [[-112, 45], [-115, 44]]] } }]}'
assert.equal(this.map.options.name, new_name); changeSelectValue(formatSelect, 'geojson')
}); happen.click(submit)
assert.equal(this.datalayer._index.length, 1)
var layer = this.datalayer.getFeatureByIndex(0)
assert.equal(layer._latlngs.length, 2) // Two shapes.
})
it('should have made Map dirty', function () { it('should import raw umap data from textarea', function () {
assert.ok(this.map.isDirty); //Right now, the import function will try to save and reload. Stop this from happening.
}); var disabledSaveFunction = this.map.save
this.map.save = function () {}
happen.click(qs('a.upload-data'))
var initialLayerCount = Object.keys(this.map.datalayers).length
formatSelect = qs('.umap-upload select[name="format"]')
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": {} } }]}'
formatSelect.value = 'umap'
submit = qs('.umap-upload input[type="button"]')
happen.click(submit)
assert.equal(Object.keys(this.map.datalayers).length, initialLayerCount + 2)
assert.equal(this.map.options.name, 'Imported map')
var foundFirstLayer = false
var foundSecondLayer = false
for (var idx in this.map.datalayers) {
var datalayer = this.map.datalayers[idx]
if (datalayer.options.name === 'Cities') {
foundFirstLayer = true
assert.equal(datalayer._index.length, 2)
}
if (datalayer.options.name === 'Tunnels') {
foundSecondLayer = true
assert.equal(datalayer._index.length, 1)
}
}
assert.equal(foundFirstLayer, true)
assert.equal(foundSecondLayer, true)
})
it('should have added dirty class on map container', function () { it('should only import options on the whitelist (umap format import)', function () {
assert.ok(L.DomUtil.hasClass(this.map._container, 'umap-is-dirty')); assert.equal(this.map.options.umap_id, 99)
}); })
}); it('should update title bar (umap format import)', function () {
var title = qs('#map div.umap-main-edit-toolbox h3 a.umap-click-to-edit')
assert.equal(title.innerHTML, 'Imported map')
})
describe('#delete()', function () { it('should reinitialize controls (umap format import)', function () {
var path = '/map/99/delete/', var minimap = qs('#map div.leaflet-control-container div.leaflet-control-minimap')
oldConfirm, assert.ok(minimap)
newConfirm = function () { })
return true;
};
before(function () { it('should update the tilelayer switcher control (umap format import)', function () {
oldConfirm = window.confirm; //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
window.confirm = newConfirm; var selectedLayer = qs('.umap-tilelayer-switcher-container li.selected')
}); assert.equal(selectedLayer, null)
after(function () { })
window.confirm = oldConfirm;
});
it('should ask for confirmation on delete link click', function (done) { it('should set the tilelayer (umap format import)', function () {
var button = qs('a.update-map-settings'); assert.equal(
assert.ok(button, 'update map info button exists'); this.map.selected_tilelayer._url,
happen.click(button); 'http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg'
var deleteLink = qs('a.umap-delete'); )
assert.ok(deleteLink, 'delete map button exists'); })
sinon.spy(window, 'confirm'); })
this.server.respondWith('POST', path, JSON.stringify({redirect: '#'}));
happen.click(deleteLink);
this.server.respond();
assert(window.confirm.calledOnce);
window.confirm.restore();
done();
});
}); describe('#localizeUrl()', function () {
it('should replace known variables', function () {
assert.equal(
this.map.localizeUrl('http://example.org/{zoom}'),
'http://example.org/' + this.map.getZoom()
)
})
describe('#importData()', function () { it('should keep unknown variables', function () {
var fileInput, textarea, submit, formatSelect, layerSelect, clearFlag; assert.equal(
this.map.localizeUrl('http://example.org/{unkown}'),
it('should build a form on click', function () { 'http://example.org/{unkown}'
happen.click(qs('a.upload-data')); )
fileInput = qs('.umap-upload input[type="file"]'); })
textarea = qs('.umap-upload textarea'); })
submit = qs('.umap-upload input[type="button"]'); })
formatSelect = qs('.umap-upload select[name="format"]');
layerSelect = qs('.umap-upload select[name="datalayer"]');
assert.ok(fileInput);
assert.ok(submit);
assert.ok(textarea);
assert.ok(formatSelect);
assert.ok(layerSelect);
});
it('should import geojson from textarea', function () {
this.datalayer.empty()
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": ""}}]}';
changeSelectValue(formatSelect, 'geojson');
happen.click(submit);
assert.equal(this.datalayer._index.length, 2);
});
it('should import osm from textarea', function () {
this.datalayer.empty()
happen.click(qs('a.upload-data'));
textarea = qs('.umap-upload textarea');
submit = qs('.umap-upload input[type="button"]');
formatSelect = qs('.umap-upload select[name="format"]');
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"}}]}';
changeSelectValue(formatSelect, 'osm');
happen.click(submit);
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 () {
this.datalayer.empty()
happen.click(qs('a.upload-data'));
textarea = qs('.umap-upload textarea');
submit = qs('.umap-upload input[type="button"]');
formatSelect = qs('.umap-upload select[name="format"]');
assert.equal(this.datalayer._index.length, 0);
textarea.value = kml_example;
changeSelectValue(formatSelect, 'kml');
happen.click(submit);
assert.equal(this.datalayer._index.length, 3);
});
it('should import gpx from textarea', function () {
this.datalayer.empty()
happen.click(qs('a.upload-data'));
textarea = qs('.umap-upload textarea');
submit = qs('.umap-upload input[type="button"]');
formatSelect = qs('.umap-upload select[name="format"]');
assert.equal(this.datalayer._index.length, 0);
textarea.value = gpx_example;
changeSelectValue(formatSelect, 'gpx');
happen.click(submit);
assert.equal(this.datalayer._index.length, 2);
});
it('should import csv from textarea', function () {
this.datalayer.empty()
happen.click(qs('a.upload-data'));
textarea = qs('.umap-upload textarea');
submit = qs('.umap-upload input[type="button"]');
formatSelect = qs('.umap-upload select[name="format"]');
assert.equal(this.datalayer._index.length, 0);
textarea.value = csv_example;
changeSelectValue(formatSelect, 'csv');
happen.click(submit);
assert.equal(this.datalayer._index.length, 1);
});
it('should replace content if asked so', function () {
happen.click(qs('a.upload-data'));
textarea = qs('.umap-upload textarea');
submit = qs('.umap-upload input[type="button"]');
formatSelect = qs('.umap-upload select[name="format"]');
clearFlag = qs('.umap-upload input[name="clear"]');
clearFlag.checked = true;
assert.equal(this.datalayer._index.length, 1);
textarea.value = csv_example;
changeSelectValue(formatSelect, 'csv');
happen.click(submit);
assert.equal(this.datalayer._index.length, 1);
});
it('should import GeometryCollection from textarea', function () {
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]]}]}';
formatSelect = qs('.umap-upload select[name="format"]');
changeSelectValue(formatSelect, 'geojson');
happen.click(submit);
assert.equal(this.datalayer._index.length, 3);
});
it('should import multipolygon', function () {
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]]]] }}';
changeSelectValue(formatSelect, 'geojson');
happen.click(submit);
assert.equal(this.datalayer._index.length, 1);
var layer = this.datalayer.getFeatureByIndex(0);
assert.equal(layer._latlngs.length, 2); // Two shapes.
assert.equal(layer._latlngs[0].length, 2); // Hole.
});
it('should import multipolyline', function () {
this.datalayer.empty()
textarea.value = '{"type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "MultiLineString", "coordinates": [[[-108, 46], [-113, 43]], [[-112, 45], [-115, 44]]] } }]}';
changeSelectValue(formatSelect, 'geojson');
happen.click(submit);
assert.equal(this.datalayer._index.length, 1);
var layer = this.datalayer.getFeatureByIndex(0);
assert.equal(layer._latlngs.length, 2); // Two shapes.
});
it('should import raw umap data from textarea', function () {
//Right now, the import function will try to save and reload. Stop this from happening.
var disabledSaveFunction = this.map.save;
this.map.save = function(){};
happen.click(qs('a.upload-data'));
var initialLayerCount = Object.keys(this.map.datalayers).length;
formatSelect = qs('.umap-upload select[name="format"]');
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": {} } }]}';
formatSelect.value = 'umap';
submit = qs('.umap-upload input[type="button"]');
happen.click(submit);
assert.equal(Object.keys(this.map.datalayers).length, initialLayerCount + 2);
assert.equal(this.map.options.name, "Imported map");
var foundFirstLayer = false;
var foundSecondLayer = false;
for (var idx in this.map.datalayers) {
var datalayer = this.map.datalayers[idx];
if (datalayer.options.name === "Cities") {
foundFirstLayer = true;
assert.equal(datalayer._index.length, 2);
}
if (datalayer.options.name === "Tunnels") {
foundSecondLayer = true;
assert.equal(datalayer._index.length, 1);
}
}
assert.equal(foundFirstLayer, true);
assert.equal(foundSecondLayer, true);
});
it('should only import options on the whitelist (umap format import)', function () {
assert.equal(this.map.options.umap_id, 99);
});
it('should update title bar (umap format import)', function () {
var title = qs("#map div.umap-main-edit-toolbox h3 a.umap-click-to-edit");
assert.equal(title.innerHTML, "Imported map");
});
it('should reinitialize controls (umap format import)', function () {
var minimap = qs("#map div.leaflet-control-container div.leaflet-control-minimap");
assert.ok(minimap);
});
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
var selectedLayer = qs(".umap-tilelayer-switcher-container li.selected");
assert.equal(selectedLayer, null);
});
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");
});
});
describe('#localizeUrl()', function () {
it('should replace known variables', function () {
assert.equal(this.map.localizeUrl('http://example.org/{zoom}'), 'http://example.org/' + this.map.getZoom());
});
it('should keep unknown variables', function () {
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 () {
this.server = sinon.fakeServer.create()
var datalayer_response = JSON.parse(JSON.stringify(RESPONSES.datalayer62_GET)) // Copy.
datalayer_response._umap_options.iconClass = 'Drop'
this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(datalayer_response))
this.map = initMap({ umap_id: 99 })
this.datalayer = this.map.getDataLayerByUmapId(62)
this.server.respond()
})
after(function () {
this.server.restore()
resetMap()
})
before(function () { describe('#iconClassChange()', function () {
this.server = sinon.fakeServer.create(); it('should change icon class', function () {
var datalayer_response = JSON.parse(JSON.stringify(RESPONSES.datalayer62_GET)); // Copy. enableEdit()
datalayer_response._umap_options.iconClass = 'Drop'; happen.click(qs('div.umap-drop-icon'))
this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(datalayer_response)); happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
this.map = initMap({umap_id: 99}); changeSelectValue(
this.datalayer = this.map.getDataLayerByUmapId(62); qs(
this.server.respond(); 'form#umap-feature-shape-properties .umap-field-iconClass select[name=iconClass]'
}); ),
after(function () { 'Circle'
this.server.restore(); )
resetMap(); 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('#iconClassChange()', function () { describe('#iconSymbolChange()', function () {
it('should change icon symbol', function () {
enableEdit()
happen.click(qs('div.umap-drop-icon'))
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'
)
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()
})
})
it('should change icon class', function () { describe('#iconClassChange()', function () {
enableEdit(); it('should change icon class', function () {
happen.click(qs('div.umap-drop-icon')); enableEdit()
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); happen.click(qs('div.umap-drop-icon'))
changeSelectValue(qs('form#umap-feature-shape-properties .umap-field-iconClass select[name=iconClass]'), 'Circle'); happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
assert.notOk(qs('div.umap-drop-icon')); changeSelectValue(
assert.ok(qs('div.umap-circle-icon')); qs(
happen.click(qs('form#umap-feature-shape-properties .umap-field-iconClass .undefine')); 'form#umap-feature-shape-properties .umap-field-iconClass select[name=iconClass]'
assert.notOk(qs('div.umap-circle-icon')); ),
assert.ok(qs('div.umap-drop-icon')); 'Circle'
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 () {
it('should clone marker', function () {
describe('#iconSymbolChange()', function () { var layer = new L.U.Marker(this.map, [10, 20], {
datalayer: this.datalayer,
it('should change icon symbol', function () { }).addTo(this.datalayer)
enableEdit(); assert.equal(this.datalayer._index.length, 4)
happen.click(qs('div.umap-drop-icon')); other = layer.clone()
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')); assert.ok(this.map.hasLayer(other))
changeInputValue(qs('form#umap-feature-shape-properties .umap-field-iconUrl input[name=iconUrl]'), '1'); assert.equal(this.datalayer._index.length, 5)
assert.equal(qs('div.umap-drop-icon span').textContent, '1'); // Must not be the same reference
changeInputValue(qs('form#umap-feature-shape-properties .umap-field-iconUrl input[name=iconUrl]'), '{name}'); assert.notEqual(layer._latlng, other._latlng)
assert.equal(qs('div.umap-drop-icon span').textContent, 'test'); assert.equal(L.Util.formatNum(layer._latlng.lat), other._latlng.lat)
clickCancel(); assert.equal(L.Util.formatNum(layer._latlng.lng), other._latlng.lng)
}); })
})
}); })
describe('#iconClassChange()', function () {
it('should change icon class', function () {
enableEdit();
happen.click(qs('div.umap-drop-icon'));
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');
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 () {
it('should clone marker', function () {
var layer = new L.U.Marker(this.map, [10, 20], {datalayer: this.datalayer}).addTo(this.datalayer);
assert.equal(this.datalayer._index.length, 4);
other = layer.clone();
assert.ok(this.map.hasLayer(other));
assert.equal(this.datalayer._index.length, 5);
// Must not be the same reference
assert.notEqual(layer._latlng, other._latlng);
assert.equal(L.Util.formatNum(layer._latlng.lat), other._latlng.lat);
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 })
after(function () { this.datalayer = this.map.getDataLayerByUmapId(62)
clickCancel(); this.server.respond()
this.server.restore(); enableEdit()
resetMap(); })
}); after(function () {
clickCancel()
this.server.restore()
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 () {
var button
}); it('should only allow edit_status', function () {
describe('#anonymous with cookie', function () { this.map.permissions.options.anonymous_edit_url = 'http://anonymous.url'
var button; button = qs('a.update-map-permissions')
happen.click(button)
expect(qs('select[name="edit_status"]')).to.be.ok
expect(qs('select[name="share_status"]')).not.to.be.ok
expect(qs('input.edit-owner')).not.to.be.ok
})
})
it('should only allow edit_status', function () { describe('#editor', function () {
this.map.permissions.options.anonymous_edit_url = 'http://anonymous.url'; var button
button = qs('a.update-map-permissions');
happen.click(button);
expect(qs('select[name="edit_status"]')).to.be.ok;
expect(qs('select[name="share_status"]')).not.to.be.ok;
expect(qs('input.edit-owner')).not.to.be.ok;
});
}); it('should only allow editors', function () {
this.map.permissions.options.owner = { id: 1, url: '/url', name: 'jojo' }
button = qs('a.update-map-permissions')
happen.click(button)
expect(qs('select[name="edit_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-editors')).to.be.ok
})
})
describe('#editor', function () { describe('#owner', function () {
var button; var button
it('should only allow editors', 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' }
button = qs('a.update-map-permissions'); this.map.options.user = { id: 1, url: '/url', name: 'jojo' }
happen.click(button); button = qs('a.update-map-permissions')
expect(qs('select[name="edit_status"]')).not.to.be.ok; happen.click(button)
expect(qs('select[name="share_status"]')).not.to.be.ok; expect(qs('select[name="edit_status"]')).to.be.ok
expect(qs('input.edit-owner')).not.to.be.ok; expect(qs('select[name="share_status"]')).to.be.ok
expect(qs('input.edit-editors')).to.be.ok; expect(qs('input.edit-owner')).to.be.ok
}); expect(qs('input.edit-editors')).to.be.ok
})
}); })
})
describe('#owner', function () {
var button;
it('should allow everything', function () {
this.map.permissions.options.owner = {id: 1, url: '/url', name: 'jojo'};
this.map.options.user = {id: 1, url: '/url', name: 'jojo'};
button = qs('a.update-map-permissions');
happen.click(button);
expect(qs('select[name="edit_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-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 () {
this.datalayer.empty()
})
describe('#isMulti()', 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 }
)
assert.notOk(layer.isMulti())
})
it('should return false for nested basic Polygon', function () {
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer })
assert.notOk(layer.isMulti())
})
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 }
)
assert.notOk(layer.isMulti())
})
it('should return true for multi Polygon', function () {
var latLngs = [
[
[
[1, 2],
[3, 4],
[5, 6],
],
],
[
[
[7, 8],
[9, 10],
[11, 12],
],
],
]
var layer = new L.U.Polygon(this.map, latLngs, { datalayer: this.datalayer })
assert.ok(layer.isMulti())
})
it('should return true for multi Polygon with hole', function () {
var latLngs = [
[
[
[10, 20],
[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())
})
})
describe('#contextmenu', function () {
afterEach(function () { afterEach(function () {
this.datalayer.empty(); // Make sure contextmenu is hidden
}); happen.once(document, { type: 'keydown', keyCode: 27 })
})
describe('#isMulti()', function () { describe('#in edit mode', function () {
it('should allow to remove shape when multi', function () {
var latlngs = [
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]],
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
],
layer = new L.U.Polygon(this.map, latlngs, {
datalayer: this.datalayer,
}).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Remove shape from the multi'), 1)
})
it('should return false for basic Polygon', function () { it('should not allow to remove shape when not multi', function () {
var layer = new L.U.Polygon(this.map, [[1, 2], [3, 4], [5, 6]], {datalayer: this.datalayer}); var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
assert.notOk(layer.isMulti()) layer = new L.U.Polygon(this.map, latlngs, {
}); datalayer: this.datalayer,
}).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Remove shape from the multi'))
})
it('should return false for nested basic Polygon', 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)
assert.notOk(layer.isMulti()) happen.once(layer._path, { type: 'contextmenu' })
}); assert.notOk(qst('Extract shape to separate feature'))
})
it('should return false for simple Polygon with hole', function () { it('should allow to isolate shape when multi', 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 latlngs = [
assert.notOk(layer.isMulti()) [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]],
}); [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
],
layer = new L.U.Polygon(this.map, latlngs, {
datalayer: this.datalayer,
}).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.ok(qst('Extract shape to separate feature'))
})
it('should return true for multi Polygon', 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)]],
[[1, 2], [3, 4], [5, 6]] [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
], ],
[ layer = new L.U.Polygon(this.map, latlngs, {
[[7, 8], [9, 10], [11, 12]] datalayer: this.datalayer,
] }).addTo(this.datalayer)
]; happen.once(layer._path, { type: 'contextmenu' })
var layer = new L.U.Polygon(this.map, latLngs, {datalayer: this.datalayer}); assert.notOk(qst('Transform to lines'))
assert.ok(layer.isMulti()) })
});
it('should return true for multi Polygon with hole', function () { it('should not allow to transform to lines when hole', function () {
var latLngs = [ var latlngs = [
[[[10, 20], [30, 40], [50, 60]]], [
[[[0, 10], [10, 10], [10, 0]], [[2, 3], [2, 4], [3, 4]]] [p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)],
]; [p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)],
var layer = new L.U.Polygon(this.map, latLngs, {datalayer: this.datalayer}); ],
assert.ok(layer.isMulti()) ],
}); layer = new L.U.Polygon(this.map, latlngs, {
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 () {
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]]
new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
this.datalayer
)
happen.at('contextmenu', 150, 150)
assert.equal(qst('Transform to lines'), 1)
})
describe('#contextmenu', 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)
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'))
})
afterEach(function () { it('should not allow to transfer shape when editedFeature is not a polygon', function () {
// Make sure contextmenu is hidden var layer = new L.U.Polygon(
happen.once(document, {type: 'keydown', keyCode: 27}); this.map,
}); [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)],
{ datalayer: this.datalayer }
).addTo(this.datalayer),
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'))
})
describe('#in edit mode', function () { it('should allow to transfer shape when another polygon is edited', function (done) {
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)
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()
})
})
})
it('should allow to remove shape when multi', function () { describe('#addShape', function () {
var latlngs = [ it('"add shape" control should not be visible by default', function () {
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], assert.notOk(qs('.umap-draw-polygon-multi'))
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]] })
],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).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('"add shape" control should be visible when editing a Polygon', function () {
var latlngs = [ var layer = new L.U.Polygon(this.map, [p2ll(100, 100), p2ll(100, 200)], {
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]] datalayer: this.datalayer,
], }).addTo(this.datalayer)
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer.edit()
happen.once(layer._path, {type: 'contextmenu'}); assert.ok(qs('.umap-draw-polygon-multi'))
assert.notOk(qst('Remove shape from the multi')); })
});
it('should not allow to isolate shape when not multi', function () { it('"add shape" control should extend the same multi', function () {
var latlngs = [ var layer = new L.U.Polygon(
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]] this.map,
], [p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); { datalayer: this.datalayer }
happen.once(layer._path, {type: 'contextmenu'}); ).addTo(this.datalayer)
assert.notOk(qst('Extract shape to separate feature')); layer.edit()
}); assert.notOk(layer.isMulti())
happen.click(qs('.umap-draw-polygon-multi'))
happen.at('mousemove', 300, 300)
happen.at('click', 300, 300)
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)
})
})
it('should allow to isolate shape when multi', function () { describe('#transferShape', function () {
var latlngs = [ it('should transfer simple polygon shape to another polygon', function () {
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[[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, {datalayer: this.datalayer}).addTo(this.datalayer); ),
happen.once(layer._path, {type: 'contextmenu'}); other = new L.U.Polygon(
assert.ok(qst('Extract shape to separate feature')); this.map,
}); [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)],
{ 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 not allow to transform to lines when multi', function () { it('should transfer multipolygon shape to another polygon', function () {
var latlngs = [ var latlngs = [
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], [
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]] [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
], [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'}); [[p2ll(200, 300), p2ll(300, 200)]],
assert.notOk(qst('Transform to lines')); ],
}); layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
this.datalayer
),
other = new L.U.Polygon(
this.map,
[p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)],
{ 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[0][0])
assert.ok(this.map.hasLayer(layer))
assert.equal(layer._latlngs.length, 1)
})
})
it('should not allow to transform to lines when hole', function () { describe('#isolateShape', function () {
var latlngs = [ it('should not allow to isolate simple polygon', function () {
[ var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)], layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
[p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)] this.datalayer
] )
], assert.equal(this.datalayer._index.length, 1)
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); assert.ok(this.map.hasLayer(layer))
happen.once(layer._path, {type: 'contextmenu'}); layer.isolateShape(p2ll(150, 150))
assert.notOk(qst('Transform to lines')); assert.equal(layer._latlngs[0].length, 3)
}); assert.equal(this.datalayer._index.length, 1)
})
it('should allow to transform to lines when not multi', function () { it('should isolate multipolygon shape', function () {
var latlngs = [ var latlngs = [
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]] [
]; [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); [p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)],
happen.at('contextmenu', 150, 150); ],
assert.equal(qst('Transform to lines'), 1); [[p2ll(200, 300), p2ll(300, 200)]],
}); ],
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
this.datalayer
)
assert.equal(this.datalayer._index.length, 1)
assert.ok(this.map.hasLayer(layer))
var other = layer.isolateShape(p2ll(150, 150))
assert.equal(this.datalayer._index.length, 2)
assert.equal(other._latlngs.length, 2)
assert.deepEqual(other._latlngs[0], latlngs[0][0])
assert.ok(this.map.hasLayer(layer))
assert.ok(this.map.hasLayer(other))
assert.equal(layer._latlngs.length, 1)
other.remove()
})
})
it('should not allow to transfer shape when not editedFeature', function () { describe('#clone', function () {
new L.U.Polygon(this.map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], {datalayer: this.datalayer}).addTo(this.datalayer); it('should clone polygon', function () {
happen.at('contextmenu', 110, 160); var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
assert.equal(qst('Delete this feature'), 1); // Make sure we have right clicked on the polygon. layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
assert.notOk(qst('Transfer shape to edited feature')); this.datalayer
}); )
assert.equal(this.datalayer._index.length, 1)
it('should not allow to transfer shape when editedFeature is not a polygon', function () { other = layer.clone()
var layer = new L.U.Polygon(this.map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], {datalayer: this.datalayer}).addTo(this.datalayer), assert.ok(this.map.hasLayer(other))
other = new L.U.Polyline(this.map, [p2ll(200, 250), p2ll(200, 300)], {datalayer: this.datalayer}).addTo(this.datalayer); assert.equal(this.datalayer._index.length, 2)
other.edit(); // Must not be the same reference
happen.once(layer._path, {type: 'contextmenu'}); assert.notEqual(layer._latlngs, other._latlngs)
assert.equal(qst('Delete this feature'), 1); // Make sure we have right clicked on the polygon. assert.equal(L.Util.formatNum(layer._latlngs[0][0].lat), other._latlngs[0][0].lat)
assert.notOk(qst('Transfer shape to edited feature')); assert.equal(L.Util.formatNum(layer._latlngs[0][0].lng), other._latlngs[0][0].lng)
}); })
})
it('should allow to transfer shape when another polygon is edited', function (done) { })
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);
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 () {
it('"add shape" control should not be visible by default', function () {
assert.notOk(qs('.umap-draw-polygon-multi'));
});
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);
layer.edit();
assert.ok(qs('.umap-draw-polygon-multi'));
});
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);
layer.edit();
assert.notOk(layer.isMulti());
happen.click(qs('.umap-draw-polygon-multi'));
happen.at('mousemove', 300, 300);
happen.at('click', 300, 300);
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 () {
it('should transfer simple polygon shape to another polygon', function () {
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),
other = new L.U.Polygon(this.map, [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)], {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 () {
var latlngs = [
[
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)]
],
[[p2ll(200, 300), p2ll(300, 200)]]
],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer),
other = new L.U.Polygon(this.map, [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)], {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[0][0]);
assert.ok(this.map.hasLayer(layer));
assert.equal(layer._latlngs.length, 1);
});
});
describe('#isolateShape', function () {
it('should not allow to isolate simple polygon', function () {
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);
assert.equal(this.datalayer._index.length, 1);
assert.ok(this.map.hasLayer(layer));
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 () {
var latlngs = [
[
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)]
],
[[p2ll(200, 300), p2ll(300, 200)]]
],
layer = new L.U.Polygon(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer);
assert.equal(this.datalayer._index.length, 1);
assert.ok(this.map.hasLayer(layer));
var other = layer.isolateShape(p2ll(150, 150));
assert.equal(this.datalayer._index.length, 2);
assert.equal(other._latlngs.length, 2);
assert.deepEqual(other._latlngs[0], latlngs[0][0]);
assert.ok(this.map.hasLayer(layer));
assert.ok(this.map.hasLayer(other));
assert.equal(layer._latlngs.length, 1);
other.remove();
});
});
describe('#clone', function () {
it('should clone polygon', function () {
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);
assert.equal(this.datalayer._index.length, 1);
other = layer.clone();
assert.ok(this.map.hasLayer(other));
assert.equal(this.datalayer._index.length, 2);
// Must not be the same reference
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].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 () {
this.datalayer.empty()
})
describe('#isMulti()', 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 }
)
assert.notOk(layer.isMulti())
})
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 }
)
assert.notOk(layer.isMulti())
})
it('should return true for multi Polyline', function () {
var latLngs = [
[
[
[1, 2],
[3, 4],
[5, 6],
],
],
[
[
[7, 8],
[9, 10],
[11, 12],
],
],
]
var layer = new L.U.Polyline(this.map, latLngs, { datalayer: this.datalayer })
assert.ok(layer.isMulti())
})
})
describe('#contextmenu', function () {
afterEach(function () { afterEach(function () {
this.datalayer.empty(); // Make sure contextmenu is hidden.
}); happen.once(document, { type: 'keydown', keyCode: 27 })
})
describe('#isMulti()', function () { describe('#in edit mode', function () {
it('should allow to remove shape when multi', function () {
var latlngs = [
[p2ll(100, 100), p2ll(100, 200)],
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)],
],
layer = new L.U.Polyline(this.map, latlngs, {
datalayer: this.datalayer,
}).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Remove shape from the multi'), 1)
})
it('should return false for basic Polyline', function () { it('should not allow to remove shape when not multi', function () {
var layer = new L.U.Polyline(this.map, [[1, 2], [3, 4], [5, 6]], {datalayer: this.datalayer}); var latlngs = [[p2ll(100, 100), p2ll(100, 200)]],
assert.notOk(layer.isMulti()) layer = new L.U.Polyline(this.map, latlngs, {
}); datalayer: this.datalayer,
}).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Remove shape from the multi'))
})
it('should return false for nested basic Polyline', function () { it('should not allow to isolate shape when not multi', function () {
var layer = new L.U.Polyline(this.map, [[[1, 2], [3, 4], [5, 6]]], {datalayer: this.datalayer}); var latlngs = [[p2ll(100, 100), p2ll(100, 200)]],
assert.notOk(layer.isMulti()) layer = new L.U.Polyline(this.map, latlngs, {
}); datalayer: this.datalayer,
}).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Extract shape to separate feature'))
})
it('should return true for multi Polyline', function () { it('should allow to isolate shape when multi', function () {
var latLngs = [ var latlngs = [
[ [p2ll(100, 150), p2ll(100, 200)],
[[1, 2], [3, 4], [5, 6]] [p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)],
], ],
[ layer = new L.U.Polyline(this.map, latlngs, {
[[7, 8], [9, 10], [11, 12]] datalayer: this.datalayer,
] }).addTo(this.datalayer)
]; happen.once(layer._path, { type: 'contextmenu' })
var layer = new L.U.Polyline(this.map, latLngs, {datalayer: this.datalayer}); assert.ok(qst('Extract shape to separate feature'))
assert.ok(layer.isMulti()) })
});
}); it('should not allow to transform to polygon when multi', function () {
var latlngs = [
[p2ll(100, 150), p2ll(100, 200)],
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)],
],
layer = new L.U.Polyline(this.map, latlngs, {
datalayer: this.datalayer,
}).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Transform to polygon'))
})
describe('#contextmenu', function () { it('should allow to transform to polygon when not multi', function () {
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)
happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Transform to polygon'), 1)
})
afterEach(function () { it('should not allow to transfer shape when not editedFeature', function () {
// Make sure contextmenu is hidden. var layer = new L.U.Polyline(this.map, [p2ll(100, 150), p2ll(100, 200)], {
happen.once(document, {type: 'keydown', keyCode: 27}); datalayer: this.datalayer,
}); }).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Transfer shape to edited feature'))
})
describe('#in edit mode', 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),
other = new L.U.Polygon(
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 remove shape when multi', function () { it('should allow to transfer shape when another line is edited', function () {
var latlngs = [ var layer = new L.U.Polyline(
[p2ll(100, 100), p2ll(100, 200)], this.map,
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
], { 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'}) other = new L.U.Polyline(this.map, [p2ll(200, 300), p2ll(300, 200)], {
assert.equal(qst('Remove shape from the multi'), 1); 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 not allow to remove shape when not 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)],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); ],
happen.once(layer._path, {type: 'contextmenu'}) layer = new L.U.Polyline(this.map, latlngs, {
assert.notOk(qst('Remove shape from the multi')); datalayer: this.datalayer,
}); }).addTo(this.datalayer)
happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Merge lines'), 1)
})
it('should not allow to isolate shape 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('Extract shape to separate feature')); assert.notOk(qst('Merge lines'))
}); })
it('should allow to isolate shape when multi', 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(100, 150), p2ll(100, 200)], layer = new L.U.Polyline(this.map, latlngs, {
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] datalayer: this.datalayer,
], }).addTo(this.datalayer)
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer.enableEdit()
happen.once(layer._path, {type: 'contextmenu'}); happen.at('contextmenu', 350, 400)
assert.ok(qst('Extract shape to separate feature')); assert.equal(qst('Split line'), 1)
}); })
it('should not allow to transform to polygon when multi', 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(100, 150), p2ll(100, 200)], layer = new L.U.Polyline(this.map, latlngs, {
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] datalayer: this.datalayer,
], }).addTo(this.datalayer)
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); layer.enableEdit()
happen.once(layer._path, {type: 'contextmenu'}); happen.at('contextmenu', 300, 350)
assert.notOk(qst('Transform to polygon')); assert.equal(qst('Delete this feature'), 1) // Make sure we have clicked on the vertex.
}); assert.notOk(qst('Split line'))
})
it('should allow to transform to polygon when not multi', function () { it('should not allow to split lines when clicking on last vertex', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [[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.equal(qst('Transform to polygon'), 1); }).addTo(this.datalayer)
}); layer.enableEdit()
happen.at('contextmenu', 400, 300)
assert.equal(qst('Delete this feature'), 1) // Make sure we have clicked on the vertex.
assert.notOk(qst('Split line'))
})
})
})
it('should not allow to transfer shape when not editedFeature', function () { describe('#addShape', function () {
var layer = new L.U.Polyline(this.map, [p2ll(100, 150), p2ll(100, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); it('"add shape" control should not be visible by default', function () {
happen.once(layer._path, {type: 'contextmenu'}); assert.notOk(qs('.umap-draw-polyline-multi'))
assert.notOk(qst('Transfer shape to edited feature')); })
});
it('should not allow to transfer shape when editedFeature is not a line', function () { it('"add shape" control should be visible when editing a Polyline', 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, 100), 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'}); layer.edit()
assert.notOk(qst('Transfer shape to edited feature')); assert.ok(qs('.umap-draw-polyline-multi'))
}); })
it('should allow to transfer shape when another line is edited', function () { it('"add shape" control should extend the same multi', 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(this.map, [p2ll(100, 100), p2ll(100, 200)], {
other = new L.U.Polyline(this.map, [p2ll(200, 300), p2ll(300, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); datalayer: this.datalayer,
other.edit(); }).addTo(this.datalayer)
happen.once(layer._path, {type: 'contextmenu'}); layer.edit()
assert.equal(qst('Transfer shape to edited feature'), 1); assert.notOk(layer.isMulti())
}); happen.click(qs('.umap-draw-polyline-multi'))
happen.at('mousemove', 300, 300)
happen.at('click', 300, 300)
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)
})
})
it('should allow to merge lines when multi', function () { describe('#transferShape', function () {
var latlngs = [ it('should transfer simple line shape to another line', function () {
[p2ll(100, 100), p2ll(100, 200)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[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),
happen.once(layer._path, {type: 'contextmenu'}) other = new L.U.Polyline(this.map, [p2ll(200, 300), p2ll(300, 200)], {
assert.equal(qst('Merge lines'), 1); 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], latlngs)
assert.notOk(this.map.hasLayer(layer))
})
it('should not allow to merge lines when not multi', function () { it('should transfer multi line shape to another line', function () {
var latlngs = [ var latlngs = [
[p2ll(100, 100), p2ll(100, 200)] [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
], [p2ll(200, 300), p2ll(300, 200)],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); ],
happen.once(layer._path, {type: 'contextmenu'}) layer = new L.U.Polyline(this.map, latlngs, {
assert.notOk(qst('Merge lines')); datalayer: this.datalayer,
}); }).addTo(this.datalayer),
other = new L.U.Polyline(this.map, [p2ll(250, 300), p2ll(350, 200)], {
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], latlngs[0])
assert.ok(this.map.hasLayer(layer))
assert.equal(layer._latlngs.length, 1)
})
})
it('should allow to split lines when clicking on vertex', function () { describe('#mergeShapes', function () {
var latlngs = [ it('should remove duplicated join point when merging', function () {
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] var latlngs = [
], [
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); [0, 0],
layer.enableEdit(); [0, 1],
happen.at('contextmenu', 350, 400); ],
assert.equal(qst('Split line'), 1); [
}); [0, 1],
[0, 2],
],
],
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 not allow to split lines when clicking on first vertex', function () { it('should revert candidate if first point is closer', function () {
var latlngs = [ var latlngs = [
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] [
], [0, 0],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); [0, 1],
layer.enableEdit(); ],
happen.at('contextmenu', 300, 350); [
assert.equal(qst('Delete this feature'), 1); // Make sure we have clicked on the vertex. [0, 2],
assert.notOk(qst('Split line')); [0, 1],
}); ],
],
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]),
])
})
})
it('should not allow to split lines when clicking on last vertex', function () { describe('#isolateShape', function () {
var latlngs = [ it('should not allow to isolate simple line', function () {
[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)] var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
], layer = new L.U.Polyline(this.map, latlngs, {
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer); datalayer: this.datalayer,
layer.enableEdit(); }).addTo(this.datalayer)
happen.at('contextmenu', 400, 300); assert.equal(this.datalayer._index.length, 1)
assert.equal(qst('Delete this feature'), 1); // Make sure we have clicked on the vertex. assert.ok(this.map.hasLayer(layer))
assert.notOk(qst('Split line')); layer.isolateShape(p2ll(150, 150))
}); assert.equal(layer._latlngs.length, 3)
assert.equal(this.datalayer._index.length, 1)
})
}); it('should isolate multipolyline shape', function () {
var latlngs = [
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[[p2ll(200, 300), p2ll(300, 200)]],
],
layer = new L.U.Polyline(this.map, latlngs, {
datalayer: this.datalayer,
}).addTo(this.datalayer)
assert.equal(this.datalayer._index.length, 1)
assert.ok(this.map.hasLayer(layer))
var other = layer.isolateShape(p2ll(150, 150))
assert.equal(this.datalayer._index.length, 2)
assert.equal(other._latlngs.length, 3)
assert.deepEqual(other._latlngs, latlngs[0])
assert.ok(this.map.hasLayer(layer))
assert.ok(this.map.hasLayer(other))
assert.equal(layer._latlngs.length, 1)
other.remove()
})
})
}); describe('#clone', function () {
it('should clone polyline', function () {
describe('#addShape', function () { var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polyline(this.map, latlngs, {
it('"add shape" control should not be visible by default', function () { datalayer: this.datalayer,
assert.notOk(qs('.umap-draw-polyline-multi')); }).addTo(this.datalayer)
}); assert.equal(this.datalayer._index.length, 1)
other = layer.clone()
it('"add shape" control should be visible when editing a Polyline', function () { assert.ok(this.map.hasLayer(other))
var layer = new L.U.Polyline(this.map, [p2ll(100, 100), p2ll(100, 200)], {datalayer: this.datalayer}).addTo(this.datalayer); assert.equal(this.datalayer._index.length, 2)
layer.edit(); // Must not be the same reference
assert.ok(qs('.umap-draw-polyline-multi')); 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].lng), other._latlngs[0].lng)
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); })
layer.edit(); })
assert.notOk(layer.isMulti());
happen.click(qs('.umap-draw-polyline-multi'));
happen.at('mousemove', 300, 300);
happen.at('click', 300, 300);
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 () {
it('should transfer simple line shape to another line', function () {
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),
other = new L.U.Polyline(this.map, [p2ll(200, 300), p2ll(300, 200)], {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], latlngs);
assert.notOk(this.map.hasLayer(layer));
});
it('should transfer multi line shape to another line', function () {
var latlngs = [
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[p2ll(200, 300), p2ll(300, 200)]
],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer),
other = new L.U.Polyline(this.map, [p2ll(250, 300), p2ll(350, 200)], {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], latlngs[0]);
assert.ok(this.map.hasLayer(layer));
assert.equal(layer._latlngs.length, 1);
});
});
describe('#mergeShapes', function () {
it('should remove duplicated join point when merging', function () {
var latlngs = [
[[0, 0], [0, 1]],
[[0, 1], [0, 2]],
],
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 () {
var latlngs = [
[[0, 0], [0, 1]],
[[0, 2], [0, 1]],
],
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 () {
it('should not allow to isolate simple line', function () {
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);
assert.equal(this.datalayer._index.length, 1);
assert.ok(this.map.hasLayer(layer));
layer.isolateShape(p2ll(150, 150));
assert.equal(layer._latlngs.length, 3);
assert.equal(this.datalayer._index.length, 1);
});
it('should isolate multipolyline shape', function () {
var latlngs = [
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
[[p2ll(200, 300), p2ll(300, 200)]]
],
layer = new L.U.Polyline(this.map, latlngs, {datalayer: this.datalayer}).addTo(this.datalayer);
assert.equal(this.datalayer._index.length, 1);
assert.ok(this.map.hasLayer(layer));
var other = layer.isolateShape(p2ll(150, 150));
assert.equal(this.datalayer._index.length, 2);
assert.equal(other._latlngs.length, 3);
assert.deepEqual(other._latlngs, latlngs[0]);
assert.ok(this.map.hasLayer(layer));
assert.ok(this.map.hasLayer(other));
assert.equal(layer._latlngs.length, 1);
other.remove();
});
});
describe('#clone', function () {
it('should clone polyline', function () {
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);
assert.equal(this.datalayer._index.length, 1);
other = layer.clone();
assert.ok(this.map.hasLayer(other));
assert.equal(this.datalayer._index.length, 2);
// Must not be the same reference
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].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 () {
this.server = sinon.fakeServer.create()
this.server.respondWith(
'GET',
'/datalayer/62/',
JSON.stringify(RESPONSES.datalayer62_GET)
)
this.map = initMap({ umap_id: 99 })
this.datalayer = this.map.getDataLayerByUmapId(62)
this.server.respond()
enableEdit()
})
after(function () {
clickCancel()
this.server.restore()
resetMap()
})
describe('#open()', function () {
var button
it('should exist table click on edit mode', function () {
button = qs(
'#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-table-edit'
)
expect(button).to.be.ok
})
it('should open table button click', function () {
happen.click(button)
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 input').length).to.eql(3) // One per feature and per property.
})
})
describe('#properties()', function () {
var feature
before(function () { before(function () {
this.server = sinon.fakeServer.create(); var firstIndex = this.datalayer._index[0]
this.server.respondWith('GET', '/datalayer/62/', JSON.stringify(RESPONSES.datalayer62_GET)); feature = this.datalayer._layers[firstIndex]
this.map = initMap({umap_id: 99}); })
this.datalayer = this.map.getDataLayerByUmapId(62);
this.server.respond();
enableEdit();
});
after(function () {
clickCancel();
this.server.restore();
resetMap();
});
describe('#open()', function () { it('should create new property column', function () {
var button; var newPrompt = function () {
return 'newprop'
}
var oldPrompt = window.prompt
window.prompt = newPrompt
var button = qs('#umap-ui-container .add-property')
expect(button).to.be.ok
happen.click(button)
expect(qsa('#umap-ui-container div.table input').length).to.eql(6) // One per feature and per property.
window.prompt = oldPrompt
})
it('should exist table click on edit mode', function () { it('should populate feature property on fill', function () {
button = qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-table-edit'); var input = qs(
expect(button).to.be.ok; 'form#umap-feature-properties_' + L.stamp(feature) + ' input[name=newprop]'
}); )
changeInputValue(input, 'the value')
expect(feature.properties.newprop).to.eql('the value')
})
it('should open table button click', function () { it('should update property name on update click', function () {
happen.click(button); var newPrompt = function () {
expect(qs('#umap-ui-container div.table')).to.be.ok; return 'newname'
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. var oldPrompt = window.prompt
}); window.prompt = newPrompt
var button = qs('#umap-ui-container div.thead div.tcell:last-of-type .umap-edit')
expect(button).to.be.ok
happen.click(button)
expect(qsa('#umap-ui-container div.table input').length).to.eql(6)
expect(feature.properties.newprop).to.be.undefined
expect(feature.properties.newname).to.eql('the value')
window.prompt = oldPrompt
})
}); it('should update property on delete click', function () {
describe('#properties()', function () { var oldConfirm,
var feature; newConfirm = function () {
return true
before(function () { }
var firstIndex = this.datalayer._index[0]; oldConfirm = window.confirm
feature = this.datalayer._layers[firstIndex]; window.confirm = newConfirm
}); var button = qs(
'#umap-ui-container div.thead div.tcell:last-of-type .umap-delete'
it('should create new property column', function () { )
var newPrompt = function () { expect(button).to.be.ok
return 'newprop'; happen.click(button)
}; FEATURE = feature
var oldPrompt = window.prompt; expect(qsa('#umap-ui-container div.table input').length).to.eql(3)
window.prompt = newPrompt; expect(feature.properties.newname).to.be.undefined
var button = qs('#umap-ui-container .add-property'); window.confirm = oldConfirm
expect(button).to.be.ok; })
happen.click(button); })
expect(qsa('#umap-ui-container div.table input').length).to.eql(6); // One per feature and per property. })
window.prompt = oldPrompt;
});
it('should populate feature property on fill', function () {
var input = qs('form#umap-feature-properties_' + L.stamp(feature) + ' input[name=newprop]');
changeInputValue(input, 'the value');
expect(feature.properties.newprop).to.eql('the value');
});
it('should update property name on update click', function () {
var newPrompt = function () {
return 'newname';
};
var oldPrompt = window.prompt;
window.prompt = newPrompt;
var button = qs('#umap-ui-container div.thead div.tcell:last-of-type .umap-edit');
expect(button).to.be.ok;
happen.click(button);
expect(qsa('#umap-ui-container div.table input').length).to.eql(6);
expect(feature.properties.newprop).to.be.undefined;
expect(feature.properties.newname).to.eql('the value');
window.prompt = oldPrompt;
});
it('should update property on delete click', function () {
var oldConfirm,
newConfirm = function () {
return true;
};
oldConfirm = window.confirm;
window.confirm = newConfirm;
var button = qs('#umap-ui-container div.thead div.tcell:last-of-type .umap-delete');
expect(button).to.be.ok;
happen.click(button);
FEATURE = feature;
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 () {
assert.equal(L.Util.toHTML('# A title'), '<h3>A title</h3>')
it('should handle title', function () { })
assert.equal(L.Util.toHTML('# A title'), '<h3>A title</h3>');
}); it('should handle title in the middle of the content', function () {
assert.equal(
it('should handle title in the middle of the content', function () { L.Util.toHTML('A phrase\n## A title'),
assert.equal(L.Util.toHTML('A phrase\n## A title'), 'A phrase<br>\n<h4>A title</h4>'); 'A phrase<br>\n<h4>A title</h4>'
}); )
})
it('should handle hr', function () {
assert.equal(L.Util.toHTML('---'), '<hr>'); it('should handle hr', function () {
}); assert.equal(L.Util.toHTML('---'), '<hr>')
})
it('should handle bold', function () {
assert.equal(L.Util.toHTML('Some **bold**'), 'Some <strong>bold</strong>'); it('should handle bold', function () {
}); assert.equal(L.Util.toHTML('Some **bold**'), 'Some <strong>bold</strong>')
})
it('should handle italic', function () {
assert.equal(L.Util.toHTML('Some *italic*'), 'Some <em>italic</em>'); it('should handle italic', function () {
}); assert.equal(L.Util.toHTML('Some *italic*'), 'Some <em>italic</em>')
})
it('should handle newlines', function () {
assert.equal(L.Util.toHTML('two\nlines'), 'two<br>\nlines'); it('should handle newlines', function () {
}); assert.equal(L.Util.toHTML('two\nlines'), 'two<br>\nlines')
})
it('should not change last newline', function () {
assert.equal(L.Util.toHTML('two\nlines\n'), 'two<br>\nlines\n'); it('should not change last newline', function () {
}); assert.equal(L.Util.toHTML('two\nlines\n'), 'two<br>\nlines\n')
})
it('should handle two successive newlines', function () {
assert.equal(L.Util.toHTML('two\n\nlines\n'), 'two<br>\n<br>\nlines\n'); it('should handle two successive newlines', function () {
}); assert.equal(L.Util.toHTML('two\n\nlines\n'), 'two<br>\n<br>\nlines\n')
})
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'); it('should handle links without formatting', function () {
}); assert.equal(
L.Util.toHTML('A simple http://osm.org link'),
it('should handle simple link in title', function () { 'A simple <a target="_blank" href="http://osm.org">http://osm.org</a> link'
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 simple link in title', 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('# http://osm.org'),
'<h3><a target="_blank" href="http://osm.org">http://osm.org</a></h3>'
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>)'); })
});
it('should handle links with url parameter', function () {
it('should handle simple link with formatting', function () { assert.equal(
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'); 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 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>');
}); it('should handle simple link inside parenthesis', function () {
assert.equal(
it('should handle simple link followed by a carriage return', function () { L.Util.toHTML('A simple link (http://osm.org)'),
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'); 'A simple link (<a target="_blank" href="http://osm.org">http://osm.org</a>)'
}); )
})
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">'); it('should handle simple link with formatting', function () {
}); assert.equal(
L.Util.toHTML('A simple [[http://osm.org]] link'),
it('should handle image without text', function () { 'A simple <a target="_blank" href="http://osm.org">http://osm.org</a> link'
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 simple link with formatting and content', 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 [[http://osm.org|link]]'),
'A simple <a target="_blank" href="http://osm.org">link</a>'
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>'); })
});
it('should handle simple link followed by a carriage return', function () {
it('should handle iframe with height', function () { assert.equal(
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>'); 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 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>');
}); it('should handle image', function () {
assert.equal(
it('should handle iframe with height with px', function () { L.Util.toHTML('A simple image: {{http://osm.org/pouet.png}}'),
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>'); 'A simple image: <img src="http://osm.org/pouet.png">'
}); )
})
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>'); it('should handle image without text', function () {
}); assert.equal(
L.Util.toHTML('{{http://osm.org/pouet.png}}'),
it('should handle iframe with height with px', function () { '<img src="http://osm.org/pouet.png">'
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('should handle image with width', 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 simple image: {{http://osm.org/pouet.png|100}}'),
'A simple image: <img src="http://osm.org/pouet.png" width="100">'
}); )
})
describe('#escapeHTML', function () {
it('should handle iframe', function () {
it('should escape HTML tags', function () { assert.equal(
assert.equal(L.Util.escapeHTML('<a href="pouet">'), '&lt;a href="pouet">'); 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 not fail with int value', function () { })
assert.equal(L.Util.escapeHTML(25), '25');
}); it('should handle iframe with height', function () {
assert.equal(
it('should not fail with null value', function () { L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html|200}}}'),
assert.equal(L.Util.escapeHTML(null), ''); '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 () {
describe('#greedyTemplate', function () { assert.equal(
L.Util.toHTML('A simple iframe: {{{http://osm.org/pouet.html|200*400}}}'),
it('should replace simple props', function () { 'A simple iframe: <div><iframe frameborder="0" src="http://osm.org/pouet.html" width="400px" height="200px"></iframe></div>'
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 handle iframe with height with px', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {missing}', {}), 'A phrase with a '); 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 process brakets in brakets', function () { )
assert.equal(L.Util.greedyTemplate('A phrase with a {{{variable}}}.', {variable: 'value'}), 'A phrase with a {{value}}.'); })
});
it('should handle iframe with url parameter', function () {
it('should not process http links', function () { assert.equal(
assert.equal(L.Util.greedyTemplate('A phrase with a {{{http://iframeurl.com}}}.', {'http://iframeurl.com': 'value'}), 'A phrase with a {{{http://iframeurl.com}}}.'); L.Util.toHTML(
}); 'A simple iframe: {{{https://osm.org/?url=https%3A//anotherurl.com}}}'
),
it('should not accept dash', function () { '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.greedyTemplate('A phrase with a {var-iable}.', {'var-iable': 'value'}), 'A phrase with a {var-iable}.'); )
}); })
it('should accept colon', function () { it('should handle iframe with height with px', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {variable:fr}.', {'variable:fr': 'value'}), 'A phrase with a value.'); assert.equal(
}); L.Util.toHTML(
'A double iframe: {{{https://osm.org/pouet}}}{{{https://osm.org/boudin}}}'
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.'); '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('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}.'); it('http link with http link as parameter as variable', function () {
}); assert.equal(
L.Util.toHTML(
it('should replace nested variables', function () { 'A phrase with a [[http://iframeurl.com?to=http://another.com]].'
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var}.', {fr: {var: 'value'}}), 'A phrase with a value.'); ),
}); 'A phrase with a <a target="_blank" href="http://iframeurl.com?to=http://another.com">http://iframeurl.com?to=http://another.com</a>.'
)
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 .'); })
});
describe('#escapeHTML', function () {
it('should not fail with nested variables and no data', function () { it('should escape HTML tags', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.foo}.', {}), 'A phrase with a .'); assert.equal(L.Util.escapeHTML('<a href="pouet">'), '&lt;a href="pouet">')
}); })
it('should handle fallback value if any', function () { it('should not fail with int value', function () {
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|"default"}.', {}), 'A phrase with a default.'); assert.equal(L.Util.escapeHTML(25), '25')
}); })
it('should handle fallback var if any', function () { it('should not fail with null value', 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.escapeHTML(null), '')
}); })
})
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.'); describe('#greedyTemplate', function () {
}); it('should replace simple props', function () {
assert.equal(
it('should use the first defined value', function () { L.Util.greedyTemplate('A phrase with a {variable}.', { variable: 'thing' }),
assert.equal(L.Util.greedyTemplate('A phrase with a {fr.var.bar|try.again|"default"}.', {try: { again: 'please'}}), 'A phrase with a please.'); 'A phrase with a thing.'
}); )
})
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.'); it('should not fail when missing key', function () {
}); assert.equal(
L.Util.greedyTemplate('A phrase with a {missing}', {}),
it('should support the first example from #820 when translated to final syntax', function () { 'A phrase with a '
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 process brakets in brakets', function () {
assert.equal(L.Util.greedyTemplate('# {name} ({ele|"-"} m ü. M.)', {name: 'Portalet', ele: 3344}), '# Portalet (3344 m ü. M.)'); assert.equal(
}); L.Util.greedyTemplate('A phrase with a {{{variable}}}.', { variable: 'value' }),
'A phrase with a {{value}}.'
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.'); })
});
it('should not process http links', function () {
it('should support empty string as fallback', function () { assert.equal(
assert.equal(L.Util.greedyTemplate('A phrase with empty string ("{var|""}") in the fallback.', {}), 'A phrase with empty string ("") in the fallback.'); L.Util.greedyTemplate('A phrase with a {{{http://iframeurl.com}}}.', {
}); 'http://iframeurl.com': 'value',
}),
it('should support e.g. links as fallback', function () { 'A phrase with a {{{http://iframeurl.com}}}.'
assert.equal(L.Util.greedyTemplate('A phrase with {var|"[[https://osm.org|link]]"} as fallback.', {}), 'A phrase with [[https://osm.org|link]] as fallback.'); )
}); })
});
it('should not accept dash', function () {
describe('#TextColorFromBackgroundColor', function () { assert.equal(
L.Util.greedyTemplate('A phrase with a {var-iable}.', { 'var-iable': 'value' }),
it('should output white for black', function () { 'A phrase with a {var-iable}.'
document.body.style.backgroundColor = 'black'; )
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#ffffff'); })
});
it('should accept colon', function () {
it('should output white for brown', function () { assert.equal(
document.body.style.backgroundColor = 'brown'; L.Util.greedyTemplate('A phrase with a {variable:fr}.', {
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#ffffff'); 'variable:fr': 'value',
}); }),
'A phrase with a value.'
it('should output black for white', function () { )
document.body.style.backgroundColor = 'white'; })
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000');
}); it('should replace even with ignore if key is found', function () {
assert.equal(
it('should output black for tan', function () { L.Util.greedyTemplate(
document.body.style.backgroundColor = 'tan'; 'A phrase with a {variable:fr}.',
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000'); { 'variable:fr': 'value' },
}); true
),
it('should output black by default', function () { 'A phrase with a value.'
document.body.style.backgroundColor = 'transparent'; )
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000'); })
});
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}.'
describe('#flattenCoordinates()', function () { )
})
it('should not alter already flat coords', function () {
var coords = [[1, 2], [3, 4]]; it('should replace nested variables', function () {
assert.deepEqual(L.Util.flattenCoordinates(coords), coords); assert.equal(
}) L.Util.greedyTemplate('A phrase with a {fr.var}.', { fr: { var: 'value' } }),
'A phrase with a value.'
it('should flatten nested coords', function () { )
var coords = [[[1, 2], [3, 4]]]; })
assert.deepEqual(L.Util.flattenCoordinates(coords), coords[0]);
coords = [[[[1, 2], [3, 4]]]]; it('should not fail if nested variable is missing', function () {
assert.deepEqual(L.Util.flattenCoordinates(coords), coords[0][0]); assert.equal(
}) L.Util.greedyTemplate('A phrase with a {fr.var.foo}.', {
fr: { var: 'value' },
it('should not fail on empty coords', function () { }),
var coords = []; 'A phrase with a .'
assert.deepEqual(L.Util.flattenCoordinates(coords), coords); )
}) })
}); it('should not fail with nested variables and no data', function () {
assert.equal(
describe('#usableOption()', function () { L.Util.greedyTemplate('A phrase with a {fr.var.foo}.', {}),
'A phrase with a .'
it('should consider false', function () { )
assert.ok(L.Util.usableOption({key: false}, 'key')); })
})
it('should handle fallback value if any', function () {
it('should consider 0', function () { assert.equal(
assert.ok(L.Util.usableOption({key: 0}, 'key')); L.Util.greedyTemplate('A phrase with a {fr.var.bar|"default"}.', {}),
}) 'A phrase with a default.'
)
it('should not consider undefined', function () { })
assert.notOk(L.Util.usableOption({}, 'key'));
}) it('should handle fallback var if any', function () {
assert.equal(
it('should not consider empty string', function () { L.Util.greedyTemplate('A phrase with a {fr.var.bar|fallback}.', {
assert.notOk(L.Util.usableOption({key: ''}, 'key')); fallback: 'default',
}) }),
'A phrase with a default.'
it('should consider null', function () { )
assert.ok(L.Util.usableOption({key: null}, 'key')); })
})
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.'
)
})
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.'
)
})
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.'
)
})
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.)'
)
})
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.)'
)
})
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.'
)
})
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.'
)
})
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.'
)
})
})
describe('#TextColorFromBackgroundColor', function () {
it('should output white for black', function () {
document.body.style.backgroundColor = 'black'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#ffffff')
})
it('should output white for brown', function () {
document.body.style.backgroundColor = 'brown'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#ffffff')
})
it('should output black for white', function () {
document.body.style.backgroundColor = 'white'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000')
})
it('should output black for tan', function () {
document.body.style.backgroundColor = 'tan'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000')
})
it('should output black by default', function () {
document.body.style.backgroundColor = 'transparent'
assert.equal(L.DomUtil.TextColorFromBackgroundColor(document.body), '#000000')
})
})
describe('#flattenCoordinates()', function () {
it('should not alter already flat coords', function () {
var coords = [
[1, 2],
[3, 4],
]
assert.deepEqual(L.Util.flattenCoordinates(coords), coords)
})
it('should flatten nested coords', function () {
var coords = [
[
[1, 2],
[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 () {
var coords = []
assert.deepEqual(L.Util.flattenCoordinates(coords), coords)
})
})
describe('#usableOption()', function () {
it('should consider false', function () {
assert.ok(L.Util.usableOption({ key: false }, 'key'))
})
it('should consider 0', function () {
assert.ok(L.Util.usableOption({ key: 0 }, 'key'))
})
it('should not consider undefined', function () {
assert.notOk(L.Util.usableOption({}, 'key'))
})
it('should not consider empty string', function () {
assert.notOk(L.Util.usableOption({ key: '' }, 'key'))
})
it('should consider null', function () {
assert.ok(L.Util.usableOption({ key: null }, 'key'))
})
})
})

View file

@ -1,301 +1,342 @@
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'}); }
if (!found) throw new Error('Value ' + value + 'not found in select ' + path_or_select); happen.once(path_or_select, { type: 'change' })
return path_or_select; if (!found)
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',
name: 'Elephants', name: 'Elephants',
displayOnLoad: true, displayOnLoad: true,
id: 62, id: 62,
pictogram_url: null, pictogram_url: null,
opacity: null, opacity: null,
weight: null, weight: null,
fillColor: '', fillColor: '',
color: '', color: '',
stroke: true, stroke: true,
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',
properties: {
umap_id: 42,
datalayers: [],
urls: {
map: '/map/{slug}_{pk}',
datalayer_view: '/datalayer/{pk}/',
map_update: '/map/{map_id}/update/settings/',
map_old_url: '/map/{username}/{slug}/',
map_clone: '/map/{map_id}/update/clone/',
map_short_url: '/m/{pk}/',
map_anonymous_edit_url: '/map/anonymous-edit/{signature}',
map_new: '/map/new/',
datalayer_update: '/map/{map_id}/datalayer/update/{pk}/',
map_delete: '/map/{map_id}/update/delete/',
map_create: '/map/create/',
logout: '/logout/',
datalayer_create: '/map/{map_id}/datalayer/create/',
login_popup_end: '/login/popupd/',
login: '/login/',
datalayer_delete: '/map/{map_id}/datalayer/delete/{pk}/',
datalayer_versions: '/map/{map_id}/datalayer/{pk}/versions/',
datalayer_version: '/datalayer/{pk}/{name}',
pictogram_list_json: '/pictogram/json/',
map_update_permissions: '/map/{map_id}/update/permissions/',
},
default_iconUrl: '../src/img/marker.png',
zoom: 6,
tilelayers: [
{
attribution: '\u00a9 OSM Contributors',
name: 'OpenStreetMap',
url_template: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
minZoom: 0,
maxZoom: 18,
id: 1,
selected: true,
}, },
"type": "Feature", {
"properties": { attribution: 'HOT and friends',
"umap_id": 42, name: 'HOT OSM-fr server',
"datalayers": [], url_template: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
"urls": { rank: 99,
"map": "/map/{slug}_{pk}", minZoom: 0,
"datalayer_view": "/datalayer/{pk}/", maxZoom: 20,
"map_update": "/map/{map_id}/update/settings/", id: 2,
"map_old_url": "/map/{username}/{slug}/", },
"map_clone": "/map/{map_id}/update/clone/", ],
"map_short_url": "/m/{pk}/", tilelayer: {
"map_anonymous_edit_url": "/map/anonymous-edit/{signature}", attribution: 'HOT and friends',
"map_new": "/map/new/", name: 'HOT OSM-fr server',
"datalayer_update": "/map/{map_id}/datalayer/update/{pk}/", url_template: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
"map_delete": "/map/{map_id}/update/delete/", rank: 99,
"map_create": "/map/create/", minZoom: 0,
"logout": "/logout/", maxZoom: 20,
"datalayer_create": "/map/{map_id}/datalayer/create/", id: 2,
"login_popup_end": "/login/popupd/", },
"login": "/login/", licences: {
"datalayer_delete": "/map/{map_id}/datalayer/delete/{pk}/", 'No licence set': {
"datalayer_versions": "/map/{map_id}/datalayer/{pk}/versions/", url: '',
"datalayer_version": "/datalayer/{pk}/{name}", name: 'No licence set',
"pictogram_list_json": "/pictogram/json/", },
"map_update_permissions": "/map/{map_id}/update/permissions/" 'Licence ouverte/Open Licence': {
}, url: 'http://www.data.gouv.fr/Licence-Ouverte-Open-Licence',
"default_iconUrl": "../src/img/marker.png", name: 'Licence ouverte/Open Licence',
"zoom": 6, },
"tilelayers": [ 'WTFPL': {
{ url: 'http://www.wtfpl.net/',
"attribution": "\u00a9 OSM Contributors", name: 'WTFPL',
"name": "OpenStreetMap", },
"url_template": "http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png", 'ODbl': {
"minZoom": 0, url: 'http://opendatacommons.org/licenses/odbl/',
"maxZoom": 18, name: 'ODbl',
"id": 1, },
"selected": true },
}, name: 'name of the map',
{ description: 'The description of the map',
"attribution": "HOT and friends", allowEdit: true,
"name": "HOT OSM-fr server", moreControl: true,
"url_template": "http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png", scaleControl: true,
"rank": 99, miniMap: true,
"minZoom": 0, datalayersControl: true,
"maxZoom": 20, displayCaptionOnLoad: false,
"id": 2 displayPopupFooter: false,
}], displayDataBrowserOnLoad: false,
"tilelayer": { },
"attribution": "HOT and friends", }
"name": "HOT OSM-fr server", default_options.properties.datalayers.push(defaultDatalayerData())
"url_template": "http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png", options.properties = L.extend({}, default_options.properties, options)
"rank": 99, return new L.U.Map('map', options)
"minZoom": 0,
"maxZoom": 20,
"id": 2
},
"licences": {
"No licence set": {
"url": "",
"name": "No licence set"
},
"Licence ouverte/Open Licence": {
"url": "http://www.data.gouv.fr/Licence-Ouverte-Open-Licence",
"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
}
};
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",
"id": 1807,
"properties": {_umap_options: {color: "OliveDrab"}, name: "test"}
}, },
{ type: 'Feature',
"geometry": { id: 1807,
"type": "LineString", properties: { _umap_options: { color: 'OliveDrab' }, name: 'test' },
"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", geometry: {
"id": 20, "properties": {"_umap_options": {"fill": false}, "name": "test"} 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],
],
}, },
{ type: 'Feature',
"geometry": { id: 20,
"type": "Polygon", properties: { _umap_options: { fill: false }, name: 'test' },
"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", geometry: {
"id": 76, type: 'Polygon',
"properties": {name: "name poly"} 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' },
},
],
},
}
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 =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<kml xmlns="http://www.opengis.net/kml/2.2">' +
'<Placemark>' +
'<name>Simple point</name>' +
'<description>Here is a simple description.</description>' +
'<Point>' +
'<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>' +
'</Point>' +
'</Placemark>' +
'<Placemark>' +
'<name>Simple path</name>' +
'<description>Simple description</description>' +
'<LineString>' +
'<coordinates>-112.2550785337791,36.07954952145647,2357 -112.2549277039738,36.08117083492122,2357 -112.2552505069063,36.08260761307279,2357</coordinates>' +
'</LineString>' +
'</Placemark>' +
'<Placemark>' +
'<name>Simple polygon</name>' +
'<description>A description.</description>' +
'<Polygon>' +
'<outerBoundaryIs>' +
'<LinearRing>' +
'<coordinates>' +
' -77.05788457660967,38.87253259892824,100 ' +
' -77.05465973756702,38.87291016281703,100 ' +
' -77.05315536854791,38.87053267794386,100 ' +
' -77.05788457660967,38.87253259892824,100 ' +
'</coordinates>' +
'</LinearRing>' +
'</outerBoundaryIs>' +
'</Polygon>' +
'</Placemark>' +
'</kml>'
var kml_example = '<?xml version="1.0" encoding="UTF-8"?>' + var gpx_example =
'<kml xmlns="http://www.opengis.net/kml/2.2">' + '<gpx' +
'<Placemark>'+ ' version="1.1"' +
'<name>Simple point</name>'+ ' creator="GPSBabel - http://www.gpsbabel.org"' +
'<description>Here is a simple description.</description>'+ ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
'<Point>'+ ' xmlns="http://www.topografix.com/GPX/1/1"' +
'<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>'+ ' xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">' +
'</Point>'+ ' <wpt lat="45.44283" lon="-121.72904"><ele>1374</ele><name>Simple Point</name><desc>Simple description</desc></wpt>' +
'</Placemark>'+ ' <trk>' +
'<Placemark>'+ ' <name>Simple path</name>' +
'<name>Simple path</name>'+ ' <desc>Simple description</desc>' +
'<description>Simple description</description>'+ ' <trkseg>' +
'<LineString>'+ ' <trkpt lat="45.4431641" lon="-121.7295456"></trkpt>' +
'<coordinates>-112.2550785337791,36.07954952145647,2357 -112.2549277039738,36.08117083492122,2357 -112.2552505069063,36.08260761307279,2357</coordinates>'+ ' <trkpt lat="45.4428615" lon="-121.7290800"></trkpt>' +
'</LineString>'+ ' <trkpt lat="45.4425697" lon="-121.7279085"></trkpt>' +
'</Placemark>'+ ' </trkseg>' +
'<Placemark>'+ ' </trk>' +
'<name>Simple polygon</name>'+ '</gpx>'
'<description>A description.</description>'+
'<Polygon>'+
'<outerBoundaryIs>'+
'<LinearRing>'+
'<coordinates>'+
' -77.05788457660967,38.87253259892824,100 '+
' -77.05465973756702,38.87291016281703,100 '+
' -77.05315536854791,38.87053267794386,100 '+
' -77.05788457660967,38.87253259892824,100 '+
'</coordinates>'+
'</LinearRing>'+
'</outerBoundaryIs>'+
'</Polygon>'+
'</Placemark>'+
'</kml>';
var gpx_example = '<gpx' + var csv_example =
' version="1.1"' + 'Foo,Latitude,Longitude,title,description\n' +
' creator="GPSBabel - http://www.gpsbabel.org"' + 'bar,41.34,122.86,a point somewhere,the description of this point'
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns="http://www.topografix.com/GPX/1/1"' +
' xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">' +
' <wpt lat="45.44283" lon="-121.72904"><ele>1374</ele><name>Simple Point</name><desc>Simple description</desc></wpt>' +
' <trk>' +
' <name>Simple path</name>' +
' <desc>Simple description</desc>' +
' <trkseg>' +
' <trkpt lat="45.4431641" lon="-121.7295456"></trkpt>' +
' <trkpt lat="45.4428615" lon="-121.7290800"></trkpt>' +
' <trkpt lat="45.4425697" lon="-121.7279085"></trkpt>' +
' </trkseg>' +
' </trk>' +
'</gpx>';
var csv_example = '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,118 +1,119 @@
<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>
<script src="../vendors/hash/leaflet-hash.js"></script> <script src="../vendors/hash/leaflet-hash.js"></script>
<script src="../vendors/i18n/Leaflet.i18n.js"></script> <script src="../vendors/i18n/Leaflet.i18n.js"></script>
<script src="../vendors/editinosm/Leaflet.EditInOSM.js"></script> <script src="../vendors/editinosm/Leaflet.EditInOSM.js"></script>
<script src="../vendors/minimap/Control.MiniMap.js"></script> <script src="../vendors/minimap/Control.MiniMap.js"></script>
<script src="../vendors/csv2geojson/csv2geojson.js"></script> <script src="../vendors/csv2geojson/csv2geojson.js"></script>
<script src="../vendors/togeojson/togeojson.js"></script> <script src="../vendors/togeojson/togeojson.js"></script>
<script src="../vendors/osmtogeojson/osmtogeojson.js"></script> <script src="../vendors/osmtogeojson/osmtogeojson.js"></script>
<script src="../vendors/contextmenu/leaflet.contextmenu.js"></script> <script src="../vendors/contextmenu/leaflet.contextmenu.js"></script>
<script src="../vendors/loading/Control.Loading.js"></script> <script src="../vendors/loading/Control.Loading.js"></script>
<script src="../vendors/markercluster/leaflet.markercluster-src.js"></script> <script src="../vendors/markercluster/leaflet.markercluster-src.js"></script>
<script src="../vendors/photon/leaflet.photon.js"></script> <script src="../vendors/photon/leaflet.photon.js"></script>
<script src="../vendors/heat/leaflet-heat.js"></script> <script src="../vendors/heat/leaflet-heat.js"></script>
<script src="../vendors/fullscreen/Leaflet.fullscreen.js"></script> <script src="../vendors/fullscreen/Leaflet.fullscreen.js"></script>
<script src="../vendors/toolbar/leaflet.toolbar-src.js"></script> <script src="../vendors/toolbar/leaflet.toolbar-src.js"></script>
<script src="../vendors/formbuilder/Leaflet.FormBuilder.js"></script> <script src="../vendors/formbuilder/Leaflet.FormBuilder.js"></script>
<script src="../vendors/measurable/Leaflet.Measurable.js"></script> <script src="../vendors/measurable/Leaflet.Measurable.js"></script>
<script src="../vendors/locatecontrol/L.Control.Locate.js"></script> <script src="../vendors/locatecontrol/L.Control.Locate.js"></script>
<script src="../js/umap.core.js"></script> <script src="../js/umap.core.js"></script>
<script src="../js/umap.autocomplete.js"></script> <script src="../js/umap.autocomplete.js"></script>
<script src="../js/umap.popup.js"></script> <script src="../js/umap.popup.js"></script>
<script src="../js/umap.xhr.js"></script> <script src="../js/umap.xhr.js"></script>
<script src="../js/umap.forms.js"></script> <script src="../js/umap.forms.js"></script>
<script src="../js/umap.icon.js"></script> <script src="../js/umap.icon.js"></script>
<script src="../js/umap.features.js"></script> <script src="../js/umap.features.js"></script>
<script src="../js/umap.layer.js"></script> <script src="../js/umap.layer.js"></script>
<script src="../js/umap.controls.js"></script> <script src="../js/umap.controls.js"></script>
<script src="../js/umap.slideshow.js"></script> <script src="../js/umap.slideshow.js"></script>
<script src="../js/umap.tableeditor.js"></script> <script src="../js/umap.tableeditor.js"></script>
<script src="../js/umap.permissions.js"></script> <script src="../js/umap.permissions.js"></script>
<script src="../js/umap.js"></script> <script src="../js/umap.js"></script>
<script src="../js/umap.ui.js"></script> <script src="../js/umap.ui.js"></script>
<link rel="stylesheet" href="../vendors/leaflet/leaflet.css" /> <link rel="stylesheet" href="../vendors/leaflet/leaflet.css" />
<link rel="stylesheet" href="../vendors/minimap/Control.MiniMap.css" /> <link rel="stylesheet" href="../vendors/minimap/Control.MiniMap.css" />
<link rel="stylesheet" href="../vendors/editinosm/Leaflet.EditInOSM.css" /> <link rel="stylesheet" href="../vendors/editinosm/Leaflet.EditInOSM.css" />
<link rel="stylesheet" href="../vendors/markercluster/MarkerCluster.css" /> <link rel="stylesheet" href="../vendors/markercluster/MarkerCluster.css" />
<link rel="stylesheet" href="../vendors/markercluster/MarkerCluster.Default.css" /> <link rel="stylesheet" href="../vendors/markercluster/MarkerCluster.Default.css" />
<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>
<script src="../../../../node_modules/chai/chai.js"></script> <script src="../../../../node_modules/chai/chai.js"></script>
<script src="../../../../node_modules/happen/happen.js"></script> <script src="../../../../node_modules/happen/happen.js"></script>
<link rel="stylesheet" href="../../../../node_modules/mocha/mocha.css" /> <link rel="stylesheet" href="../../../../node_modules/mocha/mocha.css" />
<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>
<script src="./DataLayer.js"></script> <script src="./DataLayer.js"></script>
<script src="./TableEditor.js"></script> <script src="./TableEditor.js"></script>
<script src="./Feature.js"></script> <script src="./Feature.js"></script>
<script src="./Marker.js"></script> <script src="./Marker.js"></script>
<script src="./Polyline.js"></script> <script src="./Polyline.js"></script>
<script src="./Polygon.js"></script> <script src="./Polygon.js"></script>
<script src="./Util.js"></script> <script src="./Util.js"></script>
<script src="./Controls.js"></script> <script src="./Controls.js"></script>
<script src="./Permissions.js"></script> <script src="./Permissions.js"></script>
<style type="text/css"> <style type="text/css">
#mocha { #mocha {
position: absolute; position: absolute;
top: 0; top: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
right: 0; right: 0;
z-index: 10000; z-index: 10000;
background-color: white; background-color: white;
box-shadow: 0px 0px 8px 0px black; box-shadow: 0px 0px 8px 0px black;
overflow-y: auto; overflow-y: auto;
display: none; display: none;
}
#mocha-stats {
position: absolute;
}
</style>
</head>
<body>
<div id="mocha"></div>
<div id="map"></div>
<script>
var runner = (window.mochaPhantomJS || window.mocha).run(function (failures) {
if (window.location.search.indexOf('debug') === -1)
qs('#mocha').style.display = 'block'
console.log(failures)
})
if (window.location.search.indexOf('debug') !== -1) {
runner.on('fail', function (test, err) {
console.log(test.title, test.err)
console.log(test.err.expected, test.err.actual)
console.log(test.err.stack)
})
sinon.log = function (message) {
console.log(message)
} }
#mocha-stats { }
position: absolute; </script>
} </body>
</style>
</head>
<body>
<div id="mocha"></div>
<div id="map"></div>
<script>
var runner = (window.mochaPhantomJS || window.mocha).run(function (failures) {
if (window.location.search.indexOf('debug') === -1) qs('#mocha').style.display = 'block';
console.log(failures);
});
if (window.location.search.indexOf('debug') !== -1) {
runner.on('fail', function(test, err) {
console.log(test.title, test.err);
console.log(test.err.expected, test.err.actual);
console.log(test.err.stack);
});
sinon.log = function (message) {
console.log(message);
};
}
</script>
</body>
</html> </html>