make collection.index function to handle failing tests

This commit is contained in:
Max Grossman
2018-12-17 17:16:10 -05:00
parent d8de9e785e
commit 8f33a85a12
6 changed files with 18 additions and 6 deletions

View File

@@ -9,7 +9,6 @@ import _isEmpty from 'lodash-es/isEmpty';
import _forEach from 'lodash-es/forEach';
import _map from 'lodash-es/map';
import _omit from 'lodash-es/omit';
import _reduce from 'lodash-es/reduce';
import _reject from 'lodash-es/reject';
import _values from 'lodash-es/values';
import _without from 'lodash-es/without';

View File

@@ -1,5 +1,6 @@
import _filter from 'lodash-es/filter';
import _find from 'lodash-es/find';
import _findIndex from 'lodash-es/findIndex';
import _some from 'lodash-es/some';
import _uniq from 'lodash-es/uniq';
import _values from 'lodash-es/values';
@@ -23,6 +24,11 @@ export function presetCollection(collection) {
});
},
index: function(id) {
return _findIndex(this.collection, function(d) {
return d.id === id;
});
},
matchGeometry: function(geometry) {
return presetCollection(this.collection.filter(function(d) {

View File

@@ -10,7 +10,6 @@ import { presetCategory } from './category';
import { presetCollection } from './collection';
import { presetField } from './field';
import { presetPreset } from './preset';
import { utilQsString } from '../util';
export { presetCategory };
export { presetCollection };
@@ -138,7 +137,7 @@ export function presetIndex() {
if (d.presets) {
_forEach(d.presets, function(d, id) {
var existing = all.collection.findIndex(function(p) { return p.id === id; });
var existing = all.index(id);
if (existing !== -1) {
all.collection[existing] = presetPreset(id, d, _fields, visible);
} else {
@@ -149,7 +148,7 @@ export function presetIndex() {
if (d.categories) {
_forEach(d.categories, function(d, id) {
var existing = all.collection.findIndex(function(p) { return p.id === id; });
var existing = all.index(id);
if (existing !== -1) {
all.collection[existing] = presetCategory(id, d, all);
} else {

View File

@@ -187,7 +187,6 @@ export default {
},
// adds from mapcss-parse selector check...
addRule: function(selector) {
var _areaKeys = this._areaKeys;
var rule = {
// checks relevant to mapcss-selector
checks: this.filterRuleChecks(selector),

View File

@@ -84,6 +84,15 @@ describe('iD.presetCollection', function() {
});
});
describe('#index', function() {
it('returns preset position in the collection', function() {
expect(c.index('point')).to.equal(0);
});
it('return -1 when given id for preset not in the collection', function() {
expect(c.index('foobar')).to.equal(-1);
});
});
describe('#matchGeometry', function() {
it('returns a new collection only containing presets matching a geometry', function() {
expect(c.matchGeometry('area').collection).to.include.members(

View File

@@ -300,7 +300,7 @@ describe('maprules', function() {
});
});
describe('rule', function() {
var selectors, entities;
var selectors;
before(function() {
selectors = [
{