fix unsolvable validator error for presets with locationSet

This commit is contained in:
Kyle Hensel
2024-09-09 20:57:26 +10:00
parent 0ce8136279
commit c3c0e23ba8
3 changed files with 26 additions and 3 deletions

View File

@@ -56,8 +56,9 @@ export function presetIndex() {
let _loadPromise;
_this.ensureLoaded = () => {
if (_loadPromise) return _loadPromise;
/** @param {boolean=} bypassCache - used by unit tests */
_this.ensureLoaded = (bypassCache) => {
if (_loadPromise && !bypassCache) return _loadPromise;
return _loadPromise = Promise.all([
fileFetcher.get('preset_categories'),

View File

@@ -244,7 +244,11 @@ export function validationMismatchedGeometry() {
var asSource = presetManager.match(entity, graph);
var targetGeom = targetGeoms.find(nodeGeom => {
var asTarget = presetManager.matchTags(entity.tags, nodeGeom);
const asTarget = presetManager.matchTags(
entity.tags,
nodeGeom,
entity.extent(graph).center(),
);
if (!asSource || !asTarget ||
asSource === asTarget ||
// sometimes there are two presets with the same tags for different geometries

View File

@@ -4,6 +4,17 @@ describe('iD.validations.mismatched_geometry', function () {
beforeEach(function() {
_savedAreaKeys = iD.osmAreaKeys;
context = iD.coreContext().init();
iD.fileFetcher.cache().preset_presets = {
library: {
tags: { amenity: 'library' },
geometry: ['point', 'vertex', 'line', 'area'],
locationSet: { include: ['NU'] }
},
generic_amenity: {
tags: { amenity: '*' },
geometry: ['point', 'vertex', 'line', 'area']
},
};
});
afterEach(function() {
@@ -112,4 +123,11 @@ describe('iD.validations.mismatched_geometry', function () {
expect(issue.entityIds[0]).to.eql('w-1');
});
it('does not error if the best preset is limited to certain regions', async () => {
await iD.presetManager.ensureLoaded(true);
createClosedWay({ amenity: 'library' });
const issues = validate();
expect(issues).to.have.lengthOf(0);
});
});