mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 05:12:13 +02:00
Allow Graph to be constructed with an array of entities
Useful for tests.
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
iD.Graph = function(entities, annotation) {
|
||||
if (!(this instanceof iD.Graph)) return new iD.Graph(entities, annotation);
|
||||
|
||||
this.entities = entities || {};
|
||||
if (_.isArray(entities)) {
|
||||
this.entities = {};
|
||||
for (var i = 0; i < entities.length; i++) {
|
||||
this.entities[entities[i].id] = entities[i];
|
||||
}
|
||||
} else {
|
||||
this.entities = entities || {};
|
||||
}
|
||||
|
||||
this.annotation = annotation;
|
||||
|
||||
if (iD.debug) {
|
||||
|
||||
+14
-16
@@ -1,21 +1,19 @@
|
||||
describe('Graph', function() {
|
||||
describe('iD.Graph', function() {
|
||||
it("can be constructed with an entities Object", function () {
|
||||
var entity = iD.Entity(),
|
||||
graph = iD.Graph({'n-1': entity});
|
||||
expect(graph.entity('n-1')).to.equal(entity);
|
||||
});
|
||||
|
||||
describe('Construction and access', function() {
|
||||
it('entity', function() {
|
||||
var entities = { 'n-1': {
|
||||
type: 'node',
|
||||
loc: [-80, 30],
|
||||
id: 'n-1'
|
||||
}
|
||||
};
|
||||
var graph = iD.Graph(entities, 'first graph');
|
||||
expect(graph.entity('n-1')).to.equal(entities['n-1']);
|
||||
});
|
||||
it("can be constructed with an entities Array", function () {
|
||||
var entity = iD.Entity(),
|
||||
graph = iD.Graph([entity]);
|
||||
expect(graph.entity(entity.id)).to.equal(entity);
|
||||
});
|
||||
|
||||
it('annotation', function() {
|
||||
var graph = iD.Graph({}, 'first graph');
|
||||
expect(graph.annotation).to.equal('first graph');
|
||||
});
|
||||
it('can be constructed with an annotation', function() {
|
||||
var graph = iD.Graph({}, 'first graph');
|
||||
expect(graph.annotation).to.equal('first graph');
|
||||
});
|
||||
|
||||
describe('operations', function() {
|
||||
|
||||
Reference in New Issue
Block a user