Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test for issue #4133

Also created a module for custom filters and fixed the possible timing issue with a ( dirty ) hack
  • Loading branch information...
commit ab944662ca5f67b1309af40ffac78a753536949e 1 parent 35775c5
@gseguin gseguin authored
Showing with 106 additions and 31 deletions.
  1. +15 −0 tests/unit/listview/index.html
  2. +91 −31 tests/unit/listview/listview_core.js
View
15 tests/unit/listview/index.html
@@ -281,6 +281,21 @@ <h2 id="qunit-userAgent"></h2>
</div>
</div>
+<!-- Search bar filter -->
+<div data-nstest-role="page" id='search-customfilter-test'>
+ <div data-nstest-role="header" data-nstest-position="inline">
+ <h1>Filtered List View</h1>
+ </div>
+ <div data-nstest-role="content">
+ <ul data-nstest-role="listview" data-nstest-filter="true">
+ <li>a is for aquaman</li>
+ <li>b is for batman</li>
+ <li>c is for catwoman</li>
+ <li>d is for darkwing</li>
+ </ul>
+ </div>
+</div>
+
<!-- Search bar filter with list-dividers -->
<div data-nstest-role="page" id='search-filter-with-dividers-test'>
<div data-nstest-role="header" data-nstest-position="inline">
View
122 tests/unit/listview/listview_core.js
@@ -417,11 +417,10 @@
]);
});
- module( "Search Filter");
+ module( "Search Filter" );
var searchFilterId = "#search-filter-test";
-
asyncTest( "Filter downs results when the user enters information", function() {
var $searchPage = $(searchFilterId);
$.testHelper.pageSequence([
@@ -595,6 +594,96 @@
]);
});
+ module( "Custom search filter", {
+ setup: function() {
+ var self = this;
+ this._refreshCornersCount = 0;
+ this._refreshCornersFn = $.mobile.listview.prototype._refreshCorners;
+
+ this.startTest = function() {
+ return this._refreshCornersCount === 1;
+ };
+
+ // _refreshCorners is the last method called in the filter loop
+ // so we count the number of times _refreshCorners gets invoked to stop the test
+ $.mobile.listview.prototype._refreshCorners = function() {
+ self._refreshCornersCount += 1;
+ self._refreshCornersFn.apply( this, arguments );
+ if ( self.startTest() ) {
+ start();
+ }
+ }
+ },
+ teardown: function() {
+ $.mobile.listview.prototype._refreshCorners = this._refreshCornersFn;
+ }
+ });
+
+ asyncTest( "Custom filterCallback should cause iteration on all list elements", function(){
+ var listPage = $( "#search-customfilter-test" ),
+ filterCallbackCount = 0,
+ expectedCount = 2 * listPage.find("li").length;
+ expect( 1 );
+
+ this.startTest = function() {
+ if ( this._refreshCornersCount === 3 ) {
+ equal( filterCallbackCount, expectedCount, "filterCallback should be call exactly "+ expectedCount +" times" );
+ }
+ return this._refreshCornersCount === 3;
+ }
+
+ $.testHelper.pageSequence( [
+ function(){
+ //reset for relative url refs
+ $.mobile.changePage( home );
+ },
+
+ function() {
+ $.mobile.changePage( "#search-customfilter-test" );
+ },
+
+ function() {
+ // set the listview instance callback
+ listPage.find( "ul" ).listview( "option", "filterCallback", function( text, searchValue, item ) {
+ filterCallbackCount += 1;
+
+ return text.toString().toLowerCase().indexOf( searchValue ) === -1;
+ });
+
+ // trigger a change in the search filter
+ listPage.find( "input" ).val( "at" ).trigger( "change" );
+ listPage.find( "input" ).val( "atw" ).trigger( "change" );
+
+ }
+ ]);
+ });
+
+ asyncTest( "filterCallback can be altered after widget creation", function(){
+ var listPage = $( "#search-customfilter-test" );
+ expect( listPage.find("li").length );
+
+ $.testHelper.pageSequence( [
+ function(){
+ //reset for relative url refs
+ $.mobile.changePage( home );
+ },
+
+ function() {
+ $.mobile.changePage( "#search-customfilter-test" );
+ },
+
+ function() {
+ // set the listview instance callback
+ listPage.find( "ul" ).listview( "option", "filterCallback", function() {
+ ok( true, "custom callback invoked" );
+ });
+
+ // trigger a change in the search filter
+ listPage.find( "input" ).val( "foo" ).trigger( "change" );
+ }
+ ]);
+ });
+
module( "Programmatically generated list items", {
setup: function(){
var item,
@@ -792,35 +881,6 @@
]);
});
- asyncTest( "filterCallback can be altered after widget creation", function(){
- var listPage = $( "#search-filter-test" );
- expect( listPage.find("li").length );
-
- $.testHelper.pageSequence( [
- function(){
- //reset for relative url refs
- $.mobile.changePage( home );
- },
-
- function() {
- $.mobile.changePage( "#search-filter-test" );
- },
-
- function() {
- // set the listview instance callback
- listPage.find( "ul" ).listview( "option", "filterCallback", function() {
- ok(true, "custom callback invoked");
- });
-
- // trigger a change in the search filter
- listPage.find( "input" ).val( "foo" ).trigger( "change" );
-
- //NOTE beware a poossible issue with timing here
- start();
- }
- ]);
- });
-
asyncTest( "nested pages hash key is always in the hash (replaceState)", function(){
$.testHelper.pageSequence([
function(){
Please sign in to comment.
Something went wrong with that request. Please try again.