1 |
|
2 | var tf = new TableFilter('demo', {
|
3 | base_path: '../dist/tablefilter/',
|
4 | rows_counter: true
|
5 | });
|
6 | tf.init();
|
7 | var rowsCounter = tf.feature('rowsCounter');
|
8 |
|
9 | module('Sanity checks');
|
10 | test('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 |
|
16 | module('Feature interface');
|
17 | test('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 | });
|
34 | test('Can destroy', function() {
|
35 | rowsCounter.destroy();
|
36 | deepEqual(rowsCounter.initialized, false, 'not initialised');
|
37 | });
|
38 | test('Can reset', function() {
|
39 | rowsCounter.reset();
|
40 | deepEqual(rowsCounter.enabled, true, 'enabled');
|
41 | });
|
42 | test('Can disable', function() {
|
43 | rowsCounter.disable();
|
44 | deepEqual(rowsCounter.enabled, false, 'disabled');
|
45 | });
|
46 | test('Can enable', function() {
|
47 | rowsCounter.enable();
|
48 | deepEqual(rowsCounter.enabled, true, 'enabled');
|
49 | });
|
50 | test('Can init', function() {
|
51 | rowsCounter.destroy();
|
52 | rowsCounter.enable();
|
53 | rowsCounter.init();
|
54 | deepEqual(rowsCounter.enabled, true, 'enabled');
|
55 | });
|
56 | test('Can check is enabled', function() {
|
57 | rowsCounter.isEnabled();
|
58 | deepEqual(rowsCounter.enabled, true, 'enabled');
|
59 | });
|
60 |
|
61 | module('Behaviour');
|
62 | test('RowsCounter value', function() {
|
63 | equal(rowsCounter.label.innerHTML,
|
64 | 7, 'Counter value');
|
65 | });
|
66 |
|
67 | test('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 |
|
77 | module('Pagination');
|
78 | test('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 | });
|
96 | test('Can calculate page on page change', function() {
|
97 |
|
98 | var paging = tf.feature('paging');
|
99 |
|
100 |
|
101 | paging.setPage(2);
|
102 |
|
103 |
|
104 | equal(tf.feature('rowsCounter').label.innerHTML,
|
105 | '4~6 \\ 7', 'Counter value with paging');
|
106 | });
|
107 |
|
108 | module('Tear-down');
|
109 | test('can destroy TableFilter DOM elements', function() {
|
110 | tf.destroy();
|
111 | deepEqual(tf.isInitialized(), false, 'Filters removed');
|
112 | });
|