mirror of
https://github.com/koalyptus/TableFilter.git
synced 2026-03-18 00:19:50 +01:00
Started unit tests for filter operators
This commit is contained in:
parent
91cd6a88c5
commit
20517cdfe2
13 changed files with 9552 additions and 36 deletions
80
test/test-filter-operators.html
Normal file
80
test/test-filter-operators.html
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>TableFilter filter operators</title>
|
||||
<link rel="stylesheet" href="libs/qunit/qunit.css">
|
||||
<script src="libs/qunit/qunit.js"></script>
|
||||
<script src="libs/polyfill.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<table id="demo">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>Destination</th>
|
||||
<th>Road Distance (km)</th>
|
||||
<th>By Air (hrs)</th>
|
||||
<th>By Rail (hrs)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Adelaide</td>
|
||||
<td>1412</td>
|
||||
<td>1.4</td>
|
||||
<td>25.3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Brisbane</td>
|
||||
<td>982</td>
|
||||
<td>1.5</td>
|
||||
<td>16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Canberra</td>
|
||||
<td>286</td>
|
||||
<td>.6</td>
|
||||
<td>4.3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Melbourne</td>
|
||||
<td>872</td>
|
||||
<td>1.1</td>
|
||||
<td>10.5</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Adelaide</strong></td>
|
||||
<td>Perth</td>
|
||||
<td>2781</td>
|
||||
<td>3.1</td>
|
||||
<td>38</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Adelaide</strong></td>
|
||||
<td>Alice Springs</td>
|
||||
<td>1533</td>
|
||||
<td>2</td>
|
||||
<td>20.25</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Adelaide</strong></td>
|
||||
<td>Brisbane</td>
|
||||
<td>2045</td>
|
||||
<td>2.15</td>
|
||||
<td>40</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script src="../dist/tablefilter/tablefilter.js"></script>
|
||||
<script src="test-filter-operators.js"></script>
|
||||
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
</body>
|
||||
</html>
|
||||
54
test/test-filter-operators.js
Normal file
54
test/test-filter-operators.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
(function(win, TableFilter){
|
||||
|
||||
var tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/'
|
||||
});
|
||||
tf.init();
|
||||
|
||||
module('Sanity checks');
|
||||
test('No filters', function() {
|
||||
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
||||
notEqual(tf.getFilterElement(0), null, 'Filter generated');
|
||||
});
|
||||
|
||||
module('Operators');
|
||||
test('Regex operator', function() {
|
||||
tf.setFilterValue(3, 'rgx:[4-5]');
|
||||
tf.filter();
|
||||
var filteredData = tf.getFilteredData();
|
||||
deepEqual(tf.getValidRows().length, 3, 'Expected number of matches');
|
||||
deepEqual(
|
||||
filteredData[1],
|
||||
[3, ['Sydney', 'Brisbane', '982', '1.5', '16']],
|
||||
'Expected row data');
|
||||
});
|
||||
|
||||
// test('Paging with no filters', function() {
|
||||
// tf.destroy();
|
||||
// tf = null;
|
||||
// tf = new TableFilter('demo', {
|
||||
// base_path: '../dist/tablefilter/',
|
||||
// grid: false,
|
||||
// paging: true,
|
||||
// paging_length: 3
|
||||
// });
|
||||
// tf.init();
|
||||
// deepEqual(tf.getFilterElement(4), null,
|
||||
// 'No filter element for column 4');
|
||||
// });
|
||||
|
||||
// test('Grid layout with no filters', function() {
|
||||
// tf.destroy();
|
||||
// tf = null;
|
||||
// tf = new TableFilter('demo', {
|
||||
// base_path: '../dist/tablefilter/',
|
||||
// grid_enable_default_filters: false,
|
||||
// col_width: ['100px','100px','100px','100px','100px'],
|
||||
// grid_layout: true
|
||||
// });
|
||||
// tf.init();
|
||||
// deepEqual(tf.getFilterElement(2), null,
|
||||
// 'No filter element for column 2');
|
||||
// });
|
||||
|
||||
})(window, TableFilter);
|
||||
17
test/test.js
17
test/test.js
|
|
@ -24,13 +24,15 @@
|
|||
document.querySelector('.test'),
|
||||
{
|
||||
base_path: '../dist/tablefilter/',
|
||||
filters_row_index: 1
|
||||
filters_row_index: 1,
|
||||
btn: true
|
||||
}
|
||||
);
|
||||
tf1.init();
|
||||
var btn = document.querySelector('#'+tf1.prfxValButton+'4_'+tf1.id);
|
||||
|
||||
module("Table 2: sanity checks");
|
||||
test("TableFilter object", function() {
|
||||
module('Table 2: sanity checks');
|
||||
test('TableFilter object', function() {
|
||||
notEqual(tf1.id, null, 'id check');
|
||||
equal(tf1.filtersRowIndex, 1, 'Filters row index');
|
||||
deepEqual(tf1.getCellsNb(), 5, 'filters type collection length');
|
||||
|
|
@ -45,5 +47,14 @@
|
|||
);
|
||||
equal(tf1.getFilterElement(0).nodeName, 'INPUT', 'Filter DOM element');
|
||||
});
|
||||
test('Filter button', function(){
|
||||
notEqual(btn, null, 'Button exists');
|
||||
deepEqual(btn.nodeName, 'INPUT', 'Expected element');
|
||||
});
|
||||
test('Filter button click event', function(){
|
||||
tf1.setFilterValue(4, '>30');
|
||||
btn.click();
|
||||
deepEqual(tf1.getValidRows().length, 2, 'Filter button event result');
|
||||
});
|
||||
|
||||
})(window, TableFilter);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue