Skip to content

Commit

Permalink
simplified tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scampi committed Oct 11, 2016
1 parent be44e90 commit 43767f0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ uiModules
const fieldTypes = param.filterFieldTypes;

if (fieldTypes) {
fields = $filter('fieldType')(fields, _.isFunction(fieldTypes) ? fieldTypes.bind(this, $scope.agg.vis) : fieldTypes);
const filter = _.isFunction(fieldTypes) ? fieldTypes.bind(this, $scope.agg.vis) : fieldTypes;
fields = $filter('fieldType')(fields, filter);
fields = $filter('orderBy')(fields, ['type', 'name']);
}

Expand Down
159 changes: 28 additions & 131 deletions src/ui/public/filters/__tests__/prop_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,160 +2,57 @@ import expect from 'expect.js';
import propFilter from 'ui/filters/_prop_filter';

describe('prop filter', function () {

let nameFilter;

beforeEach(function () {
nameFilter = propFilter('name');
});

it('should keep only the tables', function () {
const objects = [
{
name: 'table',
title: 'table 1'
},
{
name: 'table',
title: 'table 2'
},
{
name: 'pie',
title: 'pie 1'
}
];
expect(nameFilter(objects, 'table')).to.eql([
{
name: 'table',
title: 'table 1'
},
{
name: 'table',
title: 'table 2'
function getObjects(...names) {
const count = new Map();
const objects = [];

for (let name of names) {
if (!count.has(name)) {
count.set(name, 1);
}
]);
objects.push({
name: name,
title: `${name} ${count.get(name)}`
});
count.set(name, count.get(name) + 1);
}
return objects;
}

it('should keep only the tables', function () {
const objects = getObjects('table', 'table', 'pie');
expect(nameFilter(objects, 'table')).to.eql(getObjects('table', 'table'));
});

it('should support comma-separated values', function () {
const objects = [
{
name: 'table',
title: 'table 1'
},
{
name: 'line',
title: 'line 1'
},
{
name: 'pie',
title: 'pie 1'
}
];
expect(nameFilter(objects, 'table,line')).to.eql([
{
name: 'table',
title: 'table 1'
},
{
name: 'line',
title: 'line 1'
}
]);
const objects = getObjects('table', 'line', 'pie');
expect(nameFilter(objects, 'table,line')).to.eql(getObjects('table', 'line'));
});

it('should support an array of values', function () {
const objects = [
{
name: 'table',
title: 'table 1'
},
{
name: 'line',
title: 'line 1'
},
{
name: 'pie',
title: 'pie 1'
}
];
expect(nameFilter(objects, [ 'table', 'line' ])).to.eql([
{
name: 'table',
title: 'table 1'
},
{
name: 'line',
title: 'line 1'
}
]);
const objects = getObjects('table', 'line', 'pie');
expect(nameFilter(objects, [ 'table', 'line' ])).to.eql(getObjects('table', 'line'));
});

it('should return all objects', function () {
const objects = [
{
name: 'table',
title: 'table 1'
},
{
name: 'line',
title: 'line 1'
},
{
name: 'pie',
title: 'pie 1'
}
];
const objects = getObjects('table', 'line', 'pie');
expect(nameFilter(objects, '*')).to.eql(objects);
});

it('should allow negation', function () {
const objects = [
{
name: 'table',
title: 'table 1'
},
{
name: 'line',
title: 'line 1'
},
{
name: 'pie',
title: 'pie 1'
}
];
expect(nameFilter(objects, [ '!line' ])).to.eql([
{
name: 'table',
title: 'table 1'
},
{
name: 'pie',
title: 'pie 1'
}
]);
const objects = getObjects('table', 'line', 'pie');
expect(nameFilter(objects, [ '!line' ])).to.eql(getObjects('table', 'pie'));
});

it('should support a function for specifying what should be kept', function () {
const objects = [
{
name: 'table',
title: 'table 1'
},
{
name: 'line',
title: 'line 1'
},
{
name: 'pie',
title: 'pie 1'
}
];
const objects = getObjects('table', 'line', 'pie');
const line = (value) => value === 'line';
expect(nameFilter(objects, line)).to.eql([
{
name: 'line',
title: 'line 1'
}
]);
expect(nameFilter(objects, line)).to.eql(getObjects('line'));
});
});

0 comments on commit 43767f0

Please sign in to comment.