1 | (function(win, TableFilter){
|
2 |
|
3 | var tf = new TableFilter('demo', {
|
4 | base_path: '../dist/tablefilter/',
|
5 | col_0: 'select',
|
6 | cell_parser: {
|
7 | cols: [0],
|
8 | parse: function(tf, cell) {
|
9 | var chk = cell.getElementsByTagName('input')[0];
|
10 | if (chk.checked) {
|
11 | return 'yes';
|
12 | } else {
|
13 | return 'no';
|
14 | }
|
15 | }
|
16 | }
|
17 | });
|
18 | tf.init();
|
19 |
|
20 | module('Sanity checks');
|
21 | test('Sanity checks', function() {
|
22 | deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
23 | deepEqual(tf.cellParser.cols.length, 1,
|
24 | 'Columns implementing cell parser');
|
25 | deepEqual(typeof tf.cellParser.parse, 'function', 'Parse function');
|
26 | deepEqual(
|
27 | tf.getFilterElement(0).nodeName, 'SELECT', 'Expected filter type');
|
28 | });
|
29 |
|
30 | module('Behaviour');
|
31 | test('Can filter with parsed value', function() {
|
32 |
|
33 | tf.setFilterValue(0, 'yes');
|
34 |
|
35 |
|
36 | tf.filter();
|
37 |
|
38 |
|
39 | deepEqual(tf.getValidRows(), [2, 4, 5, 7], 'Number of parsed values');
|
40 | });
|
41 |
|
42 | test('Can parse with custom function', function() {
|
43 |
|
44 | var cell = tf.dom().rows[3].cells[0];
|
45 |
|
46 |
|
47 | var value = tf.getCellValue(cell);
|
48 |
|
49 |
|
50 | deepEqual(value, 'no', 'Value returned by custom cell parser');
|
51 | });
|
52 |
|
53 | test('Should not parse with custom function if no columns defined',
|
54 | function() {
|
55 |
|
56 | var initialCellParser = tf.cellParser;
|
57 | var hit = 0;
|
58 | var cell = tf.dom().rows[3].cells[0];
|
59 |
|
60 | tf.cellParser.cols = [];
|
61 | tf.cellParser.parse = function() {
|
62 | hit++;
|
63 | };
|
64 |
|
65 |
|
66 | tf.getCellValue(cell);
|
67 |
|
68 |
|
69 | deepEqual(hit, 0, 'Cell parser not invoked');
|
70 |
|
71 | tf.cellParser = initialCellParser;
|
72 | }
|
73 | );
|
74 |
|
75 | module('Tear-down');
|
76 | test('can destroy', function() {
|
77 | tf.destroy();
|
78 | deepEqual(tf.isInitialized(), false, 'Filters removed');
|
79 | });
|
80 | })(window, TableFilter);
|