1 | (function(win, TableFilter){
|
2 | var tf = new TableFilter('demo', {
|
3 | base_path: '../dist/tablefilter/',
|
4 | exclude_rows: [4, 9]
|
5 | });
|
6 | tf.init();
|
7 |
|
8 | module('Sanity checks');
|
9 | test('Excluded rows', function() {
|
10 | deepEqual(tf instanceof TableFilter, true, 'TableFilter type');
|
11 | deepEqual(tf.hasExcludedRows, true, 'Has excluded rows');
|
12 | deepEqual(tf.excludeRows, [4, 9], 'Excluded rows');
|
13 | });
|
14 |
|
15 | module('Behaviour');
|
16 | test('for filtered table', function() {
|
17 | tf.setFilterValue(0, 'Hello');
|
18 | tf.filter();
|
19 | var excludedRow1 = tf.dom().rows[4];
|
20 | var excludedRow2 = tf.dom().rows[9];
|
21 | deepEqual(
|
22 | tf.getRowDisplay(excludedRow1),
|
23 | '',
|
24 | 'Row display for excludedRow1'
|
25 | );
|
26 | deepEqual(
|
27 | tf.getRowDisplay(excludedRow2),
|
28 | '',
|
29 | 'Row display for excludedRow2'
|
30 | );
|
31 | });
|
32 |
|
33 | test('after filters are cleared', function() {
|
34 | tf.clearFilters();
|
35 | var excludedRow1 = tf.dom().rows[4];
|
36 | var excludedRow2 = tf.dom().rows[9];
|
37 | deepEqual(
|
38 | tf.getRowDisplay(excludedRow1),
|
39 | '',
|
40 | 'Row display for excludedRow1'
|
41 | );
|
42 | deepEqual(
|
43 | tf.getRowDisplay(excludedRow2),
|
44 | '',
|
45 | 'Row display for excludedRow2'
|
46 | );
|
47 | });
|
48 |
|
49 | test('setExcludeRows not called if no exclude rows', function() {
|
50 | tf.hasExcludedRows = false;
|
51 | var originalValidateRow = tf.validateRow;
|
52 | var hit = 0;
|
53 | tf.validateRow = function() { hit++; };
|
54 |
|
55 | tf.setExcludeRows();
|
56 |
|
57 | deepEqual(hit, 0, 'validateRow not called');
|
58 |
|
59 | tf.validateRow = originalValidateRow;
|
60 |
|
61 | testPaging();
|
62 | });
|
63 |
|
64 | function testPaging(){
|
65 | tf.destroy();
|
66 | tf = new TableFilter('demo', {
|
67 | base_path: '../dist/tablefilter/',
|
68 | exclude_rows: [4, 9],
|
69 | paging: {
|
70 | length: 2
|
71 | }
|
72 | });
|
73 | tf.init();
|
74 | var paging = tf.feature('paging');
|
75 |
|
76 | module('Behaviour with paging');
|
77 | test('for filtered table', function() {
|
78 | tf.setFilterValue(0, 'Hello');
|
79 | tf.filter();
|
80 | var excludedRow1 = tf.dom().rows[4];
|
81 | var excludedRow2 = tf.dom().rows[9];
|
82 | deepEqual(
|
83 | tf.getRowDisplay(excludedRow1),
|
84 | '',
|
85 | 'Row display for excludedRow1'
|
86 | );
|
87 | deepEqual(
|
88 | tf.getRowDisplay(excludedRow2),
|
89 | '',
|
90 | 'Row display for excludedRow2'
|
91 | );
|
92 | });
|
93 |
|
94 | test('after filters are cleared', function() {
|
95 | tf.clearFilters();
|
96 | var excludedRow1 = tf.dom().rows[4];
|
97 | var excludedRow2 = tf.dom().rows[9];
|
98 | deepEqual(
|
99 | tf.getRowDisplay(excludedRow1),
|
100 | 'none',
|
101 | 'Row display for excludedRow1'
|
102 | );
|
103 | deepEqual(
|
104 | tf.getRowDisplay(excludedRow2),
|
105 | 'none',
|
106 | 'Row display for excludedRow2'
|
107 | );
|
108 | });
|
109 |
|
110 | test('after changing pagination page', function() {
|
111 | paging.setPage(2);
|
112 | var excludedRow1 = tf.dom().rows[4];
|
113 | var excludedRow2 = tf.dom().rows[9];
|
114 | deepEqual(
|
115 | tf.getRowDisplay(excludedRow1),
|
116 | '',
|
117 | 'Row display for excludedRow1'
|
118 | );
|
119 | deepEqual(
|
120 | tf.getRowDisplay(excludedRow2),
|
121 | 'none',
|
122 | 'Row display for excludedRow2'
|
123 | );
|
124 |
|
125 | tf.destroy();
|
126 | });
|
127 | }
|
128 |
|
129 | })(window, TableFilter);
|