diff --git a/tests/unit/listview/listview_core.js b/tests/unit/listview/listview_core.js
index 26ba63e3ad4..8c5eee69d90 100755
--- a/tests/unit/listview/listview_core.js
+++ b/tests/unit/listview/listview_core.js
@@ -4,7 +4,7 @@
// TODO split out into seperate test files
(function($){
- var home = $.mobile.path.parseUrl( location.href ).pathname;
+ var home = $.mobile.path.parseUrl( location.href ).pathname;
$.mobile.defaultTransition = "none";
@@ -65,13 +65,13 @@
var page = $( ".ui-page-active" ),
items = page.find( "li" );
- ok( items.eq( 0 ).hasClass( "ui-li-has-count"), "First LI should have ui-li-has-count class" );
- ok( items.eq( 0 ).hasClass( "ui-li-has-arrow"), "First LI should have ui-li-has-arrow class" );
+ ok( items.eq( 0 ).hasClass( "ui-li-has-count"), "First LI should have ui-li-has-count class" );
+ ok( items.eq( 0 ).hasClass( "ui-li-has-arrow"), "First LI should have ui-li-has-arrow class" );
ok( !items.eq( 1 ).hasClass( "ui-li-has-count"), "Second LI should NOT have ui-li-has-count class" );
- ok( items.eq( 1 ).hasClass( "ui-li-has-arrow"), "Second LI should have ui-li-has-arrow class" );
+ ok( items.eq( 1 ).hasClass( "ui-li-has-arrow"), "Second LI should have ui-li-has-arrow class" );
ok( !items.eq( 2 ).hasClass( "ui-li-has-count"), "Third LI should NOT have ui-li-has-count class" );
ok( !items.eq( 2 ).hasClass( "ui-li-has-arrow"), "Third LI should NOT have ui-li-has-arrow class" );
- ok( items.eq( 3 ).hasClass( "ui-li-has-count"), "Fourth LI should have ui-li-has-count class" );
+ ok( items.eq( 3 ).hasClass( "ui-li-has-count"), "Fourth LI should have ui-li-has-count class" );
ok( !items.eq( 3 ).hasClass( "ui-li-has-arrow"), "Fourth LI should NOT have ui-li-has-arrow class" );
ok( !items.eq( 4 ).hasClass( "ui-li-has-count"), "Fifth LI should NOT have ui-li-has-count class" );
ok( !items.eq( 4 ).hasClass( "ui-li-has-arrow"), "Fifth LI should NOT have ui-li-has-arrow class" );
@@ -316,6 +316,176 @@
]);
});
+ module( "Autodividers" );
+
+ asyncTest( "Adds dividers based on first letters of list items.", function() {
+ $.testHelper.pageSequence([
+ function() {
+ $.testHelper.openPage( '#autodividers-test' );
+ },
+
+ function() {
+ var $new_page = $( '#autodividers-test' );
+ ok( $new_page.hasClass( 'ui-page-active' ) );
+ ok( $new_page.find( '.ui-li-divider' ).length === 4 );
+
+ start();
+ }
+ ]);
+ });
+
+ asyncTest( "Responds to addition/removal of list elements.", function() {
+ $.testHelper.pageSequence([
+ function() {
+ $.testHelper.openPage( '#autodividers-test' );
+ },
+
+ function() {
+ var $new_page = $( '#autodividers-test' );
+ ok($new_page.hasClass( 'ui-page-active' ));
+
+ var $listview = $new_page.find( 'ul' );
+
+ // should remove all existing dividers
+ ok( $new_page.find( 'li:contains("SHOULD REMOVE")' ).length === 0 );
+
+ // add li; should add an "X" divider
+ $listview.append( '
x is for xanthe' );
+ ok( $new_page.find( '.ui-li-divider' ).length === 5 );
+ ok( $new_page.find( '.ui-li-divider' ).is( ':contains("X")' ) );
+
+ // adding the same element again should create a valid list
+ // item but no new divider
+ ok( $new_page.find( '.ui-li-static' ).length === 5 );
+ $listview.append( '
x is for xanthe' );
+ ok( $new_page.find( '.ui-li-divider' ).length === 5 );
+ ok( $new_page.find( '.ui-li-divider:contains("X")' ).length === 1 );
+ ok( $new_page.find( '.ui-li-static' ).length === 6 );
+
+ // should ignore addition of non-li elements to the list
+ $listview.find( 'li:eq(0)' ).append( '
ignore me' );
+ ok( $new_page.find( '.ui-li-divider' ).length === 5 );
+ ok( $new_page.find( '.ui-li-static' ).length === 6 );
+
+ // add li with the same initial letter as another li
+ // but after the X li item; should add a second "B" divider to the
+ // end of the list
+ $listview.append( '
b is for barry' );
+ ok( $new_page.find( '.ui-li-divider' ).length === 6 );
+ ok( $new_page.find( '.ui-li-divider:contains("B")' ).length === 2 );
+
+ // remove the item with a repeated "b"; should remove the second
+ // "B" divider
+ $listview.find( 'li:contains("barry")' ).remove();
+ ok( $new_page.find( '.ui-li-divider' ).length === 5 );
+ ok( $new_page.find( '.ui-li-divider:contains("B")' ).length === 1 );
+
+ // remove li; should remove the "A" divider
+ $listview.find( 'li:contains("aquaman")' ).remove();
+ ok( $new_page.find( '.ui-li-divider' ).length === 4 );
+ ok( !$new_page.find( '.ui-li-divider' ).is( ':contains("A")' ) );
+
+ // adding another "B" item after "C" should create two separate
+ // "B" dividers
+ $listview.find( 'li:contains("catwoman")' ).after( '
b is for barry' );
+ ok( $new_page.find( '.ui-li-divider' ).length === 5 );
+ ok( $new_page.find( '.ui-li-divider:contains("B")' ).length === 2 );
+
+ // if two dividers with the same letter have only non-dividers
+ // between them, they get merged
+
+ // removing catwoman should cause the two "B" dividers to merge
+ $listview.find( 'li:contains("catwoman")' ).remove();
+ ok( $new_page.find( '.ui-li-divider:contains("B")' ).length === 1 );
+
+ // adding another "D" item before the "D" divider should only
+ // result in a single "D" divider after merging
+ $listview.find( 'li:contains("barry")' ).after( '
d is for dan' );
+ ok( $new_page.find( '.ui-li-divider:contains("D")' ).length === 1 );
+
+ start();
+ }
+ ]);
+ });
+
+ module( "Autodividers Selector" );
+
+ asyncTest( "Adds divider text from links.", function() {
+ $.testHelper.pageSequence([
+ function() {
+ $.testHelper.openPage( '#autodividers-selector-test' );
+ },
+
+ function() {
+ var $new_page = $( '#autodividers-selector-test' );
+ ok($new_page.hasClass( 'ui-page-active' ));
+
+ // check we have the right dividers based on link text
+ var $list = $( '#autodividers-selector-test-list1' );
+ ok( $list.find( '.ui-li-divider' ).length === 4 );
+ ok( $list.find( '.ui-li-divider:eq(0):contains(A)' ).length === 1 );
+ ok( $list.find( '.ui-li-divider:eq(1):contains(B)' ).length === 1 );
+ ok( $list.find( '.ui-li-divider:eq(2):contains(C)' ).length === 1 );
+ ok( $list.find( '.ui-li-divider:eq(3):contains(D)' ).length === 1 );
+
+ // check that adding a new item with link creates the right divider
+ $list.append( '
e is for ethel' );
+ ok( $list.find( '.ui-li-divider:eq(4):contains(E)' ).length === 1 );
+
+ start();
+ }
+ ]);
+ });
+
+ asyncTest( "Adds divider text based on custom selector.", function() {
+ $.testHelper.pageSequence([
+ function() {
+ $.testHelper.openPage( '#autodividers-selector-test' );
+ },
+
+ function() {
+ var $new_page = $( '#autodividers-selector-test' );
+ ok($new_page.hasClass( 'ui-page-active' ));
+
+ // check we have the right dividers based on custom selector
+ var $list = $( '#autodividers-selector-test-list2' );
+ ok( $list.find( '.ui-li-divider' ).length === 4 );
+ ok( $list.find( '.ui-li-divider:eq(0):contains(E)' ).length === 1 );
+ ok( $list.find( '.ui-li-divider:eq(1):contains(F)' ).length === 1 );
+ ok( $list.find( '.ui-li-divider:eq(2):contains(G)' ).length === 1 );
+ ok( $list.find( '.ui-li-divider:eq(3):contains(H)' ).length === 1 );
+
+ // check that adding a new item creates the right divider
+ $list.append( '
' +
+ 'i is for impy
' );
+
+ ok( $list.find( '.ui-li-divider:eq(4):contains(I)' ).length === 1 );
+
+ start();
+ }
+ ]);
+ });
+
+ asyncTest( "Adds divider text based on full text selected by custom selector.", function() {
+ $.testHelper.pageSequence([
+ function() {
+ $.testHelper.openPage( '#autodividers-selector-test' );
+ },
+
+ function() {
+ var $new_page = $( '#autodividers-selector-test' );
+ ok($new_page.hasClass( 'ui-page-active' ));
+
+ var $list = $( '#autodividers-selector-test-list3' );
+ ok( $list.find( '.ui-li-divider' ).length === 2 );
+ ok( $list.find( '.ui-li-divider:eq(0):contains(eddie)' ).length === 1 );
+ ok( $list.find( '.ui-li-divider:eq(1):contains(frankie)' ).length === 1 );
+
+ start();
+ }
+ ]);
+ });
+
module( "Search Filter");
var searchFilterId = "#search-filter-test";
@@ -355,22 +525,22 @@
]);
});
- asyncTest( "Filter works fine with \\W- or regexp-special-characters", function() {
- var $searchPage = $(searchFilterId);
- $.testHelper.pageSequence([
- function() {
- $.testHelper.openPage(searchFilterId);
- },
+ asyncTest( "Filter works fine with \\W- or regexp-special-characters", function() {
+ var $searchPage = $(searchFilterId);
+ $.testHelper.pageSequence([
+ function() {
+ $.testHelper.openPage(searchFilterId);
+ },
- function() {
- $searchPage.find('input').val('*');
- $searchPage.find('input').trigger('change');
+ function() {
+ $searchPage.find('input').val('*');
+ $searchPage.find('input').trigger('change');
- same($searchPage.find('li.ui-screen-hidden').length, 4);
- start();
- }
- ]);
- });
+ same($searchPage.find('li.ui-screen-hidden').length, 4);
+ start();
+ }
+ ]);
+ });
test( "Refresh applies thumb styling", function(){
var ul = $('.ui-page-active ul');