-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |