Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bboure committed Jul 17, 2020
1 parent 8e2b002 commit 412e40a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var tests = [
require('./view/population.js'),
require('./view/population_only_function.js'),
require('./view/sort_distance.js'),
require('./view/sort_popularity.js'),
require('./view/sources.js'),
require('./view/boundary_gid.js'),
require('./view/leaf/match.js'),
Expand Down
68 changes: 68 additions & 0 deletions test/view/sort_popularity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var sort_popularity = require('../../view/sort_popularity');
var VariableStore = require('../../lib/VariableStore');

function getBaseVariableStore(toExclude) {
var vs = new VariableStore();
vs.var('sort:field', 'popularity');

if (toExclude) {
vs.unset(toExclude);
}

return vs;

}

module.exports.tests = {};

module.exports.tests.interface = function(test, common) {
test('interface: contructor', function(t) {
t.equal(typeof sort_popularity, 'function', 'valid function');
t.equal(sort_popularity.length, 1, 'takes 1 arg');
t.end();
});

};

module.exports.tests.missing_variable_conditions = function(test, common) {
var variables = Object.keys(getBaseVariableStore().export());

variables.forEach(function(missing_variable) {
test('missing required variable ' + missing_variable + ' should return null', function(t) {
var vs = getBaseVariableStore(missing_variable);

t.equal(sort_popularity(vs), null, 'should have returned null for unset ' + missing_variable);
t.end();

});
});

};

module.exports.tests.no_exceptions_conditions = function(test, common) {
test('all properties set should return valid object', function(t) {
var vs = getBaseVariableStore();

var actual = sort_popularity(vs);

var expected = {
popularity: {
order: 'desc'
}
};

t.deepEquals(actual, expected, 'should have returned object');
t.end();

});

};

module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('sort_popularity ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

0 comments on commit 412e40a

Please sign in to comment.