tests: fix 90% of the javascript tests

This commit is contained in:
Yohan Boniface 2024-01-30 17:31:35 +01:00
parent d1df70b0f4
commit e44e0df69a
13 changed files with 532 additions and 546 deletions

View file

@ -9,6 +9,7 @@
"chai": "^3.3.0", "chai": "^3.3.0",
"eslint": "^8.56.0", "eslint": "^8.56.0",
"eslint-plugin-compat": "^4.2.0", "eslint-plugin-compat": "^4.2.0",
"fetch-mock": "^9.11.0",
"happen": "~0.1.3", "happen": "~0.1.3",
"lebab": "^3.2.1", "lebab": "^3.2.1",
"mocha": "^10.2.0", "mocha": "^10.2.0",

View file

@ -176,24 +176,26 @@ const POLYGONS = {
], ],
} }
describe('L.U.Choropleth', function () { describe('L.U.Choropleth', () => {
let path = '/map/99/datalayer/edit/62/', let path = '/map/99/datalayer/edit/62/',
poly1, poly1,
poly4, poly4,
poly9 poly9,
map,
datalayer
before(function () { before(async () => {
this.server = sinon.fakeServer.create() fetchMock.mock(/\/datalayer\/62\/\?.*/, JSON.stringify(POLYGONS))
this.server.respondWith(/\/datalayer\/62\/\?.*/, JSON.stringify(POLYGONS)) map = initMap({ umap_id: 99 })
this.map = initMap({ umap_id: 99 }) const datalayer_options = defaultDatalayerData()
this.datalayer = this.map.getDataLayerByUmapId(62) await map.initDataLayers([datalayer_options])
this.server.respond() datalayer = map.getDataLayerByUmapId(62)
this.datalayer.options.type = 'Choropleth' datalayer.options.type = 'Choropleth'
this.datalayer.options.choropleth = { datalayer.options.choropleth = {
property: 'value', property: 'value',
} }
enableEdit() enableEdit()
this.datalayer.eachLayer(function (layer) { datalayer.eachLayer(function (layer) {
if (layer.properties.name === 'number 1') { if (layer.properties.name === 'number 1') {
poly1 = layer poly1 = layer
} else if (layer.properties.name === 'number 4') { } else if (layer.properties.name === 'number 4') {
@ -203,38 +205,38 @@ describe('L.U.Choropleth', function () {
} }
}) })
}) })
after(function () { after(() => {
this.server.restore() fetchMock.restore()
resetMap() resetMap()
}) })
describe('#init()', function () { describe('#init()', () => {
it('datalayer should have 9 features', function () { it('datalayer should have 9 features', () => {
assert.equal(this.datalayer._index.length, 9) assert.equal(datalayer._index.length, 9)
}) })
}) })
describe('#compute()', function () { describe('#compute()', () => {
it('choropleth should compute default colors', function () { it('choropleth should compute default colors', () => {
this.datalayer.resetLayer(true) datalayer.resetLayer(true)
assert.deepEqual( assert.deepEqual(
this.datalayer.layer.options.breaks, datalayer.layer.options.breaks,
[45, 673, 3829, 4900, 9898, 9898] [45, 673, 3829, 4900, 9898, 9898]
) )
assert.equal(poly1._path.attributes.fill.value, '#eff3ff') assert.equal(poly1._path.attributes.fill.value, '#eff3ff')
assert.equal(poly4._path.attributes.fill.value, '#bdd7e7') assert.equal(poly4._path.attributes.fill.value, '#bdd7e7')
assert.equal(poly9._path.attributes.fill.value, '#3182bd') assert.equal(poly9._path.attributes.fill.value, '#3182bd')
}) })
it('can change brewer scheme', function () { it('can change brewer scheme', () => {
this.datalayer.options.choropleth.brewer = 'Reds' datalayer.options.choropleth.brewer = 'Reds'
this.datalayer.resetLayer(true) datalayer.resetLayer(true)
assert.equal(poly1._path.attributes.fill.value, '#fee5d9') assert.equal(poly1._path.attributes.fill.value, '#fee5d9')
assert.equal(poly4._path.attributes.fill.value, '#fcae91') assert.equal(poly4._path.attributes.fill.value, '#fcae91')
assert.equal(poly9._path.attributes.fill.value, '#de2d26') assert.equal(poly9._path.attributes.fill.value, '#de2d26')
}) })
it('choropleth should allow to change steps', function () { it('choropleth should allow to change steps', () => {
this.datalayer.options.choropleth.brewer = 'Blues' datalayer.options.choropleth.brewer = 'Blues'
this.datalayer.options.choropleth.classes = 6 datalayer.options.choropleth.classes = 6
this.datalayer.resetLayer(true) datalayer.resetLayer(true)
assert.equal(poly1._path.attributes.fill.value, '#eff3ff') assert.equal(poly1._path.attributes.fill.value, '#eff3ff')
assert.equal(poly4._path.attributes.fill.value, '#c6dbef') assert.equal(poly4._path.attributes.fill.value, '#c6dbef')
assert.equal(poly9._path.attributes.fill.value, '#3182bd') assert.equal(poly9._path.attributes.fill.value, '#3182bd')

View file

@ -1,23 +1,27 @@
describe('L.U.Controls', function () { describe('L.U.Controls', () => {
before(function () { let map, datalayer
this.server = sinon.fakeServer.create() before(async () => {
this.server.respondWith( await fetchMock.mock(
/\/datalayer\/62\/\?.*/, /\/datalayer\/62\/\?.*/,
JSON.stringify(RESPONSES.datalayer62_GET) JSON.stringify(RESPONSES.datalayer62_GET)
) )
this.map = initMap({ umap_id: 99 }) this.options = {
this.server.respond() umap_id: 99,
this.datalayer = this.map.getDataLayerByUmapId(62) }
MAP = map = initMap({ umap_id: 99 })
const datalayer_options = defaultDatalayerData()
await map.initDataLayers([datalayer_options])
datalayer = map.getDataLayerByUmapId(62)
}) })
after(function () { after(() => {
this.server.restore() fetchMock.restore()
resetMap() resetMap()
}) })
describe('#databrowser()', function () { describe('#databrowser()', () => {
let poly, marker, line let poly, marker, line
before(function () { before(() => {
this.datalayer.eachLayer(function (layer) { datalayer.eachLayer(function (layer) {
if (!poly && layer instanceof L.Polygon) { if (!poly && layer instanceof L.Polygon) {
poly = layer poly = layer
} else if (!line && layer instanceof L.Polyline) { } else if (!line && layer instanceof L.Polyline) {
@ -28,27 +32,27 @@ describe('L.U.Controls', function () {
}) })
}) })
it('should be opened at datalayer button click', function () { it('should be opened at datalayer button click', () => {
var button = qs('.umap-browse-actions .umap-browse-link') var button = qs('.umap-browse-actions .umap-browse-link')
assert.ok(button) assert.ok(button)
happen.click(button) happen.click(button)
assert.ok(qs('#umap-ui-container .umap-browse-data')) assert.ok(qs('#umap-ui-container .umap-browse-data'))
}) })
it('should contain datalayer section', function () { it('should contain datalayer section', () => {
assert.ok(qs('#browse_data_datalayer_62')) assert.ok(qs('#browse_data_datalayer_62'))
}) })
it("should contain datalayer's features list", function () { it("should contain datalayer's features list", () => {
assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 3) assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 3)
}) })
it('should sort feature in natural order', function () { it('should sort feature in natural order', () => {
poly.properties.name = '9. a poly' poly.properties.name = '9. a poly'
marker.properties.name = '1. a marker' marker.properties.name = '1. a marker'
line.properties.name = '100. a line' line.properties.name = '100. a line'
this.datalayer.reindex() datalayer.reindex()
this.map.openBrowser() map.openBrowser()
const els = qsa('.umap-browse-features li') const els = qsa('.umap-browse-features li')
assert.equal(els.length, 3) assert.equal(els.length, 3)
assert.equal(els[0].textContent, '1. a marker') assert.equal(els[0].textContent, '1. a marker')
@ -56,9 +60,9 @@ describe('L.U.Controls', function () {
assert.equal(els[2].textContent, '100. a line') assert.equal(els[2].textContent, '100. a line')
}) })
it("should redraw datalayer's features list at feature delete", function () { it("should redraw datalayer's features list at feature delete", () => {
var oldConfirm = window.confirm var oldConfirm = window.confirm
window.confirm = function () { window.confirm = () => {
return true return true
} }
enableEdit() enableEdit()
@ -68,21 +72,21 @@ describe('L.U.Controls', function () {
window.confirm = oldConfirm window.confirm = oldConfirm
}) })
it("should redraw datalayer's features list on edit cancel", function () { it("should redraw datalayer's features list on edit cancel", () => {
clickCancel() clickCancel()
happen.click(qs('.umap-browse-actions .umap-browse-link')) happen.click(qs('.umap-browse-actions .umap-browse-link'))
assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 3) assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 3)
}) })
}) })
describe('#exportPanel()', function () { describe('#exportPanel()', () => {
it('should be opened at datalayer button click', function () { it('should be opened at datalayer button click', () => {
let button = qs('.leaflet-control-embed button') let button = qs('.leaflet-control-embed button')
assert.ok(button) assert.ok(button)
happen.click(button) happen.click(button)
assert.ok(qs('#umap-ui-container .umap-share')) assert.ok(qs('#umap-ui-container .umap-share'))
}) })
it('should update iframe link', function () { it('should update iframe link', () => {
let textarea = qs('.umap-share-iframe') let textarea = qs('.umap-share-iframe')
assert.ok(textarea) assert.ok(textarea)
console.log(textarea.textContent) console.log(textarea.textContent)

View file

@ -1,55 +1,54 @@
describe('L.U.DataLayer', function () { describe('L.U.DataLayer', () => {
var path = '/map/99/datalayer/edit/62/' let path = '/map/99/datalayer/update/62/',
map,
datalayer
before(function () { before(async () => {
this.server = sinon.fakeServer.create() fetchMock.mock(/\/datalayer\/62\/\?.*/, JSON.stringify(RESPONSES.datalayer62_GET))
this.server.respondWith( fetchMock.sticky('/map/99/update/settings/', { id: 99 })
/\/datalayer\/62\/\?.*/, this.options = {
JSON.stringify(RESPONSES.datalayer62_GET) umap_id: 99,
) }
this.map = initMap({ umap_id: 99 }) MAP = map = initMap({ umap_id: 99 })
this.datalayer = this.map.getDataLayerByUmapId(62) const datalayer_options = defaultDatalayerData()
this.server.respond() await map.initDataLayers([datalayer_options])
datalayer = map.getDataLayerByUmapId(62)
enableEdit() enableEdit()
}) })
after(function () { after(() => {
this.server.restore() fetchMock.restore()
resetMap() resetMap()
}) })
describe('#init()', function () { describe('#init()', () => {
it('should be added in datalayers index', function () { it('should be added in datalayers index', () => {
assert.notEqual(this.map.datalayers_index.indexOf(this.datalayer), -1) assert.notEqual(map.datalayers_index.indexOf(datalayer), -1)
}) })
}) })
describe('#edit()', function () { describe('#edit()', () => {
var editButton, form, input, forceButton var editButton, form, input, forceButton
it('row in control should be active', function () { it('row in control should be active', () => {
assert.notOk( assert.notOk(
qs( qs('.leaflet-control-browse #browse_data_toggle_' + L.stamp(datalayer) + '.off')
'.leaflet-control-browse #browse_data_toggle_' +
L.stamp(this.datalayer) +
'.off'
)
) )
}) })
it('should have edit button', function () { it('should have edit button', () => {
editButton = qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit') editButton = qs('#browse_data_toggle_' + L.stamp(datalayer) + ' .layer-edit')
assert.ok(editButton) assert.ok(editButton)
}) })
it('should have toggle visibility element', function () { it('should have toggle visibility element', () => {
assert.ok(qs('.leaflet-control-browse i.layer-toggle')) assert.ok(qs('.leaflet-control-browse i.layer-toggle'))
}) })
it('should exist only one datalayer', function () { it('should exist only one datalayer', () => {
assert.equal(qsa('.leaflet-control-browse i.layer-toggle').length, 1) assert.equal(qsa('.leaflet-control-browse i.layer-toggle').length, 1)
}) })
it('should build a form on edit button click', function () { it('should build a form on edit button click', () => {
happen.click(editButton) happen.click(editButton)
form = qs('form.umap-form') form = qs('form.umap-form')
input = qs('form.umap-form input[name="name"]') input = qs('form.umap-form input[name="name"]')
@ -57,97 +56,81 @@ describe('L.U.DataLayer', function () {
assert.ok(input) assert.ok(input)
}) })
it('should update name on input change', function () { it('should update name on input change', () => {
var new_name = 'This is a new name' var new_name = 'This is a new name'
input.value = new_name input.value = new_name
happen.once(input, { type: 'input' }) happen.once(input, { type: 'input' })
assert.equal(this.datalayer.options.name, new_name) assert.equal(datalayer.options.name, new_name)
}) })
it('should have made datalayer dirty', function () { it('should have made datalayer dirty', () => {
assert.ok(this.datalayer.isDirty) assert.ok(datalayer.isDirty)
assert.notEqual(this.map.dirty_datalayers.indexOf(this.datalayer), -1) assert.notEqual(map.dirty_datalayers.indexOf(datalayer), -1)
}) })
it('should have made Map dirty', function () { it('should have made Map dirty', () => {
assert.ok(this.map.isDirty) assert.ok(map.isDirty)
}) })
it('should call datalayer.save on save button click', function (done) { it('should call datalayer.save on save button click', (done) => {
sinon.spy(this.datalayer, 'save') const postDatalayer = fetchMock.post(path, () => {
this.server.flush() return defaultDatalayerData()
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() clickSave()
this.server.respond() window.setTimeout(() => {
this.server.respond() assert(fetchMock.called(path))
assert(this.datalayer.save.calledOnce) done()
this.datalayer.save.restore() }, 500)
done()
}) })
it('should show alert if server respond 412', function () { it('should show alert if server respond 412', (done) => {
cleanAlert() cleanAlert()
this.server.flush() fetchMock.restore()
this.server.respondWith( fetchMock.post(path, 412)
'POST',
'/map/99/update/settings/',
JSON.stringify({ id: 99 })
)
this.server.respondWith('POST', '/map/99/datalayer/update/62/', [412, {}, ''])
happen.click(editButton) happen.click(editButton)
input = qs('form.umap-form input[name="name"]') input = qs('form.umap-form input[name="name"]')
input.value = 'a new name' input.value = 'a new name'
happen.once(input, { type: 'input' }) happen.once(input, { type: 'input' })
clickSave() clickSave()
this.server.respond() window.setTimeout(() => {
this.server.respond() assert(L.DomUtil.hasClass(map._container, 'umap-alert'))
assert(L.DomUtil.hasClass(this.map._container, 'umap-alert')) assert.notEqual(map.dirty_datalayers.indexOf(datalayer), -1)
assert.notEqual(this.map.dirty_datalayers.indexOf(this.datalayer), -1) const forceButton = qs('#umap-alert-container .umap-action')
forceButton = qs('#umap-alert-container .umap-action') assert.ok(forceButton)
assert.ok(forceButton) done()
}, 500)
}) })
it('should save anyway on force save button click', function () { it('should save anyway on force save button click', (done) => {
sinon.spy(this.map, 'continueSaving') const forceButton = qs('#umap-alert-container .umap-action')
fetchMock.restore()
fetchMock.post(path, defaultDatalayerData)
happen.click(forceButton) happen.click(forceButton)
this.server.flush() window.setTimeout(() => {
this.server.respond( assert.notOk(qs('#umap-alert-container .umap-action'))
'POST', assert(fetchMock.called(path))
'/map/99/datalayer/update/62/', assert.equal(map.dirty_datalayers.indexOf(datalayer), -1)
JSON.stringify(defaultDatalayerData()) done()
) }, 500)
assert.notOk(qs('#umap-alert-container .umap-action'))
assert(this.map.continueSaving.calledOnce)
this.map.continueSaving.restore()
assert.equal(this.map.dirty_datalayers.indexOf(this.datalayer), -1)
}) })
}) })
describe('#save() new', function () { describe('#save() new', () => {
var newLayerButton, form, input, newDatalayer, editButton, manageButton let newLayerButton, form, input, newDatalayer, editButton, manageButton
it('should have a manage datalayers action', function () { it('should have a manage datalayers action', () => {
enableEdit() enableEdit()
manageButton = qs('.manage-datalayers') manageButton = qs('.manage-datalayers')
assert.ok(manageButton) assert.ok(manageButton)
happen.click(manageButton) happen.click(manageButton)
}) })
it('should have a new layer button', function () { it('should have a new layer button', () => {
newLayerButton = qs('#umap-ui-container .add-datalayer') newLayerButton = qs('#umap-ui-container .add-datalayer')
assert.ok(newLayerButton) assert.ok(newLayerButton)
}) })
it('should build a form on new layer button click', function () { it('should build a form on new layer button click', () => {
happen.click(newLayerButton) happen.click(newLayerButton)
form = qs('form.umap-form') form = qs('form.umap-form')
input = qs('form.umap-form input[name="name"]') input = qs('form.umap-form input[name="name"]')
@ -155,86 +138,72 @@ describe('L.U.DataLayer', function () {
assert.ok(input) assert.ok(input)
}) })
it('should have an empty name', function () { it('should have an empty name', () => {
assert.notOk(input.value) assert.notOk(input.value)
}) })
it('should have created a new datalayer', function () { it('should have created a new datalayer', () => {
assert.equal(this.map.datalayers_index.length, 2) assert.equal(map.datalayers_index.length, 2)
newDatalayer = this.map.datalayers_index[1] newDatalayer = map.datalayers_index[1]
}) })
it('should have made Map dirty', function () { it('should have made Map dirty', () => {
assert.ok(this.map.isDirty) assert.ok(map.isDirty)
}) })
it('should update name on input change', function () { it('should update name on input change', () => {
var new_name = 'This is a new name' var new_name = 'This is a new name'
input.value = new_name input.value = new_name
happen.once(input, { type: 'input' }) happen.once(input, { type: 'input' })
assert.equal(newDatalayer.options.name, new_name) assert.equal(newDatalayer.options.name, new_name)
}) })
it('should set umap_id on save callback', function () { it('should set umap_id on save callback', async () => {
assert.notOk(newDatalayer.umap_id) assert.notOk(newDatalayer.umap_id)
this.server.flush() fetchMock.post('/map/99/datalayer/create/', defaultDatalayerData({ id: 63 }))
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() clickSave()
this.server.respond() return new Promise((resolve) => {
this.server.respond() // First respond will then trigger another Xhr request (continueSaving) window.setTimeout(() => {
assert.equal(newDatalayer.umap_id, 63) assert.equal(newDatalayer.umap_id, 63)
resolve()
}, 1000)
})
}) })
it('should have unset map dirty', function () { it('should have unset map dirty', () => {
assert.notOk(this.map.isDirty) assert.notOk(map.isDirty)
}) })
it('should have edit button', function () { it('should have edit button', () => {
editButton = qs('#browse_data_toggle_' + L.stamp(newDatalayer) + ' .layer-edit') editButton = qs('#browse_data_toggle_' + L.stamp(newDatalayer) + ' .layer-edit')
assert.ok(editButton) assert.ok(editButton)
}) })
it('should call update if we edit again', function () { it('should call update if we edit again', async () => {
happen.click(editButton) happen.click(editButton)
assert.notOk(this.map.isDirty) assert.notOk(map.isDirty)
input = qs('form.umap-form input[name="name"]') input = qs('form.umap-form input[name="name"]')
input.value = "a new name again but we don't care which" input.value = "a new name again but we don't care which"
happen.once(input, { type: 'input' }) happen.once(input, { type: 'input' })
assert.ok(this.map.isDirty) assert.ok(map.isDirty)
var response = function (request) { var response = () => {
return request.respond( return defaultDatalayerData({ pk: 63 })
200,
{},
JSON.stringify(defaultDatalayerData({ pk: 63 }))
)
} }
var spy = sinon.spy(response) var spy = sinon.spy(response)
this.server.flush() fetchMock.post('/map/99/datalayer/update/63/', spy)
this.server.respondWith( return new Promise((resolve) => {
'POST', clickSave()
'/map/99/update/settings/', window.setTimeout(() => {
JSON.stringify({ id: 99 }) assert.ok(spy.calledOnce)
) resolve()
this.server.respondWith('POST', '/map/99/datalayer/update/63/', spy) }, 1000)
clickSave() })
this.server.respond()
this.server.respond()
assert.ok(spy.calledOnce)
}) })
}) })
describe('#iconClassChange()', function () { describe('#iconClassChange()', () => {
it('should change icon class', function () { it('should change icon class', () => {
happen.click(qs('[data-id="' + this.datalayer._leaflet_id + '"] .layer-edit')) happen.click(qs('[data-id="' + datalayer._leaflet_id + '"] .layer-edit'))
changeSelectValue( changeSelectValue(
qs('form#datalayer-advanced-properties select[name=iconClass]'), qs('form#datalayer-advanced-properties select[name=iconClass]'),
'Circle' 'Circle'
@ -250,53 +219,53 @@ describe('L.U.DataLayer', function () {
}) })
}) })
describe('#show/hide', function () { describe('#show/hide', () => {
it('should hide features on hide', function () { it('should hide features on hide', () => {
assert.ok(qs('div.umap-div-icon')) assert.ok(qs('div.umap-div-icon'))
assert.ok(qs('path[fill="none"]')) assert.ok(qs('path[fill="none"]'))
this.datalayer.hide() datalayer.hide()
assert.notOk(qs('div.umap-div-icon')) assert.notOk(qs('div.umap-div-icon'))
assert.notOk(qs('path[fill="none"]')) assert.notOk(qs('path[fill="none"]'))
}) })
it('should show features on show', function () { it('should show features on show', () => {
assert.notOk(qs('div.umap-div-icon')) assert.notOk(qs('div.umap-div-icon'))
assert.notOk(qs('path[fill="none"]')) assert.notOk(qs('path[fill="none"]'))
this.datalayer.show() datalayer.show()
assert.ok(qs('div.umap-div-icon')) assert.ok(qs('div.umap-div-icon'))
assert.ok(qs('path[fill="none"]')) assert.ok(qs('path[fill="none"]'))
}) })
}) })
describe('#clone()', function () { describe('#clone()', () => {
it('should clone everything but the id and the name', function () { it('should clone everything but the id and the name', () => {
enableEdit() enableEdit()
var clone = this.datalayer.clone() var clone = datalayer.clone()
assert.notOk(clone.umap_id) assert.notOk(clone.umap_id)
assert.notEqual(clone.options.name, this.datalayer.name) assert.notEqual(clone.options.name, datalayer.name)
assert.ok(clone.options.name) assert.ok(clone.options.name)
assert.equal(clone.options.color, this.datalayer.options.color) assert.equal(clone.options.color, datalayer.options.color)
assert.equal(clone.options.stroke, this.datalayer.options.stroke) assert.equal(clone.options.stroke, datalayer.options.stroke)
clone._delete() clone._delete()
clickSave() clickSave()
}) })
}) })
describe('#restore()', function () { describe('#restore()', () => {
var oldConfirm, var oldConfirm,
newConfirm = function () { newConfirm = () => {
return true return true
} }
before(function () { before(() => {
oldConfirm = window.confirm oldConfirm = window.confirm
window.confirm = newConfirm window.confirm = newConfirm
}) })
after(function () { after(() => {
window.confirm = oldConfirm window.confirm = oldConfirm
}) })
it('should restore everything', function () { it('should restore everything', (done) => {
enableEdit() enableEdit()
var geojson = L.Util.CopyJSON(RESPONSES.datalayer62_GET) var geojson = L.Util.CopyJSON(RESPONSES.datalayer62_GET)
geojson.features.push({ geojson.features.push({
@ -309,33 +278,31 @@ describe('L.U.DataLayer', function () {
properties: { _umap_options: {}, name: 'new point from restore' }, properties: { _umap_options: {}, name: 'new point from restore' },
}) })
geojson._umap_options.color = 'Chocolate' geojson._umap_options.color = 'Chocolate'
this.server.respondWith( fetchMock.get('/datalayer/62/olderversion.geojson', geojson)
'GET',
'/datalayer/62/olderversion.geojson',
JSON.stringify(geojson)
)
sinon.spy(window, 'confirm') sinon.spy(window, 'confirm')
this.datalayer.restore('olderversion.geojson') datalayer.restore('olderversion.geojson')
this.server.respond() window.setTimeout(() => {
assert(window.confirm.calledOnce) assert(window.confirm.calledOnce)
window.confirm.restore() window.confirm.restore()
assert.equal(this.datalayer.umap_id, 62) assert.equal(datalayer.umap_id, 62)
assert.ok(this.datalayer.isDirty) assert.ok(datalayer.isDirty)
assert.equal(this.datalayer._index.length, 4) assert.equal(datalayer._index.length, 4)
assert.ok(qs('path[fill="Chocolate"]')) assert.ok(qs('path[fill="Chocolate"]'))
done()
}, 1000)
}) })
it('should revert anything on cancel click', function () { it('should revert anything on cancel click', () => {
clickCancel() clickCancel()
assert.equal(this.datalayer._index.length, 3) assert.equal(datalayer._index.length, 3)
assert.notOk(qs('path[fill="Chocolate"]')) assert.notOk(qs('path[fill="Chocolate"]'))
}) })
}) })
describe('#smart-options()', function () { describe('#smart-options()', () => {
let poly, marker let poly, marker
before(function () { before(() => {
this.datalayer.eachLayer(function (layer) { datalayer.eachLayer(function (layer) {
if (!poly && layer instanceof L.Polygon) { if (!poly && layer instanceof L.Polygon) {
poly = layer poly = layer
} }
@ -345,39 +312,35 @@ describe('L.U.DataLayer', function () {
}) })
}) })
it('should parse color variable', function () { it('should parse color variable', () => {
let icon = qs('div.umap-div-icon .icon_container') let icon = qs('div.umap-div-icon .icon_container')
poly.properties.mycolor = 'DarkGoldenRod' poly.properties.mycolor = 'DarkGoldenRod'
marker.properties.mycolor = 'DarkRed' marker.properties.mycolor = 'DarkRed'
marker.properties._umap_options.color = undefined marker.properties._umap_options.color = undefined
assert.notOk(qs('path[fill="DarkGoldenRod"]')) assert.notOk(qs('path[fill="DarkGoldenRod"]'))
assert.equal(icon.style.backgroundColor, 'olivedrab') assert.equal(icon.style.backgroundColor, 'olivedrab')
this.datalayer.options.color = '{mycolor}' datalayer.options.color = '{mycolor}'
this.datalayer.options.fillColor = '{mycolor}' datalayer.options.fillColor = '{mycolor}'
this.datalayer.indexProperties(poly) datalayer.indexProperties(poly)
this.datalayer.indexProperties(marker) datalayer.indexProperties(marker)
this.datalayer.redraw() datalayer.redraw()
icon = qs('div.umap-div-icon .icon_container') icon = qs('div.umap-div-icon .icon_container')
assert.equal(icon.style.backgroundColor, 'darkred') assert.equal(icon.style.backgroundColor, 'darkred')
assert.ok(qs('path[fill="DarkGoldenRod"]')) assert.ok(qs('path[fill="DarkGoldenRod"]'))
}) })
}) })
describe('#facet-search()', function () { describe('#facet-search()', () => {
before(function () { before(async () => {
this.server.respondWith( fetchMock.get(/\/datalayer\/63\/\?.*/, RESPONSES.datalayer63_GET)
/\/datalayer\/63\/\?.*/, map.options.facetKey = 'name'
JSON.stringify(RESPONSES.datalayer63_GET) await map.initDataLayers([RESPONSES.datalayer63_GET._umap_options])
)
this.map.options.facetKey = 'name'
this.map.createDataLayer(RESPONSES.datalayer63_GET._umap_options)
this.server.respond()
}) })
it('should not impact non browsable layer', function () { it('should not impact non browsable layer', () => {
assert.ok(qs('path[fill="SteelBlue"]')) assert.ok(qs('path[fill="SteelBlue"]'))
}) })
it('should allow advanced filter', function () { it('should allow advanced filter', () => {
this.map.openFacet() map.openFacet()
assert.ok(qs('div.umap-facet-search')) assert.ok(qs('div.umap-facet-search'))
// This one if from the normal datalayer // This one if from the normal datalayer
// it's name is "test", so it should be hidden // it's name is "test", so it should be hidden
@ -390,104 +353,109 @@ describe('L.U.DataLayer', function () {
assert.ok(qs('path[fill="SteelBlue"]')) assert.ok(qs('path[fill="SteelBlue"]'))
happen.click(qs('input[data-value="name poly"]')) // Undo happen.click(qs('input[data-value="name poly"]')) // Undo
}) })
it('should allow to control facet label', function () { it('should allow to control facet label', () => {
this.map.options.facetKey = 'name|Nom' map.options.facetKey = 'name|Nom'
this.map.openFacet() map.openFacet()
assert.ok(qs('div.umap-facet-search h5')) assert.ok(qs('div.umap-facet-search h5'))
assert.equal(qs('div.umap-facet-search h5').textContent, 'Nom') assert.equal(qs('div.umap-facet-search h5').textContent, 'Nom')
}) })
}) })
describe('#zoomEnd', function () { describe('#zoomEnd', () => {
it('should honour the fromZoom option', function () { it('should honour the fromZoom option', () => {
this.map.setZoom(6, { animate: false }) map.setZoom(6, { animate: false })
assert.ok(qs('path[fill="none"]')) assert.ok(qs('path[fill="none"]'))
this.datalayer.options.fromZoom = 6 datalayer.options.fromZoom = 6
this.map.setZoom(5, { animate: false }) map.setZoom(5, { animate: false })
assert.notOk(qs('path[fill="none"]')) assert.notOk(qs('path[fill="none"]'))
this.map.setZoom(6, { animate: false }) map.setZoom(6, { animate: false })
assert.ok(qs('path[fill="none"]')) assert.ok(qs('path[fill="none"]'))
}) })
it('should honour the toZoom option', function () { it('should honour the toZoom option', () => {
this.map.setZoom(6, { animate: false }) map.setZoom(6, { animate: false })
assert.ok(qs('path[fill="none"]')) assert.ok(qs('path[fill="none"]'))
this.datalayer.options.toZoom = 6 datalayer.options.toZoom = 6
this.map.setZoom(7, { animate: false }) map.setZoom(7, { animate: false })
assert.notOk(qs('path[fill="none"]')) assert.notOk(qs('path[fill="none"]'))
this.map.setZoom(6, { animate: false }) map.setZoom(6, { animate: false })
assert.ok(qs('path[fill="none"]')) assert.ok(qs('path[fill="none"]'))
}) })
}) })
describe('#displayOnLoad', function () { describe('#displayOnLoad', () => {
beforeEach(function () { before(() => {
this.server.respondWith( fetchMock.get(/\/datalayer\/64\/\?.*/, RESPONSES.datalayer64_GET)
/\/datalayer\/64\/\?.*/,
JSON.stringify(RESPONSES.datalayer64_GET)
)
this.datalayer = this.map.createDataLayer(RESPONSES.datalayer64_GET._umap_options)
// Force fetching the data, so to deal here with fake server
this.datalayer.fetchData()
this.server.respond()
this.map.setZoom(10, { animate: false })
}) })
afterEach(function () { beforeEach(async () => {
this.datalayer._delete() await map.initDataLayers([RESPONSES.datalayer64_GET._umap_options])
datalayer = map.getDataLayerByUmapId(64)
map.setZoom(10, { animate: false })
}) })
it('should not display layer at load', function () { afterEach(() => {
datalayer._delete()
})
it('should not display layer at load', () => {
assert.notOk(qs('path[fill="AliceBlue"]')) assert.notOk(qs('path[fill="AliceBlue"]'))
}) })
it('should display on click', function () { it('should display on click', (done) => {
happen.click(qs(`[data-id='${L.stamp(this.datalayer)}'] .layer-toggle`)) happen.click(qs(`[data-id='${L.stamp(datalayer)}'] .layer-toggle`))
assert.ok(qs('path[fill="AliceBlue"]')) window.setTimeout(() => {
assert.ok(qs('path[fill="AliceBlue"]'))
done()
}, 500)
}) })
it('should not display on zoom', function () { it('should not display on zoom', (done) => {
this.map.setZoom(9, { animate: false }) map.setZoom(9, { animate: false })
assert.notOk(qs('path[fill="AliceBlue"]')) window.setTimeout(() => {
assert.notOk(qs('path[fill="AliceBlue"]'))
done()
}, 500)
}) })
}) })
describe('#delete()', function () { describe('#delete()', () => {
var deleteLink, let deleteLink,
deletePath = '/map/99/datalayer/delete/62/' deletePath = '/map/99/datalayer/delete/62/'
before(() => {
datalayer = map.getDataLayerByUmapId(62)
})
it('should have a delete link in update form', function () { it('should have a delete link in update form', () => {
enableEdit() enableEdit()
happen.click( happen.click(qs('#browse_data_toggle_' + L.stamp(datalayer) + ' .layer-edit'))
qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
)
deleteLink = qs('button.delete_datalayer_button') deleteLink = qs('button.delete_datalayer_button')
assert.ok(deleteLink) assert.ok(deleteLink)
}) })
it('should delete features on datalayer delete', function () { it('should delete features on datalayer delete', () => {
happen.click(deleteLink) happen.click(deleteLink)
assert.notOk(qs('div.icon_container')) assert.notOk(qs('div.icon_container'))
}) })
it('should have set map dirty', function () { it('should have set map dirty', () => {
assert.ok(this.map.isDirty) assert.ok(map.isDirty)
}) })
it('should delete layer control row on delete', function () { it('should delete layer control row on delete', () => {
assert.notOk( assert.notOk(
qs('.leaflet-control-browse #browse_data_toggle_' + L.stamp(this.datalayer)) qs('.leaflet-control-browse #browse_data_toggle_' + L.stamp(datalayer))
) )
}) })
it('should be removed from map.datalayers_index', function () { it('should be removed from map.datalayers_index', () => {
assert.equal(this.map.datalayers_index.indexOf(this.datalayer), -1) assert.equal(map.datalayers_index.indexOf(datalayer), -1)
}) })
it('should be removed from map.datalayers', function () { it('should be removed from map.datalayers', () => {
assert.notOk(this.map.datalayers[L.stamp(this.datalayer)]) assert.notOk(map.datalayers[L.stamp(datalayer)])
}) })
it('should be visible again on edit cancel', function () { it('should be visible again on edit cancel', () => {
clickCancel() clickCancel()
assert.ok(qs('div.icon_container')) assert.ok(qs('div.icon_container'))
}) })

View file

@ -1,21 +1,25 @@
describe('L.U.FeatureMixin', function () { describe('L.U.FeatureMixin', function () {
before(function () { let map, datalayer
this.server = sinon.fakeServer.create() before(async () => {
this.server.respondWith( await fetchMock.mock(
/\/datalayer\/62\/\?.*/, /\/datalayer\/62\/\?.*/,
JSON.stringify(RESPONSES.datalayer62_GET) JSON.stringify(RESPONSES.datalayer62_GET)
) )
this.map = initMap({ umap_id: 99 }) this.options = {
this.datalayer = this.map.getDataLayerByUmapId(62) umap_id: 99,
this.server.respond() }
MAP = map = initMap({ umap_id: 99 })
const datalayer_options = defaultDatalayerData()
await map.initDataLayers([datalayer_options])
datalayer = map.getDataLayerByUmapId(62)
}) })
after(function () { after(function () {
this.server.restore() fetchMock.restore()
resetMap() resetMap()
}) })
describe('#edit()', function () { describe('#edit()', function () {
var link let link
it('should have datalayer features created', function () { it('should have datalayer features created', function () {
assert.equal( assert.equal(
@ -45,7 +49,7 @@ describe('L.U.FeatureMixin', function () {
it('should take into account styles changes made in the datalayer', function () { it('should take into account styles changes made in the datalayer', function () {
happen.click( happen.click(
qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit') qs('#browse_data_toggle_' + L.stamp(datalayer) + ' .layer-edit')
) )
var colorInput = qs('form#datalayer-advanced-properties input[name=color]') var colorInput = qs('form#datalayer-advanced-properties input[name=color]')
changeInputValue(colorInput, 'DarkRed') changeInputValue(colorInput, 'DarkRed')
@ -101,7 +105,7 @@ describe('L.U.FeatureMixin', function () {
it('should not override already set style on features', function () { it('should not override already set style on features', function () {
happen.click( happen.click(
qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit') qs('#browse_data_toggle_' + L.stamp(datalayer) + ' .layer-edit')
) )
changeInputValue(qs('#umap-ui-container form input[name=color]'), 'Chocolate') changeInputValue(qs('#umap-ui-container form input[name=color]'), 'Chocolate')
assert.notOk(qs('path[fill="DarkBlue"]')) assert.notOk(qs('path[fill="DarkBlue"]'))
@ -120,22 +124,22 @@ describe('L.U.FeatureMixin', function () {
it('should set map.editedFeature on edit', function () { it('should set map.editedFeature on edit', function () {
enableEdit() enableEdit()
assert.notOk(this.map.editedFeature) assert.notOk(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(map.editedFeature)
disableEdit() disableEdit()
}) })
it('should reset map.editedFeature on panel open', function (done) { it('should reset map.editedFeature on panel open', function (done) {
enableEdit() enableEdit()
assert.notOk(this.map.editedFeature) assert.notOk(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(map.editedFeature)
this.map.displayCaption() map.displayCaption()
window.setTimeout(function () { window.setTimeout(function () {
assert.notOk(this.map.editedFeature) assert.notOk(map.editedFeature)
disableEdit() disableEdit()
done() done()
}, 1001) // CSS transition time. }, 1001) // CSS transition time.
@ -155,7 +159,7 @@ describe('L.U.FeatureMixin', function () {
}) })
} }
it('should generate a valid geojson', function () { it('should generate a valid geojson', function () {
setFeatures(this.datalayer) setFeatures(datalayer)
assert.ok(poly) assert.ok(poly)
assert.deepEqual(poly.toGeoJSON().geometry, { assert.deepEqual(poly.toGeoJSON().geometry, {
type: 'Polygon', type: 'Polygon',
@ -176,7 +180,7 @@ describe('L.U.FeatureMixin', function () {
}) })
it('should remove empty _umap_options from exported geojson', function () { it('should remove empty _umap_options from exported geojson', function () {
setFeatures(this.datalayer) setFeatures(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)
@ -190,7 +194,7 @@ describe('L.U.FeatureMixin', function () {
describe('#openPopup()', function () { describe('#openPopup()', function () {
let poly let poly
before(function () { before(function () {
this.datalayer.eachLayer(function (layer) { datalayer.eachLayer(function (layer) {
if (!poly && layer instanceof L.Polygon) { if (!poly && layer instanceof L.Polygon) {
poly = layer poly = layer
} }
@ -233,8 +237,8 @@ describe('L.U.FeatureMixin', function () {
}) })
it('should still highlight marker after hide() and show()', function () { it('should still highlight marker after hide() and show()', function () {
this.datalayer.hide() datalayer.hide()
this.datalayer.show() datalayer.show()
happen.click(qs('div.leaflet-marker-icon')) happen.click(qs('div.leaflet-marker-icon'))
assert.ok(qs('.umap-icon-active')) assert.ok(qs('.umap-icon-active'))
}) })
@ -254,9 +258,9 @@ describe('L.U.FeatureMixin', function () {
describe('#tooltip', function () { describe('#tooltip', function () {
it('should have a tooltip when active and allow variables', function () { it('should have a tooltip when active and allow variables', function () {
this.map.options.showLabel = true map.options.showLabel = true
this.map.options.labelKey = 'Foo {name}' map.options.labelKey = 'Foo {name}'
this.datalayer.redraw() datalayer.redraw()
assert.equal( assert.equal(
qs('.leaflet-tooltip-pane .leaflet-tooltip').textContent, qs('.leaflet-tooltip-pane .leaflet-tooltip').textContent,
'Foo name poly' 'Foo name poly'
@ -266,7 +270,7 @@ describe('L.U.FeatureMixin', function () {
describe('#properties()', function () { describe('#properties()', function () {
it('should rename property', function () { it('should rename property', function () {
var poly = this.datalayer._lineToLayer({}, [ var poly = datalayer._lineToLayer({}, [
[0, 0], [0, 0],
[0, 1], [0, 1],
[0, 2], [0, 2],
@ -278,7 +282,7 @@ describe('L.U.FeatureMixin', function () {
}) })
it('should not create property when renaming', function () { it('should not create property when renaming', function () {
var poly = this.datalayer._lineToLayer({}, [ var poly = datalayer._lineToLayer({}, [
[0, 0], [0, 0],
[0, 1], [0, 1],
[0, 2], [0, 2],
@ -289,7 +293,7 @@ describe('L.U.FeatureMixin', function () {
}) })
it('should delete property', function () { it('should delete property', function () {
var poly = this.datalayer._lineToLayer({}, [ var poly = datalayer._lineToLayer({}, [
[0, 0], [0, 0],
[0, 1], [0, 1],
[0, 2], [0, 2],
@ -305,7 +309,7 @@ describe('L.U.FeatureMixin', function () {
var poly var poly
it('should filter on properties', function () { it('should filter on properties', function () {
poly = this.datalayer._lineToLayer({}, [ poly = datalayer._lineToLayer({}, [
[0, 0], [0, 0],
[0, 1], [0, 1],
[0, 2], [0, 2],
@ -337,7 +341,7 @@ describe('L.U.FeatureMixin', function () {
return true return true
} }
this.datalayer.eachLayer(function (layer) { datalayer.eachLayer(function (layer) {
if (!poly && layer instanceof L.Polygon) { if (!poly && layer instanceof L.Polygon) {
poly = layer poly = layer
} }
@ -351,7 +355,7 @@ describe('L.U.FeatureMixin', function () {
it('should allow to delete from data browser', function () { it('should allow to delete from data browser', function () {
enableEdit() enableEdit()
assert.ok(qs('path[fill="DarkBlue"]')) assert.ok(qs('path[fill="DarkBlue"]'))
this.map.openBrowser() map.openBrowser()
happen.click(qs('.feature-delete')) happen.click(qs('.feature-delete'))
assert.notOk(qs('path[fill="DarkBlue"]')) assert.notOk(qs('path[fill="DarkBlue"]'))
clickCancel() clickCancel()

View file

@ -1,26 +1,26 @@
describe('L.U.Map.Export', function () { describe('L.U.Map.Export', function () {
before(function () { let map
this.server = sinon.fakeServer.create() before(async () => {
this.server.respondWith( await fetchMock.mock(
/\/datalayer\/62\/\?.*/, /\/datalayer\/62\/\?.*/,
JSON.stringify(RESPONSES.datalayer62_GET) JSON.stringify(RESPONSES.datalayer62_GET)
) )
this.options = { this.options = {
umap_id: 99, umap_id: 99,
} }
this.map = initMap({ umap_id: 99 }) map = initMap({ umap_id: 99 })
this.server.respond() const datalayer_options = defaultDatalayerData()
this.datalayer = this.map.getDataLayerByUmapId(62) await map.initDataLayers([datalayer_options])
}) })
after(function () { after(function () {
this.server.restore() fetchMock.restore()
clickCancel() clickCancel()
resetMap() resetMap()
}) })
describe('#formatters()', function () { describe('#formatters()', function () {
it('should export to geojson', function () { it('should export to geojson', function () {
const { content, filetype, filename } = this.map.share.format('geojson') const { content, filetype, filename } = map.share.format('geojson')
assert.equal(filetype, 'application/json') assert.equal(filetype, 'application/json')
assert.equal(filename, 'name_of_the_map.geojson') assert.equal(filename, 'name_of_the_map.geojson')
assert.deepEqual(JSON.parse(content), { assert.deepEqual(JSON.parse(content), {
@ -86,7 +86,7 @@ describe('L.U.Map.Export', function () {
}) })
it('should export to gpx', function () { it('should export to gpx', function () {
const { content, filetype, filename } = this.map.share.format('gpx') const { content, filetype, filename } = map.share.format('gpx')
assert.equal(filetype, 'application/gpx+xml') assert.equal(filetype, 'application/gpx+xml')
assert.equal(filename, 'name_of_the_map.gpx') assert.equal(filename, 'name_of_the_map.gpx')
const expected = const expected =
@ -95,7 +95,7 @@ describe('L.U.Map.Export', function () {
}) })
it('should export to kml', function () { it('should export to kml', function () {
const { content, filetype, filename } = this.map.share.format('kml') const { content, filetype, filename } = map.share.format('kml')
assert.equal(filetype, 'application/vnd.google-earth.kml+xml') assert.equal(filetype, 'application/vnd.google-earth.kml+xml')
assert.equal(filename, 'name_of_the_map.kml') assert.equal(filename, 'name_of_the_map.kml')
const expected = const expected =

View file

@ -1,23 +1,24 @@
describe('L.U.Map.initialize', function () { describe('L.U.Map.initialize', function () {
let map
afterEach(function () { afterEach(function () {
resetMap() resetMap()
}) })
describe('Controls', function () { describe('Controls', async function () {
it('should not show a minimap by default', function () { it('should not show a minimap by default', function () {
this.map = initMap() map = initMap()
assert.notOk(qs('.leaflet-control-minimap')) assert.notOk(qs('.leaflet-control-minimap'))
}) })
it('should show a minimap', function () { it('should show a minimap', function () {
this.map = initMap({ miniMap: true }) map = initMap({ miniMap: true })
assert.ok(qs('.leaflet-control-minimap')) assert.ok(qs('.leaflet-control-minimap'))
}) })
}) })
describe('DefaultView', function () { describe('DefaultView', function () {
it('should set default view in default mode without data', function (done) { it('should set default view in default mode without data', function (done) {
this.map = initMap({ datalayers: [] }) map = initMap({ datalayers: [] })
// Did not find a better way to wait for tiles to be actually loaded // Did not find a better way to wait for tiles to be actually loaded
window.setTimeout(() => { window.setTimeout(() => {
assert.ok(qs('#map .leaflet-tile-pane img.leaflet-tile.leaflet-tile-loaded')) assert.ok(qs('#map .leaflet-tile-pane img.leaflet-tile.leaflet-tile-loaded'))
@ -26,7 +27,7 @@ describe('L.U.Map.initialize', function () {
}) })
it("should set default view in 'data' mode without data", function (done) { it("should set default view in 'data' mode without data", function (done) {
this.map = initMap({ datalayers: [], defaultView: 'data' }) map = initMap({ datalayers: [], defaultView: 'data' })
// Did not find a better way to wait for tiles to be actually loaded // Did not find a better way to wait for tiles to be actually loaded
window.setTimeout(() => { window.setTimeout(() => {
assert.ok(qs('#map .leaflet-tile-pane img.leaflet-tile.leaflet-tile-loaded')) assert.ok(qs('#map .leaflet-tile-pane img.leaflet-tile.leaflet-tile-loaded'))
@ -35,7 +36,7 @@ describe('L.U.Map.initialize', function () {
}) })
it("should set default view in 'latest' mode without data", function (done) { it("should set default view in 'latest' mode without data", function (done) {
this.map = initMap({ datalayers: [], defaultView: 'latest' }) map = initMap({ datalayers: [], defaultView: 'latest' })
// Did not find a better way to wait for tiles to be actually loaded // Did not find a better way to wait for tiles to be actually loaded
window.setTimeout(() => { window.setTimeout(() => {
assert.ok(qs('#map .leaflet-tile-pane img.leaflet-tile.leaflet-tile-loaded')) assert.ok(qs('#map .leaflet-tile-pane img.leaflet-tile.leaflet-tile-loaded'))

View file

@ -1,26 +1,27 @@
describe('L.U.Map', function () { describe('L.U.Map', () => {
before(function () { let map, datalayer
this.server = sinon.fakeServer.create() before(async () => {
this.server.respondWith( await fetchMock.mock(
/\/datalayer\/62\/\?.*/, /\/datalayer\/62\/\?.*/,
JSON.stringify(RESPONSES.datalayer62_GET) JSON.stringify(RESPONSES.datalayer62_GET)
) )
this.options = { this.options = {
umap_id: 99, umap_id: 99,
} }
this.map = initMap({ umap_id: 99 }) map = initMap({ umap_id: 99 })
this.server.respond() const datalayer_options = defaultDatalayerData()
this.datalayer = this.map.getDataLayerByUmapId(62) await map.initDataLayers([datalayer_options])
datalayer = map.getDataLayerByUmapId(62)
}) })
after(function () { after(() => {
this.server.restore() fetchMock.restore()
clickCancel() clickCancel()
resetMap() resetMap()
}) })
describe('#init()', function () { describe('#init()', () => {
it('should be initialized', function () { it('should be initialized', function () {
assert.equal(this.map.options.umap_id, 99) assert.equal(map.options.umap_id, 99)
}) })
it('should have created the edit button', function () { it('should have created the edit button', function () {
@ -42,7 +43,7 @@ describe('L.U.Map', function () {
it('should hide icon container div when hiding datalayer', function () { it('should hide icon container div when hiding datalayer', function () {
var el = qs( var el = qs(
'.leaflet-control-browse #browse_data_toggle_' + '.leaflet-control-browse #browse_data_toggle_' +
L.stamp(this.datalayer) + L.stamp(datalayer) +
' .layer-toggle' ' .layer-toggle'
) )
happen.click(el) happen.click(el)
@ -56,7 +57,7 @@ describe('L.U.Map', function () {
}) })
it('should have only one datalayer in its index', function () { it('should have only one datalayer in its index', function () {
assert.equal(this.map.datalayers_index.length, 1) assert.equal(map.datalayers_index.length, 1)
}) })
}) })
@ -78,20 +79,20 @@ describe('L.U.Map', function () {
var new_name = 'This is a new name' var new_name = 'This is a new name'
input.value = new_name input.value = new_name
happen.once(input, { type: 'input' }) happen.once(input, { type: 'input' })
assert.equal(this.map.options.name, new_name) assert.equal(map.options.name, new_name)
}) })
it('should have made Map dirty', function () { it('should have made Map dirty', function () {
assert.ok(this.map.isDirty) assert.ok(map.isDirty)
}) })
it('should have added dirty class on map container', function () { it('should have added dirty class on map container', function () {
assert.ok(L.DomUtil.hasClass(this.map._container, 'umap-is-dirty')) assert.ok(L.DomUtil.hasClass(map._container, 'umap-is-dirty'))
}) })
}) })
describe('#delete()', function () { describe('#delete()', function () {
var path = '/map/99/delete/', let path = '/map/99/update/delete/',
oldConfirm, oldConfirm,
newConfirm = function () { newConfirm = function () {
return true return true
@ -105,24 +106,22 @@ describe('L.U.Map', function () {
window.confirm = oldConfirm window.confirm = oldConfirm
}) })
it('should ask for confirmation on delete link click', function () { it('should ask for confirmation on delete link click', async function () {
var button = qs('a.update-map-settings') let button = qs('a.update-map-settings')
assert.ok(button, 'update map info button exists') assert.ok(button, 'update map info button exists')
happen.click(button) happen.click(button)
var deleteLink = qs('button.umap-delete') let deleteLink = qs('button.umap-delete')
assert.ok(deleteLink, 'delete map button exists') assert.ok(deleteLink, 'delete map button exists')
sinon.spy(window, 'confirm') sinon.spy(window, 'confirm')
this.server.respondWith('POST', path, JSON.stringify({ redirect: '#' })) await fetchMock.post(path, { redirect: '#' })
happen.click(deleteLink) happen.click(deleteLink)
this.server.respond()
assert(window.confirm.calledOnce) assert(window.confirm.calledOnce)
window.confirm.restore() window.confirm.restore()
}) })
}) })
describe('#importData()', function () { describe('#importData()', function () {
var fileInput, textarea, submit, formatSelect, layerSelect, clearFlag let fileInput, textarea, submit, formatSelect, layerSelect, clearFlag
it('should build a form on click', function () { it('should build a form on click', function () {
happen.click(qs('a.upload-data')) happen.click(qs('a.upload-data'))
@ -139,82 +138,82 @@ describe('L.U.Map', function () {
}) })
it('should import geojson from textarea', function () { it('should import geojson from textarea', function () {
this.datalayer.empty() datalayer.empty()
assert.equal(this.datalayer._index.length, 0) assert.equal(datalayer._index.length, 0)
textarea.value = 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": ""}}]}' '{"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') changeSelectValue(formatSelect, 'geojson')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 2) assert.equal(datalayer._index.length, 2)
}) })
it('should remove dot in property name', function () { it('should remove dot in property name', function () {
this.datalayer.empty() datalayer.empty()
assert.equal(this.datalayer._index.length, 0) assert.equal(datalayer._index.length, 0)
textarea.value = textarea.value =
'{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [6.922931671142578, 47.481161607175736]}, "type": "Feature", "properties": {"color": "", "name": "Chez R\u00e9my", "A . in the name": ""}}, {"geometry": {"type": "LineString", "coordinates": [[2.4609375, 48.88639177703194], [2.48291015625, 48.76343113791796], [2.164306640625, 48.719961222646276]]}, "type": "Feature", "properties": {"color": "", "name": "P\u00e9rif", "with a dot.": ""}}]}' '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [6.922931671142578, 47.481161607175736]}, "type": "Feature", "properties": {"color": "", "name": "Chez R\u00e9my", "A . in the name": ""}}, {"geometry": {"type": "LineString", "coordinates": [[2.4609375, 48.88639177703194], [2.48291015625, 48.76343113791796], [2.164306640625, 48.719961222646276]]}, "type": "Feature", "properties": {"color": "", "name": "P\u00e9rif", "with a dot.": ""}}]}'
changeSelectValue(formatSelect, 'geojson') changeSelectValue(formatSelect, 'geojson')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 2) assert.equal(datalayer._index.length, 2)
assert.ok(this.datalayer._propertiesIndex.includes('A _ in the name')) assert.ok(datalayer._propertiesIndex.includes('A _ in the name'))
assert.ok(this.datalayer._propertiesIndex.includes('with a dot_')) assert.ok(datalayer._propertiesIndex.includes('with a dot_'))
}) })
it('should import osm from textarea', function () { it('should import osm from textarea', function () {
this.datalayer.empty() datalayer.empty()
happen.click(qs('a.upload-data')) happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea') textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]') submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]') formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0) assert.equal(datalayer._index.length, 0)
textarea.value = 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"}}]}' '{"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') changeSelectValue(formatSelect, 'osm')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 2) assert.equal(datalayer._index.length, 2)
assert.equal( assert.equal(
this.datalayer._layers[this.datalayer._index[0]].properties.tourism, datalayer._layers[datalayer._index[0]].properties.tourism,
'information' 'information'
) )
}) })
it('should import kml from textarea', function () { it('should import kml from textarea', function () {
this.datalayer.empty() datalayer.empty()
happen.click(qs('a.upload-data')) happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea') textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]') submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]') formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0) assert.equal(datalayer._index.length, 0)
textarea.value = kml_example textarea.value = kml_example
changeSelectValue(formatSelect, 'kml') changeSelectValue(formatSelect, 'kml')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 3) assert.equal(datalayer._index.length, 3)
}) })
it('should import gpx from textarea', function () { it('should import gpx from textarea', function () {
this.datalayer.empty() datalayer.empty()
happen.click(qs('a.upload-data')) happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea') textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]') submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]') formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0) assert.equal(datalayer._index.length, 0)
textarea.value = gpx_example textarea.value = gpx_example
changeSelectValue(formatSelect, 'gpx') changeSelectValue(formatSelect, 'gpx')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 2) assert.equal(datalayer._index.length, 2)
}) })
it('should import csv from textarea', function () { it('should import csv from textarea', function () {
this.datalayer.empty() datalayer.empty()
happen.click(qs('a.upload-data')) happen.click(qs('a.upload-data'))
textarea = qs('.umap-upload textarea') textarea = qs('.umap-upload textarea')
submit = qs('.umap-upload input[type="button"]') submit = qs('.umap-upload input[type="button"]')
formatSelect = qs('.umap-upload select[name="format"]') formatSelect = qs('.umap-upload select[name="format"]')
assert.equal(this.datalayer._index.length, 0) assert.equal(datalayer._index.length, 0)
textarea.value = csv_example textarea.value = csv_example
changeSelectValue(formatSelect, 'csv') changeSelectValue(formatSelect, 'csv')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
}) })
it('should replace content if asked so', function () { it('should replace content if asked so', function () {
@ -224,52 +223,52 @@ describe('L.U.Map', function () {
formatSelect = qs('.umap-upload select[name="format"]') formatSelect = qs('.umap-upload select[name="format"]')
clearFlag = qs('.umap-upload input[name="clear"]') clearFlag = qs('.umap-upload input[name="clear"]')
clearFlag.checked = true clearFlag.checked = true
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
textarea.value = csv_example textarea.value = csv_example
changeSelectValue(formatSelect, 'csv') changeSelectValue(formatSelect, 'csv')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
}) })
it('should import GeometryCollection from textarea', function () { it('should import GeometryCollection from textarea', function () {
this.datalayer.empty() datalayer.empty()
textarea.value = 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]]}]}' '{"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"]') formatSelect = qs('.umap-upload select[name="format"]')
changeSelectValue(formatSelect, 'geojson') changeSelectValue(formatSelect, 'geojson')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 3) assert.equal(datalayer._index.length, 3)
}) })
it('should import multipolygon', function () { it('should import multipolygon', function () {
this.datalayer.empty() datalayer.empty()
textarea.value = 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]]]] }}' '{"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') changeSelectValue(formatSelect, 'geojson')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
var layer = this.datalayer.getFeatureByIndex(0) var layer = datalayer.getFeatureByIndex(0)
assert.equal(layer._latlngs.length, 2) // Two shapes. assert.equal(layer._latlngs.length, 2) // Two shapes.
assert.equal(layer._latlngs[0].length, 2) // Hole. assert.equal(layer._latlngs[0].length, 2) // Hole.
}) })
it('should import multipolyline', function () { it('should import multipolyline', function () {
this.datalayer.empty() datalayer.empty()
textarea.value = textarea.value =
'{"type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "MultiLineString", "coordinates": [[[-108, 46], [-113, 43]], [[-112, 45], [-115, 44]]] } }]}' '{"type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "MultiLineString", "coordinates": [[[-108, 46], [-113, 43]], [[-112, 45], [-115, 44]]] } }]}'
changeSelectValue(formatSelect, 'geojson') changeSelectValue(formatSelect, 'geojson')
happen.click(submit) happen.click(submit)
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
var layer = this.datalayer.getFeatureByIndex(0) var layer = datalayer.getFeatureByIndex(0)
assert.equal(layer._latlngs.length, 2) // Two shapes. assert.equal(layer._latlngs.length, 2) // Two shapes.
}) })
it('should import raw umap data from textarea', function () { it('should import raw umap data from textarea', function () {
//Right now, the import function will try to save and reload. Stop this from happening. //Right now, the import function will try to save and reload. Stop this from happening.
var disabledSaveFunction = this.map.save var disabledSaveFunction = map.save
this.map.save = function () {} map.save = function () {}
happen.click(qs('a.upload-data')) happen.click(qs('a.upload-data'))
var initialLayerCount = Object.keys(this.map.datalayers).length var initialLayerCount = Object.keys(map.datalayers).length
formatSelect = qs('.umap-upload select[name="format"]') formatSelect = qs('.umap-upload select[name="format"]')
textarea = qs('.umap-upload textarea') textarea = qs('.umap-upload textarea')
textarea.value = textarea.value =
@ -277,12 +276,12 @@ describe('L.U.Map', function () {
formatSelect.value = 'umap' formatSelect.value = 'umap'
submit = qs('.umap-upload input[type="button"]') submit = qs('.umap-upload input[type="button"]')
happen.click(submit) happen.click(submit)
assert.equal(Object.keys(this.map.datalayers).length, initialLayerCount + 2) assert.equal(Object.keys(map.datalayers).length, initialLayerCount + 2)
assert.equal(this.map.options.name, 'Imported map') assert.equal(map.options.name, 'Imported map')
var foundFirstLayer = false var foundFirstLayer = false
var foundSecondLayer = false var foundSecondLayer = false
for (var idx in this.map.datalayers) { for (var idx in map.datalayers) {
var datalayer = this.map.datalayers[idx] var datalayer = map.datalayers[idx]
if (datalayer.options.name === 'Cities') { if (datalayer.options.name === 'Cities') {
foundFirstLayer = true foundFirstLayer = true
assert.equal(datalayer._index.length, 2) assert.equal(datalayer._index.length, 2)
@ -297,7 +296,7 @@ describe('L.U.Map', function () {
}) })
it('should only import options on the whitelist (umap format import)', function () { it('should only import options on the whitelist (umap format import)', function () {
assert.equal(this.map.options.umap_id, 99) assert.equal(map.options.umap_id, 99)
}) })
it('should update title bar (umap format import)', function () { it('should update title bar (umap format import)', function () {
@ -318,7 +317,7 @@ describe('L.U.Map', function () {
it('should set the tilelayer (umap format import)', function () { it('should set the tilelayer (umap format import)', function () {
assert.equal( assert.equal(
this.map.selected_tilelayer._url, map.selected_tilelayer._url,
'http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg' 'http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg'
) )
}) })
@ -327,14 +326,14 @@ describe('L.U.Map', function () {
describe('#localizeUrl()', function () { describe('#localizeUrl()', function () {
it('should replace known variables', function () { it('should replace known variables', function () {
assert.equal( assert.equal(
this.map.localizeUrl('http://example.org/{zoom}'), map.localizeUrl('http://example.org/{zoom}'),
'http://example.org/' + this.map.getZoom() 'http://example.org/' + map.getZoom()
) )
}) })
it('should keep unknown variables', function () { it('should keep unknown variables', function () {
assert.equal( assert.equal(
this.map.localizeUrl('http://example.org/{unkown}'), map.localizeUrl('http://example.org/{unkown}'),
'http://example.org/{unkown}' 'http://example.org/{unkown}'
) )
}) })

View file

@ -1,20 +1,24 @@
describe('L.U.Marker', function () { describe('L.U.Marker', () => {
before(function () { let map, datalayer
this.server = sinon.fakeServer.create() before(async () => {
var datalayer_response = JSON.parse(JSON.stringify(RESPONSES.datalayer62_GET)) // Copy. const datalayer_response = JSON.parse(JSON.stringify(RESPONSES.datalayer62_GET)) // Copy.
datalayer_response._umap_options.iconClass = 'Drop' datalayer_response._umap_options.iconClass = 'Drop'
this.server.respondWith(/\/datalayer\/62\/\?.*/, JSON.stringify(datalayer_response)) await fetchMock.mock(/\/datalayer\/62\/\?.*/, datalayer_response)
this.map = initMap({ umap_id: 99 }) this.options = {
this.datalayer = this.map.getDataLayerByUmapId(62) umap_id: 99,
this.server.respond() }
MAP = map = initMap({ umap_id: 99 })
const datalayer_options = defaultDatalayerData()
await map.initDataLayers([datalayer_options])
datalayer = map.getDataLayerByUmapId(62)
}) })
after(function () { after(() => {
this.server.restore() fetchMock.restore()
resetMap() resetMap()
}) })
describe('#iconClassChange()', function () { describe('#iconClassChange()', () => {
it('should change icon class', function () { it('should change icon class', () => {
enableEdit() enableEdit()
happen.click(qs('div.umap-drop-icon')) happen.click(qs('div.umap-drop-icon'))
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')) happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
@ -35,8 +39,8 @@ describe('L.U.Marker', function () {
}) })
}) })
describe('#iconSymbolChange()', function () { describe('#iconSymbolChange()', () => {
it('should change icon symbol', function () { it('should change icon symbol', () => {
enableEdit() enableEdit()
happen.click(qs('div.umap-drop-icon')) happen.click(qs('div.umap-drop-icon'))
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')) happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
@ -58,8 +62,8 @@ describe('L.U.Marker', function () {
}) })
}) })
describe('#iconClassChange()', function () { describe('#iconClassChange()', () => {
it('should change icon class', function () { it('should change icon class', () => {
enableEdit() enableEdit()
happen.click(qs('div.umap-drop-icon')) happen.click(qs('div.umap-drop-icon'))
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit')) happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
@ -80,15 +84,15 @@ describe('L.U.Marker', function () {
}) })
}) })
describe('#clone', function () { describe('#clone', () => {
it('should clone marker', function () { it('should clone marker', () => {
var layer = new L.U.Marker(this.map, [10, 20], { var layer = new L.U.Marker(map, [10, 20], {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
assert.equal(this.datalayer._index.length, 4) assert.equal(datalayer._index.length, 4)
other = layer.clone() other = layer.clone()
assert.ok(this.map.hasLayer(other)) assert.ok(map.hasLayer(other))
assert.equal(this.datalayer._index.length, 5) assert.equal(datalayer._index.length, 5)
// Must not be the same reference // Must not be the same reference
assert.notEqual(layer._latlng, other._latlng) assert.notEqual(layer._latlng, other._latlng)
assert.equal(L.Util.formatNum(layer._latlng.lat), other._latlng.lat) assert.equal(L.Util.formatNum(layer._latlng.lat), other._latlng.lat)
@ -97,20 +101,20 @@ describe('L.U.Marker', function () {
}) })
describe('#edit()', function (done) { describe('#edit()', function (done) {
it('should allow changing coordinates manually', function () { it('should allow changing coordinates manually', () => {
var layer = new L.U.Marker(this.map, [10, 20], { var layer = new L.U.Marker(map, [10, 20], {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
enableEdit() enableEdit()
layer.edit() layer.edit()
changeInputValue(qs('form.umap-form input[name="lat"]'), '54.43') changeInputValue(qs('form.umap-form input[name="lat"]'), '54.43')
assert.equal(layer._latlng.lat, 54.43) assert.equal(layer._latlng.lat, 54.43)
}) })
it('should not allow invalid latitude nor longitude', function () { it('should not allow invalid latitude nor longitude', () => {
var layer = new L.U.Marker(this.map, [10, 20], { var layer = new L.U.Marker(map, [10, 20], {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
enableEdit() enableEdit()
layer.edit() layer.edit()
changeInputValue(qs('form.umap-form input[name="lat"]'), '5443') changeInputValue(qs('form.umap-form input[name="lat"]'), '5443')

View file

@ -1,14 +1,14 @@
describe('L.U.Polygon', function () { describe('L.U.Polygon', function () {
var p2ll, map var p2ll, map, datalayer
before(function () { before(function () {
this.map = map = initMap({ umap_id: 99 }) 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() datalayer = map.createDataLayer()
this.datalayer.connectToMap() datalayer.connectToMap()
}) })
after(function () { after(function () {
@ -17,32 +17,32 @@ describe('L.U.Polygon', function () {
}) })
afterEach(function () { afterEach(function () {
this.datalayer.empty() datalayer.empty()
}) })
describe('#isMulti()', function () { describe('#isMulti()', function () {
it('should return false for basic Polygon', function () { it('should return false for basic Polygon', function () {
var layer = new L.U.Polygon( var layer = new L.U.Polygon(
this.map, map,
[ [
[1, 2], [1, 2],
[3, 4], [3, 4],
[5, 6], [5, 6],
], ],
{ datalayer: this.datalayer } { datalayer: datalayer }
) )
assert.notOk(layer.isMulti()) assert.notOk(layer.isMulti())
}) })
it('should return false for nested basic Polygon', function () { it('should return false for nested basic Polygon', function () {
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]], var latlngs = [[[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(map, latlngs, { datalayer: datalayer })
assert.notOk(layer.isMulti()) assert.notOk(layer.isMulti())
}) })
it('should return false for simple Polygon with hole', function () { it('should return false for simple Polygon with hole', function () {
var layer = new L.U.Polygon( var layer = new L.U.Polygon(
this.map, map,
[ [
[ [
[1, 2], [1, 2],
@ -55,7 +55,7 @@ describe('L.U.Polygon', function () {
[11, 12], [11, 12],
], ],
], ],
{ datalayer: this.datalayer } { datalayer: datalayer }
) )
assert.notOk(layer.isMulti()) assert.notOk(layer.isMulti())
}) })
@ -77,7 +77,7 @@ describe('L.U.Polygon', function () {
], ],
], ],
] ]
var layer = new L.U.Polygon(this.map, latLngs, { datalayer: this.datalayer }) var layer = new L.U.Polygon(map, latLngs, { datalayer: datalayer })
assert.ok(layer.isMulti()) assert.ok(layer.isMulti())
}) })
@ -103,7 +103,7 @@ describe('L.U.Polygon', function () {
], ],
], ],
] ]
var layer = new L.U.Polygon(this.map, latLngs, { datalayer: this.datalayer }) var layer = new L.U.Polygon(map, latLngs, { datalayer: datalayer })
assert.ok(layer.isMulti()) assert.ok(layer.isMulti())
}) })
}) })
@ -120,27 +120,27 @@ describe('L.U.Polygon', function () {
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]],
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]], [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, { layer = new L.U.Polygon(map, latlngs, {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Remove shape from the multi'), 1) assert.equal(qst('Remove shape from the multi'), 1)
}) })
it('should not allow to remove shape when not multi', function () { it('should not allow to remove shape when not multi', function () {
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]], var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
layer = new L.U.Polygon(this.map, latlngs, { layer = new L.U.Polygon(map, latlngs, {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Remove shape from the multi')) assert.notOk(qst('Remove shape from the multi'))
}) })
it('should not allow to isolate shape when not multi', function () { it('should not allow to isolate shape when not multi', function () {
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]], var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
layer = new L.U.Polygon(this.map, latlngs, { layer = new L.U.Polygon(map, latlngs, {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Extract shape to separate feature')) assert.notOk(qst('Extract shape to separate feature'))
}) })
@ -150,9 +150,9 @@ describe('L.U.Polygon', function () {
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]],
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]], [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, { layer = new L.U.Polygon(map, latlngs, {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.ok(qst('Extract shape to separate feature')) assert.ok(qst('Extract shape to separate feature'))
}) })
@ -162,9 +162,9 @@ describe('L.U.Polygon', function () {
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]],
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]], [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, { layer = new L.U.Polygon(map, latlngs, {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Transform to lines')) assert.notOk(qst('Transform to lines'))
}) })
@ -176,26 +176,26 @@ describe('L.U.Polygon', function () {
[p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)], [p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)],
], ],
], ],
layer = new L.U.Polygon(this.map, latlngs, { layer = new L.U.Polygon(map, latlngs, {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.notOk(qst('Transform to lines')) assert.notOk(qst('Transform to lines'))
}) })
it('should allow to transform to lines when not multi', function () { it('should allow to transform to lines when not multi', function () {
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]] var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]]
new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo( new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
this.datalayer datalayer
) )
happen.at('contextmenu', 150, 150) happen.at('contextmenu', 150, 150)
assert.equal(qst('Transform to lines'), 1) assert.equal(qst('Transform to lines'), 1)
}) })
it('should not allow to transfer shape when not editedFeature', function () { it('should not allow to transfer shape when not editedFeature', function () {
new L.U.Polygon(this.map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], { new L.U.Polygon(map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
happen.at('contextmenu', 110, 160) happen.at('contextmenu', 110, 160)
assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon. assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon.
assert.notOk(qst('Transfer shape to edited feature')) assert.notOk(qst('Transfer shape to edited feature'))
@ -203,13 +203,13 @@ describe('L.U.Polygon', function () {
it('should not allow to transfer shape when editedFeature is not a polygon', function () { it('should not allow to transfer shape when editedFeature is not a polygon', function () {
var layer = new L.U.Polygon( var layer = new L.U.Polygon(
this.map, map,
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)],
{ datalayer: this.datalayer } { datalayer: datalayer }
).addTo(this.datalayer), ).addTo(datalayer),
other = new L.U.Polyline(this.map, [p2ll(200, 250), p2ll(200, 300)], { other = new L.U.Polyline(map, [p2ll(200, 250), p2ll(200, 300)], {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
other.edit() other.edit()
happen.once(layer._path, { type: 'contextmenu' }) happen.once(layer._path, { type: 'contextmenu' })
assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon. assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon.
@ -217,18 +217,18 @@ describe('L.U.Polygon', function () {
}) })
it('should allow to transfer shape when another polygon is edited', function () { it('should allow to transfer shape when another polygon is edited', function () {
this.datalayer.empty() datalayer.empty()
var layer = new L.U.Polygon( var layer = new L.U.Polygon(
this.map, map,
[p2ll(200, 300), p2ll(300, 200), p2ll(200, 100)], [p2ll(200, 300), p2ll(300, 200), p2ll(200, 100)],
{ datalayer: this.datalayer } { datalayer: datalayer }
).addTo(this.datalayer) ).addTo(datalayer)
layer.edit() // This moves the map to put "other" at the center. layer.edit() // This moves the map to put "other" at the center.
var other = new L.U.Polygon( var other = new L.U.Polygon(
this.map, map,
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)],
{ datalayer: this.datalayer } { datalayer: datalayer }
).addTo(this.datalayer) ).addTo(datalayer)
happen.once(other._path, { type: 'contextmenu' }) happen.once(other._path, { type: 'contextmenu' })
assert.equal(qst('Transfer shape to edited feature'), 1) assert.equal(qst('Transfer shape to edited feature'), 1)
layer.remove() layer.remove()
@ -242,19 +242,19 @@ describe('L.U.Polygon', function () {
}) })
it('"add shape" control should be visible when editing a Polygon', function () { it('"add shape" control should be visible when editing a Polygon', function () {
var layer = new L.U.Polygon(this.map, [p2ll(100, 100), p2ll(100, 200)], { var layer = new L.U.Polygon(map, [p2ll(100, 100), p2ll(100, 200)], {
datalayer: this.datalayer, datalayer: datalayer,
}).addTo(this.datalayer) }).addTo(datalayer)
layer.edit() layer.edit()
assert.ok(qs('.umap-draw-polygon-multi')) assert.ok(qs('.umap-draw-polygon-multi'))
}) })
it('"add shape" control should extend the same multi', function () { it('"add shape" control should extend the same multi', function () {
var layer = new L.U.Polygon( var layer = new L.U.Polygon(
this.map, map,
[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)], [p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)],
{ datalayer: this.datalayer } { datalayer: datalayer }
).addTo(this.datalayer) ).addTo(datalayer)
layer.edit() layer.edit()
assert.notOk(layer.isMulti()) assert.notOk(layer.isMulti())
happen.click(qs('.umap-draw-polygon-multi')) happen.click(qs('.umap-draw-polygon-multi'))
@ -264,26 +264,26 @@ describe('L.U.Polygon', function () {
happen.at('click', 350, 300) happen.at('click', 350, 300)
happen.at('click', 350, 300) happen.at('click', 350, 300)
assert.ok(layer.isMulti()) assert.ok(layer.isMulti())
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
}) })
}) })
describe('#transferShape', function () { describe('#transferShape', function () {
it('should transfer simple polygon shape to another polygon', function () { it('should transfer simple polygon shape to another polygon', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo( layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
this.datalayer datalayer
), ),
other = new L.U.Polygon( other = new L.U.Polygon(
this.map, map,
[p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)], [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)],
{ datalayer: this.datalayer } { datalayer: datalayer }
).addTo(this.datalayer) ).addTo(datalayer)
assert.ok(this.map.hasLayer(layer)) assert.ok(map.hasLayer(layer))
layer.transferShape(p2ll(150, 150), other) layer.transferShape(p2ll(150, 150), other)
assert.equal(other._latlngs.length, 2) assert.equal(other._latlngs.length, 2)
assert.deepEqual(other._latlngs[1][0], latlngs) assert.deepEqual(other._latlngs[1][0], latlngs)
assert.notOk(this.map.hasLayer(layer)) assert.notOk(map.hasLayer(layer))
}) })
it('should transfer multipolygon shape to another polygon', function () { it('should transfer multipolygon shape to another polygon', function () {
@ -294,19 +294,19 @@ describe('L.U.Polygon', function () {
], ],
[[p2ll(200, 300), p2ll(300, 200)]], [[p2ll(200, 300), p2ll(300, 200)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo( layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
this.datalayer datalayer
), ),
other = new L.U.Polygon( other = new L.U.Polygon(
this.map, map,
[p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)], [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)],
{ datalayer: this.datalayer } { datalayer: datalayer }
).addTo(this.datalayer) ).addTo(datalayer)
assert.ok(this.map.hasLayer(layer)) assert.ok(map.hasLayer(layer))
layer.transferShape(p2ll(150, 150), other) layer.transferShape(p2ll(150, 150), other)
assert.equal(other._latlngs.length, 2) assert.equal(other._latlngs.length, 2)
assert.deepEqual(other._latlngs[1][0], latlngs[0][0]) assert.deepEqual(other._latlngs[1][0], latlngs[0][0])
assert.ok(this.map.hasLayer(layer)) assert.ok(map.hasLayer(layer))
assert.equal(layer._latlngs.length, 1) assert.equal(layer._latlngs.length, 1)
}) })
}) })
@ -314,14 +314,14 @@ describe('L.U.Polygon', function () {
describe('#isolateShape', function () { describe('#isolateShape', function () {
it('should not allow to isolate simple polygon', function () { it('should not allow to isolate simple polygon', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo( layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
this.datalayer datalayer
) )
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
assert.ok(this.map.hasLayer(layer)) assert.ok(map.hasLayer(layer))
layer.isolateShape(p2ll(150, 150)) layer.isolateShape(p2ll(150, 150))
assert.equal(layer._latlngs[0].length, 3) assert.equal(layer._latlngs[0].length, 3)
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
}) })
it('should isolate multipolygon shape', function () { it('should isolate multipolygon shape', function () {
@ -332,17 +332,17 @@ describe('L.U.Polygon', function () {
], ],
[[p2ll(200, 300), p2ll(300, 200)]], [[p2ll(200, 300), p2ll(300, 200)]],
], ],
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo( layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
this.datalayer datalayer
) )
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
assert.ok(this.map.hasLayer(layer)) assert.ok(map.hasLayer(layer))
var other = layer.isolateShape(p2ll(150, 150)) var other = layer.isolateShape(p2ll(150, 150))
assert.equal(this.datalayer._index.length, 2) assert.equal(datalayer._index.length, 2)
assert.equal(other._latlngs.length, 2) assert.equal(other._latlngs.length, 2)
assert.deepEqual(other._latlngs[0], latlngs[0][0]) assert.deepEqual(other._latlngs[0], latlngs[0][0])
assert.ok(this.map.hasLayer(layer)) assert.ok(map.hasLayer(layer))
assert.ok(this.map.hasLayer(other)) assert.ok(map.hasLayer(other))
assert.equal(layer._latlngs.length, 1) assert.equal(layer._latlngs.length, 1)
other.remove() other.remove()
}) })
@ -351,13 +351,13 @@ describe('L.U.Polygon', function () {
describe('#clone', function () { describe('#clone', function () {
it('should clone polygon', function () { it('should clone polygon', function () {
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo( layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
this.datalayer datalayer
) )
assert.equal(this.datalayer._index.length, 1) assert.equal(datalayer._index.length, 1)
other = layer.clone() other = layer.clone()
assert.ok(this.map.hasLayer(other)) assert.ok(map.hasLayer(other))
assert.equal(this.datalayer._index.length, 2) assert.equal(datalayer._index.length, 2)
// Must not be the same reference // Must not be the same reference
assert.notEqual(layer._latlngs, other._latlngs) assert.notEqual(layer._latlngs, other._latlngs)
assert.equal(L.Util.formatNum(layer._latlngs[0][0].lat), other._latlngs[0][0].lat) assert.equal(L.Util.formatNum(layer._latlngs[0][0].lat), other._latlngs[0][0].lat)

View file

@ -1,50 +1,54 @@
describe('L.TableEditor', function () { describe('L.TableEditor', () => {
var path = '/map/99/datalayer/edit/62/' let path = '/map/99/datalayer/edit/62/',
datalayer
before(function () { before(async () => {
this.server = sinon.fakeServer.create() await fetchMock.mock(
this.server.respondWith(
/\/datalayer\/62\/\?.*/, /\/datalayer\/62\/\?.*/,
JSON.stringify(RESPONSES.datalayer62_GET) JSON.stringify(RESPONSES.datalayer62_GET)
) )
this.map = initMap({ umap_id: 99 }) this.options = {
this.datalayer = this.map.getDataLayerByUmapId(62) umap_id: 99,
this.server.respond() }
map = initMap({ umap_id: 99 })
const datalayer_options = defaultDatalayerData()
await map.initDataLayers([datalayer_options])
datalayer = map.getDataLayerByUmapId(62)
enableEdit() enableEdit()
}) })
after(function () { after(() => {
fetchMock.restore()
clickCancel() clickCancel()
this.server.restore()
resetMap() resetMap()
}) })
describe('#open()', function () { describe('#open()', () => {
var button var button
it('should exist table click on edit mode', function () { it('should exist table click on edit mode', () => {
button = qs( button = qs(
'#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-table-edit' '#browse_data_toggle_' + L.stamp(datalayer) + ' .layer-table-edit'
) )
expect(button).to.be.ok expect(button).to.be.ok
}) })
it('should open table button click', function () { it('should open table button click', () => {
happen.click(button) happen.click(button)
expect(qs('#umap-ui-container div.table')).to.be.ok expect(qs('#umap-ui-container div.table')).to.be.ok
expect(qsa('#umap-ui-container div.table form').length).to.eql(3) // One per feature. expect(qsa('#umap-ui-container div.table form').length).to.eql(3) // One per feature.
expect(qsa('#umap-ui-container div.table input').length).to.eql(3) // One per feature and per property. expect(qsa('#umap-ui-container div.table input').length).to.eql(3) // One per feature and per property.
}) })
}) })
describe('#properties()', function () { describe('#properties()', () => {
var feature var feature
before(function () { before(() => {
var firstIndex = this.datalayer._index[0] var firstIndex = datalayer._index[0]
feature = this.datalayer._layers[firstIndex] feature = datalayer._layers[firstIndex]
}) })
it('should create new property column', function () { it('should create new property column', () => {
var newPrompt = function () { var newPrompt = () => {
return 'newprop' return 'newprop'
} }
var oldPrompt = window.prompt var oldPrompt = window.prompt
@ -56,7 +60,7 @@ describe('L.TableEditor', function () {
window.prompt = oldPrompt window.prompt = oldPrompt
}) })
it('should populate feature property on fill', function () { it('should populate feature property on fill', () => {
var input = qs( var input = qs(
'form#umap-feature-properties_' + L.stamp(feature) + ' input[name=newprop]' 'form#umap-feature-properties_' + L.stamp(feature) + ' input[name=newprop]'
) )
@ -64,8 +68,8 @@ describe('L.TableEditor', function () {
expect(feature.properties.newprop).to.eql('the value') expect(feature.properties.newprop).to.eql('the value')
}) })
it('should update property name on update click', function () { it('should update property name on update click', () => {
var newPrompt = function () { var newPrompt = () => {
return 'newname' return 'newname'
} }
var oldPrompt = window.prompt var oldPrompt = window.prompt
@ -79,9 +83,9 @@ describe('L.TableEditor', function () {
window.prompt = oldPrompt window.prompt = oldPrompt
}) })
it('should update property on delete click', function () { it('should update property on delete click', () => {
var oldConfirm, var oldConfirm,
newConfirm = function () { newConfirm = () => {
return true return true
} }
oldConfirm = window.confirm oldConfirm = window.confirm

View file

@ -213,7 +213,6 @@ function initMap(options) {
}, },
}, },
} }
default_options.properties.datalayers.push(defaultDatalayerData())
options = options || {} options = options || {}
options.properties = L.extend({}, default_options.properties, options) options.properties = L.extend({}, default_options.properties, options)
options.geometry = { options.geometry = {
@ -386,10 +385,6 @@ var RESPONSES = {
}, },
} }
sinon.fakeServer.flush = function () {
this.responses = []
}
var kml_example = var kml_example =
'<?xml version="1.0" encoding="UTF-8"?>' + '<?xml version="1.0" encoding="UTF-8"?>' +
'<kml xmlns="http://www.opengis.net/kml/2.2">' + '<kml xmlns="http://www.opengis.net/kml/2.2">' +

View file

@ -75,6 +75,10 @@
<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="module">
import fetchMock from '../../../../node_modules/fetch-mock/esm/client.js';
window.fetchMock = fetchMock
</script>
<script type="text/javascript"> <script type="text/javascript">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',