diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-04-28 21:35:04 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-04-28 21:35:04 -0400 |
commit | 1bacdec6be7e9d543224c69344041aaccde059c0 (patch) | |
tree | 92829155963b371017375aa689b9f47aa2c801d6 /tests/unit/tabs | |
parent | c3d9bd070051a79e1a288935d420f85278268149 (diff) | |
download | jquery-ui-1bacdec6be7e9d543224c69344041aaccde059c0.tar.gz jquery-ui-1bacdec6be7e9d543224c69344041aaccde059c0.zip |
Tabs: Cleaned up add and remove methods.
Diffstat (limited to 'tests/unit/tabs')
-rw-r--r-- | tests/unit/tabs/tabs.html | 2 | ||||
-rw-r--r-- | tests/unit/tabs/tabs_deprecated.html | 2 | ||||
-rw-r--r-- | tests/unit/tabs/tabs_deprecated.js | 103 |
3 files changed, 66 insertions, 41 deletions
diff --git a/tests/unit/tabs/tabs.html b/tests/unit/tabs/tabs.html index 3e38f5f25..565a0b427 100644 --- a/tests/unit/tabs/tabs.html +++ b/tests/unit/tabs/tabs.html @@ -34,7 +34,7 @@ panel = $( $.ui.tabs.prototype._sanitizeSelector( "#" + tab.find( "a" ).attr( "aria-controls" ) ) ), tabIsActive = tab.hasClass( "ui-state-active" ), - panelIsActive = panel.is( ":visible" ); + panelIsActive = panel.css( "display" ) !== "none"; if ( tabIsActive && panelIsActive ) { return 1; diff --git a/tests/unit/tabs/tabs_deprecated.html b/tests/unit/tabs/tabs_deprecated.html index aae11c33d..e71fea3d4 100644 --- a/tests/unit/tabs/tabs_deprecated.html +++ b/tests/unit/tabs/tabs_deprecated.html @@ -33,7 +33,7 @@ panel = $( $.ui.tabs.prototype._sanitizeSelector( "#" + tab.find( "a" ).attr( "aria-controls" ) ) ), tabIsActive = tab.hasClass( "ui-state-active" ), - panelIsActive = panel.is( ":visible" ); + panelIsActive = panel.css( "display" ) !== "none"; if ( tabIsActive && panelIsActive ) { return 1; diff --git a/tests/unit/tabs/tabs_deprecated.js b/tests/unit/tabs/tabs_deprecated.js index c221868fc..359847d14 100644 --- a/tests/unit/tabs/tabs_deprecated.js +++ b/tests/unit/tabs/tabs_deprecated.js @@ -247,42 +247,78 @@ test('select', function() { equals( evenObj.originalEvent.type, "click", "select triggered by click" ); }); -module("tabs (deprecated): methods"); - -test('add', function() { - expect(4); - - el = $('#tabs1').tabs(); - el.tabs('add', '#new', 'New'); - - var added = $('li:last', el).simulate('mouseover'); - ok(added.is('.ui-state-hover'), 'should add mouseover handler to added tab'); - added.simulate('mouseout'); - var other = $('li:first', el).simulate('mouseover'); - ok(other.is('.ui-state-hover'), 'should not remove mouseover handler from existing tab'); - other.simulate('mouseout'); +module( "tabs (deprecated): methods" ); + +test( "add", function() { + expect( 18 ); + + var element = $( "#tabs1" ).tabs(); + tabs_state( element, 1, 0, 0 ); + + // add without index + element.tabs( "add", "#new", "New" ); + tabs_state( element, 1, 0, 0, 0 ); + var tab = element.find( ".ui-tabs-nav li" ).last(), + anchor = tab.find( "a" ); + equals( tab.text(), "New", "label" ); + equals( anchor.attr( "href" ), "#new", "href" ); + equals( anchor.attr( "aria-controls" ), "new", "aria-controls" ); + ok( !tab.hasClass( "ui-state-hover" ), "not hovered" ); + anchor.simulate( "mouseover" ); + ok( tab.hasClass( "ui-state-hover" ), "hovered" ); + anchor.simulate( "click" ); + tabs_state( element, 0, 0, 0, 1 ); + + // add remote tab with index + element.tabs( "add", "data/test.html", "New Remote", 1 ); + tabs_state( element, 0, 0, 0, 0, 1 ); + tab = element.find( ".ui-tabs-nav li" ).eq( 1 ); + anchor = tab.find( "a" ); + equals( tab.text(), "New Remote", "label" ); + equals( anchor.attr( "href" ), "data/test.html", "href" ); + ok( /^ui-tabs-\d+$/.test( anchor.attr( "aria-controls" ) ), "aria controls" ); + ok( !tab.hasClass( "ui-state-hover" ), "not hovered" ); + anchor.simulate( "mouseover" ); + ok( tab.hasClass( "ui-state-hover" ), "hovered" ); + anchor.simulate( "click" ); + tabs_state( element, 0, 1, 0, 0, 0 ); + + // add to empty tab set + element = $( "<div><ul></ul></div>" ).tabs(); + equals( element.tabs( "option", "active" ), false, "active: false on init" ); + element.tabs( "add", "#first", "First" ); + tabs_state( element, 1 ); + equals( element.tabs( "option", "active" ), 0, "active: 0 after add" ); +}); - equals($('a', added).attr('href'), '#new', 'should not expand href to full url of current page'); +test( "#5069 - ui.tabs.add creates two tab panels when using a full URL", function() { + expect( 2 ); - ok(false, "missing test - untested code is broken code."); + var element = $( "#tabs2" ).tabs(); + equals( element.children( "div" ).length, element.find( ".ui-tabs-nav li" ).length ); + element.tabs( "add", "/new", "New" ); + equals( element.children( "div" ).length, element.find( ".ui-tabs-nav li" ).length ); }); -test('remove', function() { - expect(4); +test( "remove", function() { + expect( 8 ); - el = $('#tabs1').tabs(); + var element = $( "#tabs1" ).tabs({ active: 1 }); + tabs_state( element, 0, 1, 0 ); - el.tabs('remove', 0); - equals(el.tabs('length'), 2, 'remove tab'); - equals($('li a[href$="fragment-1"]', el).length, 0, 'remove associated list item'); - equals($('#fragment-1').length, 0, 'remove associated panel'); + element.tabs( "remove", 1 ); + tabs_state( element, 0, 1 ); + equals( element.tabs( "option", "active" ), 1 ); + equals( element.find( ".ui-tabs-nav li a[href$='fragment-2']" ).length, 0, + "remove correct list item" ); + equals( element.find( "#fragment-2" ).length, 0, "remove correct panel" ); - // TODO delete tab -> focus tab to right - // TODO delete last tab -> focus tab to left + element.tabs( "remove", 1 ); + tabs_state( element, 1 ); + equals( element.tabs( "option", "active"), 0 ); - el.tabs('select', 1); - el.tabs('remove', 1); - equals(el.tabs('option', 'selected'), 0, 'update selected property'); + element.tabs( "remove", 0 ); + equals( element.tabs( "option", "active" ), false ); }); test('select', function() { @@ -314,17 +350,6 @@ test('select', function() { equals(el.tabs('option', 'active'), 1, 'should select tab by id'); }); - -test('#5069 - ui.tabs.add creates two tab panels when using a full URL', function() { - // http://dev.jqueryui.com/ticket/5069 - expect(2); - - el = $('#tabs2').tabs(); - equals(el.children('div').length, el.find('> ul > li').length, 'After creation, number of panels should be equal to number of tabs'); - el.tabs('add', '/ajax_html_echo', 'Test'); - equals(el.children('div').length, el.find('> ul > li').length, 'After add, number of panels should be equal to number of tabs'); -}); - test( "length", function() { expect( 2 ); |