add tests for iD.presets.Collection and .Category

This commit is contained in:
Ansis Brammanis
2013-03-05 15:37:34 -05:00
parent e106db76d4
commit 4fb8688d83
3 changed files with 111 additions and 0 deletions
+2
View File
@@ -254,6 +254,8 @@
<script src="spec/modes/add_point.js"></script>
<script src="spec/presets/preset.js"></script>
<script src="spec/presets/collection.js"></script>
<script src="spec/presets/category.js"></script>
<script>
(window.mochaPhantomJS || window.mocha).run();
+41
View File
@@ -0,0 +1,41 @@
describe("iD.presets.Category", function() {
var category, residential;
beforeEach(function() {
category = {
"match": {
"type": "line"
},
"icon": "highway",
"name": "roads",
"members": [
"residential"
]
};
residential = iD.presets.Preset({
name: 'residential',
match: {
tags: {
highway: 'residential'
},
type: ['line']
}
});
});
it("maps members names to preset instances", function() {
var c = iD.presets.Category(category, iD.presets.Collection([residential]));
expect(c.members.collection[0]).to.eql(residential);
});
describe("#matchType", function() {
it("matches the type of an entity", function() {
var c = iD.presets.Category(category, iD.presets.Collection([residential])),
w = iD.Way(),
n = iD.Node(),
g = iD.Graph().replace(w);
expect(c.matchType(w, g)).to.eql(true);
expect(c.matchType(n, g)).to.eql(false);
});
});
});
+68
View File
@@ -0,0 +1,68 @@
describe("iD.prests.Collection", function() {
var p = {
other: iD.presets.Preset({
name: 'other',
match: {
tags: {},
type: ['point', 'vertex', 'line', 'area']
}
}),
residential: iD.presets.Preset({
name: 'residential',
match: {
tags: {
highway: 'residential'
},
type: ['line']
}
}),
park: iD.presets.Preset({
name: 'park',
match: {
tags: {
leisure: 'park'
},
type: ['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 name", function() {
expect(c.item('residential')).to.equal(p.residential);
});
});
describe("#matchType", function() {
it("returns a new collection only containing presets matching an entity's type", function() {
expect(c.matchType(w, g).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);
});
});
});