From 7c17ab9b1e02a2911b4964dd04154501159037a4 Mon Sep 17 00:00:00 2001 From: Richard Worth Date: Tue, 3 Feb 2009 08:23:48 +0000 Subject: [PATCH] accordion unit tests: split tests into individual files --- tests/unit/accordion/accordion.html | 7 +- tests/unit/accordion/accordion.js | 150 --------------------- tests/unit/accordion/accordion_core.js | 44 +++++- tests/unit/accordion/accordion_defaults.js | 15 ++- tests/unit/accordion/accordion_events.js | 22 ++- tests/unit/accordion/accordion_methods.js | 69 +++++++++- tests/unit/accordion/accordion_options.js | 126 ++++++++++++++++- tests/unit/accordion/accordion_tickets.js | 4 - 8 files changed, 273 insertions(+), 164 deletions(-) delete mode 100644 tests/unit/accordion/accordion.js diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index 3bd3ff179..f0a3772af 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -12,7 +12,12 @@ - + + + + + + diff --git a/tests/unit/accordion/accordion.js b/tests/unit/accordion/accordion.js deleted file mode 100644 index 5fa7845ef..000000000 --- a/tests/unit/accordion/accordion.js +++ /dev/null @@ -1,150 +0,0 @@ -/* - * accordion unit tests - */ -(function($) { - -module("accordion"); - -jQuery.ui.accordion.defaults.animated = false; - -function state(accordion) { - var args = $.makeArray(arguments).slice(1); - $.each(args, function(i, n) { - equals(accordion.find(".ui-accordion-content").eq(i).is(":visible"), n); - }); -} - -$.fn.triggerEvent = function(type, target) { - return this.triggerHandler(type, [jQuery.event.fix({ type: type, target: target })]); -}; - -test("basics", function() { - state($('#list1').accordion(), 1, 0, 0); -}); - -test("autoHeight", function() { - $('#navigation').accordion({ autoHeight: false }); - equals( $('#navigation > li:eq(0) > ul').height(), 80 ); - equals( $('#navigation > li:eq(1) > ul').height(), 112 ); - equals( $('#navigation > li:eq(2) > ul').height(), 48 ); - $('#navigation').accordion("destroy").accordion({ autoHeight: true }); - equals( $('#navigation > li:eq(0) > ul').height(), 112 ); - equals( $('#navigation > li:eq(1) > ul').height(), 112 ); - equals( $('#navigation > li:eq(2) > ul').height(), 112 ); -}); - -test("activate, numeric", function() { - var ac = $('#list1').accordion({ active: 1 }); - state(ac, 0, 1, 0); - ac.accordion("activate", 2); - state(ac, 0, 0, 1); - ac.accordion("activate", 0); - state(ac, 1, 0, 0); - ac.accordion("activate", 1); - state(ac, 0, 1, 0); - ac.accordion("activate", 2); - state(ac, 0, 0, 1); - ac.accordion("activate", -1); - state(ac, 0, 0, 1); -}); - -test("activate, boolean and numeric, collapsible:true", function() { - var ac = $('#list1').accordion({collapsible: true}).accordion("activate", 2); - state(ac, 0, 0, 1); - ok("x", "----"); - ac.accordion("activate", 0); - state(ac, 1, 0, 0); - ok("x", "----"); - ac.accordion("activate", -1); - state(ac, 0, 0, 0); -}); - -test("activate, boolean, collapsible:false", function() { - var ac = $('#list1').accordion().accordion("activate", 2); - state(ac, 0, 0, 1); - ac.accordion("activate", -1); - state(ac, 0, 0, 1); -}); - -test("activate, string expression", function() { - var ac = $('#list1').accordion({ active: "a:last" }); - state(ac, 0, 0, 1); - ac.accordion("activate", ":first"); - state(ac, 1, 0, 0); - ac.accordion("activate", ":eq(1)"); - state(ac, 0, 1, 0); - ac.accordion("activate", ":last"); - state(ac, 0, 0, 1); -}); - -test("activate, jQuery or DOM element", function() { - var ac = $('#list1').accordion({ active: $("#list1 a:last") }); - state(ac, 0, 0, 1); - ac.accordion("activate", $("#list1 a:first")); - state(ac, 1, 0, 0); - ac.accordion("activate", $("#list1 a")[1]); - state(ac, 0, 1, 0); -}); - -function state2(accordion) { - var args = $.makeArray(arguments).slice(1); - $.each(args, function(i, n) { - equals(accordion.find("div").eq(i).is(":visible"), n); - }); -} - -test("handle click on header-descendant", function() { - var ac = $('#navigation').accordion({ autoHeight: false }); - ac.triggerEvent("click", $('#navigation span:contains(Bass)')[0]); - state2(ac, 0, 1, 0); -}); - -test("active:false", function() { - $("#list1").accordion({ - active: false, - collapsible: true - }); - equals( $("#list1 a.selected").size(), 0, "no headers selected" ); -}); - -test("accordionchange event, open closed and close again", function() { - expect(8); - $("#list1").accordion({ - active: false, - collapsible: true - }) - .one("accordionchange", function(event, ui) { - equals( ui.oldHeader.size(), 0 ); - equals( ui.oldContent.size(), 0 ); - equals( ui.newHeader.size(), 1 ); - equals( ui.newContent.size(), 1 ); - }) - .accordion("activate", 0) - .one("accordionchange", function(event, ui) { - equals( ui.oldHeader.size(), 1 ); - equals( ui.oldContent.size(), 1 ); - equals( ui.newHeader.size(), 0 ); - equals( ui.newContent.size(), 0 ); - }) - .accordion("activate", 0); -}); - -test("accessibility", function () { - expect(9); - var ac = $('#list1').accordion().accordion("activate", 1); - var headers = $(".ui-accordion-header"); - - equals( headers.eq(1).attr("tabindex"), "0", "active header should have tabindex=0"); - equals( headers.eq(0).attr("tabindex"), "-1", "inactive header should have tabindex=-1"); - equals( ac.attr("role"), "tablist", "main role"); - equals( headers.attr("role"), "tab", "tab roles"); - equals( headers.next().attr("role"), "tabpanel", "tabpanel roles"); - equals( headers.eq(1).attr("aria-expanded"), "true", "active tab has aria-expanded"); - equals( headers.eq(0).attr("aria-expanded"), "false", "inactive tab has aria-expanded"); - ac.accordion("activate", 0); - equals( headers.eq(0).attr("aria-expanded"), "true", "newly active tab has aria-expanded"); - equals( headers.eq(1).attr("aria-expanded"), "false", "newly inactive tab has aria-expanded"); -}); - - -})(jQuery); diff --git a/tests/unit/accordion/accordion_core.js b/tests/unit/accordion/accordion_core.js index eb74d1cef..524842037 100644 --- a/tests/unit/accordion/accordion_core.js +++ b/tests/unit/accordion/accordion_core.js @@ -1,12 +1,52 @@ /* * accordion_core.js */ + +jQuery.ui.accordion.defaults.animated = false; + +function state(accordion) { + var args = $.makeArray(arguments).slice(1); + $.each(args, function(i, n) { + equals(accordion.find(".ui-accordion-content").eq(i).is(":visible"), n); + }); +} + +function state2(accordion) { + var args = $.makeArray(arguments).slice(1); + $.each(args, function(i, n) { + equals(accordion.find("div").eq(i).is(":visible"), n); + }); +} + +$.fn.triggerEvent = function(type, target) { + return this.triggerHandler(type, [jQuery.event.fix({ type: type, target: target })]); +}; + (function($) { module("accordion: core"); -test("testname", function() { - ok(false, "missing test - untested code is broken code."); +test("handle click on header-descendant", function() { + var ac = $('#navigation').accordion({ autoHeight: false }); + ac.triggerEvent("click", $('#navigation span:contains(Bass)')[0]); + state2(ac, 0, 1, 0); +}); + +test("accessibility", function () { + expect(9); + var ac = $('#list1').accordion().accordion("activate", 1); + var headers = $(".ui-accordion-header"); + + equals( headers.eq(1).attr("tabindex"), "0", "active header should have tabindex=0"); + equals( headers.eq(0).attr("tabindex"), "-1", "inactive header should have tabindex=-1"); + equals( ac.attr("role"), "tablist", "main role"); + equals( headers.attr("role"), "tab", "tab roles"); + equals( headers.next().attr("role"), "tabpanel", "tabpanel roles"); + equals( headers.eq(1).attr("aria-expanded"), "true", "active tab has aria-expanded"); + equals( headers.eq(0).attr("aria-expanded"), "false", "inactive tab has aria-expanded"); + ac.accordion("activate", 0); + equals( headers.eq(0).attr("aria-expanded"), "true", "newly active tab has aria-expanded"); + equals( headers.eq(1).attr("aria-expanded"), "false", "newly inactive tab has aria-expanded"); }); })(jQuery); diff --git a/tests/unit/accordion/accordion_defaults.js b/tests/unit/accordion/accordion_defaults.js index c6897a23f..96482a2a1 100644 --- a/tests/unit/accordion/accordion_defaults.js +++ b/tests/unit/accordion/accordion_defaults.js @@ -3,7 +3,20 @@ */ var accordion_defaults = { - disabled: false + active: null, + animated: false, + autoHeight: true, + collapsible: false, + clearStyle: false, + disabled: false, + event: "click", + fillSpace: false, + header: "> li > :first-child,> :not(li):even", + icons: { "header": "ui-icon-triangle-1-e", "headerSelected": "ui-icon-triangle-1-s" }, + navigation: false, + navigationFilter: function() { + return this.href.toLowerCase() == location.href.toLowerCase(); + } }; commonWidgetTests('accordion', { defaults: accordion_defaults }); diff --git a/tests/unit/accordion/accordion_events.js b/tests/unit/accordion/accordion_events.js index c7bcf565e..e9e14996c 100644 --- a/tests/unit/accordion/accordion_events.js +++ b/tests/unit/accordion/accordion_events.js @@ -5,8 +5,26 @@ module("accordion: events"); -test("testname", function() { - ok(false, "missing test - untested code is broken code."); +test("accordionchange event, open closed and close again", function() { + expect(8); + $("#list1").accordion({ + active: false, + collapsible: true + }) + .one("accordionchange", function(event, ui) { + equals( ui.oldHeader.size(), 0 ); + equals( ui.oldContent.size(), 0 ); + equals( ui.newHeader.size(), 1 ); + equals( ui.newContent.size(), 1 ); + }) + .accordion("activate", 0) + .one("accordionchange", function(event, ui) { + equals( ui.oldHeader.size(), 1 ); + equals( ui.oldContent.size(), 1 ); + equals( ui.newHeader.size(), 0 ); + equals( ui.newContent.size(), 0 ); + }) + .accordion("activate", 0); }); })(jQuery); diff --git a/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index f234ec293..8b3a491a8 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -5,8 +5,73 @@ module("accordion: methods"); -test("testname", function() { - ok(false, "missing test - untested code is broken code."); +test("init", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("destroy", 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'); +}); + +test("activate, numeric", function() { + var ac = $('#list1').accordion({ active: 1 }); + state(ac, 0, 1, 0); + ac.accordion("activate", 2); + state(ac, 0, 0, 1); + ac.accordion("activate", 0); + state(ac, 1, 0, 0); + ac.accordion("activate", 1); + state(ac, 0, 1, 0); + ac.accordion("activate", 2); + state(ac, 0, 0, 1); + ac.accordion("activate", -1); + state(ac, 0, 0, 1); +}); + +test("activate, boolean and numeric, collapsible:true", function() { + var ac = $('#list1').accordion({collapsible: true}).accordion("activate", 2); + state(ac, 0, 0, 1); + ok("x", "----"); + ac.accordion("activate", 0); + state(ac, 1, 0, 0); + ok("x", "----"); + ac.accordion("activate", -1); + state(ac, 0, 0, 0); +}); + +test("activate, boolean, collapsible:false", function() { + var ac = $('#list1').accordion().accordion("activate", 2); + state(ac, 0, 0, 1); + ac.accordion("activate", -1); + state(ac, 0, 0, 1); +}); + +test("activate, string expression", function() { + var ac = $('#list1').accordion({ active: "a:last" }); + state(ac, 0, 0, 1); + ac.accordion("activate", ":first"); + state(ac, 1, 0, 0); + ac.accordion("activate", ":eq(1)"); + state(ac, 0, 1, 0); + ac.accordion("activate", ":last"); + state(ac, 0, 0, 1); +}); + +test("activate, jQuery or DOM element", function() { + var ac = $('#list1').accordion({ active: $("#list1 a:last") }); + state(ac, 0, 0, 1); + ac.accordion("activate", $("#list1 a:first")); + state(ac, 1, 0, 0); + ac.accordion("activate", $("#list1 a")[1]); + state(ac, 0, 1, 0); }); })(jQuery); diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index 3def620df..61d27ee3e 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -5,8 +5,130 @@ module("accordion: options"); -test("testname", function() { - ok(false, "missing test - untested code is broken code."); +test("{ active: first child }, default", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ active: Selector }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ active: Element }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ active: jQuery Object }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ active: true }", function() { + $("#list1").accordion({ + active: true, + collapsible: false + }); + equals( $("#list1 .ui-accordion-header.ui-state-active").size(), 1, "one header selected" ); +}); + +test("{ active: false }", function() { + $("#list1").accordion({ + active: false, + collapsible: true + }); + equals( $("#list1 .ui-accordion-header.ui-state-active").size(), 0, "no headers selected" ); +}); + +test("{ active: Number }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ animated: false }, default", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ animated: true }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ animated: String }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ autoHeight: true }, default", function() { + $('#navigation').accordion({ autoHeight: true }); + equals( $('#navigation > li:eq(0) > ul').height(), 112 ); + equals( $('#navigation > li:eq(1) > ul').height(), 112 ); + equals( $('#navigation > li:eq(2) > ul').height(), 112 ); +}); + +test("{ autoHeight: false }", function() { + $('#navigation').accordion({ autoHeight: false }); + equals( $('#navigation > li:eq(0) > ul').height(), 80 ); + equals( $('#navigation > li:eq(1) > ul').height(), 112 ); + equals( $('#navigation > li:eq(2) > ul').height(), 48 ); +}); + +test("{ clearStyle: false }, default", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ clearStyle: true }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ collapsible: false }, default", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ collapsible: true }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ event: 'click' }, default", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ event: 'mouseover' }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ fillSpace: false }, default", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ fillSpace: true }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ header: '> li > :first-child,> :not(li):even' }, default", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ header: Selector }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ header: jQuery Object }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ icons: { 'header': 'ui-icon-triangle-1-e', 'headerSelected': 'ui-icon-triangle-1-s' } }, default", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ icons: { 'header': 'ui-icon-foo', 'headerSelected': 'ui-icon-bar' } }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ navigation: false }, default", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ navigation: true }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ navigationFilter: Function }, default", function() { + ok(false, 'missing test - untested code is broken code'); }); })(jQuery); diff --git a/tests/unit/accordion/accordion_tickets.js b/tests/unit/accordion/accordion_tickets.js index f36d4c971..98d8fbe4c 100644 --- a/tests/unit/accordion/accordion_tickets.js +++ b/tests/unit/accordion/accordion_tickets.js @@ -5,8 +5,4 @@ module("accordion: tickets"); -test("testname", function() { - ok(false, "missing test - untested code is broken code."); -}); - })(jQuery); -- 2.39.5