/
collection.js
68 lines (59 loc) 路 2.27 KB
/
collection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
describe("iD.presets.Collection", function() {
var p = {
other: iD.presets.Preset('other', {
tags: {},
geometry: ['point', 'vertex', 'line', 'area']
}),
residential: iD.presets.Preset('highway/residential', {
tags: {
highway: 'residential'
},
geometry: ['line']
}),
park: iD.presets.Preset('leisure/park', {
tags: {
leisure: 'park'
},
geometry: ['point', 'area']
})
};
var c = iD.presets.Collection([p.other, p.residential]),
n = iD.Node( { id: 'n1' }),
w = iD.Way({ tags: { highway: 'residential' }}),
g = iD.Graph().replace(w);
describe("#item", function() {
it("fetches a preset by id", function() {
expect(c.item('highway/residential')).to.equal(p.residential);
});
});
describe("#matchGeometry", function() {
it("returns a new collection only containing presets matching a geometry", function() {
expect(c.matchGeometry('line').collection).to.eql([p.other, p.residential]);
});
});
describe("#matchTags", function() {
it("returns a new collection only containing presets matching an entity's tags", function() {
expect(c.matchTags(w, g)).to.eql(p.residential);
});
});
describe("#search", function() {
it("filters presets by name", function() {
expect(c.search("resid").collection.indexOf(p.residential) >= 0).to.eql(true);
});
it("is fuzzy", function() {
expect(c.search("rusid").collection.indexOf(p.residential) >= 0).to.eql(true);
});
it("always includes other", function() {
expect(c.search("blade of grass").collection.indexOf(p.other) >= 0).to.eql(true);
});
it("excludes presets with searchable: false", function() {
var excluded = iD.presets.Preset('excluded', {
tags: {},
geometry: [],
searchable: false
}),
collection = iD.presets.Collection([excluded, p.other]);
expect(collection.search("excluded").collection).not.to.include(excluded);
});
});
});