separate tag-upgrade warnings from NSI suggestions (#10801)

This commit is contained in:
Kyℓe Hensel
2025-03-05 22:42:40 +11:00
committed by GitHub
parent 7beace6698
commit a41e8c48d2
4 changed files with 207 additions and 77 deletions
+119
View File
@@ -5,13 +5,29 @@ describe('iD.validations.outdated_tags', function () {
before(function() {
iD.fileFetcher.cache().deprecated = [
{ old: { building: 'roof' }, replace: { building: 'roof', layer: '1' } },
{ old: { highway: 'no' } },
{ old: { highway: 'ford' }, replace: { ford: '*' } }
];
iD.services.nsi = {
status: () => 'ok',
upgradeTags: (tags) => {
// mock implementation of NSI: All it does it suggest
// adding `brand:wikidata` if there's a matching `brand`.
const NSI = { 'Fish Bowl': 'Q110785465' };
if (tags.brand && NSI[tags.brand] && tags['brand:wikidata'] !== NSI[tags.brand]) {
return {
matched: {},
newTags: { ...tags, 'brand:wikidata': NSI[tags.brand] }
};
}
},
};
});
after(function() {
iD.fileFetcher.cache().deprecated = [];
delete iD.services.nsi;
});
beforeEach(function() {
@@ -115,4 +131,107 @@ describe('iD.validations.outdated_tags', function () {
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
});
it('flags suggestions from NSI', async () => {
createWay({ amenity: 'fast_food', brand: 'Fish Bowl' });
const validator = iD.validationOutdatedTags(context);
await setTimeout(20);
const issues = validate(validator);
expect(issues).toHaveLength(1);
expect(issues[0]).toMatchObject({
type: 'outdated_tags',
subtype: 'noncanonical_brand',
severity: 'warning',
entityIds: ['w-1'],
});
// click on "Upgrade Tags"
issues[0].dynamicFixes()[0].onClick(context);
expect(context.graph().entity('w-1').tags).toStrictEqual({
amenity: 'fast_food',
brand: 'Fish Bowl',
'brand:wikidata': 'Q110785465', // added
});
});
it('generates 2 separate issues for deprecated tags and NSI suggestions', async () => {
createWay({ highway: 'ford', amenity: 'fast_food', brand: 'Fish Bowl' });
const validator = iD.validationOutdatedTags(context);
await setTimeout(20);
const issues = validate(validator);
expect(issues).toHaveLength(2);
expect(issues[0]).toMatchObject({
type: 'outdated_tags',
subtype: 'deprecated_tags',
severity: 'warning',
entityIds: ['w-1'],
});
expect(issues[1]).toMatchObject({
type: 'outdated_tags',
subtype: 'noncanonical_brand',
severity: 'warning',
entityIds: ['w-1'],
});
// click on "Upgrade Tags" (to fix the deprecated issue)
issues[0].dynamicFixes()[0].onClick(context);
expect(context.graph().entity('w-1').tags).toStrictEqual({
amenity: 'fast_food',
brand: 'Fish Bowl',
// brand:wikidata not added yet
ford: 'yes' // tag upgraded
});
// click on "Upgrade Tags" (to fix the NSI suggestion)
issues[1].dynamicFixes()[0].onClick(context);
expect(context.graph().entity('w-1').tags).toStrictEqual({
amenity: 'fast_food',
brand: 'Fish Bowl',
'brand:wikidata': 'Q110785465', // added
ford: 'yes' // tag already added
});
});
it('generates 2 separate issues for incomplete tags and NSI suggestions', async () => {
createWay({ building: 'roof', amenity: 'fast_food', brand: 'Fish Bowl' });
const validator = iD.validationOutdatedTags(context);
await setTimeout(20);
const issues = validate(validator);
expect(issues).toHaveLength(2);
expect(issues[0]).toMatchObject({
type: 'outdated_tags',
subtype: 'incomplete_tags',
severity: 'warning',
entityIds: ['w-1'],
});
expect(issues[1]).toMatchObject({
type: 'outdated_tags',
subtype: 'noncanonical_brand',
severity: 'warning',
entityIds: ['w-1'],
});
// click on "Upgrade Tags" (to fix the incomplete_tags issue)
issues[0].dynamicFixes()[0].onClick(context);
expect(context.graph().entity('w-1').tags).toStrictEqual({
amenity: 'fast_food',
brand: 'Fish Bowl',
// brand:wikidata not added yet
building: 'roof',
layer: '1', // tag added
});
// click on "Upgrade Tags" (to fix the NSI suggestion)
issues[1].dynamicFixes()[0].onClick(context);
expect(context.graph().entity('w-1').tags).toStrictEqual({
amenity: 'fast_food',
brand: 'Fish Bowl',
'brand:wikidata': 'Q110785465', // added
building: 'roof',
layer: '1', // tag already added
});
});
});