chore: move table editor tests to PW

This commit is contained in:
Yohan Boniface 2024-03-27 14:10:17 +01:00
parent ca8f7bf280
commit e0ff82298a
3 changed files with 27 additions and 105 deletions

View file

@ -1,104 +0,0 @@
describe('L.TableEditor', () => {
let path = '/map/99/datalayer/edit/62/',
datalayer
before(async () => {
await fetchMock.mock(
/\/datalayer\/62\/\?.*/,
JSON.stringify(RESPONSES.datalayer62_GET)
)
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(() => {
fetchMock.restore()
clickCancel()
resetMap()
})
describe('#open()', () => {
var button
it('should exist table click on edit mode', () => {
button = qs(
'#browse_data_toggle_' + L.stamp(datalayer) + ' .layer-table-edit'
)
expect(button).to.be.ok
})
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()', () => {
var feature
before(() => {
var firstIndex = datalayer._index[0]
feature = datalayer._layers[firstIndex]
})
it('should create new property column', () => {
var newPrompt = () => {
return 'newprop'
}
var oldPrompt = window.prompt
window.prompt = newPrompt
var button = qs('#umap-ui-container .add-property')
expect(button).to.be.ok
happen.click(button)
expect(qsa('#umap-ui-container div.table input').length).to.eql(6) // One per feature and per property.
window.prompt = oldPrompt
})
it('should populate feature property on fill', () => {
var input = qs(
'form#umap-feature-properties_' + L.stamp(feature) + ' input[name=newprop]'
)
changeInputValue(input, 'the value')
expect(feature.properties.newprop).to.eql('the value')
})
it('should update property name on update click', () => {
var newPrompt = () => {
return 'newname'
}
var oldPrompt = window.prompt
window.prompt = newPrompt
var button = qs('#umap-ui-container div.thead div.tcell:last-of-type .umap-edit')
expect(button).to.be.ok
happen.click(button)
expect(qsa('#umap-ui-container div.table input').length).to.eql(6)
expect(feature.properties.newprop).to.be.undefined
expect(feature.properties.newname).to.eql('the value')
window.prompt = oldPrompt
})
it('should update property on delete click', () => {
var oldConfirm,
newConfirm = () => {
return true
}
oldConfirm = window.confirm
window.confirm = newConfirm
var button = qs(
'#umap-ui-container div.thead div.tcell:last-of-type .umap-delete'
)
expect(button).to.be.ok
happen.click(button)
FEATURE = feature
expect(qsa('#umap-ui-container div.table input').length).to.eql(3)
expect(feature.properties.newname).to.be.undefined
window.confirm = oldConfirm
})
})
})

View file

@ -89,7 +89,6 @@
</script>
<script src="./_pre.js" defer></script>
<script src="./Map.js" defer></script>
<script src="./TableEditor.js" defer></script>
<script src="./Feature.js" defer></script>
<script src="./Marker.js" defer></script>
<script src="./Polyline.js" defer></script>

View file

@ -0,0 +1,27 @@
import json
import re
from pathlib import Path
from playwright.sync_api import expect
from umap.models import DataLayer
def test_table_editor(live_server, openmap, datalayer, page):
page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit")
page.get_by_role("link", name="Manage layers").click()
page.locator("#umap-ui-container").get_by_title(
"Edit properties in a table"
).click()
page.once("dialog", lambda dialog: dialog.accept(prompt_text="newprop"))
page.get_by_text("Add a new property").click()
page.locator('input[name="newprop"]').fill("newvalue")
page.once("dialog", lambda dialog: dialog.accept())
page.hover(".umap-table-editor .tcell")
page.get_by_title("Delete this property on all").first.click()
with page.expect_response(re.compile(r".*/datalayer/update/.*")):
page.get_by_role("button", name="Save").click()
saved = DataLayer.objects.last()
data = json.loads(Path(saved.geojson.path).read_text())
assert data["features"][0]["properties"]["newprop"] == "newvalue"
assert "name" not in data["features"][0]["properties"]