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

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-04-04 10:10:09 +02:00
var tag = function (elm, tag){ return elm.getElementsByTagName(tag); };
2015-04-04 10:10:09 +02:00
var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
sort: true,
sort_config: {
sort_types:[
'String',
'Number',
'String',
'String',
'EU',
'US',
'String',
'dmydate',
'mdydate'
]
},
on_sort_loaded: start
});
tf.init();
2015-04-04 10:10:09 +02:00
function start(tf, sort){
2015-04-04 10:10:09 +02:00
module('Sanity checks');
test('Sort extension', function() {
notEqual(sort, null, 'Sort instanciated');
deepEqual(sort.stt instanceof SortableTable, true, 'Sort type');
deepEqual(sort.sorted, false, 'Table not sorted');
});
2015-04-04 10:10:09 +02:00
module('UI elements');
test('Sort UI elements', function() {
var th = tf.getHeaderElement(0),
indicator = tag(th, 'img'),
validRows = tf.getValidRowsIndex(true);
2015-04-04 10:10:09 +02:00
deepEqual(indicator.length, 1, 'Sort indicator in header element');
deepEqual(
(tf.tbl.rows[validRows[0]].cells[1]).innerHTML,
'AUY78',
'First custom key cell text before sorting');
});
2015-04-04 10:10:09 +02:00
test('Sort behaviour', function() {
var th = tf.getHeaderElement(1),
validRows = tf.getValidRowsIndex();
sort.sortByColumnIndex(1);
2015-04-04 10:10:09 +02:00
deepEqual(sort.sorted, true, 'Table column sorted');
deepEqual(
(tf.tbl.rows[validRows[0]].cells[1]).innerHTML,
'QT1',
'First custom key cell text after sorting');
});
2015-04-04 10:10:09 +02:00
module('Destroy and re-init');
test('Remove sort', function() {
sort.destroy();
var th = tf.getHeaderElement(0),
indicator = tag(th, 'img');
deepEqual(tf.sort, false, 'Sort is removed');
deepEqual(indicator.length, 0, 'Sort indicator is removed');
});
2015-04-04 10:10:09 +02:00
}