Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unsolvable validator error for presets with locationSet #10459

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions modules/presets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
6 changes: 5 additions & 1 deletion modules/validations/mismatched_geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/spec/validations/mismatched_geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
});
});
Loading