UNPKG

1.8 kBJavaScriptView Raw
1var tf = new TableFilter('demo', {
2 base_path: '../dist/tablefilter/'
3});
4tf.init();
5
6module('filtering');
7test('ignore uneven rows', function() {
8 // act
9 tf.setFilterValue(1, 'Perth');
10 tf.filter();
11
12 // assert
13 deepEqual(tf.getValidRows(), [9], 'uneven row');
14 deepEqual(tf.getRowDisplay(tf.dom().rows[4]), '', 'uneven row displayed');
15 deepEqual(tf.getRowDisplay(tf.dom().rows[5]), '', 'uneven row displayed');
16 deepEqual(tf.getRowDisplay(tf.dom().rows[5]), '', 'uneven row displayed');
17});
18
19test('display uneven rows when no matches', function() {
20 // act
21 tf.clearFilters();
22 tf.setFilterValue(0, '123');
23 tf.filter();
24
25 // assert
26 deepEqual(tf.getValidRows(), [], 'uneven row');
27 deepEqual(tf.getRowDisplay(tf.dom().rows[4]), '', 'uneven row displayed');
28 deepEqual(tf.getRowDisplay(tf.dom().rows[5]), '', 'uneven row displayed');
29 deepEqual(tf.getRowDisplay(tf.dom().rows[5]), '', 'uneven row displayed');
30});
31
32module('re-initialise');
33test('can re-initialise', function() {
34 // act
35 tf.destroy();
36 tf.init();
37
38 // assert
39 deepEqual(tf.isInitialized(), true, 'Filters re-initialised');
40});
41
42test('can filter', function() {
43 // act
44 tf.setFilterValue(1, 'Perth');
45 tf.filter();
46
47 // assert
48 deepEqual(tf.getValidRows(), [9], 'uneven row');
49 deepEqual(tf.getRowDisplay(tf.dom().rows[4]), '', 'uneven row displayed');
50 deepEqual(tf.getRowDisplay(tf.dom().rows[5]), '', 'uneven row displayed');
51 deepEqual(tf.getRowDisplay(tf.dom().rows[5]), '', 'uneven row displayed');
52});
53
54module('tear-down');
55test('can destroy', function() {
56 // act
57 tf.destroy();
58
59 // assert
60 deepEqual(tf.isInitialized(), false, 'Filters removed');
61});