tests: fix 90% of the javascript tests
This commit is contained in:
parent
d1df70b0f4
commit
e44e0df69a
13 changed files with 532 additions and 546 deletions
|
@ -9,6 +9,7 @@
|
|||
"chai": "^3.3.0",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-plugin-compat": "^4.2.0",
|
||||
"fetch-mock": "^9.11.0",
|
||||
"happen": "~0.1.3",
|
||||
"lebab": "^3.2.1",
|
||||
"mocha": "^10.2.0",
|
||||
|
|
|
@ -176,24 +176,26 @@ const POLYGONS = {
|
|||
],
|
||||
}
|
||||
|
||||
describe('L.U.Choropleth', function () {
|
||||
describe('L.U.Choropleth', () => {
|
||||
let path = '/map/99/datalayer/edit/62/',
|
||||
poly1,
|
||||
poly4,
|
||||
poly9
|
||||
poly9,
|
||||
map,
|
||||
datalayer
|
||||
|
||||
before(function () {
|
||||
this.server = sinon.fakeServer.create()
|
||||
this.server.respondWith(/\/datalayer\/62\/\?.*/, JSON.stringify(POLYGONS))
|
||||
this.map = initMap({ umap_id: 99 })
|
||||
this.datalayer = this.map.getDataLayerByUmapId(62)
|
||||
this.server.respond()
|
||||
this.datalayer.options.type = 'Choropleth'
|
||||
this.datalayer.options.choropleth = {
|
||||
before(async () => {
|
||||
fetchMock.mock(/\/datalayer\/62\/\?.*/, JSON.stringify(POLYGONS))
|
||||
map = initMap({ umap_id: 99 })
|
||||
const datalayer_options = defaultDatalayerData()
|
||||
await map.initDataLayers([datalayer_options])
|
||||
datalayer = map.getDataLayerByUmapId(62)
|
||||
datalayer.options.type = 'Choropleth'
|
||||
datalayer.options.choropleth = {
|
||||
property: 'value',
|
||||
}
|
||||
enableEdit()
|
||||
this.datalayer.eachLayer(function (layer) {
|
||||
datalayer.eachLayer(function (layer) {
|
||||
if (layer.properties.name === 'number 1') {
|
||||
poly1 = layer
|
||||
} else if (layer.properties.name === 'number 4') {
|
||||
|
@ -203,38 +205,38 @@ describe('L.U.Choropleth', function () {
|
|||
}
|
||||
})
|
||||
})
|
||||
after(function () {
|
||||
this.server.restore()
|
||||
after(() => {
|
||||
fetchMock.restore()
|
||||
resetMap()
|
||||
})
|
||||
|
||||
describe('#init()', function () {
|
||||
it('datalayer should have 9 features', function () {
|
||||
assert.equal(this.datalayer._index.length, 9)
|
||||
describe('#init()', () => {
|
||||
it('datalayer should have 9 features', () => {
|
||||
assert.equal(datalayer._index.length, 9)
|
||||
})
|
||||
})
|
||||
describe('#compute()', function () {
|
||||
it('choropleth should compute default colors', function () {
|
||||
this.datalayer.resetLayer(true)
|
||||
describe('#compute()', () => {
|
||||
it('choropleth should compute default colors', () => {
|
||||
datalayer.resetLayer(true)
|
||||
assert.deepEqual(
|
||||
this.datalayer.layer.options.breaks,
|
||||
datalayer.layer.options.breaks,
|
||||
[45, 673, 3829, 4900, 9898, 9898]
|
||||
)
|
||||
assert.equal(poly1._path.attributes.fill.value, '#eff3ff')
|
||||
assert.equal(poly4._path.attributes.fill.value, '#bdd7e7')
|
||||
assert.equal(poly9._path.attributes.fill.value, '#3182bd')
|
||||
})
|
||||
it('can change brewer scheme', function () {
|
||||
this.datalayer.options.choropleth.brewer = 'Reds'
|
||||
this.datalayer.resetLayer(true)
|
||||
it('can change brewer scheme', () => {
|
||||
datalayer.options.choropleth.brewer = 'Reds'
|
||||
datalayer.resetLayer(true)
|
||||
assert.equal(poly1._path.attributes.fill.value, '#fee5d9')
|
||||
assert.equal(poly4._path.attributes.fill.value, '#fcae91')
|
||||
assert.equal(poly9._path.attributes.fill.value, '#de2d26')
|
||||
})
|
||||
it('choropleth should allow to change steps', function () {
|
||||
this.datalayer.options.choropleth.brewer = 'Blues'
|
||||
this.datalayer.options.choropleth.classes = 6
|
||||
this.datalayer.resetLayer(true)
|
||||
it('choropleth should allow to change steps', () => {
|
||||
datalayer.options.choropleth.brewer = 'Blues'
|
||||
datalayer.options.choropleth.classes = 6
|
||||
datalayer.resetLayer(true)
|
||||
assert.equal(poly1._path.attributes.fill.value, '#eff3ff')
|
||||
assert.equal(poly4._path.attributes.fill.value, '#c6dbef')
|
||||
assert.equal(poly9._path.attributes.fill.value, '#3182bd')
|
||||
|
|
|
@ -1,23 +1,27 @@
|
|||
describe('L.U.Controls', function () {
|
||||
before(function () {
|
||||
this.server = sinon.fakeServer.create()
|
||||
this.server.respondWith(
|
||||
describe('L.U.Controls', () => {
|
||||
let map, datalayer
|
||||
before(async () => {
|
||||
await fetchMock.mock(
|
||||
/\/datalayer\/62\/\?.*/,
|
||||
JSON.stringify(RESPONSES.datalayer62_GET)
|
||||
)
|
||||
this.map = initMap({ umap_id: 99 })
|
||||
this.server.respond()
|
||||
this.datalayer = this.map.getDataLayerByUmapId(62)
|
||||
this.options = {
|
||||
umap_id: 99,
|
||||
}
|
||||
MAP = map = initMap({ umap_id: 99 })
|
||||
const datalayer_options = defaultDatalayerData()
|
||||
await map.initDataLayers([datalayer_options])
|
||||
datalayer = map.getDataLayerByUmapId(62)
|
||||
})
|
||||
after(function () {
|
||||
this.server.restore()
|
||||
after(() => {
|
||||
fetchMock.restore()
|
||||
resetMap()
|
||||
})
|
||||
|
||||
describe('#databrowser()', function () {
|
||||
describe('#databrowser()', () => {
|
||||
let poly, marker, line
|
||||
before(function () {
|
||||
this.datalayer.eachLayer(function (layer) {
|
||||
before(() => {
|
||||
datalayer.eachLayer(function (layer) {
|
||||
if (!poly && layer instanceof L.Polygon) {
|
||||
poly = layer
|
||||
} 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')
|
||||
assert.ok(button)
|
||||
happen.click(button)
|
||||
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'))
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
it('should sort feature in natural order', function () {
|
||||
it('should sort feature in natural order', () => {
|
||||
poly.properties.name = '9. a poly'
|
||||
marker.properties.name = '1. a marker'
|
||||
line.properties.name = '100. a line'
|
||||
this.datalayer.reindex()
|
||||
this.map.openBrowser()
|
||||
datalayer.reindex()
|
||||
map.openBrowser()
|
||||
const els = qsa('.umap-browse-features li')
|
||||
assert.equal(els.length, 3)
|
||||
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')
|
||||
})
|
||||
|
||||
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
|
||||
window.confirm = function () {
|
||||
window.confirm = () => {
|
||||
return true
|
||||
}
|
||||
enableEdit()
|
||||
|
@ -68,21 +72,21 @@ describe('L.U.Controls', function () {
|
|||
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()
|
||||
happen.click(qs('.umap-browse-actions .umap-browse-link'))
|
||||
assert.equal(qsa('#browse_data_datalayer_62 ul li').length, 3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#exportPanel()', function () {
|
||||
it('should be opened at datalayer button click', function () {
|
||||
describe('#exportPanel()', () => {
|
||||
it('should be opened at datalayer button click', () => {
|
||||
let button = qs('.leaflet-control-embed button')
|
||||
assert.ok(button)
|
||||
happen.click(button)
|
||||
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')
|
||||
assert.ok(textarea)
|
||||
console.log(textarea.textContent)
|
||||
|
|
|
@ -1,55 +1,54 @@
|
|||
describe('L.U.DataLayer', function () {
|
||||
var path = '/map/99/datalayer/edit/62/'
|
||||
describe('L.U.DataLayer', () => {
|
||||
let path = '/map/99/datalayer/update/62/',
|
||||
map,
|
||||
datalayer
|
||||
|
||||
before(function () {
|
||||
this.server = sinon.fakeServer.create()
|
||||
this.server.respondWith(
|
||||
/\/datalayer\/62\/\?.*/,
|
||||
JSON.stringify(RESPONSES.datalayer62_GET)
|
||||
)
|
||||
this.map = initMap({ umap_id: 99 })
|
||||
this.datalayer = this.map.getDataLayerByUmapId(62)
|
||||
this.server.respond()
|
||||
before(async () => {
|
||||
fetchMock.mock(/\/datalayer\/62\/\?.*/, JSON.stringify(RESPONSES.datalayer62_GET))
|
||||
fetchMock.sticky('/map/99/update/settings/', { id: 99 })
|
||||
this.options = {
|
||||
umap_id: 99,
|
||||
}
|
||||
MAP = map = initMap({ umap_id: 99 })
|
||||
const datalayer_options = defaultDatalayerData()
|
||||
await map.initDataLayers([datalayer_options])
|
||||
datalayer = map.getDataLayerByUmapId(62)
|
||||
enableEdit()
|
||||
})
|
||||
after(function () {
|
||||
this.server.restore()
|
||||
after(() => {
|
||||
fetchMock.restore()
|
||||
resetMap()
|
||||
})
|
||||
|
||||
describe('#init()', function () {
|
||||
it('should be added in datalayers index', function () {
|
||||
assert.notEqual(this.map.datalayers_index.indexOf(this.datalayer), -1)
|
||||
describe('#init()', () => {
|
||||
it('should be added in datalayers index', () => {
|
||||
assert.notEqual(map.datalayers_index.indexOf(datalayer), -1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#edit()', function () {
|
||||
describe('#edit()', () => {
|
||||
var editButton, form, input, forceButton
|
||||
|
||||
it('row in control should be active', function () {
|
||||
it('row in control should be active', () => {
|
||||
assert.notOk(
|
||||
qs(
|
||||
'.leaflet-control-browse #browse_data_toggle_' +
|
||||
L.stamp(this.datalayer) +
|
||||
'.off'
|
||||
)
|
||||
qs('.leaflet-control-browse #browse_data_toggle_' + L.stamp(datalayer) + '.off')
|
||||
)
|
||||
})
|
||||
|
||||
it('should have edit button', function () {
|
||||
editButton = qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
|
||||
it('should have edit button', () => {
|
||||
editButton = qs('#browse_data_toggle_' + L.stamp(datalayer) + ' .layer-edit')
|
||||
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'))
|
||||
})
|
||||
|
||||
it('should exist only one datalayer', function () {
|
||||
it('should exist only one datalayer', () => {
|
||||
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)
|
||||
form = qs('form.umap-form')
|
||||
input = qs('form.umap-form input[name="name"]')
|
||||
|
@ -57,97 +56,81 @@ describe('L.U.DataLayer', function () {
|
|||
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'
|
||||
input.value = new_name
|
||||
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 () {
|
||||
assert.ok(this.datalayer.isDirty)
|
||||
assert.notEqual(this.map.dirty_datalayers.indexOf(this.datalayer), -1)
|
||||
it('should have made datalayer dirty', () => {
|
||||
assert.ok(datalayer.isDirty)
|
||||
assert.notEqual(map.dirty_datalayers.indexOf(datalayer), -1)
|
||||
})
|
||||
|
||||
it('should have made Map dirty', function () {
|
||||
assert.ok(this.map.isDirty)
|
||||
it('should have made Map dirty', () => {
|
||||
assert.ok(map.isDirty)
|
||||
})
|
||||
|
||||
it('should call datalayer.save on save button click', function (done) {
|
||||
sinon.spy(this.datalayer, 'save')
|
||||
this.server.flush()
|
||||
this.server.respondWith(
|
||||
'POST',
|
||||
'/map/99/update/settings/',
|
||||
JSON.stringify({ id: 99 })
|
||||
)
|
||||
this.server.respondWith(
|
||||
'POST',
|
||||
'/map/99/datalayer/update/62/',
|
||||
JSON.stringify(defaultDatalayerData())
|
||||
)
|
||||
it('should call datalayer.save on save button click', (done) => {
|
||||
const postDatalayer = fetchMock.post(path, () => {
|
||||
return defaultDatalayerData()
|
||||
})
|
||||
clickSave()
|
||||
this.server.respond()
|
||||
this.server.respond()
|
||||
assert(this.datalayer.save.calledOnce)
|
||||
this.datalayer.save.restore()
|
||||
done()
|
||||
window.setTimeout(() => {
|
||||
assert(fetchMock.called(path))
|
||||
done()
|
||||
}, 500)
|
||||
})
|
||||
|
||||
it('should show alert if server respond 412', function () {
|
||||
it('should show alert if server respond 412', (done) => {
|
||||
cleanAlert()
|
||||
this.server.flush()
|
||||
this.server.respondWith(
|
||||
'POST',
|
||||
'/map/99/update/settings/',
|
||||
JSON.stringify({ id: 99 })
|
||||
)
|
||||
this.server.respondWith('POST', '/map/99/datalayer/update/62/', [412, {}, ''])
|
||||
fetchMock.restore()
|
||||
fetchMock.post(path, 412)
|
||||
happen.click(editButton)
|
||||
input = qs('form.umap-form input[name="name"]')
|
||||
input.value = 'a new name'
|
||||
happen.once(input, { type: 'input' })
|
||||
clickSave()
|
||||
this.server.respond()
|
||||
this.server.respond()
|
||||
assert(L.DomUtil.hasClass(this.map._container, 'umap-alert'))
|
||||
assert.notEqual(this.map.dirty_datalayers.indexOf(this.datalayer), -1)
|
||||
forceButton = qs('#umap-alert-container .umap-action')
|
||||
assert.ok(forceButton)
|
||||
window.setTimeout(() => {
|
||||
assert(L.DomUtil.hasClass(map._container, 'umap-alert'))
|
||||
assert.notEqual(map.dirty_datalayers.indexOf(datalayer), -1)
|
||||
const forceButton = qs('#umap-alert-container .umap-action')
|
||||
assert.ok(forceButton)
|
||||
done()
|
||||
}, 500)
|
||||
})
|
||||
|
||||
it('should save anyway on force save button click', function () {
|
||||
sinon.spy(this.map, 'continueSaving')
|
||||
it('should save anyway on force save button click', (done) => {
|
||||
const forceButton = qs('#umap-alert-container .umap-action')
|
||||
fetchMock.restore()
|
||||
fetchMock.post(path, defaultDatalayerData)
|
||||
happen.click(forceButton)
|
||||
this.server.flush()
|
||||
this.server.respond(
|
||||
'POST',
|
||||
'/map/99/datalayer/update/62/',
|
||||
JSON.stringify(defaultDatalayerData())
|
||||
)
|
||||
assert.notOk(qs('#umap-alert-container .umap-action'))
|
||||
assert(this.map.continueSaving.calledOnce)
|
||||
this.map.continueSaving.restore()
|
||||
assert.equal(this.map.dirty_datalayers.indexOf(this.datalayer), -1)
|
||||
window.setTimeout(() => {
|
||||
assert.notOk(qs('#umap-alert-container .umap-action'))
|
||||
assert(fetchMock.called(path))
|
||||
assert.equal(map.dirty_datalayers.indexOf(datalayer), -1)
|
||||
done()
|
||||
}, 500)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#save() new', function () {
|
||||
var newLayerButton, form, input, newDatalayer, editButton, manageButton
|
||||
describe('#save() new', () => {
|
||||
let newLayerButton, form, input, newDatalayer, editButton, manageButton
|
||||
|
||||
it('should have a manage datalayers action', function () {
|
||||
it('should have a manage datalayers action', () => {
|
||||
enableEdit()
|
||||
manageButton = qs('.manage-datalayers')
|
||||
assert.ok(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')
|
||||
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)
|
||||
form = qs('form.umap-form')
|
||||
input = qs('form.umap-form input[name="name"]')
|
||||
|
@ -155,86 +138,72 @@ describe('L.U.DataLayer', function () {
|
|||
assert.ok(input)
|
||||
})
|
||||
|
||||
it('should have an empty name', function () {
|
||||
it('should have an empty name', () => {
|
||||
assert.notOk(input.value)
|
||||
})
|
||||
|
||||
it('should have created a new datalayer', function () {
|
||||
assert.equal(this.map.datalayers_index.length, 2)
|
||||
newDatalayer = this.map.datalayers_index[1]
|
||||
it('should have created a new datalayer', () => {
|
||||
assert.equal(map.datalayers_index.length, 2)
|
||||
newDatalayer = map.datalayers_index[1]
|
||||
})
|
||||
|
||||
it('should have made Map dirty', function () {
|
||||
assert.ok(this.map.isDirty)
|
||||
it('should have made Map dirty', () => {
|
||||
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'
|
||||
input.value = new_name
|
||||
happen.once(input, { type: 'input' })
|
||||
assert.equal(newDatalayer.options.name, new_name)
|
||||
})
|
||||
|
||||
it('should set umap_id on save callback', function () {
|
||||
it('should set umap_id on save callback', async () => {
|
||||
assert.notOk(newDatalayer.umap_id)
|
||||
this.server.flush()
|
||||
this.server.respondWith(
|
||||
'POST',
|
||||
'/map/99/update/settings/',
|
||||
JSON.stringify({ id: 99 })
|
||||
)
|
||||
this.server.respondWith(
|
||||
'POST',
|
||||
'/map/99/datalayer/create/',
|
||||
JSON.stringify(defaultDatalayerData({ id: 63 }))
|
||||
)
|
||||
fetchMock.post('/map/99/datalayer/create/', defaultDatalayerData({ id: 63 }))
|
||||
clickSave()
|
||||
this.server.respond()
|
||||
this.server.respond() // First respond will then trigger another Xhr request (continueSaving)
|
||||
assert.equal(newDatalayer.umap_id, 63)
|
||||
return new Promise((resolve) => {
|
||||
window.setTimeout(() => {
|
||||
assert.equal(newDatalayer.umap_id, 63)
|
||||
resolve()
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
|
||||
it('should have unset map dirty', function () {
|
||||
assert.notOk(this.map.isDirty)
|
||||
it('should have unset map dirty', () => {
|
||||
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')
|
||||
assert.ok(editButton)
|
||||
})
|
||||
|
||||
it('should call update if we edit again', function () {
|
||||
it('should call update if we edit again', async () => {
|
||||
happen.click(editButton)
|
||||
assert.notOk(this.map.isDirty)
|
||||
assert.notOk(map.isDirty)
|
||||
input = qs('form.umap-form input[name="name"]')
|
||||
input.value = "a new name again but we don't care which"
|
||||
happen.once(input, { type: 'input' })
|
||||
assert.ok(this.map.isDirty)
|
||||
var response = function (request) {
|
||||
return request.respond(
|
||||
200,
|
||||
{},
|
||||
JSON.stringify(defaultDatalayerData({ pk: 63 }))
|
||||
)
|
||||
assert.ok(map.isDirty)
|
||||
var response = () => {
|
||||
return defaultDatalayerData({ pk: 63 })
|
||||
}
|
||||
var spy = sinon.spy(response)
|
||||
this.server.flush()
|
||||
this.server.respondWith(
|
||||
'POST',
|
||||
'/map/99/update/settings/',
|
||||
JSON.stringify({ id: 99 })
|
||||
)
|
||||
this.server.respondWith('POST', '/map/99/datalayer/update/63/', spy)
|
||||
clickSave()
|
||||
this.server.respond()
|
||||
this.server.respond()
|
||||
assert.ok(spy.calledOnce)
|
||||
fetchMock.post('/map/99/datalayer/update/63/', spy)
|
||||
return new Promise((resolve) => {
|
||||
clickSave()
|
||||
window.setTimeout(() => {
|
||||
assert.ok(spy.calledOnce)
|
||||
resolve()
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('#iconClassChange()', function () {
|
||||
it('should change icon class', function () {
|
||||
happen.click(qs('[data-id="' + this.datalayer._leaflet_id + '"] .layer-edit'))
|
||||
describe('#iconClassChange()', () => {
|
||||
it('should change icon class', () => {
|
||||
happen.click(qs('[data-id="' + datalayer._leaflet_id + '"] .layer-edit'))
|
||||
changeSelectValue(
|
||||
qs('form#datalayer-advanced-properties select[name=iconClass]'),
|
||||
'Circle'
|
||||
|
@ -250,53 +219,53 @@ describe('L.U.DataLayer', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('#show/hide', function () {
|
||||
it('should hide features on hide', function () {
|
||||
describe('#show/hide', () => {
|
||||
it('should hide features on hide', () => {
|
||||
assert.ok(qs('div.umap-div-icon'))
|
||||
assert.ok(qs('path[fill="none"]'))
|
||||
this.datalayer.hide()
|
||||
datalayer.hide()
|
||||
assert.notOk(qs('div.umap-div-icon'))
|
||||
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('path[fill="none"]'))
|
||||
this.datalayer.show()
|
||||
datalayer.show()
|
||||
assert.ok(qs('div.umap-div-icon'))
|
||||
assert.ok(qs('path[fill="none"]'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('#clone()', function () {
|
||||
it('should clone everything but the id and the name', function () {
|
||||
describe('#clone()', () => {
|
||||
it('should clone everything but the id and the name', () => {
|
||||
enableEdit()
|
||||
var clone = this.datalayer.clone()
|
||||
var clone = datalayer.clone()
|
||||
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.equal(clone.options.color, this.datalayer.options.color)
|
||||
assert.equal(clone.options.stroke, this.datalayer.options.stroke)
|
||||
assert.equal(clone.options.color, datalayer.options.color)
|
||||
assert.equal(clone.options.stroke, datalayer.options.stroke)
|
||||
clone._delete()
|
||||
clickSave()
|
||||
})
|
||||
})
|
||||
|
||||
describe('#restore()', function () {
|
||||
describe('#restore()', () => {
|
||||
var oldConfirm,
|
||||
newConfirm = function () {
|
||||
newConfirm = () => {
|
||||
return true
|
||||
}
|
||||
|
||||
before(function () {
|
||||
before(() => {
|
||||
oldConfirm = window.confirm
|
||||
window.confirm = newConfirm
|
||||
})
|
||||
after(function () {
|
||||
after(() => {
|
||||
window.confirm = oldConfirm
|
||||
})
|
||||
|
||||
it('should restore everything', function () {
|
||||
it('should restore everything', (done) => {
|
||||
enableEdit()
|
||||
var geojson = L.Util.CopyJSON(RESPONSES.datalayer62_GET)
|
||||
geojson.features.push({
|
||||
|
@ -309,33 +278,31 @@ describe('L.U.DataLayer', function () {
|
|||
properties: { _umap_options: {}, name: 'new point from restore' },
|
||||
})
|
||||
geojson._umap_options.color = 'Chocolate'
|
||||
this.server.respondWith(
|
||||
'GET',
|
||||
'/datalayer/62/olderversion.geojson',
|
||||
JSON.stringify(geojson)
|
||||
)
|
||||
fetchMock.get('/datalayer/62/olderversion.geojson', geojson)
|
||||
sinon.spy(window, 'confirm')
|
||||
this.datalayer.restore('olderversion.geojson')
|
||||
this.server.respond()
|
||||
assert(window.confirm.calledOnce)
|
||||
window.confirm.restore()
|
||||
assert.equal(this.datalayer.umap_id, 62)
|
||||
assert.ok(this.datalayer.isDirty)
|
||||
assert.equal(this.datalayer._index.length, 4)
|
||||
assert.ok(qs('path[fill="Chocolate"]'))
|
||||
datalayer.restore('olderversion.geojson')
|
||||
window.setTimeout(() => {
|
||||
assert(window.confirm.calledOnce)
|
||||
window.confirm.restore()
|
||||
assert.equal(datalayer.umap_id, 62)
|
||||
assert.ok(datalayer.isDirty)
|
||||
assert.equal(datalayer._index.length, 4)
|
||||
assert.ok(qs('path[fill="Chocolate"]'))
|
||||
done()
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
it('should revert anything on cancel click', function () {
|
||||
it('should revert anything on cancel click', () => {
|
||||
clickCancel()
|
||||
assert.equal(this.datalayer._index.length, 3)
|
||||
assert.equal(datalayer._index.length, 3)
|
||||
assert.notOk(qs('path[fill="Chocolate"]'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('#smart-options()', function () {
|
||||
describe('#smart-options()', () => {
|
||||
let poly, marker
|
||||
before(function () {
|
||||
this.datalayer.eachLayer(function (layer) {
|
||||
before(() => {
|
||||
datalayer.eachLayer(function (layer) {
|
||||
if (!poly && layer instanceof L.Polygon) {
|
||||
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')
|
||||
poly.properties.mycolor = 'DarkGoldenRod'
|
||||
marker.properties.mycolor = 'DarkRed'
|
||||
marker.properties._umap_options.color = undefined
|
||||
assert.notOk(qs('path[fill="DarkGoldenRod"]'))
|
||||
assert.equal(icon.style.backgroundColor, 'olivedrab')
|
||||
this.datalayer.options.color = '{mycolor}'
|
||||
this.datalayer.options.fillColor = '{mycolor}'
|
||||
this.datalayer.indexProperties(poly)
|
||||
this.datalayer.indexProperties(marker)
|
||||
this.datalayer.redraw()
|
||||
datalayer.options.color = '{mycolor}'
|
||||
datalayer.options.fillColor = '{mycolor}'
|
||||
datalayer.indexProperties(poly)
|
||||
datalayer.indexProperties(marker)
|
||||
datalayer.redraw()
|
||||
icon = qs('div.umap-div-icon .icon_container')
|
||||
assert.equal(icon.style.backgroundColor, 'darkred')
|
||||
assert.ok(qs('path[fill="DarkGoldenRod"]'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('#facet-search()', function () {
|
||||
before(function () {
|
||||
this.server.respondWith(
|
||||
/\/datalayer\/63\/\?.*/,
|
||||
JSON.stringify(RESPONSES.datalayer63_GET)
|
||||
)
|
||||
this.map.options.facetKey = 'name'
|
||||
this.map.createDataLayer(RESPONSES.datalayer63_GET._umap_options)
|
||||
this.server.respond()
|
||||
describe('#facet-search()', () => {
|
||||
before(async () => {
|
||||
fetchMock.get(/\/datalayer\/63\/\?.*/, RESPONSES.datalayer63_GET)
|
||||
map.options.facetKey = 'name'
|
||||
await map.initDataLayers([RESPONSES.datalayer63_GET._umap_options])
|
||||
})
|
||||
it('should not impact non browsable layer', function () {
|
||||
it('should not impact non browsable layer', () => {
|
||||
assert.ok(qs('path[fill="SteelBlue"]'))
|
||||
})
|
||||
it('should allow advanced filter', function () {
|
||||
this.map.openFacet()
|
||||
it('should allow advanced filter', () => {
|
||||
map.openFacet()
|
||||
assert.ok(qs('div.umap-facet-search'))
|
||||
// This one if from the normal datalayer
|
||||
// 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"]'))
|
||||
happen.click(qs('input[data-value="name poly"]')) // Undo
|
||||
})
|
||||
it('should allow to control facet label', function () {
|
||||
this.map.options.facetKey = 'name|Nom'
|
||||
this.map.openFacet()
|
||||
it('should allow to control facet label', () => {
|
||||
map.options.facetKey = 'name|Nom'
|
||||
map.openFacet()
|
||||
assert.ok(qs('div.umap-facet-search h5'))
|
||||
assert.equal(qs('div.umap-facet-search h5').textContent, 'Nom')
|
||||
})
|
||||
})
|
||||
describe('#zoomEnd', function () {
|
||||
it('should honour the fromZoom option', function () {
|
||||
this.map.setZoom(6, { animate: false })
|
||||
describe('#zoomEnd', () => {
|
||||
it('should honour the fromZoom option', () => {
|
||||
map.setZoom(6, { animate: false })
|
||||
assert.ok(qs('path[fill="none"]'))
|
||||
this.datalayer.options.fromZoom = 6
|
||||
this.map.setZoom(5, { animate: false })
|
||||
datalayer.options.fromZoom = 6
|
||||
map.setZoom(5, { animate: false })
|
||||
assert.notOk(qs('path[fill="none"]'))
|
||||
this.map.setZoom(6, { animate: false })
|
||||
map.setZoom(6, { animate: false })
|
||||
assert.ok(qs('path[fill="none"]'))
|
||||
})
|
||||
|
||||
it('should honour the toZoom option', function () {
|
||||
this.map.setZoom(6, { animate: false })
|
||||
it('should honour the toZoom option', () => {
|
||||
map.setZoom(6, { animate: false })
|
||||
assert.ok(qs('path[fill="none"]'))
|
||||
this.datalayer.options.toZoom = 6
|
||||
this.map.setZoom(7, { animate: false })
|
||||
datalayer.options.toZoom = 6
|
||||
map.setZoom(7, { animate: false })
|
||||
assert.notOk(qs('path[fill="none"]'))
|
||||
this.map.setZoom(6, { animate: false })
|
||||
map.setZoom(6, { animate: false })
|
||||
assert.ok(qs('path[fill="none"]'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('#displayOnLoad', function () {
|
||||
beforeEach(function () {
|
||||
this.server.respondWith(
|
||||
/\/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 })
|
||||
describe('#displayOnLoad', () => {
|
||||
before(() => {
|
||||
fetchMock.get(/\/datalayer\/64\/\?.*/, RESPONSES.datalayer64_GET)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
this.datalayer._delete()
|
||||
beforeEach(async () => {
|
||||
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"]'))
|
||||
})
|
||||
|
||||
it('should display on click', function () {
|
||||
happen.click(qs(`[data-id='${L.stamp(this.datalayer)}'] .layer-toggle`))
|
||||
assert.ok(qs('path[fill="AliceBlue"]'))
|
||||
it('should display on click', (done) => {
|
||||
happen.click(qs(`[data-id='${L.stamp(datalayer)}'] .layer-toggle`))
|
||||
window.setTimeout(() => {
|
||||
assert.ok(qs('path[fill="AliceBlue"]'))
|
||||
done()
|
||||
}, 500)
|
||||
})
|
||||
|
||||
it('should not display on zoom', function () {
|
||||
this.map.setZoom(9, { animate: false })
|
||||
assert.notOk(qs('path[fill="AliceBlue"]'))
|
||||
it('should not display on zoom', (done) => {
|
||||
map.setZoom(9, { animate: false })
|
||||
window.setTimeout(() => {
|
||||
assert.notOk(qs('path[fill="AliceBlue"]'))
|
||||
done()
|
||||
}, 500)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#delete()', function () {
|
||||
var deleteLink,
|
||||
describe('#delete()', () => {
|
||||
let deleteLink,
|
||||
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()
|
||||
happen.click(
|
||||
qs('#browse_data_toggle_' + L.stamp(this.datalayer) + ' .layer-edit')
|
||||
)
|
||||
happen.click(qs('#browse_data_toggle_' + L.stamp(datalayer) + ' .layer-edit'))
|
||||
deleteLink = qs('button.delete_datalayer_button')
|
||||
assert.ok(deleteLink)
|
||||
})
|
||||
|
||||
it('should delete features on datalayer delete', function () {
|
||||
it('should delete features on datalayer delete', () => {
|
||||
happen.click(deleteLink)
|
||||
assert.notOk(qs('div.icon_container'))
|
||||
})
|
||||
|
||||
it('should have set map dirty', function () {
|
||||
assert.ok(this.map.isDirty)
|
||||
it('should have set map dirty', () => {
|
||||
assert.ok(map.isDirty)
|
||||
})
|
||||
|
||||
it('should delete layer control row on delete', function () {
|
||||
it('should delete layer control row on delete', () => {
|
||||
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 () {
|
||||
assert.equal(this.map.datalayers_index.indexOf(this.datalayer), -1)
|
||||
it('should be removed from map.datalayers_index', () => {
|
||||
assert.equal(map.datalayers_index.indexOf(datalayer), -1)
|
||||
})
|
||||
|
||||
it('should be removed from map.datalayers', function () {
|
||||
assert.notOk(this.map.datalayers[L.stamp(this.datalayer)])
|
||||
it('should be removed from map.datalayers', () => {
|
||||
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()
|
||||
assert.ok(qs('div.icon_container'))
|
||||
})
|
||||
|
|
|
@ -1,21 +1,25 @@
|
|||
describe('L.U.FeatureMixin', function () {
|
||||
before(function () {
|
||||
this.server = sinon.fakeServer.create()
|
||||
this.server.respondWith(
|
||||
let map, datalayer
|
||||
before(async () => {
|
||||
await fetchMock.mock(
|
||||
/\/datalayer\/62\/\?.*/,
|
||||
JSON.stringify(RESPONSES.datalayer62_GET)
|
||||
)
|
||||
this.map = initMap({ umap_id: 99 })
|
||||
this.datalayer = this.map.getDataLayerByUmapId(62)
|
||||
this.server.respond()
|
||||
this.options = {
|
||||
umap_id: 99,
|
||||
}
|
||||
MAP = map = initMap({ umap_id: 99 })
|
||||
const datalayer_options = defaultDatalayerData()
|
||||
await map.initDataLayers([datalayer_options])
|
||||
datalayer = map.getDataLayerByUmapId(62)
|
||||
})
|
||||
after(function () {
|
||||
this.server.restore()
|
||||
fetchMock.restore()
|
||||
resetMap()
|
||||
})
|
||||
|
||||
describe('#edit()', function () {
|
||||
var link
|
||||
let link
|
||||
|
||||
it('should have datalayer features created', function () {
|
||||
assert.equal(
|
||||
|
@ -45,7 +49,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
|
||||
it('should take into account styles changes made in the datalayer', function () {
|
||||
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]')
|
||||
changeInputValue(colorInput, 'DarkRed')
|
||||
|
@ -101,7 +105,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
|
||||
it('should not override already set style on features', function () {
|
||||
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')
|
||||
assert.notOk(qs('path[fill="DarkBlue"]'))
|
||||
|
@ -120,22 +124,22 @@ describe('L.U.FeatureMixin', function () {
|
|||
|
||||
it('should set map.editedFeature on edit', function () {
|
||||
enableEdit()
|
||||
assert.notOk(this.map.editedFeature)
|
||||
assert.notOk(map.editedFeature)
|
||||
happen.click(qs('path[fill="DarkBlue"]'))
|
||||
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
|
||||
assert.ok(this.map.editedFeature)
|
||||
assert.ok(map.editedFeature)
|
||||
disableEdit()
|
||||
})
|
||||
|
||||
it('should reset map.editedFeature on panel open', function (done) {
|
||||
enableEdit()
|
||||
assert.notOk(this.map.editedFeature)
|
||||
assert.notOk(map.editedFeature)
|
||||
happen.click(qs('path[fill="DarkBlue"]'))
|
||||
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
|
||||
assert.ok(this.map.editedFeature)
|
||||
this.map.displayCaption()
|
||||
assert.ok(map.editedFeature)
|
||||
map.displayCaption()
|
||||
window.setTimeout(function () {
|
||||
assert.notOk(this.map.editedFeature)
|
||||
assert.notOk(map.editedFeature)
|
||||
disableEdit()
|
||||
done()
|
||||
}, 1001) // CSS transition time.
|
||||
|
@ -155,7 +159,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
})
|
||||
}
|
||||
it('should generate a valid geojson', function () {
|
||||
setFeatures(this.datalayer)
|
||||
setFeatures(datalayer)
|
||||
assert.ok(poly)
|
||||
assert.deepEqual(poly.toGeoJSON().geometry, {
|
||||
type: 'Polygon',
|
||||
|
@ -176,7 +180,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
})
|
||||
|
||||
it('should remove empty _umap_options from exported geojson', function () {
|
||||
setFeatures(this.datalayer)
|
||||
setFeatures(datalayer)
|
||||
assert.ok(poly)
|
||||
assert.deepEqual(poly.toGeoJSON().properties, { name: 'name poly' })
|
||||
assert.ok(marker)
|
||||
|
@ -190,7 +194,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
describe('#openPopup()', function () {
|
||||
let poly
|
||||
before(function () {
|
||||
this.datalayer.eachLayer(function (layer) {
|
||||
datalayer.eachLayer(function (layer) {
|
||||
if (!poly && layer instanceof L.Polygon) {
|
||||
poly = layer
|
||||
}
|
||||
|
@ -233,8 +237,8 @@ describe('L.U.FeatureMixin', function () {
|
|||
})
|
||||
|
||||
it('should still highlight marker after hide() and show()', function () {
|
||||
this.datalayer.hide()
|
||||
this.datalayer.show()
|
||||
datalayer.hide()
|
||||
datalayer.show()
|
||||
happen.click(qs('div.leaflet-marker-icon'))
|
||||
assert.ok(qs('.umap-icon-active'))
|
||||
})
|
||||
|
@ -254,9 +258,9 @@ describe('L.U.FeatureMixin', function () {
|
|||
|
||||
describe('#tooltip', function () {
|
||||
it('should have a tooltip when active and allow variables', function () {
|
||||
this.map.options.showLabel = true
|
||||
this.map.options.labelKey = 'Foo {name}'
|
||||
this.datalayer.redraw()
|
||||
map.options.showLabel = true
|
||||
map.options.labelKey = 'Foo {name}'
|
||||
datalayer.redraw()
|
||||
assert.equal(
|
||||
qs('.leaflet-tooltip-pane .leaflet-tooltip').textContent,
|
||||
'Foo name poly'
|
||||
|
@ -266,7 +270,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
|
||||
describe('#properties()', function () {
|
||||
it('should rename property', function () {
|
||||
var poly = this.datalayer._lineToLayer({}, [
|
||||
var poly = datalayer._lineToLayer({}, [
|
||||
[0, 0],
|
||||
[0, 1],
|
||||
[0, 2],
|
||||
|
@ -278,7 +282,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
})
|
||||
|
||||
it('should not create property when renaming', function () {
|
||||
var poly = this.datalayer._lineToLayer({}, [
|
||||
var poly = datalayer._lineToLayer({}, [
|
||||
[0, 0],
|
||||
[0, 1],
|
||||
[0, 2],
|
||||
|
@ -289,7 +293,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
})
|
||||
|
||||
it('should delete property', function () {
|
||||
var poly = this.datalayer._lineToLayer({}, [
|
||||
var poly = datalayer._lineToLayer({}, [
|
||||
[0, 0],
|
||||
[0, 1],
|
||||
[0, 2],
|
||||
|
@ -305,7 +309,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
var poly
|
||||
|
||||
it('should filter on properties', function () {
|
||||
poly = this.datalayer._lineToLayer({}, [
|
||||
poly = datalayer._lineToLayer({}, [
|
||||
[0, 0],
|
||||
[0, 1],
|
||||
[0, 2],
|
||||
|
@ -337,7 +341,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
return true
|
||||
}
|
||||
|
||||
this.datalayer.eachLayer(function (layer) {
|
||||
datalayer.eachLayer(function (layer) {
|
||||
if (!poly && layer instanceof L.Polygon) {
|
||||
poly = layer
|
||||
}
|
||||
|
@ -351,7 +355,7 @@ describe('L.U.FeatureMixin', function () {
|
|||
it('should allow to delete from data browser', function () {
|
||||
enableEdit()
|
||||
assert.ok(qs('path[fill="DarkBlue"]'))
|
||||
this.map.openBrowser()
|
||||
map.openBrowser()
|
||||
happen.click(qs('.feature-delete'))
|
||||
assert.notOk(qs('path[fill="DarkBlue"]'))
|
||||
clickCancel()
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
describe('L.U.Map.Export', function () {
|
||||
before(function () {
|
||||
this.server = sinon.fakeServer.create()
|
||||
this.server.respondWith(
|
||||
let map
|
||||
before(async () => {
|
||||
await fetchMock.mock(
|
||||
/\/datalayer\/62\/\?.*/,
|
||||
JSON.stringify(RESPONSES.datalayer62_GET)
|
||||
)
|
||||
this.options = {
|
||||
umap_id: 99,
|
||||
}
|
||||
this.map = initMap({ umap_id: 99 })
|
||||
this.server.respond()
|
||||
this.datalayer = this.map.getDataLayerByUmapId(62)
|
||||
map = initMap({ umap_id: 99 })
|
||||
const datalayer_options = defaultDatalayerData()
|
||||
await map.initDataLayers([datalayer_options])
|
||||
})
|
||||
after(function () {
|
||||
this.server.restore()
|
||||
fetchMock.restore()
|
||||
clickCancel()
|
||||
resetMap()
|
||||
})
|
||||
|
||||
describe('#formatters()', 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(filename, 'name_of_the_map.geojson')
|
||||
assert.deepEqual(JSON.parse(content), {
|
||||
|
@ -86,7 +86,7 @@ describe('L.U.Map.Export', 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(filename, 'name_of_the_map.gpx')
|
||||
const expected =
|
||||
|
@ -95,7 +95,7 @@ describe('L.U.Map.Export', 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(filename, 'name_of_the_map.kml')
|
||||
const expected =
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
describe('L.U.Map.initialize', function () {
|
||||
let map
|
||||
afterEach(function () {
|
||||
resetMap()
|
||||
})
|
||||
|
||||
describe('Controls', function () {
|
||||
describe('Controls', async function () {
|
||||
it('should not show a minimap by default', function () {
|
||||
this.map = initMap()
|
||||
map = initMap()
|
||||
assert.notOk(qs('.leaflet-control-minimap'))
|
||||
})
|
||||
|
||||
it('should show a minimap', function () {
|
||||
this.map = initMap({ miniMap: true })
|
||||
map = initMap({ miniMap: true })
|
||||
assert.ok(qs('.leaflet-control-minimap'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('DefaultView', function () {
|
||||
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
|
||||
window.setTimeout(() => {
|
||||
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) {
|
||||
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
|
||||
window.setTimeout(() => {
|
||||
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) {
|
||||
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
|
||||
window.setTimeout(() => {
|
||||
assert.ok(qs('#map .leaflet-tile-pane img.leaflet-tile.leaflet-tile-loaded'))
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
describe('L.U.Map', function () {
|
||||
before(function () {
|
||||
this.server = sinon.fakeServer.create()
|
||||
this.server.respondWith(
|
||||
describe('L.U.Map', () => {
|
||||
let map, datalayer
|
||||
before(async () => {
|
||||
await fetchMock.mock(
|
||||
/\/datalayer\/62\/\?.*/,
|
||||
JSON.stringify(RESPONSES.datalayer62_GET)
|
||||
)
|
||||
this.options = {
|
||||
umap_id: 99,
|
||||
}
|
||||
this.map = initMap({ umap_id: 99 })
|
||||
this.server.respond()
|
||||
this.datalayer = this.map.getDataLayerByUmapId(62)
|
||||
map = initMap({ umap_id: 99 })
|
||||
const datalayer_options = defaultDatalayerData()
|
||||
await map.initDataLayers([datalayer_options])
|
||||
datalayer = map.getDataLayerByUmapId(62)
|
||||
})
|
||||
after(function () {
|
||||
this.server.restore()
|
||||
after(() => {
|
||||
fetchMock.restore()
|
||||
clickCancel()
|
||||
resetMap()
|
||||
})
|
||||
|
||||
describe('#init()', function () {
|
||||
describe('#init()', () => {
|
||||
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 () {
|
||||
|
@ -42,7 +43,7 @@ describe('L.U.Map', function () {
|
|||
it('should hide icon container div when hiding datalayer', function () {
|
||||
var el = qs(
|
||||
'.leaflet-control-browse #browse_data_toggle_' +
|
||||
L.stamp(this.datalayer) +
|
||||
L.stamp(datalayer) +
|
||||
' .layer-toggle'
|
||||
)
|
||||
happen.click(el)
|
||||
|
@ -56,7 +57,7 @@ describe('L.U.Map', 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'
|
||||
input.value = new_name
|
||||
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 () {
|
||||
assert.ok(this.map.isDirty)
|
||||
assert.ok(map.isDirty)
|
||||
})
|
||||
|
||||
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 () {
|
||||
var path = '/map/99/delete/',
|
||||
let path = '/map/99/update/delete/',
|
||||
oldConfirm,
|
||||
newConfirm = function () {
|
||||
return true
|
||||
|
@ -105,24 +106,22 @@ describe('L.U.Map', function () {
|
|||
window.confirm = oldConfirm
|
||||
})
|
||||
|
||||
it('should ask for confirmation on delete link click', function () {
|
||||
var button = qs('a.update-map-settings')
|
||||
it('should ask for confirmation on delete link click', async function () {
|
||||
let button = qs('a.update-map-settings')
|
||||
assert.ok(button, 'update map info button exists')
|
||||
happen.click(button)
|
||||
var deleteLink = qs('button.umap-delete')
|
||||
let deleteLink = qs('button.umap-delete')
|
||||
assert.ok(deleteLink, 'delete map button exists')
|
||||
sinon.spy(window, 'confirm')
|
||||
this.server.respondWith('POST', path, JSON.stringify({ redirect: '#' }))
|
||||
await fetchMock.post(path, { redirect: '#' })
|
||||
happen.click(deleteLink)
|
||||
this.server.respond()
|
||||
assert(window.confirm.calledOnce)
|
||||
window.confirm.restore()
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
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 () {
|
||||
happen.click(qs('a.upload-data'))
|
||||
|
@ -139,82 +138,82 @@ describe('L.U.Map', function () {
|
|||
})
|
||||
|
||||
it('should import geojson from textarea', function () {
|
||||
this.datalayer.empty()
|
||||
assert.equal(this.datalayer._index.length, 0)
|
||||
datalayer.empty()
|
||||
assert.equal(datalayer._index.length, 0)
|
||||
textarea.value =
|
||||
'{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [6.922931671142578, 47.481161607175736]}, "type": "Feature", "properties": {"color": "", "name": "Chez R\u00e9my", "description": ""}}, {"geometry": {"type": "LineString", "coordinates": [[2.4609375, 48.88639177703194], [2.48291015625, 48.76343113791796], [2.164306640625, 48.719961222646276]]}, "type": "Feature", "properties": {"color": "", "name": "P\u00e9rif", "description": ""}}]}'
|
||||
changeSelectValue(formatSelect, 'geojson')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 2)
|
||||
assert.equal(datalayer._index.length, 2)
|
||||
})
|
||||
|
||||
it('should remove dot in property name', function () {
|
||||
this.datalayer.empty()
|
||||
assert.equal(this.datalayer._index.length, 0)
|
||||
datalayer.empty()
|
||||
assert.equal(datalayer._index.length, 0)
|
||||
textarea.value =
|
||||
'{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [6.922931671142578, 47.481161607175736]}, "type": "Feature", "properties": {"color": "", "name": "Chez R\u00e9my", "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')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 2)
|
||||
assert.ok(this.datalayer._propertiesIndex.includes('A _ in the name'))
|
||||
assert.ok(this.datalayer._propertiesIndex.includes('with a dot_'))
|
||||
assert.equal(datalayer._index.length, 2)
|
||||
assert.ok(datalayer._propertiesIndex.includes('A _ in the name'))
|
||||
assert.ok(datalayer._propertiesIndex.includes('with a dot_'))
|
||||
})
|
||||
|
||||
it('should import osm from textarea', function () {
|
||||
this.datalayer.empty()
|
||||
datalayer.empty()
|
||||
happen.click(qs('a.upload-data'))
|
||||
textarea = qs('.umap-upload textarea')
|
||||
submit = qs('.umap-upload input[type="button"]')
|
||||
formatSelect = qs('.umap-upload select[name="format"]')
|
||||
assert.equal(this.datalayer._index.length, 0)
|
||||
assert.equal(datalayer._index.length, 0)
|
||||
textarea.value =
|
||||
'{"version": 0.6,"generator": "Overpass API 0.7.55.4 3079d8ea","osm3s": {"timestamp_osm_base": "2018-09-22T05:26:02Z","copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."},"elements": [{"type": "node","id": 3619112991,"lat": 48.9352995,"lon": 2.3570684,"tags": {"information": "map","map_size": "city","map_type": "scheme","tourism": "information"}},{"type": "node","id": 3682500756,"lat": 48.9804426,"lon": 2.2719725,"tags": {"information": "map","level": "0","tourism": "information"}}]}'
|
||||
changeSelectValue(formatSelect, 'osm')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 2)
|
||||
assert.equal(datalayer._index.length, 2)
|
||||
assert.equal(
|
||||
this.datalayer._layers[this.datalayer._index[0]].properties.tourism,
|
||||
datalayer._layers[datalayer._index[0]].properties.tourism,
|
||||
'information'
|
||||
)
|
||||
})
|
||||
|
||||
it('should import kml from textarea', function () {
|
||||
this.datalayer.empty()
|
||||
datalayer.empty()
|
||||
happen.click(qs('a.upload-data'))
|
||||
textarea = qs('.umap-upload textarea')
|
||||
submit = qs('.umap-upload input[type="button"]')
|
||||
formatSelect = qs('.umap-upload select[name="format"]')
|
||||
assert.equal(this.datalayer._index.length, 0)
|
||||
assert.equal(datalayer._index.length, 0)
|
||||
textarea.value = kml_example
|
||||
changeSelectValue(formatSelect, 'kml')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 3)
|
||||
assert.equal(datalayer._index.length, 3)
|
||||
})
|
||||
|
||||
it('should import gpx from textarea', function () {
|
||||
this.datalayer.empty()
|
||||
datalayer.empty()
|
||||
happen.click(qs('a.upload-data'))
|
||||
textarea = qs('.umap-upload textarea')
|
||||
submit = qs('.umap-upload input[type="button"]')
|
||||
formatSelect = qs('.umap-upload select[name="format"]')
|
||||
assert.equal(this.datalayer._index.length, 0)
|
||||
assert.equal(datalayer._index.length, 0)
|
||||
textarea.value = gpx_example
|
||||
changeSelectValue(formatSelect, 'gpx')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 2)
|
||||
assert.equal(datalayer._index.length, 2)
|
||||
})
|
||||
|
||||
it('should import csv from textarea', function () {
|
||||
this.datalayer.empty()
|
||||
datalayer.empty()
|
||||
happen.click(qs('a.upload-data'))
|
||||
textarea = qs('.umap-upload textarea')
|
||||
submit = qs('.umap-upload input[type="button"]')
|
||||
formatSelect = qs('.umap-upload select[name="format"]')
|
||||
assert.equal(this.datalayer._index.length, 0)
|
||||
assert.equal(datalayer._index.length, 0)
|
||||
textarea.value = csv_example
|
||||
changeSelectValue(formatSelect, 'csv')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 1)
|
||||
assert.equal(datalayer._index.length, 1)
|
||||
})
|
||||
|
||||
it('should replace content if asked so', function () {
|
||||
|
@ -224,52 +223,52 @@ describe('L.U.Map', function () {
|
|||
formatSelect = qs('.umap-upload select[name="format"]')
|
||||
clearFlag = qs('.umap-upload input[name="clear"]')
|
||||
clearFlag.checked = true
|
||||
assert.equal(this.datalayer._index.length, 1)
|
||||
assert.equal(datalayer._index.length, 1)
|
||||
textarea.value = csv_example
|
||||
changeSelectValue(formatSelect, 'csv')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 1)
|
||||
assert.equal(datalayer._index.length, 1)
|
||||
})
|
||||
|
||||
it('should import GeometryCollection from textarea', function () {
|
||||
this.datalayer.empty()
|
||||
datalayer.empty()
|
||||
textarea.value =
|
||||
'{"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-80.66080570220947,35.04939206472683]},{"type": "Polygon","coordinates": [[[-80.66458225250244,35.04496519190309],[-80.66344499588013,35.04603679820616],[-80.66258668899536,35.045580049697556],[-80.66387414932251,35.044280059194946],[-80.66458225250244,35.04496519190309]]]},{"type": "LineString","coordinates": [[-80.66237211227417,35.05950973022538],[-80.66269397735596,35.0592638296087],[-80.66284418106079,35.05893010615862],[-80.66308021545409,35.05833291342246],[-80.66359519958496,35.057753281001425],[-80.66387414932251,35.05740198662245],[-80.66441059112549,35.05703312589789],[-80.66486120223999,35.056787217822475],[-80.66541910171509,35.05650617911516],[-80.66563367843628,35.05631296444281],[-80.66601991653441,35.055891403570705],[-80.66619157791138,35.05545227534804],[-80.66619157791138,35.05517123204622],[-80.66625595092773,35.05489018777713],[-80.6662130355835,35.054222703761525],[-80.6662130355835,35.05392409072499],[-80.66595554351807,35.05290528508858],[-80.66569805145262,35.052044560077285],[-80.66550493240356,35.0514824490509],[-80.665762424469,35.05048117920187],[-80.66617012023926,35.04972582715769],[-80.66651344299316,35.049286665781096],[-80.66692113876343,35.0485313026898],[-80.66700696945189,35.048215102112344],[-80.66707134246826,35.04777593261294],[-80.66704988479614,35.04738946150025],[-80.66696405410767,35.04698542156371],[-80.66681385040283,35.046353007216055],[-80.66659927368164,35.04596652937105],[-80.66640615463257,35.04561518428889],[-80.6659984588623,35.045193568195565],[-80.66552639007568,35.044877354697526],[-80.6649899482727,35.04454357245502],[-80.66449642181396,35.04417465365292],[-80.66385269165039,35.04387600387859],[-80.66303730010986,35.043717894732545]]}]}'
|
||||
formatSelect = qs('.umap-upload select[name="format"]')
|
||||
changeSelectValue(formatSelect, 'geojson')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 3)
|
||||
assert.equal(datalayer._index.length, 3)
|
||||
})
|
||||
|
||||
it('should import multipolygon', function () {
|
||||
this.datalayer.empty()
|
||||
datalayer.empty()
|
||||
textarea.value =
|
||||
'{"type": "Feature", "properties": { "name": "Some states" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[-109, 36], [-109, 40], [-102, 37], [-109, 36]], [[-108, 39], [-107, 37], [-104, 37], [-108, 39]]], [[[-119, 42], [-120, 39], [-114, 41], [-119, 42]]]] }}'
|
||||
changeSelectValue(formatSelect, 'geojson')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 1)
|
||||
var layer = this.datalayer.getFeatureByIndex(0)
|
||||
assert.equal(datalayer._index.length, 1)
|
||||
var layer = datalayer.getFeatureByIndex(0)
|
||||
assert.equal(layer._latlngs.length, 2) // Two shapes.
|
||||
assert.equal(layer._latlngs[0].length, 2) // Hole.
|
||||
})
|
||||
|
||||
it('should import multipolyline', function () {
|
||||
this.datalayer.empty()
|
||||
datalayer.empty()
|
||||
textarea.value =
|
||||
'{"type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "MultiLineString", "coordinates": [[[-108, 46], [-113, 43]], [[-112, 45], [-115, 44]]] } }]}'
|
||||
changeSelectValue(formatSelect, 'geojson')
|
||||
happen.click(submit)
|
||||
assert.equal(this.datalayer._index.length, 1)
|
||||
var layer = this.datalayer.getFeatureByIndex(0)
|
||||
assert.equal(datalayer._index.length, 1)
|
||||
var layer = datalayer.getFeatureByIndex(0)
|
||||
assert.equal(layer._latlngs.length, 2) // Two shapes.
|
||||
})
|
||||
|
||||
it('should import raw umap data from textarea', function () {
|
||||
//Right now, the import function will try to save and reload. Stop this from happening.
|
||||
var disabledSaveFunction = this.map.save
|
||||
this.map.save = function () {}
|
||||
var disabledSaveFunction = map.save
|
||||
map.save = function () {}
|
||||
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"]')
|
||||
textarea = qs('.umap-upload textarea')
|
||||
textarea.value =
|
||||
|
@ -277,12 +276,12 @@ describe('L.U.Map', function () {
|
|||
formatSelect.value = 'umap'
|
||||
submit = qs('.umap-upload input[type="button"]')
|
||||
happen.click(submit)
|
||||
assert.equal(Object.keys(this.map.datalayers).length, initialLayerCount + 2)
|
||||
assert.equal(this.map.options.name, 'Imported map')
|
||||
assert.equal(Object.keys(map.datalayers).length, initialLayerCount + 2)
|
||||
assert.equal(map.options.name, 'Imported map')
|
||||
var foundFirstLayer = false
|
||||
var foundSecondLayer = false
|
||||
for (var idx in this.map.datalayers) {
|
||||
var datalayer = this.map.datalayers[idx]
|
||||
for (var idx in map.datalayers) {
|
||||
var datalayer = map.datalayers[idx]
|
||||
if (datalayer.options.name === 'Cities') {
|
||||
foundFirstLayer = true
|
||||
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 () {
|
||||
assert.equal(this.map.options.umap_id, 99)
|
||||
assert.equal(map.options.umap_id, 99)
|
||||
})
|
||||
|
||||
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 () {
|
||||
assert.equal(
|
||||
this.map.selected_tilelayer._url,
|
||||
map.selected_tilelayer._url,
|
||||
'http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg'
|
||||
)
|
||||
})
|
||||
|
@ -327,14 +326,14 @@ describe('L.U.Map', function () {
|
|||
describe('#localizeUrl()', function () {
|
||||
it('should replace known variables', function () {
|
||||
assert.equal(
|
||||
this.map.localizeUrl('http://example.org/{zoom}'),
|
||||
'http://example.org/' + this.map.getZoom()
|
||||
map.localizeUrl('http://example.org/{zoom}'),
|
||||
'http://example.org/' + map.getZoom()
|
||||
)
|
||||
})
|
||||
|
||||
it('should keep unknown variables', function () {
|
||||
assert.equal(
|
||||
this.map.localizeUrl('http://example.org/{unkown}'),
|
||||
map.localizeUrl('http://example.org/{unkown}'),
|
||||
'http://example.org/{unkown}'
|
||||
)
|
||||
})
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
describe('L.U.Marker', function () {
|
||||
before(function () {
|
||||
this.server = sinon.fakeServer.create()
|
||||
var datalayer_response = JSON.parse(JSON.stringify(RESPONSES.datalayer62_GET)) // Copy.
|
||||
describe('L.U.Marker', () => {
|
||||
let map, datalayer
|
||||
before(async () => {
|
||||
const datalayer_response = JSON.parse(JSON.stringify(RESPONSES.datalayer62_GET)) // Copy.
|
||||
datalayer_response._umap_options.iconClass = 'Drop'
|
||||
this.server.respondWith(/\/datalayer\/62\/\?.*/, JSON.stringify(datalayer_response))
|
||||
this.map = initMap({ umap_id: 99 })
|
||||
this.datalayer = this.map.getDataLayerByUmapId(62)
|
||||
this.server.respond()
|
||||
await fetchMock.mock(/\/datalayer\/62\/\?.*/, datalayer_response)
|
||||
this.options = {
|
||||
umap_id: 99,
|
||||
}
|
||||
MAP = map = initMap({ umap_id: 99 })
|
||||
const datalayer_options = defaultDatalayerData()
|
||||
await map.initDataLayers([datalayer_options])
|
||||
datalayer = map.getDataLayerByUmapId(62)
|
||||
})
|
||||
after(function () {
|
||||
this.server.restore()
|
||||
after(() => {
|
||||
fetchMock.restore()
|
||||
resetMap()
|
||||
})
|
||||
|
||||
describe('#iconClassChange()', function () {
|
||||
it('should change icon class', function () {
|
||||
describe('#iconClassChange()', () => {
|
||||
it('should change icon class', () => {
|
||||
enableEdit()
|
||||
happen.click(qs('div.umap-drop-icon'))
|
||||
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
|
||||
|
@ -35,8 +39,8 @@ describe('L.U.Marker', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('#iconSymbolChange()', function () {
|
||||
it('should change icon symbol', function () {
|
||||
describe('#iconSymbolChange()', () => {
|
||||
it('should change icon symbol', () => {
|
||||
enableEdit()
|
||||
happen.click(qs('div.umap-drop-icon'))
|
||||
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
|
||||
|
@ -58,8 +62,8 @@ describe('L.U.Marker', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('#iconClassChange()', function () {
|
||||
it('should change icon class', function () {
|
||||
describe('#iconClassChange()', () => {
|
||||
it('should change icon class', () => {
|
||||
enableEdit()
|
||||
happen.click(qs('div.umap-drop-icon'))
|
||||
happen.click(qs('ul.leaflet-inplace-toolbar a.umap-toggle-edit'))
|
||||
|
@ -80,15 +84,15 @@ describe('L.U.Marker', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('#clone', function () {
|
||||
it('should clone marker', function () {
|
||||
var layer = new L.U.Marker(this.map, [10, 20], {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
assert.equal(this.datalayer._index.length, 4)
|
||||
describe('#clone', () => {
|
||||
it('should clone marker', () => {
|
||||
var layer = new L.U.Marker(map, [10, 20], {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
assert.equal(datalayer._index.length, 4)
|
||||
other = layer.clone()
|
||||
assert.ok(this.map.hasLayer(other))
|
||||
assert.equal(this.datalayer._index.length, 5)
|
||||
assert.ok(map.hasLayer(other))
|
||||
assert.equal(datalayer._index.length, 5)
|
||||
// Must not be the same reference
|
||||
assert.notEqual(layer._latlng, other._latlng)
|
||||
assert.equal(L.Util.formatNum(layer._latlng.lat), other._latlng.lat)
|
||||
|
@ -97,20 +101,20 @@ describe('L.U.Marker', function () {
|
|||
})
|
||||
|
||||
describe('#edit()', function (done) {
|
||||
it('should allow changing coordinates manually', function () {
|
||||
var layer = new L.U.Marker(this.map, [10, 20], {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
it('should allow changing coordinates manually', () => {
|
||||
var layer = new L.U.Marker(map, [10, 20], {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
enableEdit()
|
||||
layer.edit()
|
||||
changeInputValue(qs('form.umap-form input[name="lat"]'), '54.43')
|
||||
assert.equal(layer._latlng.lat, 54.43)
|
||||
})
|
||||
|
||||
it('should not allow invalid latitude nor longitude', function () {
|
||||
var layer = new L.U.Marker(this.map, [10, 20], {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
it('should not allow invalid latitude nor longitude', () => {
|
||||
var layer = new L.U.Marker(map, [10, 20], {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
enableEdit()
|
||||
layer.edit()
|
||||
changeInputValue(qs('form.umap-form input[name="lat"]'), '5443')
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
describe('L.U.Polygon', function () {
|
||||
var p2ll, map
|
||||
var p2ll, map, datalayer
|
||||
|
||||
before(function () {
|
||||
this.map = map = initMap({ umap_id: 99 })
|
||||
map = initMap({ umap_id: 99 })
|
||||
enableEdit()
|
||||
p2ll = function (x, y) {
|
||||
return map.containerPointToLatLng([x, y])
|
||||
}
|
||||
this.datalayer = this.map.createDataLayer()
|
||||
this.datalayer.connectToMap()
|
||||
datalayer = map.createDataLayer()
|
||||
datalayer.connectToMap()
|
||||
})
|
||||
|
||||
after(function () {
|
||||
|
@ -17,32 +17,32 @@ describe('L.U.Polygon', function () {
|
|||
})
|
||||
|
||||
afterEach(function () {
|
||||
this.datalayer.empty()
|
||||
datalayer.empty()
|
||||
})
|
||||
|
||||
describe('#isMulti()', function () {
|
||||
it('should return false for basic Polygon', function () {
|
||||
var layer = new L.U.Polygon(
|
||||
this.map,
|
||||
map,
|
||||
[
|
||||
[1, 2],
|
||||
[3, 4],
|
||||
[5, 6],
|
||||
],
|
||||
{ datalayer: this.datalayer }
|
||||
{ datalayer: datalayer }
|
||||
)
|
||||
assert.notOk(layer.isMulti())
|
||||
})
|
||||
|
||||
it('should return false for nested basic Polygon', function () {
|
||||
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
|
||||
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer })
|
||||
layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer })
|
||||
assert.notOk(layer.isMulti())
|
||||
})
|
||||
|
||||
it('should return false for simple Polygon with hole', function () {
|
||||
var layer = new L.U.Polygon(
|
||||
this.map,
|
||||
map,
|
||||
[
|
||||
[
|
||||
[1, 2],
|
||||
|
@ -55,7 +55,7 @@ describe('L.U.Polygon', function () {
|
|||
[11, 12],
|
||||
],
|
||||
],
|
||||
{ datalayer: this.datalayer }
|
||||
{ datalayer: datalayer }
|
||||
)
|
||||
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())
|
||||
})
|
||||
|
||||
|
@ -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())
|
||||
})
|
||||
})
|
||||
|
@ -120,27 +120,27 @@ describe('L.U.Polygon', function () {
|
|||
[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]],
|
||||
[[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]],
|
||||
],
|
||||
layer = new L.U.Polygon(this.map, latlngs, {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
layer = new L.U.Polygon(map, latlngs, {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
happen.once(layer._path, { type: 'contextmenu' })
|
||||
assert.equal(qst('Remove shape from the multi'), 1)
|
||||
})
|
||||
|
||||
it('should not allow to remove shape when not multi', function () {
|
||||
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
|
||||
layer = new L.U.Polygon(this.map, latlngs, {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
layer = new L.U.Polygon(map, latlngs, {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
happen.once(layer._path, { type: 'contextmenu' })
|
||||
assert.notOk(qst('Remove shape from the multi'))
|
||||
})
|
||||
|
||||
it('should not allow to isolate shape when not multi', function () {
|
||||
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]],
|
||||
layer = new L.U.Polygon(this.map, latlngs, {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
layer = new L.U.Polygon(map, latlngs, {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
happen.once(layer._path, { type: 'contextmenu' })
|
||||
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(300, 350), p2ll(350, 400), p2ll(400, 300)]],
|
||||
],
|
||||
layer = new L.U.Polygon(this.map, latlngs, {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
layer = new L.U.Polygon(map, latlngs, {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
happen.once(layer._path, { type: 'contextmenu' })
|
||||
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(300, 350), p2ll(350, 400), p2ll(400, 300)]],
|
||||
],
|
||||
layer = new L.U.Polygon(this.map, latlngs, {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
layer = new L.U.Polygon(map, latlngs, {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
happen.once(layer._path, { type: 'contextmenu' })
|
||||
assert.notOk(qst('Transform to lines'))
|
||||
})
|
||||
|
@ -176,26 +176,26 @@ describe('L.U.Polygon', function () {
|
|||
[p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)],
|
||||
],
|
||||
],
|
||||
layer = new L.U.Polygon(this.map, latlngs, {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
layer = new L.U.Polygon(map, latlngs, {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
happen.once(layer._path, { type: 'contextmenu' })
|
||||
assert.notOk(qst('Transform to lines'))
|
||||
})
|
||||
|
||||
it('should allow to transform to lines when not multi', function () {
|
||||
var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]]
|
||||
new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
|
||||
this.datalayer
|
||||
new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
|
||||
datalayer
|
||||
)
|
||||
happen.at('contextmenu', 150, 150)
|
||||
assert.equal(qst('Transform to lines'), 1)
|
||||
})
|
||||
|
||||
it('should not allow to transfer shape when not editedFeature', function () {
|
||||
new L.U.Polygon(this.map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
new L.U.Polygon(map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
happen.at('contextmenu', 110, 160)
|
||||
assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon.
|
||||
assert.notOk(qst('Transfer shape to edited feature'))
|
||||
|
@ -203,13 +203,13 @@ describe('L.U.Polygon', function () {
|
|||
|
||||
it('should not allow to transfer shape when editedFeature is not a polygon', function () {
|
||||
var layer = new L.U.Polygon(
|
||||
this.map,
|
||||
map,
|
||||
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)],
|
||||
{ datalayer: this.datalayer }
|
||||
).addTo(this.datalayer),
|
||||
other = new L.U.Polyline(this.map, [p2ll(200, 250), p2ll(200, 300)], {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
{ datalayer: datalayer }
|
||||
).addTo(datalayer),
|
||||
other = new L.U.Polyline(map, [p2ll(200, 250), p2ll(200, 300)], {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
other.edit()
|
||||
happen.once(layer._path, { type: 'contextmenu' })
|
||||
assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon.
|
||||
|
@ -217,18 +217,18 @@ describe('L.U.Polygon', function () {
|
|||
})
|
||||
|
||||
it('should allow to transfer shape when another polygon is edited', function () {
|
||||
this.datalayer.empty()
|
||||
datalayer.empty()
|
||||
var layer = new L.U.Polygon(
|
||||
this.map,
|
||||
map,
|
||||
[p2ll(200, 300), p2ll(300, 200), p2ll(200, 100)],
|
||||
{ datalayer: this.datalayer }
|
||||
).addTo(this.datalayer)
|
||||
{ datalayer: datalayer }
|
||||
).addTo(datalayer)
|
||||
layer.edit() // This moves the map to put "other" at the center.
|
||||
var other = new L.U.Polygon(
|
||||
this.map,
|
||||
map,
|
||||
[p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)],
|
||||
{ datalayer: this.datalayer }
|
||||
).addTo(this.datalayer)
|
||||
{ datalayer: datalayer }
|
||||
).addTo(datalayer)
|
||||
happen.once(other._path, { type: 'contextmenu' })
|
||||
assert.equal(qst('Transfer shape to edited feature'), 1)
|
||||
layer.remove()
|
||||
|
@ -242,19 +242,19 @@ describe('L.U.Polygon', function () {
|
|||
})
|
||||
|
||||
it('"add shape" control should be visible when editing a Polygon', function () {
|
||||
var layer = new L.U.Polygon(this.map, [p2ll(100, 100), p2ll(100, 200)], {
|
||||
datalayer: this.datalayer,
|
||||
}).addTo(this.datalayer)
|
||||
var layer = new L.U.Polygon(map, [p2ll(100, 100), p2ll(100, 200)], {
|
||||
datalayer: datalayer,
|
||||
}).addTo(datalayer)
|
||||
layer.edit()
|
||||
assert.ok(qs('.umap-draw-polygon-multi'))
|
||||
})
|
||||
|
||||
it('"add shape" control should extend the same multi', function () {
|
||||
var layer = new L.U.Polygon(
|
||||
this.map,
|
||||
map,
|
||||
[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)],
|
||||
{ datalayer: this.datalayer }
|
||||
).addTo(this.datalayer)
|
||||
{ datalayer: datalayer }
|
||||
).addTo(datalayer)
|
||||
layer.edit()
|
||||
assert.notOk(layer.isMulti())
|
||||
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)
|
||||
assert.ok(layer.isMulti())
|
||||
assert.equal(this.datalayer._index.length, 1)
|
||||
assert.equal(datalayer._index.length, 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#transferShape', function () {
|
||||
it('should transfer simple polygon shape to another polygon', function () {
|
||||
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
|
||||
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
|
||||
this.datalayer
|
||||
layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
|
||||
datalayer
|
||||
),
|
||||
other = new L.U.Polygon(
|
||||
this.map,
|
||||
map,
|
||||
[p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)],
|
||||
{ datalayer: this.datalayer }
|
||||
).addTo(this.datalayer)
|
||||
assert.ok(this.map.hasLayer(layer))
|
||||
{ datalayer: datalayer }
|
||||
).addTo(datalayer)
|
||||
assert.ok(map.hasLayer(layer))
|
||||
layer.transferShape(p2ll(150, 150), other)
|
||||
assert.equal(other._latlngs.length, 2)
|
||||
assert.deepEqual(other._latlngs[1][0], latlngs)
|
||||
assert.notOk(this.map.hasLayer(layer))
|
||||
assert.notOk(map.hasLayer(layer))
|
||||
})
|
||||
|
||||
it('should transfer multipolygon shape to another polygon', function () {
|
||||
|
@ -294,19 +294,19 @@ describe('L.U.Polygon', function () {
|
|||
],
|
||||
[[p2ll(200, 300), p2ll(300, 200)]],
|
||||
],
|
||||
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
|
||||
this.datalayer
|
||||
layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
|
||||
datalayer
|
||||
),
|
||||
other = new L.U.Polygon(
|
||||
this.map,
|
||||
map,
|
||||
[p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)],
|
||||
{ datalayer: this.datalayer }
|
||||
).addTo(this.datalayer)
|
||||
assert.ok(this.map.hasLayer(layer))
|
||||
{ datalayer: datalayer }
|
||||
).addTo(datalayer)
|
||||
assert.ok(map.hasLayer(layer))
|
||||
layer.transferShape(p2ll(150, 150), other)
|
||||
assert.equal(other._latlngs.length, 2)
|
||||
assert.deepEqual(other._latlngs[1][0], latlngs[0][0])
|
||||
assert.ok(this.map.hasLayer(layer))
|
||||
assert.ok(map.hasLayer(layer))
|
||||
assert.equal(layer._latlngs.length, 1)
|
||||
})
|
||||
})
|
||||
|
@ -314,14 +314,14 @@ describe('L.U.Polygon', function () {
|
|||
describe('#isolateShape', function () {
|
||||
it('should not allow to isolate simple polygon', function () {
|
||||
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
|
||||
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
|
||||
this.datalayer
|
||||
layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
|
||||
datalayer
|
||||
)
|
||||
assert.equal(this.datalayer._index.length, 1)
|
||||
assert.ok(this.map.hasLayer(layer))
|
||||
assert.equal(datalayer._index.length, 1)
|
||||
assert.ok(map.hasLayer(layer))
|
||||
layer.isolateShape(p2ll(150, 150))
|
||||
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 () {
|
||||
|
@ -332,17 +332,17 @@ describe('L.U.Polygon', function () {
|
|||
],
|
||||
[[p2ll(200, 300), p2ll(300, 200)]],
|
||||
],
|
||||
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
|
||||
this.datalayer
|
||||
layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
|
||||
datalayer
|
||||
)
|
||||
assert.equal(this.datalayer._index.length, 1)
|
||||
assert.ok(this.map.hasLayer(layer))
|
||||
assert.equal(datalayer._index.length, 1)
|
||||
assert.ok(map.hasLayer(layer))
|
||||
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.deepEqual(other._latlngs[0], latlngs[0][0])
|
||||
assert.ok(this.map.hasLayer(layer))
|
||||
assert.ok(this.map.hasLayer(other))
|
||||
assert.ok(map.hasLayer(layer))
|
||||
assert.ok(map.hasLayer(other))
|
||||
assert.equal(layer._latlngs.length, 1)
|
||||
other.remove()
|
||||
})
|
||||
|
@ -351,13 +351,13 @@ describe('L.U.Polygon', function () {
|
|||
describe('#clone', function () {
|
||||
it('should clone polygon', function () {
|
||||
var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)],
|
||||
layer = new L.U.Polygon(this.map, latlngs, { datalayer: this.datalayer }).addTo(
|
||||
this.datalayer
|
||||
layer = new L.U.Polygon(map, latlngs, { datalayer: datalayer }).addTo(
|
||||
datalayer
|
||||
)
|
||||
assert.equal(this.datalayer._index.length, 1)
|
||||
assert.equal(datalayer._index.length, 1)
|
||||
other = layer.clone()
|
||||
assert.ok(this.map.hasLayer(other))
|
||||
assert.equal(this.datalayer._index.length, 2)
|
||||
assert.ok(map.hasLayer(other))
|
||||
assert.equal(datalayer._index.length, 2)
|
||||
// Must not be the same reference
|
||||
assert.notEqual(layer._latlngs, other._latlngs)
|
||||
assert.equal(L.Util.formatNum(layer._latlngs[0][0].lat), other._latlngs[0][0].lat)
|
||||
|
|
|
@ -1,50 +1,54 @@
|
|||
describe('L.TableEditor', function () {
|
||||
var path = '/map/99/datalayer/edit/62/'
|
||||
describe('L.TableEditor', () => {
|
||||
let path = '/map/99/datalayer/edit/62/',
|
||||
datalayer
|
||||
|
||||
before(function () {
|
||||
this.server = sinon.fakeServer.create()
|
||||
this.server.respondWith(
|
||||
before(async () => {
|
||||
await fetchMock.mock(
|
||||
/\/datalayer\/62\/\?.*/,
|
||||
JSON.stringify(RESPONSES.datalayer62_GET)
|
||||
)
|
||||
this.map = initMap({ umap_id: 99 })
|
||||
this.datalayer = this.map.getDataLayerByUmapId(62)
|
||||
this.server.respond()
|
||||
this.options = {
|
||||
umap_id: 99,
|
||||
}
|
||||
map = initMap({ umap_id: 99 })
|
||||
const datalayer_options = defaultDatalayerData()
|
||||
await map.initDataLayers([datalayer_options])
|
||||
datalayer = map.getDataLayerByUmapId(62)
|
||||
enableEdit()
|
||||
})
|
||||
after(function () {
|
||||
after(() => {
|
||||
fetchMock.restore()
|
||||
clickCancel()
|
||||
this.server.restore()
|
||||
resetMap()
|
||||
})
|
||||
|
||||
describe('#open()', function () {
|
||||
describe('#open()', () => {
|
||||
var button
|
||||
|
||||
it('should exist table click on edit mode', function () {
|
||||
it('should exist table click on edit mode', () => {
|
||||
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
|
||||
})
|
||||
|
||||
it('should open table button click', function () {
|
||||
it('should open table button click', () => {
|
||||
happen.click(button)
|
||||
expect(qs('#umap-ui-container div.table')).to.be.ok
|
||||
expect(qsa('#umap-ui-container div.table form').length).to.eql(3) // One per feature.
|
||||
expect(qsa('#umap-ui-container div.table input').length).to.eql(3) // One per feature and per property.
|
||||
})
|
||||
})
|
||||
describe('#properties()', function () {
|
||||
describe('#properties()', () => {
|
||||
var feature
|
||||
|
||||
before(function () {
|
||||
var firstIndex = this.datalayer._index[0]
|
||||
feature = this.datalayer._layers[firstIndex]
|
||||
before(() => {
|
||||
var firstIndex = datalayer._index[0]
|
||||
feature = datalayer._layers[firstIndex]
|
||||
})
|
||||
|
||||
it('should create new property column', function () {
|
||||
var newPrompt = function () {
|
||||
it('should create new property column', () => {
|
||||
var newPrompt = () => {
|
||||
return 'newprop'
|
||||
}
|
||||
var oldPrompt = window.prompt
|
||||
|
@ -56,7 +60,7 @@ describe('L.TableEditor', function () {
|
|||
window.prompt = oldPrompt
|
||||
})
|
||||
|
||||
it('should populate feature property on fill', function () {
|
||||
it('should populate feature property on fill', () => {
|
||||
var input = qs(
|
||||
'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')
|
||||
})
|
||||
|
||||
it('should update property name on update click', function () {
|
||||
var newPrompt = function () {
|
||||
it('should update property name on update click', () => {
|
||||
var newPrompt = () => {
|
||||
return 'newname'
|
||||
}
|
||||
var oldPrompt = window.prompt
|
||||
|
@ -79,9 +83,9 @@ describe('L.TableEditor', function () {
|
|||
window.prompt = oldPrompt
|
||||
})
|
||||
|
||||
it('should update property on delete click', function () {
|
||||
it('should update property on delete click', () => {
|
||||
var oldConfirm,
|
||||
newConfirm = function () {
|
||||
newConfirm = () => {
|
||||
return true
|
||||
}
|
||||
oldConfirm = window.confirm
|
||||
|
|
|
@ -213,7 +213,6 @@ function initMap(options) {
|
|||
},
|
||||
},
|
||||
}
|
||||
default_options.properties.datalayers.push(defaultDatalayerData())
|
||||
options = options || {}
|
||||
options.properties = L.extend({}, default_options.properties, options)
|
||||
options.geometry = {
|
||||
|
@ -386,10 +385,6 @@ var RESPONSES = {
|
|||
},
|
||||
}
|
||||
|
||||
sinon.fakeServer.flush = function () {
|
||||
this.responses = []
|
||||
}
|
||||
|
||||
var kml_example =
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' +
|
||||
'<kml xmlns="http://www.opengis.net/kml/2.2">' +
|
||||
|
|
|
@ -75,6 +75,10 @@
|
|||
<script src="../../../../node_modules/chai/chai.js"></script>
|
||||
<script src="../../../../node_modules/happen/happen.js"></script>
|
||||
<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">
|
||||
mocha.setup({
|
||||
ui: 'bdd',
|
||||
|
|
Loading…
Reference in a new issue