mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-26 01:47:49 +02:00
move deprecatedTags logic out of osmEntity and into a helper function (#10842)
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import {
|
||||
deprecatedTagValuesByKey,
|
||||
getDeprecatedTags,
|
||||
type DataDeprecated,
|
||||
} from '../../../modules/osm/deprecated';
|
||||
|
||||
var deprecated: DataDeprecated = [
|
||||
{ old: { highway: 'no' } },
|
||||
{ old: { amenity: 'toilet' }, replace: { amenity: 'toilets' } },
|
||||
{ old: { speedlimit: '*' }, replace: { maxspeed: '$1' } },
|
||||
{
|
||||
old: { man_made: 'water_tank' },
|
||||
replace: { man_made: 'storage_tank', content: 'water' },
|
||||
},
|
||||
{
|
||||
old: { amenity: 'gambling', gambling: 'casino' },
|
||||
replace: { amenity: 'casino' },
|
||||
},
|
||||
];
|
||||
|
||||
describe('getDeprecatedTags', () => {
|
||||
it('returns none if entity has no tags', () => {
|
||||
expect(getDeprecatedTags({}, deprecated)).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it('returns none when no tags are deprecated', () => {
|
||||
expect(getDeprecatedTags({ amenity: 'toilets' }, deprecated)).toStrictEqual(
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
it('returns 1:0 replacement', () => {
|
||||
expect(getDeprecatedTags({ highway: 'no' }, deprecated)).toStrictEqual([
|
||||
{ old: { highway: 'no' } },
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns 1:1 replacement', () => {
|
||||
expect(getDeprecatedTags({ amenity: 'toilet' }, deprecated)).toStrictEqual([
|
||||
{ old: { amenity: 'toilet' }, replace: { amenity: 'toilets' } },
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns 1:1 wildcard', () => {
|
||||
expect(getDeprecatedTags({ speedlimit: '50' }, deprecated)).toStrictEqual([
|
||||
{ old: { speedlimit: '*' }, replace: { maxspeed: '$1' } },
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns 1:2 total replacement', () => {
|
||||
expect(
|
||||
getDeprecatedTags({ man_made: 'water_tank' }, deprecated),
|
||||
).toStrictEqual([
|
||||
{
|
||||
old: { man_made: 'water_tank' },
|
||||
replace: { man_made: 'storage_tank', content: 'water' },
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns 1:2 partial replacement', () => {
|
||||
expect(
|
||||
getDeprecatedTags(
|
||||
{ man_made: 'water_tank', content: 'water' },
|
||||
deprecated,
|
||||
),
|
||||
).toStrictEqual([
|
||||
{
|
||||
old: { man_made: 'water_tank' },
|
||||
replace: { man_made: 'storage_tank', content: 'water' },
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns 2:1 replacement', () => {
|
||||
expect(
|
||||
getDeprecatedTags(
|
||||
{ amenity: 'gambling', gambling: 'casino' },
|
||||
deprecated,
|
||||
),
|
||||
).toStrictEqual([
|
||||
{
|
||||
old: { amenity: 'gambling', gambling: 'casino' },
|
||||
replace: { amenity: 'casino' },
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deprecatedTagValuesByKey', () => {
|
||||
it('groups simple deprecations by key', () => {
|
||||
expect(deprecatedTagValuesByKey(deprecated)).toStrictEqual({
|
||||
amenity: ['toilet'], // `gambling` not included
|
||||
highway: ['no'],
|
||||
man_made: ['water_tank'],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -226,60 +226,6 @@ describe('iD.osmEntity', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#deprecatedTags', function () {
|
||||
var deprecated = [
|
||||
{ old: { highway: 'no' } },
|
||||
{ old: { amenity: 'toilet' }, replace: { amenity: 'toilets' } },
|
||||
{ old: { speedlimit: '*' }, replace: { maxspeed: '$1' } },
|
||||
{ old: { man_made: 'water_tank' }, replace: { man_made: 'storage_tank', content: 'water' } },
|
||||
{ old: { amenity: 'gambling', gambling: 'casino' }, replace: { amenity: 'casino' } }
|
||||
];
|
||||
|
||||
it('returns none if entity has no tags', function () {
|
||||
expect(iD.osmEntity().deprecatedTags(deprecated)).to.eql([]);
|
||||
});
|
||||
|
||||
it('returns none when no tags are deprecated', function () {
|
||||
expect(iD.osmEntity({ tags: { amenity: 'toilets' } }).deprecatedTags(deprecated)).to.eql([]);
|
||||
});
|
||||
|
||||
it('returns 1:0 replacement', function () {
|
||||
expect(iD.osmEntity({ tags: { highway: 'no' } }).deprecatedTags(deprecated)).to.eql(
|
||||
[{ old: { highway: 'no' } }]
|
||||
);
|
||||
});
|
||||
|
||||
it('returns 1:1 replacement', function () {
|
||||
expect(iD.osmEntity({ tags: { amenity: 'toilet' } }).deprecatedTags(deprecated)).to.eql(
|
||||
[{ old: { amenity: 'toilet' }, replace: { amenity: 'toilets' } }]
|
||||
);
|
||||
});
|
||||
|
||||
it('returns 1:1 wildcard', function () {
|
||||
expect(iD.osmEntity({ tags: { speedlimit: '50' } }).deprecatedTags(deprecated)).to.eql(
|
||||
[{ old: { speedlimit: '*' }, replace: { maxspeed: '$1' } }]
|
||||
);
|
||||
});
|
||||
|
||||
it('returns 1:2 total replacement', function () {
|
||||
expect(iD.osmEntity({ tags: { man_made: 'water_tank' } }).deprecatedTags(deprecated)).to.eql(
|
||||
[{ old: { man_made: 'water_tank' }, replace: { man_made: 'storage_tank', content: 'water' } }]
|
||||
);
|
||||
});
|
||||
|
||||
it('returns 1:2 partial replacement', function () {
|
||||
expect(iD.osmEntity({ tags: { man_made: 'water_tank', content: 'water' } }).deprecatedTags(deprecated)).to.eql(
|
||||
[{ old: { man_made: 'water_tank' }, replace: { man_made: 'storage_tank', content: 'water' } }]
|
||||
);
|
||||
});
|
||||
|
||||
it('returns 2:1 replacement', function () {
|
||||
expect(iD.osmEntity({ tags: { amenity: 'gambling', gambling: 'casino' } }).deprecatedTags(deprecated)).to.eql(
|
||||
[{ old: { amenity: 'gambling', gambling: 'casino' }, replace: { amenity: 'casino' } }]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#hasInterestingTags', function () {
|
||||
it('returns false if the entity has no tags', function () {
|
||||
expect(iD.osmEntity().hasInterestingTags()).to.equal(false);
|
||||
|
||||
Reference in New Issue
Block a user