1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-17 05:46:39 +02:00
TableFilter/test/test-col-ops.js

103 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-11-15 09:39:10 +01:00
2015-05-10 13:12:31 +02:00
var id = function (id){ return document.getElementById(id); };
2015-06-09 10:46:08 +02:00
var table = id('demo');
2015-05-10 13:12:31 +02:00
var totRowIndex = table.getElementsByTagName('tr').length;
2014-11-15 09:39:10 +01:00
2015-05-10 13:12:31 +02:00
var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
2016-10-07 14:08:13 +02:00
rows_always_visible: [
totRowIndex-2,
totRowIndex-1,
totRowIndex,
],
extensions: [{
name: 'colOps',
2016-10-07 14:08:13 +02:00
id: [
'sum1', 'sum2',
'min1', 'min2',
'max1', 'max2'
],
col: [
2, 3,
2, 3,
2, 3
],
operation: [
'sum', 'mean',
'min', 'min',
'max', 'max'
],
write_method: [
'innerhtml', 'innerhtml',
'innerhtml', 'innerhtml',
'innerhtml', 'innerhtml'
],
exclude_row: [
totRowIndex-2,
totRowIndex-1,
totRowIndex
],
2015-05-10 13:12:31 +02:00
decimal_precision: [0, 2],
2016-10-07 14:08:13 +02:00
tot_row_index: [
totRowIndex-2, totRowIndex-2,
totRowIndex-1, totRowIndex-1,
totRowIndex, totRowIndex
]
}]
2015-05-10 13:12:31 +02:00
});
tf.init();
2014-11-15 09:39:10 +01:00
2015-05-10 13:12:31 +02:00
module('Sanity checks');
test('Column operations', function() {
var colOps = tf.extension('colOps');
deepEqual(typeof colOps, 'object', 'ColOps instanciated');
2015-05-10 13:12:31 +02:00
equal(id('sum1').innerHTML, 9911, 'Sum result');
equal(id('sum2').innerHTML, 1.69, 'Mean result');
2016-10-07 14:08:13 +02:00
equal(id('min1').innerHTML, 286.00, 'Min result');
equal(id('min2').innerHTML, 0.60, 'Min result');
2015-05-10 13:12:31 +02:00
});
module('Behaviour checks');
test('Column operations after filtering', function() {
tf.setFilterValue(0, 'syd');
tf.filter();
equal(id('sum1').innerHTML, 3552, 'Sum result');
equal(id('sum2').innerHTML, 1.15, 'Mean result');
2016-10-07 14:08:13 +02:00
equal(id('min1').innerHTML, 286.00, 'Min result');
equal(id('min2').innerHTML, 0.60, 'Min result');
tf.clearFilters();
});
2016-10-07 14:08:13 +02:00
// module('Behaviour checks with grid layout');
// test('Column operations', function() {
// tf.destroy();
// tf = null;
// totRowIndex = totRowIndex-2;
// tf = new TableFilter('demo', {
// base_path: '../dist/tablefilter/',
// grid_layout: true,
// rows_always_visible: [totRowIndex],
// extensions: [{
// name: 'colOps',
// id: ['sum1', 'sum2'],
// col: [2, 3],
// operation: ['sum', 'mean'],
// write_method: ['innerhtml', 'innerhtml'],
// exclude_row: [totRowIndex],
// decimal_precision: [0, 2],
// tot_row_index: [totRowIndex, totRowIndex]
// }]
// });
// tf.init();
2016-10-07 14:08:13 +02:00
// equal(id('sum1').innerHTML, 9911, 'Sum result');
// equal(id('sum2').innerHTML, 1.69, 'Mean result');
2016-10-07 14:08:13 +02:00
// tf.setFilterValue(2, '>1000');
// tf.filter();
// equal(id('sum1').innerHTML, 7771, 'Sum result');
// equal(id('sum2').innerHTML, 2.16, 'Mean result');
2016-10-07 14:08:13 +02:00
// tf.destroy();
// });