From 5d23e8eacd95b0bcb859c4303a39709ef8a4dc86 Mon Sep 17 00:00:00 2001 From: David Petersen Date: Tue, 19 Apr 2011 12:54:41 -0400 Subject: Tabs: Fix issues with refresh method, add refresh method tests --- tests/unit/tabs/tabs_methods.js | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/unit/tabs/tabs_methods.js b/tests/unit/tabs/tabs_methods.js index c7c043760..9d6864218 100644 --- a/tests/unit/tabs/tabs_methods.js +++ b/tests/unit/tabs/tabs_methods.js @@ -86,7 +86,7 @@ test( "disable( index )", function() { }); test('refresh', function() { - expect(5); + expect( 13 ); var el = $('
').tabs(), ul = el.find('ul'); @@ -95,22 +95,45 @@ test('refresh', function() { ul.append('
  • Test 1
  • '); el.tabs('refresh'); + equals( el.tabs('option', 'active'), 0, 'First tab added should be auto active'); + ok( $( "li:eq(0)", el).is('.ui-tabs-active'), 'First tab should be auto active'); equals( el.find('.ui-tabs-panel').length, 1, 'Panel created after refresh'); ul.find('li').remove(); el.tabs('refresh'); equals( el.find('.ui-tabs-panel').length, 0, 'Panel removed after refresh'); + equals( el.tabs('option', 'active'), false, 'No tabs are active'); - ul.append('
  • Test 1
  • '); - $('
    Test Panel 1
    ').insertAfter( ul ); + // Hide second tab + $('
  • Test 1
  • Test 2
  • Test 3
  • ') + .appendTo( ul ); + $('
    Test Panel 1
    Test Panel 2
    Test Panel 3
    ') + .insertAfter( ul ); el.tabs('refresh'); - el.tabs('option', 'active', 0); - equals( el.tabs('option', 'active'), 0, 'First tab added should be auto active'); + equals( el.tabs('option', 'active'), 0, 'Second tab added should not be auto active'); + equals( $( "#test2", el ).css("display"), "none", 'Second panel is hidden'); - ul.append('
  • Test 2
  • '); - $('
    Test Panel 2
    ').insertAfter( ul ); + // Make second tab active and then remove the first one + el.tabs('option', 'active', 1); + el.find('a[href="#test1"]').parent().remove(); el.tabs('refresh'); - equals( el.tabs('option', 'active'), 0, 'Second tab added should not be auto active'); + equals( el.tabs('option', 'active'), 0, 'Active index correctly updated'); + ok( el.find('a[href="#test2"]').parent().is('.ui-tabs-active'), 'Tab is still active'); + + // Refresh with disabled tabs + el.tabs('disable', 1); + same( el.tabs('option', 'disabled'), [ 1 ], 'Second tab disabled'); + + el.find('a[href="#test3"]').remove(); + ul.append('
  • Test 4
  • '); + $('
    Test Panel 4
    ').insertAfter( ul ); + el.tabs('refresh'); + equals( el.tabs('option', 'disabled'), false, 'Not disabled'); + + ul.append('
  • Test 3
  • '); + $('
    Test Panel 3
    ').insertAfter( ul ); + el.tabs('refresh'); + same( el.tabs('option', 'disabled'), [ 2 ], 'Second tab disabled'); }); test('load', function() { -- cgit v1.2.3