mirror of
https://github.com/koalyptus/TableFilter.git
synced 2026-03-14 22:55:44 +01:00
more unit tests
This commit is contained in:
parent
949f21f446
commit
d69f60aced
11 changed files with 101 additions and 11 deletions
|
|
@ -8,6 +8,7 @@
|
|||
<script src="libs/polyfill.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="external-container"></div>
|
||||
<table id="demo" cellpadding="0" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
|
|
@ -75,4 +76,4 @@
|
|||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -58,6 +58,61 @@ test('Can check is enabled', function() {
|
|||
deepEqual(clearButton.enabled, true, 'enabled');
|
||||
});
|
||||
|
||||
module('Behaviour');
|
||||
test('Cannot init if already initialised', function() {
|
||||
// setup
|
||||
clearButton.initialized = true;
|
||||
var emit = clearButton.emitter.emit;
|
||||
var hit = 0;
|
||||
clearButton.emitter.emit = function() {
|
||||
hit++;
|
||||
};
|
||||
|
||||
// act
|
||||
clearButton.init();
|
||||
|
||||
// assert
|
||||
deepEqual(hit, 0, 'does not initialise');
|
||||
|
||||
clearButton.emitter.emit = emit;
|
||||
});
|
||||
|
||||
test('onClick does nothing if not enabled', function() {
|
||||
// setup
|
||||
clearButton.disable();
|
||||
var clearFilters = clearButton.tf.clearFilters;
|
||||
var hit = 0;
|
||||
clearButton.tf.clearFilters = function() {
|
||||
hit++;
|
||||
};
|
||||
|
||||
// act
|
||||
clearButton.onClick();
|
||||
|
||||
// assert
|
||||
deepEqual(hit, 0, 'onClick does nothing');
|
||||
|
||||
clearButton.tf.clearFilters = clearFilters;
|
||||
});
|
||||
|
||||
test('onClick calls clearFilters if enabled', function() {
|
||||
// setup
|
||||
clearButton.enable();
|
||||
var clearFilters = clearButton.tf.clearFilters;
|
||||
var hit = 0;
|
||||
clearButton.tf.clearFilters = function() {
|
||||
hit++;
|
||||
};
|
||||
|
||||
// act
|
||||
clearButton.onClick();
|
||||
|
||||
// assert
|
||||
deepEqual(hit, 1, 'onClick calls clearFilters');
|
||||
|
||||
clearButton.tf.clearFilters = clearFilters;
|
||||
});
|
||||
|
||||
module('UI elements');
|
||||
test('ClearButton UI elements', function() {
|
||||
var container = clearButton.container;
|
||||
|
|
@ -73,7 +128,7 @@ test('Remove UI', function() {
|
|||
deepEqual(btnResetEl, null, 'Clear button is removed');
|
||||
});
|
||||
|
||||
test('Re-set UI', function() {
|
||||
test('Re-set UI with no icons and text button', function() {
|
||||
clearButton.destroy();
|
||||
tf.enableIcons = false;
|
||||
clearButton.html = null;
|
||||
|
|
@ -85,6 +140,40 @@ test('Re-set UI', function() {
|
|||
deepEqual(btnResetEl.innerText, 'Clear', 'Clear button text');
|
||||
});
|
||||
|
||||
test('Destroy and init with text button and icons enabled', function() {
|
||||
tf.destroy();
|
||||
tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
btn_reset: {
|
||||
text: 'Clear all'
|
||||
}
|
||||
});
|
||||
tf.init();
|
||||
|
||||
clearButton = tf.feature('clearButton');
|
||||
|
||||
var btnResetEl = clearButton.element;
|
||||
deepEqual(btnResetEl.nodeName, 'A', 'Clear button tag changed');
|
||||
deepEqual(btnResetEl.innerText, 'Clear all', 'Clear button text');
|
||||
});
|
||||
|
||||
test('Destroy and init in external container', function() {
|
||||
tf.destroy();
|
||||
tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
btn_reset: {
|
||||
target_id: 'external-container'
|
||||
}
|
||||
});
|
||||
tf.init();
|
||||
|
||||
clearButton = tf.feature('clearButton');
|
||||
|
||||
deepEqual(clearButton.element.nodeName, 'INPUT', 'Clear button tag');
|
||||
deepEqual(clearButton.container.parentNode.id, 'external-container',
|
||||
'container id');
|
||||
});
|
||||
|
||||
module('Tear-down');
|
||||
test('can destroy TableFilter DOM elements', function() {
|
||||
tf.destroy();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue