mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-05-23 16:52:26 +02:00
Added Store unit tests
This commit is contained in:
parent
be57e7bb09
commit
92cfcf8d9f
|
@ -2848,7 +2848,7 @@ TableFilter.prototype = {
|
|||
var slcR = this.resultsPerPageSlc;
|
||||
var slcPagesSelIndex = (this.pageSelectorType==this.fltTypeSlc) ?
|
||||
this.pagingSlc.selectedIndex :
|
||||
parseInt(this.pagingSlc.value-1,10);
|
||||
parseInt(this.pagingSlc.value-1, 10);
|
||||
this.pagingLength = parseInt(slcR.options[slcR.selectedIndex].value,10);
|
||||
this.startPagingRow = this.pagingLength*slcPagesSelIndex;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// Configure RequireJS so it resolves relative module paths from the `src`
|
||||
// folder.
|
||||
require.config({
|
||||
baseUrl: '../src',
|
||||
baseUrl: '../src'
|
||||
});
|
||||
|
||||
}());
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>TableFilter alternate rows tests</title>
|
||||
<title>TableFilter grid layout</title>
|
||||
<link rel="stylesheet" href="libs/qunit/qunit.css">
|
||||
<link rel="stylesheet" href="../dist/filtergrid.css">
|
||||
<script src="libs/qunit/qunit.js"></script>
|
||||
|
|
82
test/test-store.html
Normal file
82
test/test-store.html
Normal file
|
@ -0,0 +1,82 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>TableFilter store</title>
|
||||
<link rel="stylesheet" href="libs/qunit/qunit.css">
|
||||
<link rel="stylesheet" href="../dist/filtergrid.css">
|
||||
<script src="libs/qunit/qunit.js"></script>
|
||||
<script>
|
||||
// Defer Qunit so RequireJS can work its magic and resolve all modules.
|
||||
QUnit.config.autostart = false;
|
||||
QUnit.config.autoload = false;
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<table id="demo" cellpadding="0" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>Destination</th>
|
||||
<th>Road Distance (km)</th>
|
||||
<th>By Air (hrs)</th>
|
||||
<th>By Rail (hrs)</th>
|
||||
</tr>
|
||||
<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 data-main="test-store" src="../libs/requirejs/require.js"></script>
|
||||
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
</body>
|
||||
</html>
|
64
test/test-store.js
Normal file
64
test/test-store.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
requirejs(['test-config', '../src/core'], function(config, TableFilter){
|
||||
|
||||
QUnit.start();
|
||||
|
||||
var Store = require('modules/store').Store;
|
||||
var Cookie = require('cookie').Cookie;
|
||||
|
||||
var tf = new TableFilter('demo', {
|
||||
paging: true,
|
||||
paging_length: 2,
|
||||
results_per_page: ['Results per page', [2,4,6]],
|
||||
remember_grid_values: true,
|
||||
remember_page_number: true,
|
||||
remember_page_length: true
|
||||
});
|
||||
|
||||
Cookie.remove(tf.fltsValuesCookie);
|
||||
Cookie.remove(tf.pgNbCookie);
|
||||
Cookie.remove(tf.pgLenCookie);
|
||||
|
||||
tf.init();
|
||||
tf._ClearFilters();
|
||||
|
||||
module('Sanity checks');
|
||||
test('Store module', function() {
|
||||
deepEqual(tf.Cpt.Store instanceof Store, true, 'Store type');
|
||||
notEqual(tf.Cpt.Store, null, 'Store instanciated');
|
||||
deepEqual(tf.Cpt.Store.duration, 100000, 'Store duration');
|
||||
});
|
||||
|
||||
module('Check page number persistence');
|
||||
test('Page number value', function() {
|
||||
tf._ClearFilters();
|
||||
tf._Filter();
|
||||
tf._ChangePage(1);
|
||||
var cookieName = tf.pgNbCookie;
|
||||
deepEqual(tf.Cpt.Store.getPageNb(cookieName), '2', 'Page number value');
|
||||
tf._ClearFilters();
|
||||
tf._Filter();
|
||||
});
|
||||
|
||||
module('Check page length persistence');
|
||||
test('Page length value', function() {
|
||||
tf.resultsPerPageSlc.options[2].selected = true;
|
||||
tf._ChangeResultsPerPage();
|
||||
var cookieName = tf.pgLenCookie;
|
||||
deepEqual(tf.Cpt.Store.getPageLength(cookieName), '2', 'Page length value');
|
||||
tf._ClearFilters();
|
||||
tf._Filter();
|
||||
});
|
||||
|
||||
module('Check filters persistence');
|
||||
test('Filters value', function() {
|
||||
tf.SetFilterValue(0, 'Sydney');
|
||||
tf.SetFilterValue(3, '1.5');
|
||||
tf._Filter();
|
||||
var cookieName = tf.fltsValuesCookie;
|
||||
deepEqual(tf.Cpt.Store.getFilterValues(cookieName)[0], 'Sydney', 'Filter 0 value');
|
||||
deepEqual(tf.Cpt.Store.getFilterValues(cookieName)[3], '1.5', 'Filter 3 value');
|
||||
tf._ClearFilters();
|
||||
tf._Filter();
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in a new issue