2014-11-16 01:29:07 +01:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
var tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
|
|
|
rows_counter: true
|
|
|
|
});
|
|
|
|
tf.init();
|
2015-11-14 16:14:13 +01:00
|
|
|
var rowsCounter = tf.feature('rowsCounter');
|
2014-11-16 01:29:07 +01:00
|
|
|
|
2015-05-14 12:08:19 +02:00
|
|
|
module('Sanity checks');
|
|
|
|
test('RowsCounter component', function() {
|
2015-11-14 16:14:13 +01:00
|
|
|
notEqual(rowsCounter, null, 'RowsCounter instanciated');
|
2016-11-01 03:58:25 +01:00
|
|
|
notEqual(rowsCounter.container, null, 'RowsCounter container element');
|
|
|
|
notEqual(rowsCounter.label, null, 'RowsCounter label element');
|
2015-05-14 12:08:19 +02:00
|
|
|
});
|
2015-01-26 10:31:25 +01:00
|
|
|
|
2015-11-14 16:14:13 +01:00
|
|
|
module('Feature interface');
|
|
|
|
test('Properties', function() {
|
|
|
|
deepEqual(
|
|
|
|
rowsCounter.tf instanceof TableFilter, true, 'TableFilter instance');
|
|
|
|
deepEqual(rowsCounter.feature, 'rowsCounter', 'Feature name');
|
|
|
|
deepEqual(rowsCounter.enabled, true, 'Feature enabled');
|
|
|
|
deepEqual(rowsCounter.initialized, true, 'Feature enabled');
|
2015-12-28 01:18:55 +01:00
|
|
|
deepEqual(typeof rowsCounter.emitter, 'object',
|
|
|
|
'Feature has emitter instance');
|
2015-11-14 16:14:13 +01:00
|
|
|
deepEqual(typeof rowsCounter.config, 'object', 'TF configuration object');
|
|
|
|
deepEqual(typeof rowsCounter.init, 'function', 'Feature init method');
|
|
|
|
deepEqual(typeof rowsCounter.destroy, 'function', 'Feature destroy method');
|
|
|
|
deepEqual(typeof rowsCounter.reset, 'function', 'Feature reset method');
|
|
|
|
deepEqual(typeof rowsCounter.enable, 'function', 'Feature enable method');
|
|
|
|
deepEqual(typeof rowsCounter.disable, 'function', 'Feature enable method');
|
|
|
|
deepEqual(
|
|
|
|
typeof rowsCounter.isEnabled, 'function', 'Feature enable method');
|
|
|
|
});
|
|
|
|
test('Can destroy', function() {
|
|
|
|
rowsCounter.destroy();
|
2015-12-06 12:33:11 +01:00
|
|
|
deepEqual(rowsCounter.initialized, false, 'not initialised');
|
2015-11-14 16:14:13 +01:00
|
|
|
});
|
|
|
|
test('Can reset', function() {
|
|
|
|
rowsCounter.reset();
|
|
|
|
deepEqual(rowsCounter.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
test('Can disable', function() {
|
|
|
|
rowsCounter.disable();
|
|
|
|
deepEqual(rowsCounter.enabled, false, 'disabled');
|
|
|
|
});
|
|
|
|
test('Can enable', function() {
|
|
|
|
rowsCounter.enable();
|
|
|
|
deepEqual(rowsCounter.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
test('Can init', function() {
|
|
|
|
rowsCounter.destroy();
|
|
|
|
rowsCounter.enable();
|
|
|
|
rowsCounter.init();
|
|
|
|
deepEqual(rowsCounter.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
test('Can check is enabled', function() {
|
|
|
|
rowsCounter.isEnabled();
|
|
|
|
deepEqual(rowsCounter.enabled, true, 'enabled');
|
|
|
|
});
|
|
|
|
|
|
|
|
module('Behaviour');
|
|
|
|
test('RowsCounter value', function() {
|
2016-08-05 17:26:53 +02:00
|
|
|
equal(rowsCounter.label.innerHTML,
|
2015-07-01 10:01:52 +02:00
|
|
|
7, 'Counter value');
|
2015-05-14 12:08:19 +02:00
|
|
|
});
|
2014-11-16 01:29:07 +01:00
|
|
|
|
2015-07-01 10:01:52 +02:00
|
|
|
test('RowsCounter component with filtered table', function() {
|
|
|
|
tf.setFilterValue(0, 'Syd');
|
|
|
|
tf.filter();
|
|
|
|
|
2016-08-05 17:26:53 +02:00
|
|
|
equal(rowsCounter.label.innerHTML,
|
2015-07-01 10:01:52 +02:00
|
|
|
4, 'Counter value');
|
|
|
|
|
|
|
|
tf.clearFilters();
|
|
|
|
});
|
|
|
|
|
2015-11-14 16:14:13 +01:00
|
|
|
module('Pagination');
|
2015-07-01 10:01:52 +02:00
|
|
|
test('RowsCounter component with paging', function() {
|
|
|
|
tf.destroy();
|
|
|
|
tf = null;
|
|
|
|
tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
2017-05-02 14:31:02 +02:00
|
|
|
rows_counter: {
|
|
|
|
text: 'Records: ',
|
|
|
|
separator: '~',
|
|
|
|
over_text: ' \\ '
|
|
|
|
},
|
2017-06-14 14:12:44 +02:00
|
|
|
paging: {
|
|
|
|
length: 3
|
|
|
|
}
|
2015-07-01 10:01:52 +02:00
|
|
|
});
|
|
|
|
tf.init();
|
2016-08-05 17:26:53 +02:00
|
|
|
equal(tf.feature('rowsCounter').label.innerHTML,
|
2017-05-02 14:31:02 +02:00
|
|
|
'1~3 \\ 7', 'Counter value with paging');
|
2016-05-26 09:23:21 +02:00
|
|
|
});
|
|
|
|
test('Can calculate page on page change', function() {
|
|
|
|
//setup
|
|
|
|
var paging = tf.feature('paging');
|
|
|
|
|
|
|
|
//act
|
|
|
|
paging.setPage(2);
|
|
|
|
|
|
|
|
//assert
|
2016-08-05 17:26:53 +02:00
|
|
|
equal(tf.feature('rowsCounter').label.innerHTML,
|
2017-05-02 14:31:02 +02:00
|
|
|
'4~6 \\ 7', 'Counter value with paging');
|
2014-11-16 01:29:07 +01:00
|
|
|
});
|
2015-11-16 13:21:19 +01:00
|
|
|
|
|
|
|
module('Tear-down');
|
|
|
|
test('can destroy TableFilter DOM elements', function() {
|
|
|
|
tf.destroy();
|
2016-05-27 09:40:22 +02:00
|
|
|
deepEqual(tf.isInitialized(), false, 'Filters removed');
|
2015-11-16 13:21:19 +01:00
|
|
|
});
|