| 1 |
*! |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
jQuery(function($){ |
| 43 |
QUnit.module('Widgets', { |
| 44 |
beforeEach: function(assert) { |
| 45 |
this.ts = $.tablesorter; |
| 46 |
|
| 47 |
|
| 48 |
if ( /\(table2\)/.test(assert.test.testName) ) { |
| 49 |
this.$table = $('#testblock').html('<table class="tablesorter">' + |
| 50 |
'<thead><tr>' + |
| 51 |
'<th class="filter-select">AlphaNumeric</th>' + |
| 52 |
'<th class="filter-select filter-match">Numeric</th>' + |
| 53 |
'<th>Animals</th>' + |
| 54 |
'<th>Sites</th>' + |
| 55 |
'</tr></thead><tbody>' + |
| 56 |
'<tr><td>abc</td><td>1</td><td>Koala</td><td>http://www.google.com</td></tr>' + |
| 57 |
'<tr><td>abc 1</td><td>234</td><td>Ox</td><td>http://www.yahoo.com</td></tr>' + |
| 58 |
'<tr><td>abc 9</td><td>111</td><td>Girafee</td><td>http://www.facebook.com</td></tr>' + |
| 59 |
'<tr><td>zyx 24</td><td>123</td><td>Bison</td><td>http://www.whitehouse.gov/</td></tr>' + |
| 60 |
'<tr><td>abc 11</td><td>3</td><td>Chimp</td><td>http://www.ucla.edu/</td></tr>' + |
| 61 |
'<tr><td>abc 2</td><td>56</td><td>Elephant</td><td>http://www.wikipedia.org/</td></tr>' + |
| 62 |
'<tr><td>abc 9</td><td>155</td><td>Lion</td><td>http://www.nytimes.com/</td></tr>' + |
| 63 |
'<tr><td>ABC 10</td><td>87</td><td>Zebra</td><td>http://www.google.com</td></tr>' + |
| 64 |
'<tr><td>zyx 1</td><td>999</td><td>Koala</td><td>http://www.mit.edu/</td></tr>' + |
| 65 |
'<tr><td>zyx 12</td><td>0</td><td>Llama</td><td>http://www.nasa.gov/</td></tr>' + |
| 66 |
'</tbody></table>').find('table'); |
| 67 |
} else { |
| 68 |
this.$table = $('#testblock').html('<table class="tablesorter">' + |
| 69 |
'<thead><tr>' + |
| 70 |
'<th class="rank">Rank</th>' + |
| 71 |
'<th class="first filter-match">First Name</th>' + |
| 72 |
'<th class="last">Last Name</th>' + |
| 73 |
'<th data-value="<20">Age</th>' + |
| 74 |
'<th class="total">Total</th>' + |
| 75 |
'<th>Discount</th>' + |
| 76 |
'<th>Date</th>' + |
| 77 |
'<th class="last2">L4st N4me2</th>' + |
| 78 |
'</tr></thead><tbody>' + |
| 79 |
'<tr><td>1</td><td>Philip Aaron Wong</td><td>Johnson Sr Esq</td><td>25</td><td>$5.95</td><td>22%</td><td>Jun 26, 2004 7:22 AM</td><td>Johnson Sr Esq</td></tr>' + |
| 80 |
'<tr><td>11</td><td>Aaron</td><td>Hibert</td><td>12</td><td>$2.99</td><td>5%</td><td>Aug 21, 2009 12:21 PM</td><td>Hibert</td></tr>' + |
| 81 |
'<tr><td>12</td><td>Brandon Clark</td><td>Henry Jr</td><td>51</td><td>$42.29</td><td>18%</td><td>Oct 13, 2000 1:15 PM</td><td>Henry Jr</td></tr>' + |
| 82 |
'<tr><td>111</td><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td><td>Parker</td></tr>' + |
| 83 |
'<tr><td>21</td><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td><td>Hood</td></tr>' + |
| 84 |
'<tr><td>013</td><td>Clark</td><td>Kent Sr.</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td><td>Kent Sr.</td></tr>' + |
| 85 |
'<tr><td>005</td><td>Bruce</td><td>Almighty Esq</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2021 9:12 AM</td><td>Almighty Esq</td></tr>' + |
| 86 |
'<tr><td>10</td><td>Alex</td><td>Dumass</td><td>13</td><td>$5.29</td><td>4%</td><td>Jan 8, 2012 5:11 PM</td><td>Dumass</td></tr>' + |
| 87 |
'<tr><td>16</td><td>Jim</td><td>Franco</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2004 11:23 AM</td><td>Franco</td></tr>' + |
| 88 |
'<tr><td>166</td><td>Bruce Lee</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td><td>Evans</td></tr>' + |
| 89 |
'<tr><td>100</td><td>Brenda Dexter</td><td>McMasters</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2010 7:23 PM</td><td>McMasters</td></tr>' + |
| 90 |
'<tr><td>55</td><td>Dennis</td><td>Bronson</td><td>65</td><td>$123.00</td><td></td><td>Jan 20, 2001 1:12 PM</td><td>Bronson</td></tr>' + |
| 91 |
'<tr><td>9</td><td>Martha</td><td>delFuego</td><td>25</td><td>$22.09</td><td>17%</td><td>Jun 11, 2011 10:55 AM</td><td>delFuego</td></tr>' + |
| 92 |
'</tbody></table>').find('table'); |
| 93 |
} |
| 94 |
|
| 95 |
this.table = this.$table[0]; |
| 96 |
this.init = false; |
| 97 |
|
| 98 |
var self = this; |
| 99 |
var initTablesort = function(){ |
| 100 |
self.$table.tablesorter({ |
| 101 |
ignoreCase: false, |
| 102 |
widgets: ['zebra', 'filter'], |
| 103 |
headers: { |
| 104 |
'.rank' : { filter: false } |
| 105 |
}, |
| 106 |
widgetOptions: { |
| 107 |
filter_functions : { |
| 108 |
'.last2' : true, |
| 109 |
'.rank' : { |
| 110 |
'< 10' : function(e, n) { return n <= 10; }, |
| 111 |
'> 10' : function(e, n) { return n > 10; } |
| 112 |
} |
| 113 |
}, |
| 114 |
filter_selectSource : { |
| 115 |
|
| 116 |
|
| 117 |
'.last2' : function(table, column) { |
| 118 |
return ['abc', 'def', 'zyx']; |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
}); |
| 123 |
}; |
| 124 |
|
| 125 |
var onEventCallback = function(){ |
| 126 |
self.init = true; |
| 127 |
self.c = self.table.config, |
| 128 |
self.wo = self.c.widgetOptions; |
| 129 |
}; |
| 130 |
|
| 131 |
return QUnit.SequentialRunner().next( |
| 132 |
QUnit.assertOnEvent( |
| 133 |
self.$table, |
| 134 |
'filterInit', |
| 135 |
initTablesort, |
| 136 |
onEventCallback |
| 137 |
) |
| 138 |
).promise(); |
| 139 |
|
| 140 |
}, |
| 141 |
afterEach: function(assert) { |
| 142 |
var done = assert.async(); |
| 143 |
this.$table.trigger('destroy', [false, done]); |
| 144 |
} |
| 145 |
}); |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
QUnit.test( 'Filter: init', function(assert) { |
| 152 |
assert.expect(6); |
| 153 |
|
| 154 |
assert.equal( this.init, true, 'Init event' ); |
| 155 |
assert.equal( this.$table.hasClass('hasFilters'), true, '`hasFilters` class applied' ); |
| 156 |
|
| 157 |
assert.equal( this.ts.filter.regex.child.test( this.c.cssChildRow ), true, 'child row regex check' ); |
| 158 |
assert.equal( this.ts.filter.regex.filtered.test( this.wo.filter_filteredRow ), true, 'filtered row regex check' ); |
| 159 |
|
| 160 |
assert.equal ( this.c.$table.find('.tablesorter-filter').eq(0).hasClass('disabled'), true, 'filter disabled & headers class name working' ); |
| 161 |
|
| 162 |
assert.cacheCompare( this.table, 3, [ 12, 18, 13, 18 ], 'starting filter value on age column', true ); |
| 163 |
}); |
| 164 |
|
| 165 |
QUnit.test( 'Filter column range', function(assert) { |
| 166 |
assert.expect(10); |
| 167 |
var range = $.tablesorter.filter.findRange, |
| 168 |
c = { columns: 10 }; |
| 169 |
|
| 170 |
assert.deepEqual( range( c, '6' ), [ 6 ], '6' ); |
| 171 |
assert.deepEqual( range( c, '5, 6' ), [ 5,6 ], '5, 6' ); |
| 172 |
assert.deepEqual( range( c, '5 - 6' ), [ 5,6 ], '5 - 6' ); |
| 173 |
assert.deepEqual( range( c, '1-3,5-6,8' ), [ 1,2,3,5,6,8 ], '1-3,5-6,8' ); |
| 174 |
assert.deepEqual( range( c, '6- 3, 2,4' ), [ 3,4,5,6,2,4 ], '6- 3,2,4 (dupes included)' ); |
| 175 |
assert.deepEqual( range( c, '-1-3, 11' ), [ 1,2,3 ], '-1-3, 11 (negative & out of range ignored)' ); |
| 176 |
assert.deepEqual( range( c, '8-12' ), [ 8,9 ], '8-12 (not out of range)' ); |
| 177 |
assert.deepEqual( range( c, 'all' ), [ 0,1,2,3,4,5,6,7,8,9 ], 'all' ); |
| 178 |
assert.deepEqual( range( c, 'any-text' ), [ 0,1,2,3,4,5,6,7,8,9 ], 'text with dash -> all columns' ); |
| 179 |
assert.deepEqual( range( c, 'a-b-c,100' ), [ 0,1,2,3,4,5,6,7,8,9 ], 'text with dashes & commas -> all columns' ); |
| 180 |
}); |
| 181 |
|
| 182 |
QUnit.test( 'Filter process filters', function(assert) { |
| 183 |
assert.expect(2); |
| 184 |
var processFilters = this.ts.filter.processFilters, |
| 185 |
filters = [], |
| 186 |
results = []; |
| 187 |
filters[1] = 5; filters[2] = 'test'; filters[3] = true; filters[4] = null; |
| 188 |
results[1] = '5'; results[2] = 'test'; results[3] = 'true'; |
| 189 |
|
| 190 |
|
| 191 |
assert.deepEqual( processFilters( filters, true ), results ); |
| 192 |
assert.deepEqual( processFilters( filters, false ), results ); |
| 193 |
}); |
| 194 |
|
| 195 |
QUnit.test( 'Filter comparison', function(assert) { |
| 196 |
assert.expect(10); |
| 197 |
var undef, |
| 198 |
c = { columns: 10 }, |
| 199 |
compare = this.ts.filter.equalFilters; |
| 200 |
|
| 201 |
assert.equal( compare( c, [], [] ), true, 'two empty arrays' ); |
| 202 |
assert.equal( compare( c, [], '' ), true, 'empty array + empty string' ); |
| 203 |
assert.equal( compare( c, '', [] ), true, 'empty string + empty array' ); |
| 204 |
assert.equal( compare( c, ['', '', ''], [] ), true, 'empty array len 3 vs len 0' ); |
| 205 |
assert.equal( compare( c, ['1', undef, ''], ['1'] ), true, 'equal but diff len' ); |
| 206 |
assert.equal( compare( c, [undef, '1', ''], [undef, '1'] ), true, 'equal but diff len' ); |
| 207 |
assert.equal( compare( c, [] ), true, 'undefined second filter' ); |
| 208 |
assert.equal( compare( c, ['', undef] ), true, 'undefined second filter' ); |
| 209 |
|
| 210 |
assert.equal( compare( c, ['1', '', ''], ['', '1', ''] ), false, 'same value diff position' ); |
| 211 |
assert.equal( compare( c, [undef, '1', ''], ['', undef, '1'] ), false, 'same value diff position' ); |
| 212 |
}); |
| 213 |
|
| 214 |
QUnit.test( 'Filter searches', function(assert) { |
| 215 |
var ts = this.ts, |
| 216 |
c = this.c, |
| 217 |
wo = this.wo, |
| 218 |
$table = this.$table, |
| 219 |
table = this.table; |
| 220 |
assert.expect(40); |
| 221 |
|
| 222 |
return QUnit.SequentialRunner( |
| 223 |
function(actions, assertions) { |
| 224 |
return QUnit.assertOnEvent($table, 'filterEnd', actions, assertions); |
| 225 |
} |
| 226 |
).nextTask( |
| 227 |
function(){ ts.setFilters( table, ['', 'e'] ); }, |
| 228 |
function(){ assert.cacheCompare( table, 1, ['Peter', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter', 'Dennis'], 'search regular', true ); } |
| 229 |
).nextTask( |
| 230 |
function(){ ts.setFilters( table, ['', '~bee'] ); }, |
| 231 |
function(){ assert.cacheCompare( table, 1, ['Bruce Lee', 'Brenda Dexter'], 'search fuzzy', true ); } |
| 232 |
).nextTask( |
| 233 |
function(){ ts.setFilters( table, ['', '~piano'] ); }, |
| 234 |
function(){ assert.cacheCompare( table, 1, ['Philip Aaron Wong'], 'search fuzzy2', true ); } |
| 235 |
).nextTask( |
| 236 |
function(){ ts.setFilters( table, ['', 'john='] ); }, |
| 237 |
function(){ assert.cacheCompare( table, 1, ['John'], 'search exact', true ); } |
| 238 |
).nextTask( |
| 239 |
function(){ ts.setFilters( table, ['', '', 'a?s'] ); }, |
| 240 |
function(){ assert.cacheCompare( table, 2, ['Dumass', 'Evans'], 'search wildcard, one character (?)', true ); } |
| 241 |
).nextTask( |
| 242 |
function(){ ts.setFilters( table, ['', '', 'a*s'] ); }, |
| 243 |
function(){ assert.cacheCompare( table, 2, ['Dumass', 'Evans', 'McMasters'], 'search wildcard, multiple characters (*)', true ); } |
| 244 |
).nextTask( |
| 245 |
function(){ ts.setFilters( table, ['', '/r$/'] ); }, |
| 246 |
function(){ assert.cacheCompare( table, 1, ['Peter', 'Brenda Dexter'], 'search regex', true ); } |
| 247 |
).nextTask( |
| 248 |
function(){ ts.setFilters( table, ['', '', '', '', '>10'] ); }, |
| 249 |
function(){ assert.cacheCompare( table, 4, [42.29, 19.99, 15.89, 153.19, 14.19, 13.19, 55.2, 123, 22.09], 'search operator (>10)', true ); } |
| 250 |
).nextTask( |
| 251 |
function(){ ts.setFilters( table, ['', '', '', '', '>100'] ); }, |
| 252 |
function(){ assert.cacheCompare( table, 4, [153.19, 123], 'search operator (>100); ensure search filtered gets cleared', true ); } |
| 253 |
).nextTask( |
| 254 |
function(){ ts.setFilters( table, ['', '', '', '', '', '>=20'] ); }, |
| 255 |
function(){ assert.cacheCompare( table, 5, [22, 20, 25, 44, 44], 'search operator (>=)', true ); } |
| 256 |
).nextTask( |
| 257 |
function(){ ts.setFilters( table, ['', '', '', '', '', '<10'] ); }, |
| 258 |
function(){ assert.cacheCompare( table, 5, [5, 4], 'search operator (<10)', true ); } |
| 259 |
).nextTask( |
| 260 |
function(){ ts.setFilters( table, ['', '', '', '', '', '<100'] ); }, |
| 261 |
function(){ assert.cacheCompare( table, 5, [22, 5, 18, 20, 25, 44, 44, 4, 14, 11, 15, 17], 'search operator (<100); ensure search filtered gets cleared', true ); } |
| 262 |
).nextTask( |
| 263 |
function(){ ts.setFilters( table, ['', '', '', '', '', '<=20'] ); }, |
| 264 |
function(){ assert.cacheCompare( table, 5, [5, 18, 20, 4, 14, 11, 15, 17], 'search operator (<=)', true ); } |
| 265 |
).nextTask( |
| 266 |
function(){ ts.setFilters( table, ['', '!a'] ); }, |
| 267 |
function(){ assert.cacheCompare( table, 1, ['Peter', 'John', 'Bruce', 'Jim', 'Bruce Lee', 'Dennis'], 'search not match', true ); } |
| 268 |
).nextTask( |
| 269 |
function(){ ts.setFilters( table, ['', '!aa'] ); }, |
| 270 |
function(){ assert.cacheCompare( table, 1, ['Brandon Clark', 'Peter', 'John', 'Clark', 'Bruce', 'Alex', 'Jim', 'Bruce Lee', 'Brenda Dexter', 'Dennis', 'Martha'], 'search not match; ensure search filtered gets cleared', true ); } |
| 271 |
).nextTask( |
| 272 |
function(){ ts.setFilters( table, ['', '', '', '', '', '', '', '', '!3'] ); }, |
| 273 |
function(){ assert.cacheCompare( table, 0, [1, 11, 111, 9], 'search not any match', true ); } |
| 274 |
).nextTask( |
| 275 |
function(){ ts.setFilters( table, ['', 'br && c'] ); }, |
| 276 |
function(){ assert.cacheCompare( table, 1, ['Brandon Clark', 'Bruce', 'Bruce Lee'], 'search and match', true ); } |
| 277 |
).nextTask( |
| 278 |
function(){ ts.setFilters( table, ['', 'br && cl'] ); }, |
| 279 |
function(){ assert.cacheCompare( table, 1, ['Brandon Clark'], 'search and match; ensure search filtered gets cleared', true ); } |
| 280 |
).nextTask( |
| 281 |
function(){ ts.setFilters( table, ['', 'c* && l && a'] ); }, |
| 282 |
function(){ assert.cacheCompare( table, 1, ['Brandon Clark', 'Clark'], 'search "c* && l && a"', true ); } |
| 283 |
).nextTask( |
| 284 |
function(){ ts.setFilters( table, ['', 'a && !o'] ); }, |
| 285 |
function(){ assert.cacheCompare( table, 1, ['Clark', 'Alex', 'Brenda Dexter', 'Martha'], 'search "a && !o"', true ); } |
| 286 |
).nextTask( |
| 287 |
function(){ ts.setFilters( table, ['', '', '' , '>20 && <40'] ); }, |
| 288 |
function(){ assert.cacheCompare( table, 3, [25, 28, 33, 24, 22, 25], 'search ">20 && <40"', true ); } |
| 289 |
).nextTask( |
| 290 |
function(){ ts.setFilters( table, ['', '', '' , '<15 or >40'] ); }, |
| 291 |
function(){ assert.cacheCompare( table, 3, [12, 51, 45, 13, 65], 'search "<15 or >40"', true ); } |
| 292 |
).nextTask( |
| 293 |
function(){ ts.setFilters( table, ['', 'alex|br*'] ); }, |
| 294 |
function(){ assert.cacheCompare( table, 1, ['Brandon Clark', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter'], 'search OR match', true ); } |
| 295 |
).nextTask( |
| 296 |
function(){ ts.setFilters( table, ['', '/(Alex|Aar'] ); }, |
| 297 |
function(){ assert.cacheCompare( table, 1, [], 'Partial OR match, but invalid regex', true ); } |
| 298 |
).nextTask( |
| 299 |
function(){ ts.setFilters( table, ['', '/(Alex && '] ); }, |
| 300 |
function(){ assert.cacheCompare( table, 1, [], 'Partial AND match, and way messed up regex', true ); } |
| 301 |
).nextTask( |
| 302 |
function(){ ts.setFilters( table, ['', '', '', '', '5 - 10'] ); }, |
| 303 |
function(){ assert.cacheCompare( table, 4, [5.95, 9.99, 5.29], 'search range', true ); } |
| 304 |
).nextTask( |
| 305 |
function(){ ts.setFilters( table, ['', '', '', '', '5 - 100'] ); }, |
| 306 |
function(){ assert.cacheCompare( table, 4, [5.95, 42.29, 9.99, 19.99, 15.89, 5.29, 14.19, 13.19, 55.2, 22.09], 'search range; ensure search filtered gets cleared', true ); } |
| 307 |
).nextTask( |
| 308 |
function(){ ts.setFilters( table, ['', '', '', '', '', '', '', '', '4:>40'] ); }, |
| 309 |
function(){ assert.cacheCompare( table, 3, [51, 45, 65], 'search "4:>40" in anyMatch', true ); } |
| 310 |
).nextTask( |
| 311 |
function(){ ts.setFilters( table, ['', '', '', '', '', '', '', '', '2:~aa'] ); }, |
| 312 |
function(){ assert.cacheCompare( table, 1, ['Philip Aaron Wong', 'Aaron', 'Brandon Clark', 'Martha'], 'search "2:~aa" in anyMatch', true ); } |
| 313 |
).nextTask( |
| 314 |
function(){ ts.setFilters( table, ['', '', '', '', '', '', '', '', '1:5 && 7:12'] ); }, |
| 315 |
function(){ assert.cacheCompare( table, 3, [45, 65], 'search "1:5 && 7:12" in anyMatch', true ); } |
| 316 |
).nextTask( |
| 317 |
function(){ ts.setFilters( table, ['', '', '', '', '', '', '', '', 'rank:5 && date:12'] ); }, |
| 318 |
function(){ assert.cacheCompare( table, 3, [45, 65], 'search "rank:5 && date:12" in anyMatch', true ); } |
| 319 |
).nextTask( |
| 320 |
function(){ ts.setFilters( table, ['', '', '', '', '', '', '', '', 'name:e'] ); }, |
| 321 |
function(){ assert.cacheCompare( table, 1, ['Peter', 'Bruce', 'Bruce Lee', 'Brenda Dexter'], 'search "name:e" in anyMatch', true ); } |
| 322 |
).nextTask( |
| 323 |
function(){ ts.setFilters( table, ['', '', '', '', '', '', '', '', 'first:e && last:e'] ); }, |
| 324 |
function(){ assert.cacheCompare( table, 1, ['Peter', 'Bruce', 'Bruce Lee', 'Brenda Dexter'], 'search "name:e" in anyMatch', true ); } |
| 325 |
).nextTask( |
| 326 |
function(){ |
| 327 |
wo.filter_startsWith = false; |
| 328 |
ts.setFilters( table, ['', 'aa'], true ); |
| 329 |
}, |
| 330 |
function(){ assert.cacheCompare( table, 1, ['Philip Aaron Wong', 'Aaron'], 'search - filter_startsWith : false', true ); } |
| 331 |
).nextTask( |
| 332 |
function(){ |
| 333 |
wo.filter_startsWith = true; |
| 334 |
c.$table.trigger('search', false); |
| 335 |
}, |
| 336 |
function(){ |
| 337 |
assert.cacheCompare( table, 1, ['Aaron'], 'search - filter_startsWith : true', true ); |
| 338 |
wo.filter_startsWith = false; |
| 339 |
} |
| 340 |
).nextTask( |
| 341 |
function(){ |
| 342 |
wo.filter_ignoreCase = false; |
| 343 |
c.$table.trigger('search', false); |
| 344 |
}, |
| 345 |
function(){ |
| 346 |
assert.cacheCompare( table, 1, [], 'search - filter_ignoreCase : false', true ); |
| 347 |
wo.filter_ignoreCase = true; |
| 348 |
} |
| 349 |
).nextTask( |
| 350 |
function(){ ts.setFilters( table, ['', 'alex|br*|c'] ); }, |
| 351 |
function(){ assert.cacheCompare( table, 1, ['Brandon Clark', 'Clark', 'Bruce', 'Alex', 'Bruce Lee', 'Brenda Dexter'], 'search - filter-match', true ); } |
| 352 |
).nextTask( |
| 353 |
function(){ |
| 354 |
c.$table.find('.tablesorter-header').eq(1).removeClass('filter-match'); |
| 355 |
c.$table.trigger('search', false); |
| 356 |
}, |
| 357 |
function(){ assert.cacheCompare( table, 1, ['Bruce', 'Alex'], 'search - filter-match removed', true ); } |
| 358 |
).nextTask( |
| 359 |
function(){ c.$table.trigger('filterReset'); }, |
| 360 |
function(){ assert.cacheCompare( table, 5, [22, 5, 18, 20, 25, 44, 44, 4, 14, 11, 15, '', 17], 'filterReset', true ); } |
| 361 |
).nextTask( |
| 362 |
function(){ |
| 363 |
wo.filter_startsWith = false; |
| 364 |
ts.setFilters( table, ['', '', '', '', '', '', '< 1/1/2001'], true ); |
| 365 |
}, |
| 366 |
function(){ assert.cacheCompare( table, 6, [ new Date('Oct 13, 2000 1:15 PM').getTime() ], 'search - filter-parsed', true ); } |
| 367 |
).promise(); |
| 368 |
}); |
| 369 |
|
| 370 |
QUnit.test( 'Filter: function & selectSource', function(assert) { |
| 371 |
assert.expect(3); |
| 372 |
|
| 373 |
var $t, opts = []; |
| 374 |
$t = this.c.$table.find('.tablesorter-filter-row select:last'); |
| 375 |
assert.equal ( $t.length !== 0, true, 'filter_functions: true working' ); |
| 376 |
|
| 377 |
this.c.$table.find('.tablesorter-filter-row select:first option').each(function(){ |
| 378 |
opts.push( $.trim( $(this).text() ) ); |
| 379 |
}); |
| 380 |
assert.equal ( 'len=' + opts.length + ',' + opts.join(''), 'len=3,< 10> 10', 'filter_functions set' ); |
| 381 |
|
| 382 |
opts = []; |
| 383 |
$t.find('option').each(function(){ |
| 384 |
opts.push( $.trim( $(this).text() ) ); |
| 385 |
}); |
| 386 |
assert.equal ( 'len=' + opts.length + ',' + opts.join(''), 'len=4,abcdefzyx', 'filter_selectSource set' ); |
| 387 |
}); |
| 388 |
|
| 389 |
QUnit.test( 'Filter: select & matching (table2)', function(assert) { |
| 390 |
var self = this, |
| 391 |
ts = this.ts, |
| 392 |
$table = this.$table, |
| 393 |
table = this.table; |
| 394 |
assert.expect(4); |
| 395 |
|
| 396 |
return QUnit.SequentialRunner( |
| 397 |
function(actions, assertions) { |
| 398 |
return QUnit.assertOnEvent($table, 'filterEnd', actions, assertions); |
| 399 |
} |
| 400 |
).nextTask( |
| 401 |
function(){ ts.setFilters( table, ['abc 1'] ); }, |
| 402 |
function(){ assert.cacheCompare( table, 0, ['abc 1'], 'select exact search', true ); } |
| 403 |
).nextTask( |
| 404 |
function(){ ts.setFilters( table, ['/abc\\s1$/'] ); }, |
| 405 |
function(){ assert.cacheCompare( table, 0, ['abc 1'], 'select exact search using regex', true ); } |
| 406 |
).nextTask( |
| 407 |
function(){ |
| 408 |
$table.find( '.filter-select' ).eq(0).addClass( 'filter-match' ); |
| 409 |
ts.setFilters( table, [ 'abc 1' ] ); |
| 410 |
}, |
| 411 |
function(){ assert.cacheCompare( table, 0, ['abc 1', 'abc 11', 'ABC 10'], 'select match search', true ); } |
| 412 |
).nextTask( |
| 413 |
function(){ ts.setFilters( table, ['', '1'] ); }, |
| 414 |
function(){ assert.cacheCompare( table, 1, [ 1, 111, 123, 155], 'select match seach', true ); } |
| 415 |
).promise(); |
| 416 |
}); |
| 417 |
|
| 418 |
}); |