From 86c4bc910549b48761a1037d7948be88664fa987 Mon Sep 17 00:00:00 2001 From: tyr Date: Thu, 20 Feb 2014 18:42:54 +0100 Subject: [PATCH] add tests for "restoring from v3 JSON" (core/history.js) --- test/spec/core/history.js | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/test/spec/core/history.js b/test/spec/core/history.js index 6c7a21496..bbffe247e 100644 --- a/test/spec/core/history.js +++ b/test/spec/core/history.js @@ -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); + }); }); });