UNPKG

3.58 kBJavaScriptView Raw
1
2var tf = new TableFilter('demo', {
3 base_path: '../dist/tablefilter/',
4 rows_counter: true
5});
6tf.init();
7var rowsCounter = tf.feature('rowsCounter');
8
9module('Sanity checks');
10test('RowsCounter component', function() {
11 notEqual(rowsCounter, null, 'RowsCounter instanciated');
12 notEqual(rowsCounter.container, null, 'RowsCounter container element');
13 notEqual(rowsCounter.label, null, 'RowsCounter label element');
14});
15
16module('Feature interface');
17test('Properties', function() {
18 deepEqual(
19 rowsCounter.tf instanceof TableFilter, true, 'TableFilter instance');
20 deepEqual(rowsCounter.feature, 'rowsCounter', 'Feature name');
21 deepEqual(rowsCounter.enabled, true, 'Feature enabled');
22 deepEqual(rowsCounter.initialized, true, 'Feature enabled');
23 deepEqual(typeof rowsCounter.emitter, 'object',
24 'Feature has emitter instance');
25 deepEqual(typeof rowsCounter.config, 'object', 'TF configuration object');
26 deepEqual(typeof rowsCounter.init, 'function', 'Feature init method');
27 deepEqual(typeof rowsCounter.destroy, 'function', 'Feature destroy method');
28 deepEqual(typeof rowsCounter.reset, 'function', 'Feature reset method');
29 deepEqual(typeof rowsCounter.enable, 'function', 'Feature enable method');
30 deepEqual(typeof rowsCounter.disable, 'function', 'Feature enable method');
31 deepEqual(
32 typeof rowsCounter.isEnabled, 'function', 'Feature enable method');
33});
34test('Can destroy', function() {
35 rowsCounter.destroy();
36 deepEqual(rowsCounter.initialized, false, 'not initialised');
37});
38test('Can reset', function() {
39 rowsCounter.reset();
40 deepEqual(rowsCounter.enabled, true, 'enabled');
41});
42test('Can disable', function() {
43 rowsCounter.disable();
44 deepEqual(rowsCounter.enabled, false, 'disabled');
45});
46test('Can enable', function() {
47 rowsCounter.enable();
48 deepEqual(rowsCounter.enabled, true, 'enabled');
49});
50test('Can init', function() {
51 rowsCounter.destroy();
52 rowsCounter.enable();
53 rowsCounter.init();
54 deepEqual(rowsCounter.enabled, true, 'enabled');
55});
56test('Can check is enabled', function() {
57 rowsCounter.isEnabled();
58 deepEqual(rowsCounter.enabled, true, 'enabled');
59});
60
61module('Behaviour');
62test('RowsCounter value', function() {
63 equal(rowsCounter.label.innerHTML,
64 7, 'Counter value');
65});
66
67test('RowsCounter component with filtered table', function() {
68 tf.setFilterValue(0, 'Syd');
69 tf.filter();
70
71 equal(rowsCounter.label.innerHTML,
72 4, 'Counter value');
73
74 tf.clearFilters();
75});
76
77module('Pagination');
78test('RowsCounter component with paging', function() {
79 tf.destroy();
80 tf = null;
81 tf = new TableFilter('demo', {
82 base_path: '../dist/tablefilter/',
83 rows_counter: {
84 text: 'Records: ',
85 separator: '~',
86 over_text: ' \\ '
87 },
88 paging: {
89 length: 3
90 }
91 });
92 tf.init();
93 equal(tf.feature('rowsCounter').label.innerHTML,
94 '1~3 \\ 7', 'Counter value with paging');
95});
96test('Can calculate page on page change', function() {
97 //setup
98 var paging = tf.feature('paging');
99
100 //act
101 paging.setPage(2);
102
103 //assert
104 equal(tf.feature('rowsCounter').label.innerHTML,
105 '4~6 \\ 7', 'Counter value with paging');
106});
107
108module('Tear-down');
109test('can destroy TableFilter DOM elements', function() {
110 tf.destroy();
111 deepEqual(tf.isInitialized(), false, 'Filters removed');
112});