UNPKG

1.98 kBJavaScriptView Raw
1
2var tag = function (elm, tag){ return elm.getElementsByTagName(tag); };
3
4var tf = new TableFilter('demo', {
5 base_path: '../dist/tablefilter/',
6 extensions:[{
7 name: 'sort',
8 types:[
9 'String',
10 'Number',
11 'String',
12 'String',
13 'EU',
14 'US',
15 'String',
16 'dmydate',
17 'mdydate'
18 ],
19 on_sort_loaded: start
20 }]
21});
22tf.init();
23
24function start(tf, sort){
25
26 module('Sanity checks');
27 test('Sort extension', function() {
28 notEqual(sort, null, 'Sort instanciated');
29 deepEqual(sort.stt instanceof SortableTable, true, 'Sort type');
30 deepEqual(sort.sorted, false, 'Table not sorted');
31 deepEqual(sort.initialized, true, 'Sort initialized');
32 });
33
34 module('UI elements');
35 test('Sort UI elements', function() {
36 var th = tf.getHeaderElement(0),
37 indicator = tag(th, 'img'),
38 validRows = tf.getValidRows(true);
39
40 deepEqual(indicator.length, 1, 'Sort indicator in header element');
41 deepEqual(
42 (tf.dom().rows[validRows[0]].cells[1]).innerHTML,
43 'AUY78',
44 'First custom key cell text before sorting');
45 });
46
47 test('Sort behaviour', function() {
48 validRows = tf.getValidRows();
49 sort.sortByColumnIndex(1);
50
51 deepEqual(sort.sorted, true, 'Table column sorted');
52 deepEqual(
53 (tf.dom().rows[validRows[0]].cells[1]).innerHTML,
54 'QT1',
55 'First custom key cell text after sorting');
56 });
57
58 module('Destroy and re-init');
59 test('Remove sort', function() {
60 sort.destroy();
61 var th = tf.getHeaderElement(0),
62 indicator = tag(th, 'img');
63 deepEqual(sort.initialized, false, 'Sort is removed');
64 deepEqual(indicator.length, 0, 'Sort indicator is removed');
65 });
66
67}