also check preset aliases in suspicious names validation

see #9522
This commit is contained in:
Martin Raifer
2025-03-17 13:31:26 +01:00
parent 74dc459a4a
commit 58cb5a0b80
3 changed files with 43 additions and 30 deletions

View File

@@ -34,7 +34,7 @@ describe('iD.validations.suspicious_name', function () {
genericWords: ['^stores?$']
};
iD.fileFetcher.cache().preset_presets = {
'Velero': { tags: { craft: 'sailmaker' }, geometry: ['line'] },
'Velero': { tags: { craft: 'sailmaker' }, aliases: ['Velaio'], geometry: ['line'] },
'Constructor de barco': { tags: { craft: 'boatbuilder' }, geometry: ['line'] },
};
});
@@ -71,57 +71,57 @@ describe('iD.validations.suspicious_name', function () {
return issues;
}
it('has no errors on init', async () => {
it('has no errors on init', () => {
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
});
it('ignores way with no tags', async () => {
it('ignores way with no tags', () => {
createWay({});
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
});
it('ignores feature with no name', async () => {
it('ignores feature with no name', () => {
createWay({ shop: 'supermarket' });
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
});
it('ignores feature with a specific name', async () => {
it('ignores feature with a specific name', () => {
createWay({ shop: 'supermarket', name: 'Lou\'s' });
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
});
it('ignores feature with a specific name that includes a generic name', async () => {
it('ignores feature with a specific name that includes a generic name', () => {
createWay({ shop: 'supermarket', name: 'Lou\'s Store' });
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
});
it('ignores feature matching excludeNamed pattern in name-suggestion-index', async () => {
it('ignores feature matching excludeNamed pattern in name-suggestion-index', () => {
createWay({ shop: 'supermarket', name: 'famiglia cooperativa' });
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
});
it('flags feature matching a excludeGeneric pattern in name-suggestion-index', async () => {
it('flags feature matching a excludeGeneric pattern in name-suggestion-index', () => {
createWay({ shop: 'supermarket', name: 'super mercado' });
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
@@ -131,10 +131,10 @@ describe('iD.validations.suspicious_name', function () {
expect(issue.entityIds[0]).to.eql('w-1');
});
it('flags feature matching a global exclude pattern in name-suggestion-index', async () => {
it('flags feature matching a global exclude pattern in name-suggestion-index', () => {
createWay({ shop: 'supermarket', name: 'store' });
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
@@ -144,10 +144,10 @@ describe('iD.validations.suspicious_name', function () {
expect(issue.entityIds[0]).to.eql('w-1');
});
it('flags feature with a name that is just a defining tag key', async () => {
it('flags feature with a name that is just a defining tag key', () => {
createWay({ amenity: 'drinking_water', name: 'Amenity' });
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
@@ -157,10 +157,10 @@ describe('iD.validations.suspicious_name', function () {
expect(issue.entityIds[0]).to.eql('w-1');
});
it('flags feature with a name that is just a defining tag value', async () => {
it('flags feature with a name that is just a defining tag value', () => {
createWay({ shop: 'red_bicycle_emporium', name: 'Red Bicycle Emporium' });
var validator = iD.validationSuspiciousName(context);
await setTimeout(20);
var issues = validate(validator);
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
@@ -181,6 +181,17 @@ describe('iD.validations.suspicious_name', function () {
expect(issues[0].hash).to.eql('name:ca=Velero');
});
it('flags feature with a name that matches a preset alias', async () => {
await iD.presetManager.ensureLoaded(true);
createWay({ craft: 'sailmaker', 'name:it': 'Velaio' });
const validator = iD.validationSuspiciousName(context);
const issues = validate(validator);
expect(issues).to.have.lengthOf(1);
expect(issues[0].type).to.eql('suspicious_name');
expect(issues[0].hash).to.eql('name:it=Velaio');
});
it('flags feature with a name that matches the preset name and tag name', async () => {
await iD.presetManager.ensureLoaded(true);
createWay({ craft: 'boatbuilder', 'name:mi': 'boatbuilder', name: 'cOnStRuCtOr de barco' });