add tests for "restoring from v3 JSON" (core/history.js)

This commit is contained in:
tyr
2014-02-20 18:42:54 +01:00
parent fc0a15e6c4
commit 86c4bc9105

View File

@@ -350,5 +350,72 @@ describe("iD.History", function () {
expect(history.imageryUsed()).to.eql(["Bing"]);
expect(iD.Entity.id.next).to.eql({node: -1, way: -2, relation: -3});
});
it("restores from v3 JSON (creation)", function() {
var json = {
"version": 3,
"entities": [
{"loc": [1, 2], "id": "n-1"}
],
"baseEntities": [],
"stack": [
{},
{"modified": ["n-1v0"], "imageryUsed": ["Bing"], "annotation": "Added a point."}
],
"nextIDs": {"node": -2, "way": -1, "relation": -1},
"index": 1
};
history.fromJSON(JSON.stringify(json));
expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [1, 2]}));
expect(history.undoAnnotation()).to.eql("Added a point.");
expect(history.imageryUsed()).to.eql(["Bing"]);
expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1});
expect(history.difference().created().length).to.eql(1);
});
it("restores from v3 JSON (modification)", function() {
var json = {
"version": 3,
"entities": [
{"loc": [1, 2], "id": "n-1"},
{"loc": [2, 3], "id": "n-1", "v": 1}
],
"baseEntities": [{"loc": [1, 2], "id": "n-1"}],
"stack": [
{},
{"modified": ["n-1v0"], "imageryUsed": ["Bing"], "annotation": "Added a point."},
{"modified": ["n-1v1"], "imageryUsed": ["Bing"], "annotation": "Moved a point."}
],
"nextIDs": {"node": -2, "way": -1, "relation": -1},
"index": 2
};
history.fromJSON(JSON.stringify(json));
expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [2, 3], v: 1}));
expect(history.undoAnnotation()).to.eql("Moved a point.");
expect(history.imageryUsed()).to.eql(["Bing"]);
expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1});
expect(history.difference().modified().length).to.eql(1);
});
it("restores from v3 JSON (deletion)", function() {
var json = {
"version": 3,
"entities": [],
"baseEntities": [],
"stack": [
{},
{"deleted": ["n1"], "imageryUsed": ["Bing"], "annotation": "Deleted a point."}
],
"nextIDs": {"node": -1, "way": -2, "relation": -3},
"index": 1
};
history.fromJSON(JSON.stringify(json));
history.merge([iD.Node({id: 'n1'})]);
expect(history.graph().hasEntity('n1')).to.be.undefined;
expect(history.undoAnnotation()).to.eql("Deleted a point.");
expect(history.imageryUsed()).to.eql(["Bing"]);
expect(iD.Entity.id.next).to.eql({node: -1, way: -2, relation: -3});
expect(history.difference().deleted().length).to.eql(1);
});
});
});