Skip to content

Commit

Permalink
Merge remote-tracking branch 'k-yle/kh/mismatched-geom-error' into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
tyrasd committed Nov 13, 2024
2 parents fd967bf + c3c0e23 commit 93c8e3d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
#### :camera: Street-Level
#### :white_check_mark: Validation
#### :bug: Bugfixes
* Fix unsolvable validator error triggered by regional presets ([#10459])
#### :earth_asia: Localization
* Update Sinitic languages in the Multilingual Names field ([#10488], thanks [@winstonsung])
* Update the list of languages in the Wikipedia field ([#10489])
Expand All @@ -54,6 +55,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
* Migrate unit tests from karma to vitest ([#10452])

[#10452]: https://github.com/openstreetmap/iD/pull/10452
[#10459]: https://github.com/openstreetmap/iD/pull/10459
[#10488]: https://github.com/openstreetmap/iD/pull/10488
[#10489]: https://github.com/openstreetmap/iD/pull/10489
[@winstonsung]: https://github.com/winstonsung/
Expand Down
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);
});
});

0 comments on commit 93c8e3d

Please sign in to comment.