1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-02 06:43:08 +02:00
TableFilter/test/test-cell-parser.js
2017-02-26 21:43:36 +11:00

59 lines
1.6 KiB
JavaScript

(function(win, TableFilter){
var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
col_0: 'select',
cell_parser: {
cols: [0],
parse: function(tf, cell) {
var chk = cell.getElementsByTagName('input')[0];
if (chk.checked) {
return 'yes';
} else {
return 'no';
}
}
}
});
tf.init();
module('Sanity checks');
test('Sanity checks', function() {
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
deepEqual(tf.cellParser.cols.length, 1,
'Columns implementing cell parser')
deepEqual(typeof tf.cellParser.parse, 'function', 'Parse function');
deepEqual(
tf.getFilterElement(0).nodeName, 'SELECT', 'Expected filter type');
});
module('Behaviour');
test('Can filter with parsed value', function() {
// setup
tf.setFilterValue(0, 'yes');
// act
tf.filter();
// assert
deepEqual(tf.getValidRows(), [2, 4, 5, 7], 'Number of parsed values');
});
test('Can parse with custom function', function() {
// setup
var cell = tf.tbl.rows[3].cells[0];
// act
var value = tf.getCellValue(cell);
// assert
deepEqual(value, 'no', 'Value returned by custom cell parser');
});
module('Tear-down');
test('can destroy', function() {
tf.destroy();
deepEqual(tf.isInitialized(), false, 'Filters removed');
});
})(window, TableFilter);