1 |
|
2 | var tag = function (elm, tag){ return elm.getElementsByTagName(tag); };
|
3 |
|
4 | var tf = new TableFilter('demo', {
|
5 | base_path: '../dist/tablefilter/',
|
6 | grid_layout: true,
|
7 | extensions:[{
|
8 | name: 'sort',
|
9 | types: ['string','string','number','number','number'],
|
10 | on_sort_loaded: startSimple
|
11 | }]
|
12 | });
|
13 | tf.init();
|
14 |
|
15 | var tf1 = new TableFilter('demo2', {
|
16 | base_path: '../dist/tablefilter/',
|
17 | paging: true,
|
18 | grid_layout: true,
|
19 | extensions:[{
|
20 | name: 'sort',
|
21 | types: ['string','string','number','number','number'],
|
22 | on_sort_loaded: startPaging
|
23 | }]
|
24 | });
|
25 | tf1.init();
|
26 |
|
27 | function startSimple(tf, sort){
|
28 | module('Sanity checks');
|
29 | test('Sort extension', function() {
|
30 | notEqual(sort, null, 'Sort instanciated');
|
31 | deepEqual(sort.stt instanceof SortableTable, true, 'Sort type');
|
32 | deepEqual(sort.sorted, false, 'Table not sorted');
|
33 | deepEqual(sort.initialized, true, 'Sort initialized');
|
34 | });
|
35 |
|
36 | test('Sort behaviour', function() {
|
37 | sort.sortByColumnIndex(0);
|
38 |
|
39 | deepEqual(sort.sorted, true, 'Table column sorted');
|
40 | });
|
41 |
|
42 | module('Destroy and re-init');
|
43 | test('Remove sort', function() {
|
44 | sort.destroy();
|
45 | var th = tf.getHeaderElement(0),
|
46 | indicator = tag(th, 'img');
|
47 | deepEqual(sort.initialized, false, 'Sort is removed');
|
48 | deepEqual(indicator.length, 0, 'Sort indicator is removed');
|
49 | });
|
50 |
|
51 | }
|
52 |
|
53 | function startPaging(tf, sort){
|
54 |
|
55 | module('Sanity checks');
|
56 | test('Sort extension', function() {
|
57 | notEqual(sort, null, 'Sort instanciated');
|
58 | deepEqual(sort.stt instanceof SortableTable, true, 'Sort type');
|
59 | deepEqual(sort.sorted, false, 'Table not sorted');
|
60 | deepEqual(sort.initialized, true, 'Sort initialized');
|
61 | deepEqual(tf.paging, true, 'Table is paged');
|
62 | });
|
63 |
|
64 | module('UI elements');
|
65 | test('Sort UI elements', function() {
|
66 | var th = tf.getHeaderElement(0),
|
67 | indicator = tag(th, 'img');
|
68 |
|
69 | deepEqual(indicator.length, 1, 'Sort indicator in header element');
|
70 | });
|
71 |
|
72 | test('Sort behaviour', function() {
|
73 | sort.sortByColumnIndex(0);
|
74 | deepEqual(sort.sorted, true, 'Table column sorted');
|
75 | });
|
76 |
|
77 | module('Destroy and re-init');
|
78 | test('Remove sort', function() {
|
79 | sort.destroy();
|
80 | var th = tf.getHeaderElement(0),
|
81 | indicator = tag(th, 'img');
|
82 | deepEqual(sort.initialized, false, 'Sort is removed');
|
83 | deepEqual(indicator.length, 0, 'Sort indicator is removed');
|
84 | });
|
85 |
|
86 | }
|