From 3f1f85a1e93254cc0f5e74ae3145c823cdc2bb22 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 6 Feb 2020 16:10:55 -0500 Subject: [PATCH] Restore some odd but necessary workarounds to the presetCollection test --- test/spec/presets/collection.js | 153 +++++++++++++------------------- 1 file changed, 61 insertions(+), 92 deletions(-) diff --git a/test/spec/presets/collection.js b/test/spec/presets/collection.js index 249fde827..298a37e69 100644 --- a/test/spec/presets/collection.js +++ b/test/spec/presets/collection.js @@ -1,75 +1,44 @@ describe('iD.presetCollection', function() { + // Note: __TEST is added to these because the search uses localized + // preset.name() keyed on id, which would use the names from en.json. + // Except for fallback presets which must have those names because of the logic in fallback() var p = { - point: iD.presetPreset('point', { - name: 'Point', - tags: {}, - geometry: ['point'] - }), - line: iD.presetPreset('line', { - name: 'Line', - tags: {}, - geometry: ['line'] - }), - area: iD.presetPreset('area', { - name: 'Area', - tags: {}, - geometry: ['area'] - }), - grill: iD.presetPreset('amenity/bbq', { - name: 'Grill', - tags: { amenity: 'bbq' }, - geometry: ['point'], - terms: [] - }), - sandpit: iD.presetPreset('amenity/grit_bin', { - name: 'Sandpit', - tags: { amenity: 'grit_bin' }, - geometry: ['point'], - terms: [] - }), - residential: iD.presetPreset('highway/residential', { - name: 'Residential Area', - tags: { highway: 'residential' }, - geometry: ['point', 'area'], - terms: [] - }), - grass1: iD.presetPreset('landuse/grass1', { - name: 'Grass', - tags: { landuse: 'grass' }, - geometry: ['point', 'area'], - terms: [] - }), - grass2: iD.presetPreset('landuse/grass2', { - name: 'Ğṝȁß', - tags: { landuse: 'ğṝȁß' }, - geometry: ['point', 'area'], - terms: [] - }), - park: iD.presetPreset('leisure/park', { - name: 'Park', - tags: { leisure: 'park' }, - geometry: ['point', 'area'], - terms: [ 'grass' ], - matchScore: 0.5 - }), - parking: iD.presetPreset('amenity/parking', { - name: 'Parking', - tags: { amenity: 'parking' }, - geometry: ['point', 'area'], - terms: [ 'cars' ] - }), - soccer: iD.presetPreset('leisure/pitch/soccer', { - name: 'Soccer Field', - tags: { leisure: 'pitch', sport: 'soccer' }, - geometry: ['point', 'area'], - terms: ['fußball'] - }), - football: iD.presetPreset('leisure/pitch/american_football', { - name: 'Football Field', - tags: { leisure: 'pitch', sport: 'american_football' }, - geometry: ['point', 'area'], - terms: ['gridiron'] - }) + point: iD.presetPreset('point', + { name: 'Point', tags: {}, geometry: ['point'], matchScore: 0.1 } + ), + line: iD.presetPreset('line', + { name: 'Line', tags: {}, geometry: ['line'], matchScore: 0.1 } + ), + area: iD.presetPreset('area', + { name: 'Area', tags: { area: 'yes' }, geometry: ['area'], matchScore: 0.1 } + ), + grill: iD.presetPreset('__TEST/amenity/bbq', + { name: 'Grill', tags: { amenity: 'bbq' }, geometry: ['point'], terms: [] } + ), + sandpit: iD.presetPreset('__TEST/amenity/grit_bin', + { name: 'Sandpit', tags: { amenity: 'grit_bin' }, geometry: ['point'], terms: [] } + ), + residential: iD.presetPreset('__TEST/highway/residential', + { name: 'Residential Area', tags: { highway: 'residential' }, geometry: ['point', 'area'], terms: [] } + ), + grass1: iD.presetPreset('__TEST/landuse/grass1', + { name: 'Grass', tags: { landuse: 'grass' }, geometry: ['point', 'area'], terms: [] } + ), + grass2: iD.presetPreset('__TEST/landuse/grass2', + { name: 'Ğṝȁß', tags: { landuse: 'ğṝȁß' }, geometry: ['point', 'area'], terms: [] } + ), + park: iD.presetPreset('__TEST/leisure/park', + { name: 'Park', tags: { leisure: 'park' }, geometry: ['point', 'area'], terms: [ 'grass' ], matchScore: 0.5 } + ), + parking: iD.presetPreset('__TEST/amenity/parking', + { name: 'Parking', tags: { amenity: 'parking' }, geometry: ['point', 'area'], terms: [ 'cars' ] } + ), + soccer: iD.presetPreset('__TEST/leisure/pitch/soccer', + { name: 'Soccer Field', tags: { leisure: 'pitch', sport: 'soccer' }, geometry: ['point', 'area'], terms: ['fußball'] } + ), + football: iD.presetPreset('__TEST/leisure/pitch/american_football', + { name: 'Football Field', tags: { leisure: 'pitch', sport: 'american_football' }, geometry: ['point', 'area'], terms: ['gridiron'] } + ) }; @@ -80,7 +49,7 @@ describe('iD.presetCollection', function() { describe('#item', function() { it('fetches a preset by id', function() { - expect(c.item('highway/residential')).to.equal(p.residential); + expect(c.item('__TEST/highway/residential')).to.equal(p.residential); }); }); @@ -103,42 +72,42 @@ describe('iD.presetCollection', function() { describe('#search', function() { it('matches leading name', function() { - var col = c.search('resid', 'area').collection; - expect(col.indexOf(p.residential)).to.eql(0); // 1. 'Residential' (by name) + var result = c.search('resid', 'area').collection; + expect(result.indexOf(p.residential)).to.eql(0); // 1. 'Residential' (by name) }); it('returns alternate matches in correct order', function() { - var col = c.search('gri', 'point').matchGeometry('point').collection; - expect(col.indexOf(p.grill), 'Grill').to.eql(0); // 1. 'Grill' (leading name) - expect(col.indexOf(p.football), 'Football').to.eql(1); // 2. 'Football' (leading term 'gridiron') - expect(col.indexOf(p.sandpit), 'Sandpit').to.eql(2); // 3. 'Sandpit' (leading tag value 'grit_bin') - expect(col.indexOf(p.grass1), 'Grass').to.be.within(3,5); // 4. 'Grass' (similar name) - expect(col.indexOf(p.grass2), 'Ğṝȁß').to.be.within(3,5); // 5. 'Ğṝȁß' (similar name) - expect(col.indexOf(p.park), 'Park').to.be.within(3,5); // 6. 'Park' (similar term 'grass') + var result = c.search('gri', 'point').matchGeometry('point').collection; + expect(result.indexOf(p.grill), 'Grill').to.eql(0); // 1. 'Grill' (leading name) + expect(result.indexOf(p.football), 'Football').to.eql(1); // 2. 'Football' (leading term 'gridiron') + expect(result.indexOf(p.sandpit), 'Sandpit').to.eql(2); // 3. 'Sandpit' (leading tag value 'grit_bin') + expect(result.indexOf(p.grass1), 'Grass').to.be.within(3,5); // 4. 'Grass' (similar name) + expect(result.indexOf(p.grass2), 'Ğṝȁß').to.be.within(3,5); // 5. 'Ğṝȁß' (similar name) + expect(result.indexOf(p.park), 'Park').to.be.within(3,5); // 6. 'Park' (similar term 'grass') }); it('sorts preset with matchScore penalty below others', function() { - var col = c.search('par', 'point').matchGeometry('point').collection; - expect(col.indexOf(p.parking), 'Parking').to.eql(0); // 1. 'Parking' (default matchScore) - expect(col.indexOf(p.park), 'Park').to.eql(1); // 2. 'Park' (low matchScore) + var result = c.search('par', 'point').matchGeometry('point').collection; + expect(result.indexOf(p.parking), 'Parking').to.eql(0); // 1. 'Parking' (default matchScore) + expect(result.indexOf(p.park), 'Park').to.eql(1); // 2. 'Park' (low matchScore) }); it('ignores matchScore penalty for exact name match', function() { - var col = c.search('park', 'point').matchGeometry('point').collection; - expect(col.indexOf(p.park), 'Park').to.eql(0); // 1. 'Park' (low matchScore) - expect(col.indexOf(p.parking), 'Parking').to.eql(1); // 2. 'Parking' (default matchScore) + var result = c.search('park', 'point').matchGeometry('point').collection; + expect(result.indexOf(p.park), 'Park').to.eql(0); // 1. 'Park' (low matchScore) + expect(result.indexOf(p.parking), 'Parking').to.eql(1); // 2. 'Parking' (default matchScore) }); it('considers diacritics on exact matches', function() { - var col = c.search('ğṝȁ', 'point').matchGeometry('point').collection; - expect(col.indexOf(p.grass2), 'Ğṝȁß').to.eql(0); // 1. 'Ğṝȁß' (leading name) - expect(col.indexOf(p.grass1), 'Grass').to.eql(1); // 2. 'Grass' (similar name) + var result = c.search('ğṝȁ', 'point').matchGeometry('point').collection; + expect(result.indexOf(p.grass2), 'Ğṝȁß').to.eql(0); // 1. 'Ğṝȁß' (leading name) + expect(result.indexOf(p.grass1), 'Grass').to.eql(1); // 2. 'Grass' (similar name) }); it('replaces diacritics on fuzzy matches', function() { - var col = c.search('graß', 'point').matchGeometry('point').collection; - expect(col.indexOf(p.grass1), 'Grass').to.be.within(0,1); // 1. 'Grass' (similar name) - expect(col.indexOf(p.grass2), 'Ğṝȁß').to.be.within(0,1); // 2. 'Ğṝȁß' (similar name) + var result = c.search('graß', 'point').matchGeometry('point').collection; + expect(result.indexOf(p.grass1), 'Grass').to.be.within(0,1); // 1. 'Grass' (similar name) + expect(result.indexOf(p.grass2), 'Ğṝȁß').to.be.within(0,1); // 2. 'Ğṝȁß' (similar name) }); it('includes the appropriate fallback preset', function() {