Test that fallback presets are there before data is loaded

Also, we don't actually need a vertex preset anymore, it was removed a while ago
This commit is contained in:
Bryan Housel
2020-02-06 17:04:11 -05:00
parent 2edf81605c
commit 9faf8c0fe5
2 changed files with 34 additions and 5 deletions

View File

@@ -23,18 +23,17 @@ export function presetIndex(context) {
let _presetData;
// seed the preset lists with geometry fallbacks
const POINT = presetPreset('point', { name: 'Point', tags: {}, geometry: ['point'], matchScore: 0.1 } );
const VERTEX = presetPreset('vertex', { name: 'Point', tags: {}, geometry: ['vertex'], matchScore: 0.1 } );
const POINT = presetPreset('point', { name: 'Point', tags: {}, geometry: ['point', 'vertex'], matchScore: 0.1 } );
const LINE = presetPreset('line', { name: 'Line', tags: {}, geometry: ['line'], matchScore: 0.1 } );
const AREA = presetPreset('area', { name: 'Area', tags: { area: 'yes' }, geometry: ['area'], matchScore: 0.1 } );
const RELATION = presetPreset('relation', { name: 'Relation', tags: {}, geometry: ['relation'], matchScore: 0.1 } );
let _this = presetCollection([POINT, VERTEX, LINE, AREA, RELATION]);
let _presets = { point: POINT, vertex: VERTEX, line: LINE, area: AREA, relation: RELATION };
let _this = presetCollection([POINT, LINE, AREA, RELATION]);
let _presets = { point: POINT, line: LINE, area: AREA, relation: RELATION };
let _defaults = {
point: presetCollection([POINT]),
vertex: presetCollection([VERTEX]),
vertex: presetCollection([POINT]),
line: presetCollection([LINE]),
area: presetCollection([AREA]),
relation: presetCollection([RELATION])

View File

@@ -12,6 +12,36 @@ describe('iD.presetIndex', function () {
});
describe('#init', function () {
it('has a fallback point preset', function () {
var node = iD.osmNode({ id: 'n' });
var graph = iD.coreGraph([node]);
var presets = iD.coreContext().init().presets();
expect(presets.match(node, graph).id).to.eql('point');
});
it('has a fallback line preset', function () {
var node = iD.osmNode({ id: 'n' });
var way = iD.osmWay({ id: 'w', nodes: ['n'] });
var graph = iD.coreGraph([node, way]);
var presets = iD.coreContext().init().presets();
expect(presets.match(way, graph).id).to.eql('line');
});
it('has a fallback area preset', function () {
var node = iD.osmNode({ id: 'n' });
var way = iD.osmWay({ id: 'w', nodes: ['n'], tags: { area: 'yes' }});
var graph = iD.coreGraph([node, way]);
var presets = iD.coreContext().init().presets();
expect(presets.match(way, graph).id).to.eql('area');
});
it('has a fallback relation preset', function () {
var relation = iD.osmRelation({ id: 'r' });
var graph = iD.coreGraph([relation]);
var presets = iD.coreContext().init().presets();
expect(presets.match(relation, graph).id).to.eql('relation');
});
});
describe('#match', function () {
var testPresets = {
residential: { tags: { highway: 'residential' }, geometry: ['line'] },