From 037f5d5ce193556ac977217056767e00a77e5c76 Mon Sep 17 00:00:00 2001 From: Richard Worth Date: Tue, 3 Feb 2009 13:37:54 +0000 Subject: [PATCH] tabs unit tests: split tests into individual files, added some missing tests --- tests/unit/tabs/tabs.html | 7 +- tests/unit/tabs/tabs.js | 301 ------------------------------- tests/unit/tabs/tabs_core.js | 4 - tests/unit/tabs/tabs_defaults.js | 12 +- tests/unit/tabs/tabs_events.js | 37 +++- tests/unit/tabs/tabs_methods.js | 83 ++++++++- tests/unit/tabs/tabs_options.js | 135 +++++++++++++- tests/unit/tabs/tabs_tickets.js | 55 +++++- 8 files changed, 322 insertions(+), 312 deletions(-) delete mode 100644 tests/unit/tabs/tabs.js diff --git a/tests/unit/tabs/tabs.html b/tests/unit/tabs/tabs.html index be484b603..d9cb4d138 100644 --- a/tests/unit/tabs/tabs.html +++ b/tests/unit/tabs/tabs.html @@ -13,7 +13,12 @@ - + + + + + +
diff --git a/tests/unit/tabs/tabs.js b/tests/unit/tabs/tabs.js deleted file mode 100644 index a1ecf9a19..000000000 --- a/tests/unit/tabs/tabs.js +++ /dev/null @@ -1,301 +0,0 @@ -/* - * tabs unit tests - */ -(function($) { -// -// Tabs Test Helper Functions -// - -var defaults = { - ajaxOptions: null, - cache: false, - cookie: null, - collapsible: false, - disabled: [], - event: 'click', - fx: null, - idPrefix: 'ui-tabs-', - panelTemplate: '
', - spinner: 'Loading…', - tabTemplate: '
  • #{label}
  • ' -}; - -var el; - -module('tabs'); - - test('init', function() { - expect(9); - - el = $('#tabs1').tabs(); - - ok(true, '.tabs() called on element'); - ok( el.is('.ui-tabs.ui-widget.ui-widget-content.ui-corner-all'), 'attach classes to container'); - ok( $('ul', el).is('.ui-tabs-nav.ui-helper-reset.ui-helper-clearfix.ui-widget-header.ui-corner-all'), 'attach classes to list' ); - ok( $('div:eq(0)', el).is('.ui-tabs-panel.ui-widget-content.ui-corner-bottom'), 'attach classes to panel' ); - ok( $('li:eq(0)', el).is('.ui-tabs-selected.ui-state-active.ui-corner-top'), 'attach classes to active li'); - ok( $('li:eq(1)', el).is('.ui-state-default.ui-corner-top'), 'attach classes to inactive li'); - equals( el.data('selected.tabs'), 0, 'selected.tabs set' ); - equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 0, 'second tab active'); - equals( $('div', el).index( $('div.ui-tabs-hide', '#tabs1') ), 1, 'second panel should be hidden' ); - - }); - - test('destroy', function() { - expect(5); - - el = $('#tabs1').tabs(); - el.tabs('destroy'); - - ok( el.is(':not(.ui-tabs, .ui-widget, .ui-widget-content, .ui-corner-all)'), 'remove classes from container'); - ok( $('ul', el).is(':not(.ui-tabs-nav, .ui-helper-reset, .ui-helper-clearfix, .ui-widget-header, .ui-corner-all)'), 'remove classes from list' ); - ok( $('div:eq(1)', el).is(':not(.ui-tabs-panel, .ui-widget-content, .ui-corner-bottom, .ui-tabs-hide)'), 'remove classes to panel' ); - ok( $('li:eq(0)', el).is(':not(.ui-tabs-selected, .ui-state-active, .ui-corner-top)'), 'remove classes from active li'); - ok( $('li:eq(1)', el).is(':not(.ui-state-default, .ui-corner-top)'), 'remove classes from inactive li'); - - }); - - test("defaults", function() { - el = $('#tabs1').tabs(); - $.each(defaults, function(key, val) { - var actual = el.data(key + '.tabs'), expected = val; - same(actual, expected, key); - }); - el.tabs('destroy'); - }); - - test('add', function() { - expect(0); - - }); - - test('remove', function() { - expect(4); - - el = $('#tabs1').tabs(); - - 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'); - - // TODO delete tab -> focus tab to right - // TODO delete last tab -> focus tab to left - - el.tabs('select', 1); - el.tabs('remove', 1); - equals(el.data('selected.tabs'), 0, 'update selected property'); - }); - - test('enable', function() { - expect(0); - - }); - - test('disable', function() { - expect(0); - - }); - - test('select', function() { - expect(0); - - }); - - test('load', function() { - expect(0); - - }); - - test('url', function() { - expect(0); - - }); - - test('length', function() { - expect(1); - - el = $('#tabs1').tabs(); - equals(el.tabs('length'), $('ul a', el).length, ' should return length'); - - }); - - test('callback ui object', function() { - expect(3); - - var uiObj; - el = $('#tabs1').tabs({ - show: function(event, ui) { - uiObj = ui; - } - }); - equals(uiObj.tab, $('#tabs1 a')[0], 'should have tab as DOM anchor element'); - equals(uiObj.panel, $('#tabs1 div')[0], 'should have panel as DOM div element'); - equals(uiObj.index, 0, ' should have index'); - - }); - - test('selected property', function() { - expect(5); - - $('#tabs1').tabs(); - equals($('#tabs1').data('selected.tabs'), 0, 'selected should be 0 by default'); - - reset(); - $('#tabs1').tabs({ selected: null }); - equals($('#tabs1').data('selected.tabs'), -1, 'selected should be -1 for all tabs unselected'); - - reset(); - $('#tabs1').tabs({ selected: -1 }); - equals($('#tabs1').data('selected.tabs'), -1, 'selected should be -1 for all tabs unselected'); - - reset(); - $('#tabs1').tabs({ selected: 1 }); - equals($('#tabs1').data('selected.tabs'), 1, 'selected should be specified tab'); - - reset(); - $('#tabs1').tabs({ selected: 8 }); - equals($('#tabs1').data('selected.tabs'), 0, 'selected should default to zero if given value is out of index'); - - }); - -module('tabs: Options'); - - test('selected: null', function() { - expect(2); - - el = $('#tabs1'); - - el.tabs({ selected: null }); - equals( $('li.ui-tabs-selected', el).length, 0, 'no tab should be selected' ); - equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' ); - - }); - - test('collapsible', function() { - expect(4); - - el = $('#tabs1'); - - el.tabs({ collapsible: true }); - equals(el.data('collapsible.tabs'), true, 'option set'); - ok(el.is('.ui-tabs-collapsible'), 'extra class "ui-tabs-collapsible" attached'); - el.tabs('select', 0); - equals($('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden'); - el.data('collapsible.tabs', false); - ok(el.is(':not(.ui-tabs-collapsible)'), 'extra class "ui-tabs-collapsible" not attached'); - - }); - - // deprecated... shadows collapsible - test('deselectable (deprecated)', function() { - expect(4); - - el = $('#tabs1'); - - el.tabs({ deselectable: true }); - equals(el.data('collapsible.tabs'), true, 'option set'); - ok(el.is('.ui-tabs-collapsible'), 'extra class "ui-tabs-collapsible" attached'); - el.tabs('select', 0); - equals($('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden'); - el.data('deselectable.tabs', false); - ok(el.is(':not(.ui-tabs-collapsible)'), 'extra class "ui-tabs-collapsible" not attached'); - - }); - - test('cookie', function() { - expect(6); - - el = $('#tabs1'); - var cookieName = 'tabs_test', cookieObj = { name: cookieName }; - $.cookie(cookieName, null); // blank state - var cookie = function() { - return parseInt($.cookie(cookieName), 10); - }; - - el.tabs({ cookie: cookieObj }); - equals(cookie(), 0, 'initial cookie value'); - - el.tabs('destroy'); - el.tabs({ selected: 1, cookie: cookieObj }); - equals(cookie(), 1, 'initial cookie value, from selected property'); - - el.tabs('select', 2); - equals(cookie(), 2, 'cookie value updated after select'); - - el.tabs('destroy'); - $.cookie(cookieName, 1); - el.tabs({ cookie: cookieObj }); - equals(cookie(), 1, 'initial cookie value, from existing cookie'); - - el.tabs('destroy'); - el.tabs({ cookie: cookieObj, collapsible: true }); - el.tabs('select', 0); - equals(cookie(), -1, 'cookie value for all tabs unselected'); - - el.tabs('destroy'); - ok($.cookie(cookieName) === null, 'erase cookie after destroy'); - - }); - - -module('tabs: Tickets'); - - test('id containing colon, #2715', function() { // http://ui.jquery.com/bugs/ticket/2715 - expect(4); - - el = $('#tabs2').tabs(); - ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' ); - ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' ); - - el.tabs('select', 1).tabs('select', 0); - ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' ); - ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' ); - - }); - - test('panel containing inline style, #????', function() { - expect(3); - - var inlineStyle = function(property) { - return $('#inline-style')[0].style[property]; - }; - var expected = inlineStyle('height'); - - el = $('#tabs2').tabs(); - equals(inlineStyle('height'), expected, 'init should not remove inline style'); - - el.tabs('select', 1); - equals(inlineStyle('height'), expected, 'show tab should not remove inline style'); - - el.tabs('select', 0); - equals(inlineStyle('height'), expected, 'hide tab should not remove inline style'); - - }); - - test('Ajax tab with url containing a fragment identifier fails to load, #3627', function() { // http://ui.jquery.com/bugs/ticket/3627 - expect(1); - - el = $('#tabs2').tabs(); - - ok(/test.html$/.test( $('a:eq(2)', el).data('load.tabs') ), 'should ignore fragment identifier'); - - }); - - test('IE expands hash to full url and misinterprets tab as ajax, #4033', function() { // http://ui.jquery.com/bugs/ticket/4033 - expect(1); - - el = $('
    ') - .appendTo('#main').tabs(); - - equals($('a', el).data('load.tabs'), undefined, 'should not create ajax tab'); - - }); - - -// test('', function() { -// expect(0); -// -// }); - -})(jQuery); diff --git a/tests/unit/tabs/tabs_core.js b/tests/unit/tabs/tabs_core.js index 480573bfd..6d3efc5fd 100644 --- a/tests/unit/tabs/tabs_core.js +++ b/tests/unit/tabs/tabs_core.js @@ -5,8 +5,4 @@ module("tabs: core"); -test("testname", function() { - ok(false, "missing test - untested code is broken code."); -}); - })(jQuery); diff --git a/tests/unit/tabs/tabs_defaults.js b/tests/unit/tabs/tabs_defaults.js index badbc2126..7c9ae8be5 100644 --- a/tests/unit/tabs/tabs_defaults.js +++ b/tests/unit/tabs/tabs_defaults.js @@ -3,7 +3,17 @@ */ var tabs_defaults = { - disabled: false + ajaxOptions: null, + cache: false, + cookie: null, + collapsible: false, + disabled: [], + event: 'click', + fx: null, + idPrefix: 'ui-tabs-', + panelTemplate: '
    ', + spinner: 'Loading…', + tabTemplate: '
  • #{label}
  • ' }; commonWidgetTests('tabs', { defaults: tabs_defaults }); diff --git a/tests/unit/tabs/tabs_events.js b/tests/unit/tabs/tabs_events.js index 3c3ea8d86..d49a34782 100644 --- a/tests/unit/tabs/tabs_events.js +++ b/tests/unit/tabs/tabs_events.js @@ -5,7 +5,42 @@ module("tabs: events"); -test("testname", function() { +test('select', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('load', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('show', function() { + expect(3); + + var uiObj; + el = $('#tabs1').tabs({ + show: function(event, ui) { + uiObj = ui; + } + }); + equals(uiObj.tab, $('#tabs1 a')[0], 'should have tab as DOM anchor element'); + equals(uiObj.panel, $('#tabs1 div')[0], 'should have panel as DOM div element'); + equals(uiObj.index, 0, ' should have index'); + +}); + +test('add', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('remove', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('enable', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('disable', function() { ok(false, "missing test - untested code is broken code."); }); diff --git a/tests/unit/tabs/tabs_methods.js b/tests/unit/tabs/tabs_methods.js index 9ab8216c9..65f7f7a78 100644 --- a/tests/unit/tabs/tabs_methods.js +++ b/tests/unit/tabs/tabs_methods.js @@ -5,7 +5,88 @@ module("tabs: methods"); -test("testname", function() { +test('init', function() { + expect(9); + + el = $('#tabs1').tabs(); + + ok(true, '.tabs() called on element'); + ok( el.is('.ui-tabs.ui-widget.ui-widget-content.ui-corner-all'), 'attach classes to container'); + ok( $('ul', el).is('.ui-tabs-nav.ui-helper-reset.ui-helper-clearfix.ui-widget-header.ui-corner-all'), 'attach classes to list' ); + ok( $('div:eq(0)', el).is('.ui-tabs-panel.ui-widget-content.ui-corner-bottom'), 'attach classes to panel' ); + ok( $('li:eq(0)', el).is('.ui-tabs-selected.ui-state-active.ui-corner-top'), 'attach classes to active li'); + ok( $('li:eq(1)', el).is('.ui-state-default.ui-corner-top'), 'attach classes to inactive li'); + equals( el.data('selected.tabs'), 0, 'selected.tabs set' ); + equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 0, 'second tab active'); + equals( $('div', el).index( $('div.ui-tabs-hide', '#tabs1') ), 1, 'second panel should be hidden' ); + +}); + +test('destroy', function() { + expect(5); + + el = $('#tabs1').tabs(); + el.tabs('destroy'); + + ok( el.is(':not(.ui-tabs, .ui-widget, .ui-widget-content, .ui-corner-all)'), 'remove classes from container'); + ok( $('ul', el).is(':not(.ui-tabs-nav, .ui-helper-reset, .ui-helper-clearfix, .ui-widget-header, .ui-corner-all)'), 'remove classes from list' ); + ok( $('div:eq(1)', el).is(':not(.ui-tabs-panel, .ui-widget-content, .ui-corner-bottom, .ui-tabs-hide)'), 'remove classes to panel' ); + ok( $('li:eq(0)', el).is(':not(.ui-tabs-selected, .ui-state-active, .ui-corner-top)'), 'remove classes from active li'); + ok( $('li:eq(1)', el).is(':not(.ui-state-default, .ui-corner-top)'), 'remove classes from inactive li'); + +}); + +test('enable', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('disable', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('add', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('remove', function() { + expect(4); + + el = $('#tabs1').tabs(); + + 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'); + + // TODO delete tab -> focus tab to right + // TODO delete last tab -> focus tab to left + + el.tabs('select', 1); + el.tabs('remove', 1); + equals(el.data('selected.tabs'), 0, 'update selected property'); +}); + +test('select', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('load', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('url', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('length', function() { + expect(1); + + el = $('#tabs1').tabs(); + equals(el.tabs('length'), $('ul a', el).length, ' should return length'); + +}); + +test('rotate', function() { ok(false, "missing test - untested code is broken code."); }); diff --git a/tests/unit/tabs/tabs_options.js b/tests/unit/tabs/tabs_options.js index 02147ff70..86f7941b4 100644 --- a/tests/unit/tabs/tabs_options.js +++ b/tests/unit/tabs/tabs_options.js @@ -5,7 +5,140 @@ module("tabs: options"); -test("testname", function() { +test('ajaxOptions', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('cache', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('collapsible', function() { + expect(4); + + el = $('#tabs1'); + + el.tabs({ collapsible: true }); + equals(el.data('collapsible.tabs'), true, 'option set'); + ok(el.is('.ui-tabs-collapsible'), 'extra class "ui-tabs-collapsible" attached'); + el.tabs('select', 0); + equals($('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden'); + el.data('collapsible.tabs', false); + ok(el.is(':not(.ui-tabs-collapsible)'), 'extra class "ui-tabs-collapsible" not attached'); + +}); + +test('cookie', function() { + expect(6); + + el = $('#tabs1'); + var cookieName = 'tabs_test', cookieObj = { name: cookieName }; + $.cookie(cookieName, null); // blank state + var cookie = function() { + return parseInt($.cookie(cookieName), 10); + }; + + el.tabs({ cookie: cookieObj }); + equals(cookie(), 0, 'initial cookie value'); + + el.tabs('destroy'); + el.tabs({ selected: 1, cookie: cookieObj }); + equals(cookie(), 1, 'initial cookie value, from selected property'); + + el.tabs('select', 2); + equals(cookie(), 2, 'cookie value updated after select'); + + el.tabs('destroy'); + $.cookie(cookieName, 1); + el.tabs({ cookie: cookieObj }); + equals(cookie(), 1, 'initial cookie value, from existing cookie'); + + el.tabs('destroy'); + el.tabs({ cookie: cookieObj, collapsible: true }); + el.tabs('select', 0); + equals(cookie(), -1, 'cookie value for all tabs unselected'); + + el.tabs('destroy'); + ok($.cookie(cookieName) === null, 'erase cookie after destroy'); + +}); + +// deprecated... shadows collapsible +test('deselectable (deprecated)', function() { + expect(4); + + el = $('#tabs1'); + + el.tabs({ deselectable: true }); + equals(el.data('collapsible.tabs'), true, 'option set'); + ok(el.is('.ui-tabs-collapsible'), 'extra class "ui-tabs-collapsible" attached'); + el.tabs('select', 0); + equals($('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden'); + el.data('deselectable.tabs', false); + ok(el.is(':not(.ui-tabs-collapsible)'), 'extra class "ui-tabs-collapsible" not attached'); + +}); + +test('disabled', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('events', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('fx', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('idPrefix', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('panelTemplate', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('selected: null', function() { + expect(2); + + el = $('#tabs1'); + + el.tabs({ selected: null }); + equals( $('li.ui-tabs-selected', el).length, 0, 'no tab should be selected' ); + equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' ); + +}); + +test('selected property', function() { + expect(5); + + $('#tabs1').tabs(); + equals($('#tabs1').data('selected.tabs'), 0, 'selected should be 0 by default'); + + reset(); + $('#tabs1').tabs({ selected: null }); + equals($('#tabs1').data('selected.tabs'), -1, 'selected should be -1 for all tabs unselected'); + + reset(); + $('#tabs1').tabs({ selected: -1 }); + equals($('#tabs1').data('selected.tabs'), -1, 'selected should be -1 for all tabs unselected'); + + reset(); + $('#tabs1').tabs({ selected: 1 }); + equals($('#tabs1').data('selected.tabs'), 1, 'selected should be specified tab'); + + reset(); + $('#tabs1').tabs({ selected: 8 }); + equals($('#tabs1').data('selected.tabs'), 0, 'selected should default to zero if given value is out of index'); + +}); + +test('spinner', function() { + ok(false, "missing test - untested code is broken code."); +}); + +test('tabTemplate', function() { ok(false, "missing test - untested code is broken code."); }); diff --git a/tests/unit/tabs/tabs_tickets.js b/tests/unit/tabs/tabs_tickets.js index 1d3485e88..9874a1192 100644 --- a/tests/unit/tabs/tabs_tickets.js +++ b/tests/unit/tabs/tabs_tickets.js @@ -5,8 +5,59 @@ module("tabs: tickets"); -test("testname", function() { - ok(false, "missing test - untested code is broken code."); +test('#2715 - id containing colon', function() { + // http://dev.jqueryui.com/ticket/2715 + expect(4); + + el = $('#tabs2').tabs(); + ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' ); + ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' ); + + el.tabs('select', 1).tabs('select', 0); + ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' ); + ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' ); + }); +test('#???? - panel containing inline style', function() { + expect(3); + + var inlineStyle = function(property) { + return $('#inline-style')[0].style[property]; + }; + var expected = inlineStyle('height'); + + el = $('#tabs2').tabs(); + equals(inlineStyle('height'), expected, 'init should not remove inline style'); + + el.tabs('select', 1); + equals(inlineStyle('height'), expected, 'show tab should not remove inline style'); + + el.tabs('select', 0); + equals(inlineStyle('height'), expected, 'hide tab should not remove inline style'); + +}); + +test('#3627 - Ajax tab with url containing a fragment identifier fails to load', function() { + // http://dev.jqueryui.com/ticket/3627 + expect(1); + + el = $('#tabs2').tabs(); + + ok(/test.html$/.test( $('a:eq(2)', el).data('load.tabs') ), 'should ignore fragment identifier'); + +}); + +test('#4033 - IE expands hash to full url and misinterprets tab as ajax', function() { + // http://dev.jqueryui.com/ticket/4033 + expect(1); + + el = $('
    ') + .appendTo('#main').tabs(); + + equals($('a', el).data('load.tabs'), undefined, 'should not create ajax tab'); + +}); + + })(jQuery); -- 2.39.5