Skip to content

Commit

Permalink
fix history tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgrossman committed Jun 12, 2019
1 parent 42af31c commit 21d8219
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion modules/osm/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function osmEntity(attrs) {
if (attrs && attrs.type) {
return osmEntity[attrs.type].apply(this, arguments);
} else if (attrs && attrs.id && attrs.id.includes(String(_activeLayer.id))) {
return osmEntity[osmEntity.id.type(attrs.id).apply(this, arguments)];
return osmEntity[osmEntity.id.type(attrs.id)].apply(this, arguments);
}
// Initialize a generic Entity (used only in tests).
return (new osmEntity()).initialize(arguments);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"all": "npm-run-all -s clean build dist",
"build": "webpack --env.NODE_ENV=prod",
"build:analyze": "webpack --env.NODE_ENV=analyze",
"build:dev": "webpack --env.NODE_ENV=dev",
"clean": "shx rm -f dist/*.js dist/*.map dist/*.css dist/img/*.svg",
"dist": "npm-run-all -p dist:**",
"dist:mapillary": "shx mkdir -p dist/mapillary-js && shx cp -R node_modules/mapillary-js/dist/* dist/mapillary-js/",
Expand Down
56 changes: 28 additions & 28 deletions test/spec/core/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ describe('iD.History', function () {
var json = {
'stack': [
{'entities': {}},
{'entities': {'n-1': {'loc': [1, 2], 'id': 'n-1'}}, 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'}
{'entities': {'n-1_50': {'loc': [1, 2], 'id': 'n-1_50'}}, '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.graph().entity('n-1_50')).to.eql(iD.Node({id: 'n-1_50', 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});
Expand All @@ -407,14 +407,14 @@ describe('iD.History', function () {
var json = {
'stack': [
{'entities': {}},
{'entities': {'n-1': {'loc': [1, 2], 'id': 'n-1'}}, 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'},
{'entities': {'n-1': {'loc': [2, 3], 'id': 'n-1', 'v': 1}}, 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'}
{'entities': {'n-1_50': {'loc': [1, 2], 'id': 'n-1_50'}}, 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'},
{'entities': {'n-1_50': {'loc': [2, 3], 'id': 'n-1_50', 'v': 1}}, '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.graph().entity('n-1_50')).to.eql(iD.Node({id: 'n-1_50', 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});
Expand All @@ -424,14 +424,14 @@ describe('iD.History', function () {
var json = {
'stack': [
{'entities': {}},
{'entities': {'n1': 'undefined'}, 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'}
{'entities': {'n1_50': 'undefined'}, '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;
history.merge([iD.Node({id: 'n1_50'})]);
expect(history.graph().hasEntity('n1_50')).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});
Expand All @@ -441,17 +441,17 @@ describe('iD.History', function () {
var json = {
'version': 2,
'entities': [
{'loc': [1, 2], 'id': 'n-1'}
{'loc': [1, 2], 'id': 'n-1_50'}
],
'stack': [
{},
{'modified': ['n-1v0'], 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'}
{'modified': ['n-1_50v0'], '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.graph().entity('n-1_50')).to.eql(iD.Node({id: 'n-1_50', 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});
Expand All @@ -462,18 +462,18 @@ describe('iD.History', function () {
var json = {
'version': 2,
'entities': [
{'loc': [2, 3], 'id': 'n1', 'v': 1}
{'loc': [2, 3], 'id': 'n1_50', 'v': 1}
],
'stack': [
{},
{'modified': ['n1v1'], 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'}
{'modified': ['n1_50v1'], 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'}
],
'nextIDs': {'node': -2, 'way': -1, 'relation': -1},
'index': 1
};
history.fromJSON(JSON.stringify(json));
history.merge([iD.Node({id: 'n1'})]); // Shouldn't be necessary; flaw in v2 format (see #2135)
expect(history.graph().entity('n1')).to.eql(iD.Node({id: 'n1', loc: [2, 3], v: 1}));
history.merge([iD.Node({id: 'n1_50'})]); // Shouldn't be necessary; flaw in v2 format (see #2135)
expect(history.graph().entity('n1_50')).to.eql(iD.Node({id: 'n1_50', 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});
Expand All @@ -486,14 +486,14 @@ describe('iD.History', function () {
'entities': [],
'stack': [
{},
{'deleted': ['n1'], 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'}
{'deleted': ['n1_50'], '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'})]); // Shouldn't be necessary; flaw in v2 format (see #2135)
expect(history.graph().hasEntity('n1')).to.be.undefined;
history.merge([iD.Node({id: 'n1_50'})]); // Shouldn't be necessary; flaw in v2 format (see #2135)
expect(history.graph().hasEntity('n1_50')).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});
Expand All @@ -504,18 +504,18 @@ describe('iD.History', function () {
var json = {
'version': 3,
'entities': [
{'loc': [1, 2], 'id': 'n-1'}
{'loc': [1, 2], 'id': 'n-1_50'}
],
'baseEntities': [],
'stack': [
{},
{'modified': ['n-1v0'], 'imageryUsed': ['Bing'], 'annotation': 'Added a point.'}
{'modified': ['n-1_50v0'], '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.graph().entity('n-1_50')).to.eql(iD.Node({id: 'n-1_50', 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});
Expand All @@ -526,18 +526,18 @@ describe('iD.History', function () {
var json = {
'version': 3,
'entities': [
{'loc': [2, 3], 'id': 'n1', 'v': 1}
{'loc': [2, 3], 'id': 'n1_50', 'v': 1}
],
'baseEntities': [{'loc': [1, 2], 'id': 'n1'}],
'baseEntities': [{'loc': [1, 2], 'id': 'n1_50'}],
'stack': [
{},
{'modified': ['n1v1'], 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'}
{'modified': ['n1_50v1'], 'imageryUsed': ['Bing'], 'annotation': 'Moved a point.'}
],
'nextIDs': {'node': -2, 'way': -1, 'relation': -1},
'index': 1
};
history.fromJSON(JSON.stringify(json));
expect(history.graph().entity('n1')).to.eql(iD.Node({id: 'n1', loc: [2, 3], v: 1}));
expect(history.graph().entity('n1_50')).to.eql(iD.Node({id: 'n1_50', 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});
Expand All @@ -548,16 +548,16 @@ describe('iD.History', function () {
var json = {
'version': 3,
'entities': [],
'baseEntities': [{'loc': [1, 2], 'id': 'n1'}],
'baseEntities': [{'loc': [1, 2], 'id': 'n1_50'}],
'stack': [
{},
{'deleted': ['n1'], 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'}
{'deleted': ['n1_50'], 'imageryUsed': ['Bing'], 'annotation': 'Deleted a point.'}
],
'nextIDs': {'node': -1, 'way': -2, 'relation': -3},
'index': 1
};
history.fromJSON(JSON.stringify(json));
expect(history.graph().hasEntity('n1')).to.be.undefined;
expect(history.graph().hasEntity('n1_50')).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});
Expand Down
20 changes: 10 additions & 10 deletions test/spec/spec_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ window.Hoot = {
layers: {
loadedLayers: {
50: {
name: 'a',
id: 50,
activeLayer: true,
activeIds: {
node: 0,
way: 0,
relation: 0,
changeset: 0
},
refType: 'primary'
name: 'a',
id: 50,
activeLayer: true,
activeIds: {
node: 0,
way: 0,
relation: 0,
changeset: 0
},
refType: 'primary'
}
}
}
Expand Down

0 comments on commit 21d8219

Please sign in to comment.