Started dateType unit tests

This commit is contained in:
Max Guglielmi 2016-10-12 14:15:19 +11:00
parent d26ed8e2b9
commit c5b4251039
16 changed files with 24564 additions and 65 deletions

4
dist/starter.html vendored
View File

@ -1,10 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>tablefilter v0.3.2 - Starter</title>
<title>tablefilter v0.3.3 - Starter</title>
</head>
<body>
<h1>tablefilter v0.3.2</h1>
<h1>tablefilter v0.3.3</h1>

View File

@ -1,6 +1,6 @@
/**
* tablefilter v0.3.2 by Max Guglielmi
* build date: 2016-10-10T07:02:16.305Z
* tablefilter v0.3.3 by Max Guglielmi
* build date: 2016-10-11T03:04:52.541Z
* MIT License
*/
span.colVisSpan{text-align:left;}span.colVisSpan a.colVis{display:inline-block;padding:7px 5px 0;font-size:inherit;font-weight:inherit;vertical-align:top}div.colVisCont{position:relative;background:#fff;-webkit-box-shadow:3px 3px 2px #888;-moz-box-shadow:3px 3px 2px #888;box-shadow:3px 3px 2px #888;position:absolute;display:none;border:1px solid #ccc;height:auto;width:250px;background-color:#fff;margin:35px 0 0 -100px;z-index:10000;padding:10px 10px 10px 10px;text-align:left;font-size:12px;}div.colVisCont:after,div.colVisCont:before{bottom:100%;left:50%;border:solid transparent;content:" ";height:0;width:0;position:absolute;pointer-events:none}div.colVisCont:after{border-color:rgba(255,255,255,0);border-bottom-color:#fff;border-width:10px;margin-left:-10px}div.colVisCont:before{border-color:rgba(255,255,255,0);border-bottom-color:#ccc;border-width:12px;margin-left:-12px}div.colVisCont p{margin:6px auto 6px auto}div.colVisCont a.colVis{display:initial;font-weight:inherit}ul.cols_checklist{padding:0;margin:0;list-style:none;}ul.cols_checklist label{display:block}ul.cols_checklist input{vertical-align:middle;margin:2px 5px 2px 1px}li.cols_checklist_item{padding:4px;margin:0;}li.cols_checklist_item:hover{background-color:#335ea8;color:#fff}.cols_checklist_slc_item{background-color:#335ea8;color:#fff}

View File

@ -1,6 +1,6 @@
/**
* tablefilter v0.3.2 by Max Guglielmi
* build date: 2016-10-10T07:02:16.305Z
* tablefilter v0.3.3 by Max Guglielmi
* build date: 2016-10-11T03:04:52.541Z
* MIT License
*/
span.expClpFlt a.btnExpClpFlt{width:35px;height:35px;display:inline-block;}span.expClpFlt a.btnExpClpFlt:hover{background-color:#f4f4f4}span.expClpFlt img{padding:8px 11px 11px 11px}

View File

@ -1,6 +1,6 @@
/**
* tablefilter v0.3.2 by Max Guglielmi
* build date: 2016-10-10T07:02:16.305Z
* tablefilter v0.3.3 by Max Guglielmi
* build date: 2016-10-11T03:04:52.541Z
* MIT License
*/
.activeHeader{background-color:#66afe9 !important;color:#fff !important}

View File

@ -1,6 +1,6 @@
/**
* tablefilter v0.3.2 by Max Guglielmi
* build date: 2016-10-10T07:02:16.305Z
* tablefilter v0.3.3 by Max Guglielmi
* build date: 2016-10-11T03:04:52.541Z
* MIT License
*/
table.TF{border-left:1px solid #ccc;border-top:none;border-right:none;border-bottom:none;}table.TF th{background:#ebecee url("images/bg_th.jpg") left top repeat-x;border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;border-left:1px solid #fff;border-top:1px solid #fff;color:#333}table.TF td{border-bottom:1px dotted #999;padding:5px}.fltrow{background-color:#ebecee !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #666 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #999 !important}input.flt{width:99% !important}.inf{height:$min-height;background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important}input.reset{background:transparent url("images/btn_eraser.gif") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;}.nextPage:hover{background:transparent url("images/btn_over_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important;}.previousPage:hover{background:transparent url("images/btn_over_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;}.firstPage:hover{background:transparent url("images/btn_over_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;}.lastPage:hover{background:transparent url("images/btn_over_last_page.gif") center center no-repeat !important}div.grd_Cont{background-color:#ebecee !important;border:1px solid #ccc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#d5d5d5}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important;}div.grd_headTblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#ebecee url("images/bg_th.jpg") left top repeat-x !important;border-bottom:1px solid #d0d0d0 !important;border-right:1px solid #d0d0d0 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #999 !important}.grd_inf{background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important;border-top:1px solid #d0d0d0 !important}.loader{border:1px solid #999}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#fff}.odd{background-color:#d5d5d5}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.activeHeader{background:#999 !important}

View File

@ -1,6 +1,6 @@
/**
* tablefilter v0.3.2 by Max Guglielmi
* build date: 2016-10-10T07:02:16.305Z
* tablefilter v0.3.3 by Max Guglielmi
* build date: 2016-10-11T03:04:52.541Z
* MIT License
*/
table.TF{border-left:1px dotted #81963b;border-top:none;border-right:0;border-bottom:none;}table.TF th{background:#39424b url("images/bg_headers.jpg") left top repeat-x;border-bottom:0;border-right:1px dotted #d0d0d0;border-left:0;border-top:0;color:#fff}table.TF td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b;padding:5px}.fltrow{background-color:#81963b !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #687830 !important}input.flt{width:99% !important}.inf{background:#d8d8d8;height:$min-height}input.reset{width:53px;background:transparent url("images/btn_filter.png") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important}div.grd_Cont{background:#81963b url("images/bg_headers.jpg") left top repeat-x !important;border:1px solid #ccc !important;padding:0 1px 1px 1px !important;}div.grd_Cont .even{background-color:#bccd83}div.grd_Cont .odd{background-color:#fff}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important;}div.grd_tblCont table td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b}div.grd_tblCont table th,div.grd_headTblCont table th{background:transparent url("images/bg_headers.jpg") 0 0 repeat-x !important;border-bottom:0 !important;border-right:1px dotted #d0d0d0 !important;border-left:0 !important;border-top:0 !important;padding:0 4px 0 4px !important;color:#fff !important;height:35px !important}div.grd_headTblCont table td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;background-color:#81963b !important;padding:1px 3px 1px 3px !important}.grd_inf{background-color:#d8d8d8;border-top:1px solid #d0d0d0 !important}.loader{border:0 !important;background:#81963b !important}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#bccd83}.odd{background-color:#fff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.activeHeader{background:#81963b !important}

View File

@ -1,6 +1,6 @@
/**
* tablefilter v0.3.2 by Max Guglielmi
* build date: 2016-10-10T07:02:16.305Z
* tablefilter v0.3.3 by Max Guglielmi
* build date: 2016-10-11T03:04:52.541Z
* MIT License
*/
table.TF{padding:0;color:#000;border-right:1px solid #a4bed4;border-top:1px solid #a4bed4;border-left:1px solid #a4bed4;border-bottom:0;}table.TF th{margin:0;color:inherit;background:#d1e5fe url("images/bg_skyblue.gif") 0 0 repeat-x;border-color:#fdfdfd #a4bed4 #a4bed4 #fdfdfd;border-width:1px;border-style:solid}table.TF td{margin:0;padding:5px;color:inherit;border-bottom:1px solid #a4bed4;border-left:0;border-top:0;border-right:0}.fltrow{background-color:#d1e5fe !important;}.fltrow th,.fltrow td{padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #a4bed4 !important}input.flt{width:99% !important}.inf{background-color:#e3efff !important;border:1px solid #a4bed4;height:$min-height;color:#004a6f}div.tot,div.status{border-right:0 !important}.helpBtn:hover{background-color:transparent}input.reset{background:transparent url("images/icn_clear_filters.png") center center no-repeat !important}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.nextPage:hover{background:#ffe4ab url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.previousPage{background:transparent url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.previousPage:hover{background:#ffe4ab url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.firstPage:hover{background:#ffe4ab url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.lastPage:hover{background:#ffe4ab url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.activeHeader{background:#ffe4ab !important;border:1px solid #ffb552 !important;color:inherit !important}div.grd_Cont{background-color:#d9eaed !important;border:1px solid #9cc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#e3efff}div.grd_headTblCont{background-color:#d9eaed !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#d9eaed url("images/bg_skyblue.gif") left top repeat-x;border-bottom:1px solid #a4bed4;border-right:1px solid #a4bed4 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #a4bed4 !important;border-right:0 !important;border-left:0 !important;border-top:0 !important}.grd_inf{background-color:#cce2fe;color:#004a6f;border-top:1px solid #9cc !important;}.grd_inf a{text-decoration:none;font-weight:bold}.loader{background-color:#2d8eef;border:1px solid #cce2fe;border-radius:5px}.even{background-color:#fff}.odd{background-color:#e3efff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.ezActiveRow{background-color:#ffdc61 !important;color:inherit}.ezSelectedRow{background-color:#ffe4ab !important;color:inherit}.ezActiveCell{background-color:#fff !important;color:#000 !important;font-weight:bold}.ezETSelectedCell{background-color:#fff !important;font-weight:bold;color:#000 !important}

File diff suppressed because one or more lines are too long

2828
dist/tablefilter/tf-1.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "tablefilter",
"version": "0.3.2",
"version": "0.3.3",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {
@ -33,7 +33,7 @@
"babel-loader": "^6.2.5",
"babel-plugin-transform-es2015-classes": "^6.14.0",
"babel-preset-es2015": "^6.16.0",
"clean-webpack-plugin": "^0.1.12",
"clean-webpack-plugin": "^0.1.13",
"grunt": "^1.0.1",
"grunt-babel": "^6.0.0",
"grunt-contrib-clean": "^1.0.0",
@ -46,7 +46,7 @@
"grunt-eslint": "19.0.0",
"grunt-gh-pages": "^2.0.0",
"grunt-string-replace": "^1.3.1",
"grunt-webpack": "^1.0.16",
"grunt-webpack": "^1.0.18",
"script-loader": "^0.7.0",
"string-replace-webpack-plugin": "^0.0.4",
"sugar-date": "2.0.0",

View File

@ -149,8 +149,7 @@ export default class AdapterSortableTable extends Feature {
}
// Add any date format if needed
let dateType = tf.feature('dateType');
dateType.addConfigFormats(this.sortTypes);
this.emitter.emit('add-date-type-formats', this.tf, this.sortTypes);
this.overrideSortableTable();
this.setSortTypes();

View File

@ -47,6 +47,11 @@ export class DateType extends Feature {
// Add formats from column types configuration if any
this.addConfigFormats(this.tf.colTypes);
this.emitter.on(
['add-date-type-formats'],
(tf, types) => this.addConfigFormats(types)
);
// Broadcast date-type initialization
this.emitter.emit('date-type-initialized', this.tf, this);
@ -127,6 +132,11 @@ export class DateType extends Feature {
// TODO: remove added formats
this.emitter.off(
['add-date-type-formats'],
(tf, types) => this.addConfigFormats(types)
);
this.initialized = false;
}
}

View File

@ -45,48 +45,47 @@ export class HighlightKeyword {
);
this.emitter.on(
['highlight-keyword'],
(tf, cell, word) =>
this.highlight(cell, word, this.highlightCssClass)
(tf, cell, term) =>
this.highlight(cell, term, this.highlightCssClass)
);
}
/**
* Highlight occurences of searched term in passed node
* @param {Node} node
* @param {String} word Searched term
* @param {String} term Searched term
* @param {String} cssClass Css class name
*
* TODO: refactor this method
*/
highlight(node, word, cssClass) {
highlight(node, term, cssClass) {
// Iterate into this nodes childNodes
if (node.hasChildNodes) {
let children = node.childNodes;
for (let i = 0; i < children.length; i++) {
this.highlight(children[i], word, cssClass);
this.highlight(children[i], term, cssClass);
}
}
if (node.nodeType === 3) {
let tempNodeVal = node.nodeValue.toLowerCase();
let tempWordVal = word.toLowerCase();
let nodeVal = node.nodeValue.toLowerCase();
let termIdx = nodeVal.indexOf(term.toLowerCase());
if (tempNodeVal.indexOf(tempWordVal) !== -1) {
if (termIdx !== -1) {
let pn = node.parentNode;
if (pn && pn.className !== cssClass) {
// word not highlighted yet
// term not highlighted yet
let nv = node.nodeValue,
ni = tempNodeVal.indexOf(tempWordVal),
// Create a load of replacement nodes
before = createText(nv.substr(0, ni)),
docWordVal = nv.substr(ni, word.length),
after = createText(nv.substr(ni + word.length)),
hiwordtext = createText(docWordVal),
hiword = createElm('span');
hiword.className = cssClass;
hiword.appendChild(hiwordtext);
before = createText(nv.substr(0, termIdx)),
value = nv.substr(termIdx, term.length),
after = createText(nv.substr(termIdx + term.length)),
text = createText(value),
container = createElm('span');
container.className = cssClass;
container.appendChild(text);
pn.insertBefore(before, node);
pn.insertBefore(hiword, node);
pn.insertBefore(container, node);
pn.insertBefore(after, node);
pn.removeChild(node);
}
@ -96,18 +95,16 @@ export class HighlightKeyword {
/**
* Removes highlight to nodes matching passed string
* @param {String} word
* @param {String} term
* @param {String} cssClass Css class to remove
*/
unhighlight(word, cssClass) {
unhighlight(term, cssClass) {
let highlightedNodes = this.tf.tbl.querySelectorAll(`.${cssClass}`);
for (let i = 0; i < highlightedNodes.length; i++) {
let n = highlightedNodes[i];
let nodeVal = getText(n),
tempNodeVal = nodeVal.toLowerCase(),
tempWordVal = word.toLowerCase();
let nodeVal = getText(n);
if (tempNodeVal.indexOf(tempWordVal) !== -1) {
if (nodeVal.toLowerCase().indexOf(term.toLowerCase()) !== -1) {
let parentNode = n.parentNode;
parentNode.replaceChild(createText(nodeVal), n);
parentNode.normalize();
@ -143,8 +140,8 @@ export class HighlightKeyword {
);
this.emitter.off(
['highlight-keyword'],
(tf, cell, word) =>
this.highlight(cell, word, this.highlightCssClass)
(tf, cell, term) =>
this.highlight(cell, term, this.highlightCssClass)
);
}
}

View File

@ -1017,8 +1017,8 @@ export class TableFilter {
// Instanciate sugar date wrapper
if (!Mod.dateType) {
Mod.dateType = new DateType(this);
Mod.dateType.init();
}
Mod.dateType.init();
// Instantiate help feature and initialise only if set true
if (!Mod.help) {

356
test/test-date-type.html Normal file
View File

@ -0,0 +1,356 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TableFilter date type tests</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>Email</th>
<th>Id</th>
<th>Phone</th>
<th>&euro;</th>
<th>US $</th>
<th>Url</th>
<th>EU Date</th>
<th>US Date</th>
<th>DD-MMM-YYYY Date</th>
<th>IP</th>
</tr>
</thead>
<tbody>
<tr>
<td>devo@flexomat.com</td>
<td>66672</td>
<td>941-964-8535</td>
<td>
<div align="right">2.482,79</div>
</td>
<td>
<div align="right">2,482.79</div>
</td>
<td>http://gmail.com</td>
<td>14/12/1988</td>
<td>12/14/1988</td>
<td>14-Dec-1988</td>
<td>186.114.137.213</td>
</tr>
<tr>
<td>henry@mountdev.net</td>
<td>35889</td>
<td>941-964-9543</td>
<td>
<div align="right">2.776,09</div>
</td>
<td>
<div align="right">2,776.09</div>
</td>
<td>http://www.gmail.com</td>
<td>19/1/1984</td>
<td>1/19/1984</td>
<td>19-Jan-1984</td>
<td>170.138.54.12</td>
</tr>
<tr>
<td>christian@reno.gov</td>
<td>60021</td>
<td>941-964-5617</td>
<td>
<div align="right">2.743,41</div>
</td>
<td>
<div align="right">2,743.41</div>
</td>
<td>http://www.dotnet.ca</td>
<td>25/3/2000</td>
<td>3/25/2000</td>
<td>25-Mar-2000</td>
<td>219.115.156.141</td>
</tr>
<tr>
<td>muffins@donuts.com</td>
<td>17927</td>
<td>941-964-9511</td>
<td>
<div align="right">2.998,18</div>
</td>
<td>
<div align="right">2,998.18</div>
</td>
<td>http://google.se</td>
<td>24/1/1993</td>
<td>1/24/1993</td>
<td>24-Jan-1993</td>
<td>252.253.244.189</td>
</tr>
<tr>
<td>muffins@reno.gov</td>
<td>76375</td>
<td>941-964-2757</td>
<td>
<div align="right">1.836,09</div>
</td>
<td>
<div align="right">1,836.09</div>
</td>
<td>http://www.samba.org</td>
<td>4/4/1988</td>
<td>4/4/1988</td>
<td>4-Apr-1988</td>
<td>88.233.9.89</td>
</tr>
<tr>
<td>mendez@gmail.com</td>
<td>45834</td>
<td>941-964-2575</td>
<td>
<div align="right">2.805,46</div>
</td>
<td>
<div align="right">2,805.46</div>
</td>
<td>http://flexomat.com</td>
<td>12/12/1985</td>
<td>12/12/1985</td>
<td>12-Dec-1985</td>
<td>88.233.9.89</td>
</tr>
<tr>
<td>dev@gmail.com</td>
<td>20022</td>
<td>941-964-4967</td>
<td>
<div align="right">3.296,54</div>
</td>
<td>
<div align="right">3,296.54</div>
</td>
<td>http://www.flexomat.com</td>
<td>3/7/2002</td>
<td>7/3/2002</td>
<td>3-Jul-2002</td>
<td>219.115.156.145</td>
</tr>
<tr>
<td>foo@polyester.se</td>
<td>55987</td>
<td>941-964-745</td>
<td>
<div align="right">2.953,73</div>
</td>
<td>
<div align="right">2,953.73</div>
</td>
<td>http://www.donuts.com</td>
<td>4/8/1987</td>
<td>8/4/1987</td>
<td>4-Aug-1987</td>
<td>88.233.9.87</td>
</tr>
<tr>
<td>adam@aftonbladet.se</td>
<td>38867</td>
<td>941-964-6302</td>
<td>
<div align="right">1.949,27</div>
</td>
<td>
<div align="right">1,949.27</div>
</td>
<td>http://flexomat.com</td>
<td>27/7/1995</td>
<td>7/27/1995</td>
<td>27-Jul-1995</td>
<td>170.138.54.16</td>
</tr>
<tr>
<td>devo@donuts.com</td>
<td>51426</td>
<td>941-964-1234</td>
<td>
<div align="right">1.067,00</div>
</td>
<td>
<div align="right">1,067.00</div>
</td>
<td>http://www.polyester.se</td>
<td>5/1/1986</td>
<td>1/5/1986</td>
<td>5-Jan-1986</td>
<td>252.253.244.186</td>
</tr>
<tr>
<td>henry@samba.org</td>
<td>40859</td>
<td>941-964-4856</td>
<td>
<div align="right">3.401,19</div>
</td>
<td>
<div align="right">3,401.19</div>
</td>
<td>http://www.flexomat.com</td>
<td>7/3/1990</td>
<td>3/7/1990</td>
<td>7-Mar-1990</td>
<td>88.233.9.85</td>
</tr>
<tr>
<td>found@dotnet.ca</td>
<td>23986</td>
<td>941-964-2686</td>
<td>
<div align="right">1.393,52</div>
</td>
<td>
<div align="right">1,393.52</div>
</td>
<td>http://lostnfound.org</td>
<td>22/7/1993</td>
<td>7/22/1993</td>
<td>22-Jul-1993</td>
<td>113.231.1.44</td>
</tr>
<tr>
<td>carl@fish.org</td>
<td>73392</td>
<td>941-964-5792</td>
<td>
<div align="right">3.876,04</div>
</td>
<td>
<div align="right">3,876.04</div>
</td>
<td>http://www.google.se</td>
<td>14/7/1984</td>
<td>7/14/1984</td>
<td>14-Jul-1984</td>
<td>219.115.156.137</td>
</tr>
<tr>
<td>found@mountdev.net</td>
<td>03519</td>
<td>941-964-1599</td>
<td>
<div align="right">1.176,48</div>
</td>
<td>
<div align="right">1,176.48</div>
</td>
<td>http://donuts.com</td>
<td>6/8/2000</td>
<td>8/6/2000</td>
<td>6-Aug-2000</td>
<td>88.233.9.86</td>
</tr>
<tr>
<td>lost@fish.org</td>
<td>36628</td>
<td>941-964-5985</td>
<td>
<div align="right">822,23</div>
</td>
<td>
<div align="right">822.23</div>
</td>
<td>http://www.gmail.com</td>
<td>14/7/1994</td>
<td>7/14/1994</td>
<td>14-Jul-1994</td>
<td>252.253.244.184</td>
</tr>
<tr>
<td>mendez@dotnet.ca</td>
<td>90442</td>
<td>941-964-1649</td>
<td>
<div align="right">1.985,72</div>
</td>
<td>
<div align="right">1,975.72</div>
</td>
<td>http://reno.gov</td>
<td>20/10/1997</td>
<td>10/20/1997</td>
<td>20-Oct-1997</td>
<td>113.231.1.79</td>
</tr>
<tr>
<td>carl@donuts.com</td>
<td>00412</td>
<td>941-964-6432</td>
<td>
<div align="right">1.834,77</div>
</td>
<td>
<div align="right">1,834.77</div>
</td>
<td>http://gmail.com</td>
<td>23/8/1997</td>
<td>8/23/1997</td>
<td>23-Aug-1997</td>
<td>170.138.54.19</td>
</tr>
<tr>
<td>foo@fish.org</td>
<td>80653</td>
<td>941-964-1022</td>
<td>
<div align="right">260,26</div>
</td>
<td>
<div align="right">260.26</div>
</td>
<td>http://samba.org</td>
<td>24/11/1991</td>
<td>11/24/1991</td>
<td>24-Nov-1991</td>
<td>88.233.9.89</td>
</tr>
<tr>
<td>found@fish.org</td>
<td>54635</td>
<td>941-964-6439</td>
<td>
<div align="right">1.442,80</div>
</td>
<td>
<div align="right">1,442.80</div>
</td>
<td>http://dotnet.ca</td>
<td>12/7/1987</td>
<td>7/12/1987</td>
<td>12-Jul-1987</td>
<td>88.233.9.90</td>
</tr>
<tr>
<td>found@flexomat.com</td>
<td>20953</td>
<td>941-964-5544</td>
<td>
<div align="right">575,42</div>
</td>
<td>
<div align="right">575.42</div>
</td>
<td>http://gmail.com</td>
<td>10/6/1988</td>
<td>6/10/1988</td>
<td>10-Jun-1988</td>
<td>88.233.19.89</td>
</tr>
</tbody>
</table>
<script src="../dist/tablefilter/tablefilter.js"></script>
<script src="test-date-type.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>

311
test/test-date-type.js Normal file
View File

@ -0,0 +1,311 @@
var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
col_types: [
null, null, null,
{ type: 'formatted-number', decimal: ',', thousands: ','},
'formatted-number', null,
{ type: 'date', locale: 'fr', },
{ type: 'date', locale: 'en', format: '{dd}-{MM}-{yyyy|yy}' },
{ type: 'date', locale: 'en', format: ['{dd}-{months}-{yyyy|yy}'] },
'IpAddress'
]
});
tf.init();
var dateType = tf.feature('dateType');
module('Sanity checks');
test('DateType feature', function() {
deepEqual(typeof dateType, 'object', 'DateType instanciated');
deepEqual(dateType.locale, 'en', 'DateType default locale');
notEqual(dateType.datetime, null, 'Sugar date instance');
});
module('Feature interface');
test('Properties', function() {
deepEqual(dateType.tf instanceof TableFilter, true, 'TableFilter instance');
deepEqual(dateType.feature, 'dateType', 'Feature name');
deepEqual(dateType.enabled, true, 'Feature enabled');
deepEqual(dateType.initialized, true, 'Feature enabled');
deepEqual(typeof dateType.emitter, 'object', 'Feature has emitter instance');
deepEqual(typeof dateType.config, 'object', 'TF configuration object');
deepEqual(typeof dateType.init, 'function', 'Feature init method');
deepEqual(typeof dateType.destroy, 'function', 'Feature destroy method');
deepEqual(typeof dateType.reset, 'function', 'Feature reset method');
deepEqual(typeof dateType.enable, 'function', 'Feature enable method');
deepEqual(typeof dateType.disable, 'function', 'Feature enable method');
deepEqual(typeof dateType.isEnabled, 'function', 'Feature enable method');
});
test('Can destroy', function() {
dateType.destroy();
deepEqual(dateType.initialized, false, 'not initialised');
});
test('Can reset', function() {
dateType.reset();
deepEqual(dateType.enabled, true, 'enabled');
});
test('Can disable', function() {
dateType.disable();
deepEqual(dateType.enabled, false, 'disabled');
});
test('Can enable', function() {
dateType.enable();
deepEqual(dateType.enabled, true, 'enabled');
});
test('Can init', function() {
dateType.destroy();
dateType.enable();
dateType.init();
deepEqual(dateType.initialized, true, 'initialised');
});
test('Can check is enabled', function() {
dateType.isEnabled();
deepEqual(dateType.enabled, true, 'enabled');
});
module('Behaviour');
test('Can parse date', function() {
var date0 = dateType.parse('10/25/2017', 'en-US');
var date1 = dateType.parse('25/10/2017', 'en-GB');
var date2 = dateType.parse('1997-07-16T19:20:30+01:00', 'en');
var date3 = dateType.parse('14-Jul-2005', 'fr');
deepEqual(date0.toISOString(), '2017-10-24T13:00:00.000Z', 'en-US date');
deepEqual(date1.toISOString(), '2017-10-24T13:00:00.000Z', 'en-GB date');
deepEqual(date2.toISOString(), '1997-07-16T18:20:30.000Z', 'ISO date');
deepEqual(date3.getTime(), 1121263200000, 'fr date');
});
// module('Sanity checks');
// test('Data types', function() {
// deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
// deepEqual(
// tf.hasType(3, ['formatted-number']) &&
// tf.hasType(4, ['formatted-number']),
// true, 'Has number column types'
// );
// deepEqual(
// tf.hasType(6, ['date']) &&
// tf.hasType(7, ['date']) &&
// tf.hasType(8, ['date']),
// true, 'Has date column types'
// );
// });
// module('Data types filtering');
// test('Can filter a column with a string', function() {
// // act
// tf.setFilterValue(0, 'carl');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [14, 18], 'Expected rows');
// });
// test('Can filter a EU formatted number', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(3, '1.836,09');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [6], 'Expected rows');
// });
// test('Can filter a EU formatted number column with a number', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(3, 3876);
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [14], 'Expected rows');
// });
// test('Can filter a EU formatted number column with a number without ' +
// 'thousands separator', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(3, '1393,52');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [13], 'Expected rows');
// });
// test('Can filter a EU formatted number column with a number without ' +
// 'decimals', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(3, '2.805');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [7], 'Expected rows');
// });
// test('Can filter a formatted number', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(4, '1,836.09');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [6], 'Expected rows');
// });
// test('Can filter a formatted number column with a number', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(4, 3876);
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [14], 'Expected rows');
// });
// test('Can filter a formatted number column with a number without ' +
// 'thousands separator', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(4, '1393.52');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [13], 'Expected rows');
// });
// test('Can filter a formatted number column with a number without ' +
// 'decimals', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(4, '2,805');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [7], 'Expected rows');
// });
// test('Can filter a EU formatted date column', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(6, '14/7/1994');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [16], 'Expected rows');
// });
// test('Can filter a EU formatted date column with different date separator',
// function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(6, '20-10-97');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [17], 'Expected rows');
// });
// test('Can filter a formatted date column', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(7, '7/14/1994');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [16], 'Expected rows');
// });
// test('Can filter a formatted date column with different date separator',
// function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(7, '10-20-97');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [17], 'Expected rows');
// });
// test('Can filter a dd-MMM-yyy formatted date column', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(8, '3-Jul-2002');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [8], 'Expected rows');
// });
// test('Can filter a dd-MMM-yyy formatted date column with different date ' +
// 'separator', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(8, '25.Mar.2000');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [4], 'Expected rows');
// });
// test('Can filter an IP address column', function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(9, '219.115.156.145');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [8], 'Expected rows');
// });
// test('Can filter an IP address column with a truncated IP address',
// function() {
// // setup
// tf.clearFilters();
// // act
// tf.setFilterValue(9, '219.115.15');
// tf.filter();
// // assert
// deepEqual(tf.getValidRows(), [4, 8, 14], 'Expected rows');
// });
// module('Tear-down');
// test('can destroy TableFilter DOM elements', function() {
// tf.destroy();
// deepEqual(tf.isInitialized(), false, 'Filters removed');
// });