mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Merge pull request #5639 from wonga00/more_tests
Added more validation tests
This commit is contained in:
@@ -13,7 +13,7 @@ import { select as d3_select } from 'd3-selection';
|
||||
import { t, currentLocale, addTranslation, setLocale } from '../util/locale';
|
||||
|
||||
import { coreHistory } from './history';
|
||||
import { IssueManager } from '../validations/issueManager';
|
||||
import { IssueManager } from '../validations/issue_manager';
|
||||
import { dataLocales, dataEn } from '../../data';
|
||||
import { geoRawMercator } from '../geo/raw_mercator';
|
||||
import { modeSelect } from '../modes/select';
|
||||
|
||||
@@ -19,6 +19,7 @@ export * from './ui/settings/index';
|
||||
export * from './ui/index';
|
||||
export * from './util/index';
|
||||
export * from './validations/index';
|
||||
export { IssueManager } from './validations/issue_manager';
|
||||
|
||||
/* export some legacy symbols: */
|
||||
import { services } from './services/index';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import * as d3 from 'd3';
|
||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||
|
||||
import _filter from 'lodash-es/filter';
|
||||
|
||||
import { utilRebind } from '../util/rebind';
|
||||
|
||||
export function IssueManager(context) {
|
||||
var dispatch = d3.dispatch('reload'),
|
||||
var dispatch = d3_dispatch('reload'),
|
||||
self = {},
|
||||
issues = [];
|
||||
|
||||
@@ -143,7 +143,11 @@
|
||||
<script src='spec/util/session_mutex.js'></script>
|
||||
<script src='spec/util/util.js'></script>
|
||||
|
||||
<script src='spec/validations/issue_manager.js'></script>
|
||||
<script src='spec/validations/deprecated_tag.js'></script>
|
||||
<script src='spec/validations/missing_tag.js'></script>
|
||||
<script src='spec/validations/disconnected_highway.js'></script>
|
||||
<script src='spec/validations/tag_suggests_area.js'></script>
|
||||
<script src='spec/validations/crossing_ways.js'></script>
|
||||
<script src='spec/operations/detach_node.js'></script>
|
||||
<script>
|
||||
|
||||
50
test/spec/validations/deprecated_tag.js
Normal file
50
test/spec/validations/deprecated_tag.js
Normal file
@@ -0,0 +1,50 @@
|
||||
describe('iD.validations.deprecated_tag', function () {
|
||||
var context;
|
||||
|
||||
beforeEach(function() {
|
||||
context = iD.Context();
|
||||
});
|
||||
|
||||
function createWay(tags) {
|
||||
var n1 = iD.Node({id: 'n-1', loc: [4,4]});
|
||||
var n2 = iD.Node({id: 'n-2', loc: [4,5]});
|
||||
|
||||
var w = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2'], tags: tags});
|
||||
|
||||
context.perform(
|
||||
iD.actionAddEntity(n1),
|
||||
iD.actionAddEntity(n2),
|
||||
iD.actionAddEntity(w)
|
||||
);
|
||||
}
|
||||
|
||||
function validate() {
|
||||
var validator = iD.validationDeprecatedTag(context);
|
||||
var changes = context.history().changes();
|
||||
return validator(changes, context.graph());
|
||||
}
|
||||
|
||||
it('has no errors on init', function() {
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('has no errors on good tags', function() {
|
||||
createWay({'highway': 'unclassified'});
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('finds deprecated tags', function() {
|
||||
createWay({'highway': 'ford'});
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(1);
|
||||
var issue = issues[0];
|
||||
expect(issue.type).to.eql(iD.ValidationIssueType.deprecated_tags);
|
||||
expect(issue.severity).to.eql(iD.ValidationIssueSeverity.warning);
|
||||
expect(issue.entities).to.have.lengthOf(1);
|
||||
expect(issue.entities[0].id).to.eql('w-1');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
71
test/spec/validations/disconnected_highway.js
Normal file
71
test/spec/validations/disconnected_highway.js
Normal file
@@ -0,0 +1,71 @@
|
||||
describe('iD.validations.disconnected_highway', function () {
|
||||
var context;
|
||||
|
||||
beforeEach(function() {
|
||||
context = iD.Context();
|
||||
});
|
||||
|
||||
function createWay(tags) {
|
||||
var n1 = iD.Node({id: 'n-1', loc: [4,4]});
|
||||
var n2 = iD.Node({id: 'n-2', loc: [4,5]});
|
||||
|
||||
var w = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2'], tags: tags});
|
||||
|
||||
context.perform(
|
||||
iD.actionAddEntity(n1),
|
||||
iD.actionAddEntity(n2),
|
||||
iD.actionAddEntity(w)
|
||||
);
|
||||
}
|
||||
|
||||
function createConnectingWays() {
|
||||
var n1 = iD.Node({id: 'n-1', loc: [4,4]});
|
||||
var n2 = iD.Node({id: 'n-2', loc: [4,5]});
|
||||
var n3 = iD.Node({id: 'n-3', loc: [5,5]});
|
||||
|
||||
var w = iD.Way(
|
||||
{id: 'w-1', nodes: ['n-1', 'n-2'],
|
||||
tags: {'highway': 'unclassified'}});
|
||||
var w2 = iD.Way({
|
||||
id: 'w-2', nodes: ['n-1', 'n-3'],
|
||||
tags: {'highway': 'unclassified'}});
|
||||
|
||||
context.perform(
|
||||
iD.actionAddEntity(n1),
|
||||
iD.actionAddEntity(n2),
|
||||
iD.actionAddEntity(n3),
|
||||
iD.actionAddEntity(w),
|
||||
iD.actionAddEntity(w2)
|
||||
);
|
||||
}
|
||||
|
||||
function validate() {
|
||||
var validator = iD.validationDisconnectedHighway(context);
|
||||
var changes = context.history().changes();
|
||||
return validator(changes, context.graph());
|
||||
}
|
||||
|
||||
it('has no errors on init', function() {
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('finds disconnected highway', function() {
|
||||
createWay({'highway': 'unclassified'});
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(1);
|
||||
var issue = issues[0];
|
||||
expect(issue.type).to.eql(iD.ValidationIssueType.disconnected_highway);
|
||||
expect(issue.severity).to.eql(iD.ValidationIssueSeverity.warning);
|
||||
expect(issue.entities).to.have.lengthOf(1);
|
||||
expect(issue.entities[0].id).to.eql('w-1');
|
||||
});
|
||||
|
||||
it('ignores roads that are connected', function() {
|
||||
createConnectingWays();
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
43
test/spec/validations/issue_manager.js
Normal file
43
test/spec/validations/issue_manager.js
Normal file
@@ -0,0 +1,43 @@
|
||||
describe('iD.validations.IssueManager', function () {
|
||||
var context;
|
||||
|
||||
beforeEach(function() {
|
||||
context = iD.Context();
|
||||
});
|
||||
|
||||
function createInvalidWay() {
|
||||
var n1 = iD.Node({id: 'n-1', loc: [4,4]});
|
||||
var n2 = iD.Node({id: 'n-2', loc: [4,5]});
|
||||
|
||||
var w = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2']});
|
||||
|
||||
context.perform(
|
||||
iD.actionAddEntity(n1),
|
||||
iD.actionAddEntity(n2),
|
||||
iD.actionAddEntity(w)
|
||||
);
|
||||
}
|
||||
|
||||
it('has no issues on init', function() {
|
||||
var issueManager = new iD.IssueManager(context);
|
||||
var issues = issueManager.getIssues();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('populates issues on validate', function() {
|
||||
createInvalidWay();
|
||||
var issueManager = new iD.IssueManager(context);
|
||||
var issues = issueManager.getIssues();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
|
||||
issueManager.validate();
|
||||
issues = issueManager.getIssues();
|
||||
expect(issues).to.have.lengthOf(1);
|
||||
var issue = issues[0];
|
||||
expect(issue.type).to.eql(iD.ValidationIssueType.missing_tag);
|
||||
expect(issue.entities).to.have.lengthOf(1);
|
||||
expect(issue.entities[0].id).to.eql('w-1');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
@@ -19,7 +19,7 @@ describe('iD.validations.missing_tag', function () {
|
||||
}
|
||||
|
||||
function validate() {
|
||||
var validator = iD.validationMissingTag();
|
||||
var validator = iD.validationMissingTag(context);
|
||||
var changes = context.history().changes();
|
||||
return validator(changes, context.graph());
|
||||
}
|
||||
|
||||
63
test/spec/validations/tag_suggests_area.js
Normal file
63
test/spec/validations/tag_suggests_area.js
Normal file
@@ -0,0 +1,63 @@
|
||||
describe('iD.validations.tag_suggests_area', function () {
|
||||
var context;
|
||||
|
||||
beforeEach(function() {
|
||||
context = iD.Context();
|
||||
});
|
||||
|
||||
function createWay(tags) {
|
||||
var n1 = iD.Node({id: 'n-1', loc: [4,4]});
|
||||
var n2 = iD.Node({id: 'n-2', loc: [4,5]});
|
||||
|
||||
var w = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2'], tags: tags});
|
||||
|
||||
context.perform(
|
||||
iD.actionAddEntity(n1),
|
||||
iD.actionAddEntity(n2),
|
||||
iD.actionAddEntity(w)
|
||||
);
|
||||
}
|
||||
|
||||
function createPoint(tags) {
|
||||
var n1 = iD.Node({id: 'n-1', loc: [4,4], tags: tags});
|
||||
context.perform(
|
||||
iD.actionAddEntity(n1)
|
||||
);
|
||||
}
|
||||
|
||||
function validate() {
|
||||
var validator = iD.validationTagSuggestsArea(context);
|
||||
var changes = context.history().changes();
|
||||
return validator(changes, context.graph());
|
||||
}
|
||||
|
||||
it('has no errors on init', function() {
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('has no errors on good tags', function() {
|
||||
createWay({'highway': 'unclassified'});
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('ignores points', function() {
|
||||
createPoint({'building': 'yes'});
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('finds tags that suggest area', function() {
|
||||
createWay({'building': 'yes'});
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(1);
|
||||
var issue = issues[0];
|
||||
expect(issue.type).to.eql(iD.ValidationIssueType.tag_suggests_area);
|
||||
expect(issue.severity).to.eql(iD.ValidationIssueSeverity.warning);
|
||||
expect(issue.entities).to.have.lengthOf(1);
|
||||
expect(issue.entities[0].id).to.eql('w-1');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user