From b792bd46ec9b1b55bf2289faedd4ab3614c9319a Mon Sep 17 00:00:00 2001 From: Richard Worth Date: Wed, 7 Jan 2009 03:31:15 +0000 Subject: restructured unit tests folder --- tests/accordion.html | 96 --- tests/accordion.js | 150 ---- tests/all.html | 225 ----- tests/all_2.html | 82 -- tests/core.html | 63 -- tests/core.js | 78 -- tests/datepicker.html | 30 - tests/datepicker.js | 1387 ------------------------------- tests/dialog.html | 26 - tests/dialog.js | 723 ---------------- tests/draggable.html | 28 - tests/draggable.js | 787 ------------------ tests/droppable.html | 27 - tests/droppable.js | 223 ----- tests/images/test.jpg | Bin 915 -> 0 bytes tests/progressbar.html | 24 - tests/progressbar.js | 68 -- tests/resizable.html | 25 - tests/resizable.js | 416 --------- tests/selectable.html | 30 - tests/selectable.js | 196 ----- tests/simulate/jquery.simulate.js | 152 ---- tests/slider.html | 27 - tests/slider.js | 396 --------- tests/sortable.html | 30 - tests/sortable.js | 148 ---- tests/tabs.html | 45 - tests/tabs.js | 243 ------ tests/testsuite.css | 4 - tests/testsuite.js | 10 - tests/ui.html | 34 - tests/ui.js | 36 - tests/unit/accordion/accordion.html | 96 +++ tests/unit/accordion/accordion.js | 150 ++++ tests/unit/all/all.html | 226 +++++ tests/unit/all/all_2.html | 82 ++ tests/unit/core/core.html | 63 ++ tests/unit/core/core.js | 78 ++ tests/unit/datepicker/datepicker.html | 30 + tests/unit/datepicker/datepicker.js | 1387 +++++++++++++++++++++++++++++++ tests/unit/dialog/dialog.html | 26 + tests/unit/dialog/dialog.js | 723 ++++++++++++++++ tests/unit/draggable/draggable.html | 28 + tests/unit/draggable/draggable.js | 787 ++++++++++++++++++ tests/unit/droppable/droppable.html | 27 + tests/unit/droppable/droppable.js | 223 +++++ tests/unit/progressbar/progressbar.html | 24 + tests/unit/progressbar/progressbar.js | 68 ++ tests/unit/resizable/images/test.jpg | Bin 0 -> 915 bytes tests/unit/resizable/resizable.html | 25 + tests/unit/resizable/resizable.js | 416 +++++++++ tests/unit/selectable/selectable.html | 30 + tests/unit/selectable/selectable.js | 196 +++++ tests/unit/slider/slider.html | 27 + tests/unit/slider/slider.js | 396 +++++++++ tests/unit/sortable/sortable.html | 30 + tests/unit/sortable/sortable.js | 148 ++++ tests/unit/tabs/tabs.html | 44 + tests/unit/tabs/tabs.js | 243 ++++++ tests/unit/testsuite.css | 4 + tests/unit/testsuite.js | 10 + 61 files changed, 5587 insertions(+), 5809 deletions(-) delete mode 100644 tests/accordion.html delete mode 100644 tests/accordion.js delete mode 100644 tests/all.html delete mode 100644 tests/all_2.html delete mode 100644 tests/core.html delete mode 100644 tests/core.js delete mode 100644 tests/datepicker.html delete mode 100644 tests/datepicker.js delete mode 100644 tests/dialog.html delete mode 100644 tests/dialog.js delete mode 100644 tests/draggable.html delete mode 100644 tests/draggable.js delete mode 100644 tests/droppable.html delete mode 100644 tests/droppable.js delete mode 100644 tests/images/test.jpg delete mode 100644 tests/progressbar.html delete mode 100644 tests/progressbar.js delete mode 100644 tests/resizable.html delete mode 100644 tests/resizable.js delete mode 100644 tests/selectable.html delete mode 100644 tests/selectable.js delete mode 100644 tests/simulate/jquery.simulate.js delete mode 100644 tests/slider.html delete mode 100644 tests/slider.js delete mode 100644 tests/sortable.html delete mode 100644 tests/sortable.js delete mode 100644 tests/tabs.html delete mode 100644 tests/tabs.js delete mode 100644 tests/testsuite.css delete mode 100644 tests/testsuite.js delete mode 100644 tests/ui.html delete mode 100644 tests/ui.js create mode 100644 tests/unit/accordion/accordion.html create mode 100644 tests/unit/accordion/accordion.js create mode 100644 tests/unit/all/all.html create mode 100644 tests/unit/all/all_2.html create mode 100644 tests/unit/core/core.html create mode 100644 tests/unit/core/core.js create mode 100644 tests/unit/datepicker/datepicker.html create mode 100644 tests/unit/datepicker/datepicker.js create mode 100644 tests/unit/dialog/dialog.html create mode 100644 tests/unit/dialog/dialog.js create mode 100644 tests/unit/draggable/draggable.html create mode 100644 tests/unit/draggable/draggable.js create mode 100644 tests/unit/droppable/droppable.html create mode 100644 tests/unit/droppable/droppable.js create mode 100644 tests/unit/progressbar/progressbar.html create mode 100644 tests/unit/progressbar/progressbar.js create mode 100644 tests/unit/resizable/images/test.jpg create mode 100644 tests/unit/resizable/resizable.html create mode 100644 tests/unit/resizable/resizable.js create mode 100644 tests/unit/selectable/selectable.html create mode 100644 tests/unit/selectable/selectable.js create mode 100644 tests/unit/slider/slider.html create mode 100644 tests/unit/slider/slider.js create mode 100644 tests/unit/sortable/sortable.html create mode 100644 tests/unit/sortable/sortable.js create mode 100644 tests/unit/tabs/tabs.html create mode 100644 tests/unit/tabs/tabs.js create mode 100644 tests/unit/testsuite.css create mode 100644 tests/unit/testsuite.js diff --git a/tests/accordion.html b/tests/accordion.html deleted file mode 100644 index e22d753b4..000000000 --- a/tests/accordion.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - jQuery UI Accordion Test Suite - - - - - - - - - - - - - - -
- -
-
- There is one obvious advantage: -
-

- You've seen it coming! -
- Buy now and get nothing for free! -
- Well, at least no free beer. Perhaps a bear, if you can afford it. -

-
-
-
- Now that you've got... -
-

- your bear, you have to admit it! -
- No, we aren't selling bears. -

-

- We could talk about renting one. -

-
-
-
- Rent one bear, ... -
-

- get two for three beer. -

-

- And now, for something completely different. -

-
-
-
- - - -
- - - diff --git a/tests/accordion.js b/tests/accordion.js deleted file mode 100644 index d9f8c4b64..000000000 --- a/tests/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").parent().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( 90, $('#navigation div:first').height() ); - equals( 126, $('#navigation div:eq(1)').height() ); - equals( 54, $('#navigation div:last').height() ); - $('#navigation').accordion("destroy").accordion({ autoHeight: true }); - equals( 126, $('#navigation div:first').height() ); - equals( 126, $('#navigation div:eq(1)').height() ); - equals( 126, $('#navigation div:last').height() ); -}); - -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, alwaysOpen:false", function() { - var ac = $('#list1').accordion({alwaysOpen: false}).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, alwaysOpen:true", 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, - alwaysOpen: false - }); - equals( $("#list1 a.selected").size(), 0, "no headers selected" ); -}); - -test("accordionchange event, open closed and close again", function() { - expect(8); - $("#list1").accordion({ - active: false, - alwaysOpen: false - }) - .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/all.html b/tests/all.html deleted file mode 100644 index af23bad42..000000000 --- a/tests/all.html +++ /dev/null @@ -1,225 +0,0 @@ - - - - jQuery UI All Tests - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

jQuery UI All Tests

- -

- -

Run individual testsuites or doubleclick a test below

- - -
    - -
    - -

    - -
    Relative
    -
    Absolute
    - -
    -
    -
    -
    - -
    - There is one obvious advantage: -
    -

    - You've seen it coming!
    - Buy now and get nothing for free!
    - Well, at least no free beer. Perhaps a bear, if you can afford it. -

    -
    - Now that you've got... -
    -

    - your bear, you have to admit it!
    - No, we aren't selling bears. -

    -

    - We could talk about renting one. -

    -
    - Rent one bear, ... -
    -

    - get two for three beer. -

    -

    - And now, for something completely different. -

    -
    -
    - - -
    -
    Red
    -
    - Fancy stuff about red thingies. -
    -
    Green
    -
    - Green! Green! Green! -
    -
    Blue
    -
    - Cool kids are blue. -
    -
    - -
    -
    -
    Tennis
    -
    - One ball, two players. Lots of fun. -
    -
    -
    -
    Soccer
    -
    - One ball, 22 players. Lots of fun. -
    -
    -
    -
    Baseball
    -
    - Well, one ball, some guys running around, some guys hitting others with a stick.
    - Sounds like fun, doesn't it? -
    -
    - Well, apart from the running part. -
    -
    -
    - -
    I'm a resizable.
    - - - - - - - -

    - - - -
    - -
    -
      -
    • 1
    • -
    • 2
    • -
    • 3
    • -
    -
    -
    -
    -
    -
    -
      -
    • 1
    • -
    • 2
    • -
    -
    -
    -
    - -
    - - \ No newline at end of file diff --git a/tests/all_2.html b/tests/all_2.html deleted file mode 100644 index 42d86d39d..000000000 --- a/tests/all_2.html +++ /dev/null @@ -1,82 +0,0 @@ - - - - jQuery UI All Tests - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    jQuery UI All Tests

    - -

    - -

    Run individual testsuites or doubleclick a test below

    - - -
      - -
      - -
      - - - \ No newline at end of file diff --git a/tests/core.html b/tests/core.html deleted file mode 100644 index 06679794d..000000000 --- a/tests/core.html +++ /dev/null @@ -1,63 +0,0 @@ - - - - jQuery UI Core Test Suite - - - - - - - - - - - - - -
      -
      - - - - - - - - - anchor - anchor -
      -
      - - - - - - - - -
      -
      - - - - -
      -
      - - - - -
      -
      -
      - - - diff --git a/tests/core.js b/tests/core.js deleted file mode 100644 index 4be475486..000000000 --- a/tests/core.js +++ /dev/null @@ -1,78 +0,0 @@ -/* - * core unit tests - */ -(function($) { - -module("selectors"); - -test("tabbable - enabled elements", function() { - expect(10); - - ok( $('#input1-1').is(':tabbable'), 'input, no type'); - ok( $('#input1-2').is(':tabbable'), 'input, type text'); - ok( $('#input1-3').is(':tabbable'), 'input, type checkbox'); - ok( $('#input1-4').is(':tabbable'), 'input, type radio'); - ok( $('#input1-5').is(':tabbable'), 'input, type button'); - ok(!$('#input1-6').is(':tabbable'), 'input, type hidden'); - ok( $('#input1-7').is(':tabbable'), 'select'); - ok( $('#input1-8').is(':tabbable'), 'textarea'); - ok( $('#anchor1-1').is(':tabbable'), 'anchor with href'); - ok(!$('#anchor1-2').is(':tabbable'), 'anchor without href'); -}); - -test("tabbable - disabled elements", function() { - expect(8); - - ok(!$('#input2-1').is(':tabbable'), 'input, no type'); - ok(!$('#input2-2').is(':tabbable'), 'input, type text'); - ok(!$('#input2-3').is(':tabbable'), 'input, type checkbox'); - ok(!$('#input2-4').is(':tabbable'), 'input, type radio'); - ok(!$('#input2-5').is(':tabbable'), 'input, type button'); - ok(!$('#input2-6').is(':tabbable'), 'input, type hidden'); - ok(!$('#input2-7').is(':tabbable'), 'select'); - ok(!$('#input2-8').is(':tabbable'), 'textarea'); -}); - -test("tabbable - hidden styles", function() { - expect(6); - - ok(!$('#input3-1').is(':tabbable'), 'input, hidden wrapper - display: none'); - ok(!$('#anchor3-1').is(':tabbable'), 'anchor, hidden wrapper - display: none'); - ok(!$('#input3-2').is(':tabbable'), 'input, hidden wrapper - visibility: hidden'); - ok(!$('#anchor3-2').is(':tabbable'), 'anchor, hidden wrapper - visibility: hidden'); - ok(!$('#input3-3').is(':tabbable'), 'input, display: none'); - ok(!$('#input3-4').is(':tabbable'), 'input, visibility: hidden'); -}); - -test("tabbable - tabindex", function() { - expect(4); - - ok( $('#input4-1').is(':tabbable'), 'input, tabindex 0'); - ok( $('#input4-2').is(':tabbable'), 'input, tabindex 10'); - ok(!$('#input4-3').is(':tabbable'), 'input, tabindex -1'); - ok(!$('#input4-4').is(':tabbable'), 'input, tabindex -50'); -}); - -module('jQuery extensions'); - -test("attr - aria", function() { - expect(6); - - var el = $('#aria'); - - ok(!el.attr('role'), 'role is empty via attr'); - equals(el.attr('role', 'tablist').attr('role'), 'tablist', 'role is tablist'); - - equals(el.attr('aria-expanded'), undefined, 'aria expanded is undefined'); - - el.attr('aria-expanded', true); - equals(el.attr('aria-expanded'), 'true', 'aria expanded is true'); - - el.removeAttr('aria-expanded'); - equals(el.attr('aria-expanded'), undefined, 'aria expanded is undefined after removing'); - - el.attr('aria-expanded', false); - equals(el.attr('aria-expanded'), 'false', 'aria expanded is false'); -}); - -})(jQuery); diff --git a/tests/datepicker.html b/tests/datepicker.html deleted file mode 100644 index c25f1eae0..000000000 --- a/tests/datepicker.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - jQuery UI Datepicker Test Suite - - - - - - - - - - - - - - - - - - -
      -

      -
      - - - diff --git a/tests/datepicker.js b/tests/datepicker.js deleted file mode 100644 index dadb5a997..000000000 --- a/tests/datepicker.js +++ /dev/null @@ -1,1387 +0,0 @@ -/* - * datepicker unit tests - */ -(function($) { - -module('datepicker'); - -function equalsDate(d1, d2, message) { - if (!d1 || !d2) { - ok(false, message + ' - missing date'); - return; - } - d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()); - d2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()); - equals(d1.toString(), d2.toString(), message); -} - -function equalsDateArray(a1, a2, message) { - if (!a1 || !a2) { - ok(false, message + ' - missing dates'); - return; - } - a1[0] = (a1[0] ? new Date(a1[0].getFullYear(), a1[0].getMonth(), a1[0].getDate()) : ''); - a1[1] = (a1[1] ? new Date(a1[1].getFullYear(), a1[1].getMonth(), a1[1].getDate()) : ''); - a2[0] = (a2[0] ? new Date(a2[0].getFullYear(), a2[0].getMonth(), a2[0].getDate()) : ''); - a2[1] = (a2[1] ? new Date(a2[1].getFullYear(), a2[1].getMonth(), a2[1].getDate()) : ''); - same(a1, a2, message); -} - -function init(id, options) { - $.datepicker.setDefaults($.datepicker.regional['']); - var inp = $(id); - inp.datepicker($.extend({duration: ''}, options || {})); - return inp; -} - -var PROP_NAME = 'datepicker'; - -test('setDefaults', function() { - var inp = init('#inp'); - var dp = $('#ui-datepicker-div'); - ok(!dp.is(':visible'), 'Initially invisible'); - ok(inp.is('.hasDatepicker'), 'Marker class set'); - ok($($.datepicker.dpDiv).html() == '', 'Content empty'); - inp.datepicker('show'); - ok($($.datepicker.dpDiv).html() != '', 'Content present'); - inp.datepicker('hide'); - equals($.datepicker._defaults.showOn, 'focus', 'Initial showOn'); - $.datepicker.setDefaults({showOn: 'button'}); - equals($.datepicker._defaults.showOn, 'button', 'Change default showOn'); - $.datepicker.setDefaults({showOn: 'focus'}); - equals($.datepicker._defaults.showOn, 'focus', 'Restore showOn'); -}); - -test('destroy', function() { - var inp = init('#inp'); - ok(inp.is('.hasDatepicker'), 'Default - marker class set'); - ok($.data(inp[0], PROP_NAME), 'Default - instance present'); - ok(inp.next().is('#alt'), 'Default - button absent'); - inp.datepicker('destroy'); - inp = $('#inp'); - ok(!inp.is('.hasDatepicker'), 'Default - marker class cleared'); - ok(!$.data(inp[0], PROP_NAME), 'Default - instance absent'); - ok(inp.next().is('#alt'), 'Default - button absent'); - // With button - inp= init('#inp', {showOn: 'both'}); - ok(inp.is('.hasDatepicker'), 'Button - marker class set'); - ok($.data(inp[0], PROP_NAME), 'Button - instance present'); - ok(inp.next().text() == '...', 'Button - button added'); - inp.datepicker('destroy'); - inp = $('#inp'); - ok(!inp.is('.hasDatepicker'), 'Button - marker class cleared'); - ok(!$.data(inp[0], PROP_NAME), 'Button - instance absent'); - ok(inp.next().is('#alt'), 'Button - button removed'); - // With append text - inp = init('#inp', {appendText: 'Testing'}); - ok(inp.is('.hasDatepicker'), 'Append - marker class set'); - ok($.data(inp[0], PROP_NAME), 'Append - instance present'); - ok(inp.next().text() == 'Testing', 'Append - append text added'); - inp.datepicker('destroy'); - inp = $('#inp'); - ok(!inp.is('.hasDatepicker'), 'Append - marker class cleared'); - ok(!$.data(inp[0], PROP_NAME), 'Append - instance absent'); - ok(inp.next().is('#alt'), 'Append - append text removed'); - // With both - inp= init('#inp', {showOn: 'both', buttonImageOnly: true, - buttonImage: 'img/calendar.gif', appendText: 'Testing'}); - ok(inp.is('.hasDatepicker'), 'Both - marker class set'); - ok($.data(inp[0], PROP_NAME), 'Both - instance present'); - ok(inp.next()[0].nodeName.toLowerCase() == 'img', 'Both - button added'); - ok(inp.next().next().text() == 'Testing', 'Both - append text added'); - inp.datepicker('destroy'); - inp = $('#inp'); - ok(!inp.is('.hasDatepicker'), 'Both - marker class cleared'); - ok(!$.data(inp[0], PROP_NAME), 'Both - instance absent'); - ok(inp.next().is('#alt'), 'Both - button and append text absent'); - // Inline - var inl = init('#inl'); - ok(inl.is('.hasDatepicker'), 'Inline - marker class set'); - ok(inl.html() != '', 'Inline - datepicker present'); - ok($.data(inl[0], PROP_NAME), 'Inline - instance present'); - ok(inl.next().length == 0 || inl.next().is('p'), 'Inline - button absent'); - inl.datepicker('destroy'); - inl = $('#inl'); - ok(!inl.is('.hasDatepicker'), 'Inline - marker class cleared'); - ok(inl.html() == '', 'Inline - datepicker absent'); - ok(!$.data(inl[0], PROP_NAME), 'Inline - instance absent'); - ok(inl.next().length == 0 || inl.next().is('p'), 'Inline - button absent'); -}); - -test('option', function() { - var inp = init('#inp'); - var inst = $.data(inp[0], PROP_NAME); - equals(inst.settings.showOn, null, 'Initial setting showOn'); - equals($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance showOn'); - equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn'); - inp.datepicker('option', 'showOn', 'button'); - equals(inst.settings.showOn, 'button', 'Change setting showOn'); - equals($.datepicker._get(inst, 'showOn'), 'button', 'Change instance showOn'); - equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); - inp.datepicker('option', {showOn: 'both'}); - equals(inst.settings.showOn, 'both', 'Change setting showOn'); - equals($.datepicker._get(inst, 'showOn'), 'both', 'Change instance showOn'); - equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); - inp.datepicker('option', 'showOn', undefined); - equals(inst.settings.showOn, null, 'Clear setting showOn'); - equals($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance showOn'); - equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); -}); - -test('change', function() { - var inp = init('#inp'); - var inst = $.data(inp[0], PROP_NAME); - equals(inst.settings.showOn, null, 'Initial setting showOn'); - equals($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance showOn'); - equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn'); - inp.datepicker('change', 'showOn', 'button'); - equals(inst.settings.showOn, 'button', 'Change setting showOn'); - equals($.datepicker._get(inst, 'showOn'), 'button', 'Change instance showOn'); - equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); - inp.datepicker('change', {showOn: 'both'}); - equals(inst.settings.showOn, 'both', 'Change setting showOn'); - equals($.datepicker._get(inst, 'showOn'), 'both', 'Change instance showOn'); - equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); - inp.datepicker('change', 'showOn', undefined); - equals(inst.settings.showOn, null, 'Clear setting showOn'); - equals($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance showOn'); - equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); -}); - -test('invocation', function() { - var inp = init('#inp'); - var dp = $('#ui-datepicker-div'); - var body = $('body'); - // On focus - var button = inp.siblings('button'); - ok(button.length == 0, 'Focus - button absent'); - var image = inp.siblings('img'); - ok(image.length == 0, 'Focus - image absent'); - inp.focus(); - ok(dp.is(':visible'), 'Focus - rendered on focus'); - inp.simulate('keydown', {keyCode: $.simulate.VK_ESC}); - ok(!dp.is(':visible'), 'Focus - hidden on exit'); - inp.focus(); - ok(dp.is(':visible'), 'Focus - rendered on focus'); - body.simulate('mousedown', {}); - ok(!dp.is(':visible'), 'Focus - hidden on external click'); - inp.datepicker('hide').datepicker('destroy'); - // On button - inp = init('#inp', {showOn: 'button', buttonText: 'Popup'}); - ok(!dp.is(':visible'), 'Button - initially hidden'); - button = inp.siblings('button'); - image = inp.siblings('img'); - ok(button.length == 1, 'Button - button present'); - ok(image.length == 0, 'Button - image absent'); - equals(button.text(), 'Popup', 'Button - button text'); - inp.focus(); - ok(!dp.is(':visible'), 'Button - not rendered on focus'); - button.click(); - ok(dp.is(':visible'), 'Button - rendered on button click'); - button.click(); - ok(!dp.is(':visible'), 'Button - hidden on second button click'); - inp.datepicker('hide').datepicker('destroy'); - // On image button - inp = init('#inp', {showOn: 'button', buttonImageOnly: true, - buttonImage: 'img/calendar.gif', buttonText: 'Cal'}); - ok(!dp.is(':visible'), 'Image button - initially hidden'); - button = inp.siblings('button'); - ok(button.length == 0, 'Image button - button absent'); - image = inp.siblings('img'); - ok(image.length == 1, 'Image button - image present'); - equals(image.attr('src'), 'img/calendar.gif', 'Image button - image source'); - equals(image.attr('title'), 'Cal', 'Image button - image text'); - inp.focus(); - ok(!dp.is(':visible'), 'Image button - not rendered on focus'); - image.click(); - ok(dp.is(':visible'), 'Image button - rendered on image click'); - image.click(); - ok(!dp.is(':visible'), 'Image button - hidden on second image click'); - inp.datepicker('hide').datepicker('destroy'); - // On both - inp = init('#inp', {showOn: 'both', buttonImage: 'img/calendar.gif'}); - ok(!dp.is(':visible'), 'Both - initially hidden'); - button = inp.siblings('button'); - ok(button.length == 1, 'Both - button present'); - image = inp.siblings('img'); - ok(image.length == 0, 'Both - image absent'); - image = button.children('img'); - ok(image.length == 1, 'Both - button image present'); - inp.focus(); - ok(dp.is(':visible'), 'Both - rendered on focus'); - body.simulate('mousedown', {}); - ok(!dp.is(':visible'), 'Both - hidden on external click'); - button.click(); - ok(dp.is(':visible'), 'Both - rendered on button click'); - button.click(); - ok(!dp.is(':visible'), 'Both - hidden on second button click'); - inp.datepicker('hide').datepicker('destroy'); -}); - -test('baseStructure', function() { - var dp = $('#ui-datepicker-div'); - var inp = init('#inp'); - inp.focus(); - var iframe = ($.browser.msie && parseInt($.browser.version) < 7); - ok(dp.is(':visible'), 'Structure - datepicker visible'); - ok(!dp.is('.ui-datepicker-rtl'), 'Structure - not right-to-left'); - ok(!dp.is('.ui-datepicker-multi'), 'Structure - not multi-month'); - equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure - child count'); - - var header = dp.children(':first'); - ok(header.is('div.ui-datepicker-header'), 'Structure - header division'); - equals(header.children().length, 3, 'Structure - header child count'); - ok(header.children(':first').is('a.ui-datepicker-prev') && header.children(':first').html() != '', 'Structure - prev link'); - ok(header.children(':eq(1)').is('a.ui-datepicker-next') && header.children(':eq(1)').html() != '', 'Structure - next link'); - - var title = header.children(':last'); - ok(title.is('div.ui-datepicker-title') && title.html() != '','Structure - title division'); - equals(title.children().length, 2, 'Structure - title child count'); - ok(title.children(':first').is('span.ui-datepicker-month') && title.children(':first').text() != '', 'Structure - month text') - ok(title.children(':last').is('span.ui-datepicker-year') && title.children(':last').text() != '', 'Structure - year text') - - var table = dp.children(':eq(1)'); - ok(table.is('table.ui-datepicker-calendar'), 'Structure - month table'); - ok(table.children(':first').is('thead'), 'Structure - month table thead'); - var thead = table.children(':first').children(':first'); - ok(thead.is('tr'), 'Structure - month table title row'); - equals(thead.find('th').length, 7, 'Structure - month table title cells'); - ok(table.children(':eq(1)').is('tbody'), 'Structure - month table body'); - ok(table.children(':eq(1)').children('tr').length >= 4, 'Structure - month table week count'); - var week = table.children(':eq(1)').children(':first'); - ok(week.is('tr'), 'Structure - month table week row'); - equals(week.children().length, 7, 'Structure - week child count'); - ok(week.children(':first').is('td.ui-datepicker-week-end'), 'Structure - month table first day cell'); - ok(week.children(':last').is('td.ui-datepicker-week-end'), 'Structure - month table second day cell'); - ok(dp.children('iframe').length == (iframe ? 1 : 0), 'Structure - iframe'); - inp.datepicker('hide').datepicker('destroy'); - - // Editable month/year and button panel - inp = init('#inp', {changeMonth: true, changeYear: true, showButtonPanel: true}); - inp.focus(); - - var title = dp.find('div.ui-datepicker-title'); - ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure - month selector'); - ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure - year selector'); - - var panel = dp.children(':last'); - ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure - button panel division'); - equals(panel.children().length, 2, 'Structure - button panel child count'); - ok(panel.children(':first').is('button.ui-datepicker-current'), 'Structure - today button'); - ok(panel.children(':last').is('button.ui-datepicker-close'), 'Structure - close button'); - inp.datepicker('hide').datepicker('destroy'); - - // Multi-month 2 - inp = init('#inp', {numberOfMonths: 2}); - inp.focus(); - ok(dp.is('.ui-datepicker-multi'), 'Structure multi [2] - multi-month'); - equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure multi [2] - child count'); - month = dp.children(':first'); - ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi [2] - first month division'); - month = dp.children(':eq(1)'); - ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi [2] - second month division'); - inp.datepicker('hide').datepicker('destroy'); - - // Multi-month [2, 2] - inp = init('#inp', {numberOfMonths: [2, 2]}); - inp.focus(); - ok(dp.is('.ui-datepicker-multi'), 'Structure multi - multi-month'); - equals(dp.children().length, 4 + (iframe ? 1 : 0), 'Structure multi [2,2] - child count'); - month = dp.children(':first'); - ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - first month division'); - month = dp.children(':eq(1)'); - ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - second month division'); - month = dp.children(':eq(2)'); - ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - third month division'); - month = dp.children(':eq(3)'); - ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - fourth month division'); - inp.datepicker('hide').datepicker('destroy'); - - // Inline - var inl = init('#inl'); - dp = inl.children(); - ok(dp.is('.ui-datepicker-inline'), 'Structure inline - main div'); - ok(!dp.is('.ui-datepicker-rtl'), 'Structure inline - not right-to-left'); - ok(!dp.is('.ui-datepicker-multi'), 'Structure inline - not multi-month'); - equals(dp.children().length, 2, 'Structure inline - child count'); - var header = dp.children(':first'); - ok(header.is('div.ui-datepicker-header'), 'Structure inline - header division'); - equals(header.children().length, 3, 'Structure inline - header child count'); - var table = month.children(':eq(1)'); - ok(table.is('table.ui-datepicker-calendar'), 'Structure inline - month table'); - ok(table.children(':first').is('thead'), 'Structure inline - month table thead'); - ok(table.children(':eq(1)').is('tbody'), 'Structure inline - month table body'); - inl.datepicker('destroy'); - - // Inline multi-month - inl = init('#inl', {numberOfMonths: 2}); - dp = inl.children(); - ok(dp.is('.ui-datepicker-inline') && dp.is('.ui-datepicker-multi'), 'Structure inline multi - main div'); - equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure multi - child count'); - month = dp.children(':first'); - ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi - first month division'); - month = dp.children(':eq(1)'); - ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi - second month division'); - inl.datepicker('destroy'); -}); - -test('customStructure', function() { - var dp = $('#ui-datepicker-div'); - // Check right-to-left localisation - var inp = init('#inp', $.datepicker.regional['he']); - inp.data('showButtonPanel.datepicker',true); - inp.focus(); - var iframe = ($.browser.msie && parseInt($.browser.version) < 7); - ok(dp.is('.ui-datepicker-rtl'), 'Structure RTL - right-to-left'); - var header = dp.children(':first'); - ok(header.is('div.ui-datepicker-header'), 'Structure RTL - header division'); - equals(header.children().length, 3, 'Structure RTL - header child count'); - ok(header.children(':first').is('a.ui-datepicker-next'), 'Structure RTL - prev link'); - ok(header.children(':eq(1)').is('a.ui-datepicker-prev'), 'Structure RTL - next link'); - var panel = dp.children(':last'); - ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure RTL - button division'); - equals(panel.children().length, 2, 'Structure RTL - button panel child count'); - ok(panel.children(':first').is('button.ui-datepicker-close'), 'Structure RTL - close button'); - ok(panel.children(':last').is('button.ui-datepicker-current'), 'Structure RTL - today button'); - inp.datepicker('hide').datepicker('destroy'); - - // Hide prev/next - inp = init('#inp', {hideIfNoPrevNext: true, minDate: new Date(2008, 2 - 1, 4), maxDate: new Date(2008, 2 - 1, 14)}); - inp.val('02/10/2008').focus(); - var header = dp.children(':first'); - ok(header.is('div.ui-datepicker-header'), 'Structure hide prev/next - header division'); - equals(header.children().length, 1, 'Structure hide prev/next - links child count'); - ok(header.children(':first').is('div.ui-datepicker-title'), 'Structure hide prev/next - title division'); - inp.datepicker('hide').datepicker('destroy'); - - // Changeable Month with read-only year - inp = init('#inp', {changeMonth: true}); - inp.focus(); - var title = dp.children(':first').children(':last'); - equals(title.children().length, 2, 'Structure changeable month - title child count'); - ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure changeable month - month selector'); - ok(title.children(':last').is('span.ui-datepicker-year'), 'Structure changeable month - read-only year'); - inp.datepicker('hide').datepicker('destroy'); - - // Changeable year with read-only month - inp = init('#inp', {changeYear: true}); - inp.focus(); - var title = dp.children(':first').children(':last'); - equals(title.children().length, 2, 'Structure changeable year - title child count'); - ok(title.children(':first').is('span.ui-datepicker-month'), 'Structure changeable year - read-only month'); - ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure changeable year - year selector'); - inp.datepicker('hide').datepicker('destroy'); - - // Read-only first day of week - inp = init('#inp', {changeFirstDay: false}); - inp.focus(); - var thead = dp.find('.ui-datepicker-calendar thead tr'); - equals(thead.children().length, 7, 'Structure read-only first day - thead child count'); - equals(thead.find('a').length, 0, 'Structure read-only first day - thead links count'); - inp.datepicker('hide').datepicker('destroy'); -}); - -test('enableDisable', function() { - var inp = init('#inp'); - ok(!inp.datepicker('isDisabled'), 'Enable/disable - initially marked as enabled'); - ok(!inp[0].disabled, 'Enable/disable - field initially enabled'); - inp.datepicker('disable'); - ok(inp.datepicker('isDisabled'), 'Enable/disable - now marked as disabled'); - ok(inp[0].disabled, 'Enable/disable - field now disabled'); - inp.datepicker('enable'); - ok(!inp.datepicker('isDisabled'), 'Enable/disable - now marked as enabled'); - ok(!inp[0].disabled, 'Enable/disable - field now enabled'); - inp.datepicker('destroy'); - // With a button - inp = init('#inp', {showOn: 'button'}); - ok(!inp.datepicker('isDisabled'), 'Enable/disable button - initially marked as enabled'); - ok(!inp[0].disabled, 'Enable/disable button - field initially enabled'); - ok(!inp.next('button')[0].disabled, 'Enable/disable button - button initially enabled'); - inp.datepicker('disable'); - ok(inp.datepicker('isDisabled'), 'Enable/disable button - now marked as disabled'); - ok(inp[0].disabled, 'Enable/disable button - field now disabled'); - ok(inp.next('button')[0].disabled, 'Enable/disable button - button now disabled'); - inp.datepicker('enable'); - ok(!inp.datepicker('isDisabled'), 'Enable/disable button - now marked as enabled'); - ok(!inp[0].disabled, 'Enable/disable button - field now enabled'); - ok(!inp.next('button')[0].disabled, 'Enable/disable button - button now enabled'); - inp.datepicker('destroy'); - // With an image button - inp = init('#inp', {showOn: 'button', buttonImageOnly: true, - buttonImage: 'img/calendar.gif'}); - ok(!inp.datepicker('isDisabled'), 'Enable/disable image - initially marked as enabled'); - ok(!inp[0].disabled, 'Enable/disable image - field initially enabled'); - ok(inp.next('img').css('opacity') == 1, 'Enable/disable image - image initially enabled'); - inp.datepicker('disable'); - ok(inp.datepicker('isDisabled'), 'Enable/disable image - now marked as disabled'); - ok(inp[0].disabled, 'Enable/disable image - field now disabled'); - ok(inp.next('img').css('opacity') != 1, 'Enable/disable image - image now disabled'); - inp.datepicker('enable'); - ok(!inp.datepicker('isDisabled'), 'Enable/disable image - now marked as enabled'); - ok(!inp[0].disabled, 'Enable/disable image - field now enabled'); - ok(inp.next('img').css('opacity') == 1, 'Enable/disable image - image now enabled'); - inp.datepicker('destroy'); - // Inline - var inl = init('#inl'); - var dp = $('.ui-datepicker-inline', inl); - ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - initially marked as enabled'); - ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visually disabled initially'); - inl.datepicker('disable'); - ok(inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as disabled'); - ok(dp.children().is('.ui-state-disabled'), 'Enable/disable inline - visually disabled'); - inl.datepicker('enable'); - ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as enabled'); - ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visiually disabled'); - inl.datepicker('destroy'); -}); - -test('keystrokes', function() { - var inp = init('#inp'); - var date = new Date(); - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke enter'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), - 'Keystroke enter - preset'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+home'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); - ok(inp.datepicker('getDate') == null, 'Keystroke ctrl+end'); - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ESC}); - ok(inp.datepicker('getDate') == null, 'Keystroke esc'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ESC}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), - 'Keystroke esc - preset'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ESC}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), - 'Keystroke esc - abandoned'); - // Moving by day or week - inp.val('').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_LEFT}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() - 1); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+left'); - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_LEFT}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() + 1); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke left'); - inp.val('').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_RIGHT}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() + 1); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+right'); - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_RIGHT}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() - 1); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke right'); - inp.val('').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_UP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() - 7); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+up'); - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_UP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() + 7); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke up'); - inp.val('').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() + 7); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+down'); - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() - 7); - equalsDate(inp.datepicker('getDate'), date, 'Keystroke down'); - // Moving by month or year - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 4), - 'Keystroke pgup'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 4), - 'Keystroke pgdn'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 4), - 'Keystroke ctrl+pgup'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 4), - 'Keystroke ctrl+pgdn'); - // Check for moving to short months - inp.val('03/31/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29), - 'Keystroke pgup - Feb'); - inp.val('01/30/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29), - 'Keystroke pgdn - Feb'); - inp.val('02/29/2008').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 28), - 'Keystroke ctrl+pgup - Feb'); - inp.val('02/29/2008').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 28), - 'Keystroke ctrl+pgdn - Feb'); - // Goto current - inp.datepicker('option', {gotoCurrent: true}). - datepicker('hide').val('02/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), - 'Keystroke ctrl+home'); - // Change steps - inp.datepicker('option', {stepMonths: 2, gotoCurrent: false}). - datepicker('hide').val('02/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2007, 12 - 1, 4), - 'Keystroke pgup step 2'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 4 - 1, 4), - 'Keystroke pgdn step 2'); -}); - -test('mouse', function() { - var inp = init('#inp'); - var dp = $('#ui-datepicker-div'); - var date = new Date(); - inp.val('').datepicker('show'); - $('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {}); - date.setDate(10); - equalsDate(inp.datepicker('getDate'), date, 'Mouse click'); - inp.val('02/04/2008').datepicker('show'); - $('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 12), - 'Mouse click - preset'); - inp.val('02/04/2008').datepicker('show'); - inp.val('').datepicker('show'); - $('button.ui-datepicker-close', dp).simulate('click', {}); - ok(inp.datepicker('getDate') == null, 'Mouse click - close'); - inp.val('02/04/2008').datepicker('show'); - $('button.ui-datepicker-close', dp).simulate('click', {}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), - 'Mouse click - close + preset'); - inp.val('02/04/2008').datepicker('show'); - $('a.ui-datepicker-prev', dp).simulate('click', {}); - $('button.ui-datepicker-close', dp).simulate('click', {}); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), - 'Mouse click - abandoned'); - // Current/previous/next - inp.val('02/04/2008').datepicker('option', {showButtonPanel: true}).datepicker('show'); - $('.ui-datepicker-current', dp).simulate('click', {}); - $('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {}); - date.setDate(14); - equalsDate(inp.datepicker('getDate'), date, 'Mouse click - current'); - inp.val('02/04/2008').datepicker('show'); - $('.ui-datepicker-prev', dp).simulate('click'); - $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click'); - equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 16), - 'Mouse click - previous'); - inp.val('02/04/2008').datepicker('show'); - $('.ui-datepicker-next', dp).simulate('click'); - $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click'); - equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 18), - 'Mouse click - next'); - // Previous/next with minimum/maximum - inp.datepicker('option', {minDate: new Date(2008, 2 - 1, 2), - maxDate: new Date(2008, 2 - 1, 26)}).val('02/04/2008').datepicker('show'); - $('.ui-datepicker-prev', dp).simulate('click'); - $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click'); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 16), - 'Mouse click - previous + min/max'); - inp.val('02/04/2008').datepicker('show'); - $('.ui-datepicker-next', dp).simulate('click'); - $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click'); - equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 18), - 'Mouse click - next + min/max'); - // Inline - var inl = init('#inl'); - var dp = $('.ui-datepicker-inline', inl); - var date = new Date(); - inl.datepicker('setDate', date); - $('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {}); - date.setDate(10); - equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline'); - inl.datepicker('option', {showButtonPanel: true}).datepicker('setDate', new Date(2008, 2 - 1, 4)); - $('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {}); - equalsDate(inl.datepicker('getDate'), new Date(2008, 2 - 1, 12), 'Mouse click inline - preset'); - inl.datepicker('option', {showButtonPanel: true}); - $('.ui-datepicker-current', dp).simulate('click', {}); - $('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {}); - date.setDate(14); - equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline - current'); - inl.datepicker('setDate', new Date(2008, 2 - 1, 4)); - $('.ui-datepicker-prev', dp).simulate('click'); - $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click'); - equalsDate(inl.datepicker('getDate'), new Date(2008, 1 - 1, 16), - 'Mouse click inline - previous'); - inl.datepicker('setDate', new Date(2008, 2 - 1, 4)); - $('.ui-datepicker-next', dp).simulate('click'); - $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click'); - equalsDate(inl.datepicker('getDate'), new Date(2008, 3 - 1, 18), - 'Mouse click inline - next'); -}); - -test('defaultDate', function() { - var inp = init('#inp'); - var date = new Date(); - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), date, 'Default date null'); - // numeric values - inp.datepicker('option', {defaultDate: -2}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() - 2); - equalsDate(inp.datepicker('getDate'), date, 'Default date -2'); - inp.datepicker('option', {defaultDate: 3}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() + 5); - equalsDate(inp.datepicker('getDate'), date, 'Default date 3'); - inp.datepicker('option', {defaultDate: 1 / 0}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() - 3); - equalsDate(inp.datepicker('getDate'), date, 'Default date Infinity'); - inp.datepicker('option', {defaultDate: 1 / 'a'}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), date, 'Default date NaN'); - // string values - inp.datepicker('option', {defaultDate: '-1d'}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() - 1); - equalsDate(inp.datepicker('getDate'), date, 'Default date -1d'); - inp.datepicker('option', {defaultDate: '+3D'}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() + 4); - equalsDate(inp.datepicker('getDate'), date, 'Default date +3D'); - inp.datepicker('option', {defaultDate: ' -2 w '}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date = new Date(); - date.setDate(date.getDate() - 14); - equalsDate(inp.datepicker('getDate'), date, 'Default date -2 w'); - inp.datepicker('option', {defaultDate: '+1 W'}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() + 21); - equalsDate(inp.datepicker('getDate'), date, 'Default date +1 W'); - inp.datepicker('option', {defaultDate: ' -1 m '}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date = new Date(); - date.setMonth(date.getMonth() - 1); - equalsDate(inp.datepicker('getDate'), date, 'Default date -1 m'); - inp.datepicker('option', {defaultDate: '+2M'}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setMonth(date.getMonth() + 3); - equalsDate(inp.datepicker('getDate'), date, 'Default date +2M'); - inp.datepicker('option', {defaultDate: '-2y'}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date = new Date(); - date.setFullYear(date.getFullYear() - 2); - equalsDate(inp.datepicker('getDate'), date, 'Default date -2y'); - inp.datepicker('option', {defaultDate: '+1 Y '}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setFullYear(date.getFullYear() + 3); - equalsDate(inp.datepicker('getDate'), date, 'Default date +1 Y'); - inp.datepicker('option', {defaultDate: '+1M +10d'}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date = new Date(); - date.setMonth(date.getMonth() + 1); - date.setDate(date.getDate() + 10); - equalsDate(inp.datepicker('getDate'), date, 'Default date +1M +10d'); - date = new Date(2007, 1 - 1, 26); - inp.datepicker('option', {defaultDate: date}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), date, 'Default date 01/26/2007'); -}); - -test('miscellaneous', function() { - var dp = $('#ui-datepicker-div'); - var inp = init('#inp'); - // Year range - var genRange = function(start, offset) { - var range = ''; - for (var i = start; i < start + offset; i++) { - range += i; - } - return range; - }; - inp.val('02/04/2008').datepicker('show'); - equals(dp.find('.ui-datepicker-year').text(), '2008', 'Year range - read-only default'); - inp.datepicker('hide').datepicker('option', {changeYear: true}).datepicker('show'); - equals(dp.find('.ui-datepicker-year').text(), genRange(new Date().getFullYear() - 10, 21), 'Year range - changeable default'); - inp.datepicker('hide').datepicker('option', {yearRange: '-6:+2', changeYear: true}).datepicker('show'); - equals(dp.find('.ui-datepicker-year').text(), genRange(new Date().getFullYear() - 6, 9), 'Year range - -6:+2'); - inp.datepicker('hide').datepicker('option', {yearRange: '2000:2010', changeYear: true}).datepicker('show'); - equals(dp.find('.ui-datepicker-year').text(), genRange(2000, 11), 'Year range - 2000:2010'); - - // Navigation as date format - inp.datepicker('option', {showButtonPanel: true}); - equals(dp.find('.ui-datepicker-prev').text(), 'Prev', 'Navigation prev - default'); - equals(dp.find('.ui-datepicker-current').text(), 'Today', 'Navigation current - default'); - equals(dp.find('.ui-datepicker-next').text(), 'Next', 'Navigation next - default'); - inp.datepicker('hide').datepicker('option', {navigationAsDateFormat: true, prevText: '< M', currentText: 'MM', nextText: 'M >'}).val('02/04/2008').datepicker('show'); - var longNames = $.datepicker.regional[''].monthNames; - var shortNames = $.datepicker.regional[''].monthNamesShort; - var date = new Date(); - equals(dp.find('.ui-datepicker-prev').text(), '< ' + shortNames[0], 'Navigation prev - as date format'); - equals(dp.find('.ui-datepicker-current').text(), - longNames[date.getMonth()], 'Navigation current - as date format'); - equals(dp.find('.ui-datepicker-next').text(), - shortNames[2] + ' >', 'Navigation next - as date format'); - inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}); - equals(dp.find('.ui-datepicker-prev').text(), - '< ' + shortNames[1], 'Navigation prev - as date format + pgdn'); - equals(dp.find('.ui-datepicker-current').text(), - longNames[date.getMonth()], 'Navigation current - as date format + pgdn'); - equals(dp.find('.ui-datepicker-next').text(), - shortNames[3] + ' >', 'Navigation next - as date format + pgdn'); - inp.datepicker('hide').datepicker('option', {gotoCurrent: true}). - val('02/04/2008').datepicker('show'); - equals(dp.find('.ui-datepicker-prev').text(), - '< ' + shortNames[0], 'Navigation prev - as date format + goto current'); - equals(dp.find('.ui-datepicker-current').text(), - longNames[1], 'Navigation current - as date format + goto current'); - equals(dp.find('.ui-datepicker-next').text(), - shortNames[2] + ' >', 'Navigation next - as date format + goto current'); -}); - -test('minMax', function() { - var inp = init('#inp'); - var lastYear = new Date(2007, 6 - 1, 4); - var nextYear = new Date(2009, 6 - 1, 4); - var minDate = new Date(2008, 2 - 1, 29); - var maxDate = new Date(2008, 12 - 1, 7); - inp.val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), lastYear, - 'Min/max - null, null - ctrl+pgup'); - inp.val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), nextYear, - 'Min/max - null, null - ctrl+pgdn'); - inp.datepicker('option', {minDate: minDate}). - datepicker('hide').val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), minDate, - 'Min/max - 02/29/2008, null - ctrl+pgup'); - inp.val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), nextYear, - 'Min/max - 02/29/2008, null - ctrl+pgdn'); - inp.datepicker('option', {maxDate: maxDate}). - datepicker('hide').val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), minDate, - 'Min/max - 02/29/2008, 12/07/2008 - ctrl+pgup'); - inp.val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), maxDate, - 'Min/max - 02/29/2008, 12/07/2008 - ctrl+pgdn'); - inp.datepicker('option', {minDate: null}). - datepicker('hide').val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), lastYear, - 'Min/max - null, 12/07/2008 - ctrl+pgup'); - inp.val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), maxDate, - 'Min/max - null, 12/07/2008 - ctrl+pgdn'); - // Relative dates - var date = new Date(); - date.setDate(date.getDate() - 7); - inp.datepicker('option', {minDate: '-1w', maxDate: '+1 M +10 D '}). - datepicker('hide').val('').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), date, - 'Min/max - -1w, +1 M +10 D - ctrl+pgup'); - date = new Date(); - date.setMonth(date.getMonth() + 1); - date.setDate(date.getDate() + 10); - inp.val('').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDate(inp.datepicker('getDate'), date, - 'Min/max - -1w, +1 M +10 D - ctrl+pgdn'); -}); - -test('setDate', function() { - var inp = init('#inp'); - var date1 = new Date(2008, 6 - 1, 4); - var date2 = new Date(); - ok(inp.datepicker('getDate') == null, 'Set date - default'); - inp.datepicker('setDate', date1); - equalsDate(inp.datepicker('getDate'), date1, 'Set date - 2008-06-04'); - date1 = new Date(); - date1.setDate(date1.getDate() + 7); - inp.datepicker('setDate', +7); - equalsDate(inp.datepicker('getDate'), date1, 'Set date - +7'); - date2.setFullYear(date2.getFullYear() + 2); - inp.datepicker('setDate', '+2y'); - equalsDate(inp.datepicker('getDate'), date2, 'Set date - +2y'); - inp.datepicker('setDate', date1, date2); - equalsDate(inp.datepicker('getDate'), date1, 'Set date - two dates'); - inp.datepicker('setDate'); - ok(inp.datepicker('getDate') == null, 'Set date - null'); - // Inline - var inl = init('#inl'); - date1 = new Date(2008, 6 - 1, 4); - date2 = new Date(); - equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - default'); - inl.datepicker('setDate', date1); - equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - 2008-06-04'); - date1 = new Date(); - date1.setDate(date1.getDate() + 7); - inl.datepicker('setDate', +7); - equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - +7'); - date2.setFullYear(date2.getFullYear() + 2); - inl.datepicker('setDate', '+2y'); - equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - +2y'); - inl.datepicker('setDate', date1, date2); - equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - two dates'); - inl.datepicker('setDate'); - ok(inl.datepicker('getDate') == null, 'Set date inline - null'); - // Alternate field - var alt = $('#alt'); - inp.datepicker('option', {altField: '#alt', altFormat: 'yy-mm-dd'}); - date1 = new Date(2008, 6 - 1, 4); - inp.datepicker('setDate', date1); - equals(inp.val(), '06/04/2008', 'Set date alternate - 06/04/2008'); - equals(alt.val(), '2008-06-04', 'Set date alternate - 2008-06-04'); -}); - -test('altField', function() { - var inp = init('#inp'); - var alt = $('#alt'); - // No alternate field set - alt.val(''); - inp.val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(inp.val(), '06/04/2008', 'Alt field - dp - enter'); - equals(alt.val(), '', 'Alt field - alt not set'); - // Alternate field set - alt.val(''); - inp.datepicker('option', {altField: '#alt', altFormat: 'yy-mm-dd'}). - val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(inp.val(), '06/04/2008', 'Alt field - dp - enter'); - equals(alt.val(), '2008-06-04', 'Alt field - alt - enter'); - // Move from initial date - alt.val(''); - inp.val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(inp.val(), '07/04/2008', 'Alt field - dp - pgdn'); - equals(alt.val(), '2008-07-04', 'Alt field - alt - pgdn'); - // Alternate field set - closed - alt.val(''); - inp.val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ESC}); - equals(inp.val(), '06/04/2008', 'Alt field - dp - pgdn/esc'); - equals(alt.val(), '', 'Alt field - alt - pgdn/esc'); - // Clear date and alternate - alt.val(''); - inp.val('06/04/2008').datepicker('show'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); - equals(inp.val(), '', 'Alt field - dp - ctrl+end'); - equals(alt.val(), '', 'Alt field - alt - ctrl+end'); -}); - -test('daylightSaving', function() { - var inp = init('#inp'); - var dp = $('#ui-datepicker-div'); - ok(true, 'Daylight saving - ' + new Date()); - // Australia, Sydney - AM change, southern hemisphere - inp.val('04/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(6) a', dp).simulate('click'); - equals(inp.val(), '04/05/2008', 'Daylight saving - Australia 04/05/2008'); - inp.val('04/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(7) a', dp).simulate('click'); - equals(inp.val(), '04/06/2008', 'Daylight saving - Australia 04/06/2008'); - inp.val('04/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(8) a', dp).simulate('click'); - equals(inp.val(), '04/07/2008', 'Daylight saving - Australia 04/07/2008'); - inp.val('10/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(6) a', dp).simulate('click'); - equals(inp.val(), '10/04/2008', 'Daylight saving - Australia 10/04/2008'); - inp.val('10/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(7) a', dp).simulate('click'); - equals(inp.val(), '10/05/2008', 'Daylight saving - Australia 10/05/2008'); - inp.val('10/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(8) a', dp).simulate('click'); - equals(inp.val(), '10/06/2008', 'Daylight saving - Australia 10/06/2008'); - // Brasil, Brasilia - midnight change, southern hemisphere - inp.val('02/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(20) a', dp).simulate('click'); - equals(inp.val(), '02/16/2008', 'Daylight saving - Brasil 02/16/2008'); - inp.val('02/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(21) a', dp).simulate('click'); - equals(inp.val(), '02/17/2008', 'Daylight saving - Brasil 02/17/2008'); - inp.val('02/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(22) a', dp).simulate('click'); - equals(inp.val(), '02/18/2008', 'Daylight saving - Brasil 02/18/2008'); - inp.val('10/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(13) a', dp).simulate('click'); - equals(inp.val(), '10/11/2008', 'Daylight saving - Brasil 10/11/2008'); - inp.val('10/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(14) a', dp).simulate('click'); - equals(inp.val(), '10/12/2008', 'Daylight saving - Brasil 10/12/2008'); - inp.val('10/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(15) a', dp).simulate('click'); - equals(inp.val(), '10/13/2008', 'Daylight saving - Brasil 10/13/2008'); - // Lebanon, Beirut - midnight change, northern hemisphere - inp.val('03/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(34) a', dp).simulate('click'); - equals(inp.val(), '03/29/2008', 'Daylight saving - Lebanon 03/29/2008'); - inp.val('03/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(35) a', dp).simulate('click'); - equals(inp.val(), '03/30/2008', 'Daylight saving - Lebanon 03/30/2008'); - inp.val('03/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(36) a', dp).simulate('click'); - equals(inp.val(), '03/31/2008', 'Daylight saving - Lebanon 03/31/2008'); - inp.val('10/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(27) a', dp).simulate('click'); - equals(inp.val(), '10/25/2008', 'Daylight saving - Lebanon 10/25/2008'); - inp.val('10/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(28) a', dp).simulate('click'); - equals(inp.val(), '10/26/2008', 'Daylight saving - Lebanon 10/26/2008'); - inp.val('10/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(29) a', dp).simulate('click'); - equals(inp.val(), '10/27/2008', 'Daylight saving - Lebanon 10/27/2008'); - // US, Eastern - AM change, northern hemisphere - inp.val('03/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(13) a', dp).simulate('click'); - equals(inp.val(), '03/08/2008', 'Daylight saving - US 03/08/2008'); - inp.val('03/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(14) a', dp).simulate('click'); - equals(inp.val(), '03/09/2008', 'Daylight saving - US 03/09/2008'); - inp.val('03/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(15) a', dp).simulate('click'); - equals(inp.val(), '03/10/2008', 'Daylight saving - US 03/10/2008'); - inp.val('11/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(6) a', dp).simulate('click'); - equals(inp.val(), '11/01/2008', 'Daylight saving - US 11/01/2008'); - inp.val('11/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(7) a', dp).simulate('click'); - equals(inp.val(), '11/02/2008', 'Daylight saving - US 11/02/2008'); - inp.val('11/01/2008').datepicker('show'); - $('.ui-datepicker-calendar td:eq(8) a', dp).simulate('click'); - equals(inp.val(), '11/03/2008', 'Daylight saving - US 11/03/2008'); -}); - -var beforeShowThis = null; -var beforeShowInput = null; -var beforeShowInst = null; - -function beforeAll(input, inst) { - beforeShowThis = this; - beforeShowInput = input; - beforeShowInst = inst; - return {currentText: 'Current'}; -} - -var beforeShowDayThis = null; -var beforeShowDayOK = true; - -function beforeDay(date) { - beforeShowDayThis = this; - beforeShowDayOK &= (date > new Date(2008, 1 - 1, 26) && - date < new Date(2008, 3 - 1, 6)); - return [(date.getDate() % 2 == 0), (date.getDate() % 10 == 0 ? 'day10' : ''), - (date.getDate() % 3 == 0 ? 'Divisble by 3' : '')]; -} - -function calcWeek(date) { - var doy = date.getDate() + 6; - for (var m = date.getMonth() - 1; m >= 0; m--) - doy += $.datepicker._getDaysInMonth(date.getFullYear(), m); - // Simple count from 01/01 starting at week 1 - return Math.floor(doy / 7); -} - -test('callbacks', function() { - // Before show - var inp = init('#inp', {beforeShow: beforeAll}); - var inst = $.data(inp[0], 'datepicker'); - equals($.datepicker._get(inst, 'currentText'), 'Today', 'Before show - initial'); - inp.val('02/04/2008').datepicker('show'); - equals($.datepicker._get(inst, 'currentText'), 'Current', 'Before show - changed'); - ok(beforeShowThis.id == inp[0].id, 'Before show - this OK'); - ok(beforeShowInput.id == inp[0].id, 'Before show - input OK'); - isObj(beforeShowInst, inst, 'Before show - inst OK'); - inp.datepicker('hide').datepicker('destroy'); - // Before show day - inp = init('#inp', {beforeShowDay: beforeDay}); - var dp = $('#ui-datepicker-div'); - inp.val('02/04/2008').datepicker('show'); - ok(beforeShowDayThis.id == inp[0].id, 'Before show day - this OK'); - ok(beforeShowDayOK, 'Before show day - dates OK'); - var day20 = dp.find('.ui-datepicker-calendar td:contains("20")'); - var day21 = dp.find('.ui-datepicker-calendar td:contains("21")'); - ok(!day20.is('.ui-datepicker-unselectable'), 'Before show day - unselectable 20'); - ok(day21.is('.ui-datepicker-unselectable'), 'Before show day - unselectable 21'); - ok(day20.is('.day10'), 'Before show day - CSS 20'); - ok(!day21.is('.day10'), 'Before show day - CSS 21'); - ok(day20.attr('title') == '', 'Before show day - title 20'); - ok(day21.attr('title') == 'Divisble by 3', 'Before show day - title 21'); - inp.datepicker('hide').datepicker('destroy'); -}); - -var selectedThis = null; -var selectedDate = null; -var selectedInst = null; - -function callback(date, inst) { - selectedThis = this; - selectedDate = date; - selectedInst = inst; -} - -function callback2(year, month, inst) { - selectedThis = this; - selectedDate = year + '/' + month; - selectedInst = inst; -} - -test('events', function() { - var inp = init('#inp', {onSelect: callback}); - var date = new Date(); - // onSelect - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(selectedThis, inp[0], 'Callback selected this'); - equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback selected inst'); - equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), - 'Callback selected date'); - inp.val('').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date.setDate(date.getDate() + 7); - equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), - 'Callback selected date - ctrl+down'); - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ESC}); - equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), - 'Callback selected date - esc'); - // onChangeMonthYear - inp.datepicker('option', {onChangeMonthYear: callback2, onSelect: null}). - val('').datepicker('show'); - var newMonthYear = function(date) { - return date.getFullYear() + '/' + (date.getMonth() + 1); - }; - date = new Date(); - date.setDate(1); - inp.simulate('keydown', {keyCode: $.simulate.VK_PGUP}); - date.setMonth(date.getMonth() - 1); - equals(selectedThis, inp[0], 'Callback change month/year this'); - equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback change month/year inst'); - equals(selectedDate, newMonthYear(date), - 'Callback change month/year date - pgup'); - inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}); - date.setMonth(date.getMonth() + 1); - equals(selectedDate, newMonthYear(date), - 'Callback change month/year date - pgdn'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}); - date.setFullYear(date.getFullYear() - 1); - equals(selectedDate, newMonthYear(date), - 'Callback change month/year date - ctrl+pgup'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}); - date.setFullYear(date.getFullYear() + 1); - equals(selectedDate, newMonthYear(date), - 'Callback change month/year date - ctrl+home'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}); - date.setFullYear(date.getFullYear() + 1); - equals(selectedDate, newMonthYear(date), - 'Callback change month/year date - ctrl+pgdn'); - inp.datepicker('setDate', new Date(2007, 1 - 1, 26)); - equals(selectedDate, '2007/1', 'Callback change month/year date - setDate'); - selectedDate = null; - inp.datepicker('setDate', new Date(2007, 1 - 1, 12)); - ok(selectedDate == null, 'Callback change month/year date - setDate no change'); - // onChangeMonthYear step by 2 - inp.datepicker('option', {stepMonths: 2}). - datepicker('hide').val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGUP}); - date.setMonth(date.getMonth() - 14); - equals(selectedDate, newMonthYear(date), - 'Callback change month/year by 2 date - pgup'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}); - date.setMonth(date.getMonth() - 12); - equals(selectedDate, newMonthYear(date), - 'Callback change month/year by 2 date - ctrl+pgup'); - inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}); - date.setMonth(date.getMonth() + 2); - equals(selectedDate, newMonthYear(date), - 'Callback change month/year by 2 date - pgdn'); - inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}); - date.setMonth(date.getMonth() + 12); - equals(selectedDate, newMonthYear(date), - 'Callback change month/year by 2 date - ctrl+pgdn'); - // onClose - inp.datepicker('option', {onClose: callback, onChangeMonthYear: null, stepMonths: 1}). - val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ESC}); - equals(selectedThis, inp[0], 'Callback close this'); - equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback close inst'); - equals(selectedDate, '', 'Callback close date - esc'); - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', new Date()), - 'Callback close date - enter'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ESC}); - equals(selectedDate, '02/04/2008', 'Callback close date - preset'); - inp.val('02/04/2008').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); - equals(selectedDate, '', 'Callback close date - ctrl+end'); -}); - -test('localisation', function() { - var inp = init('#inp', $.datepicker.regional['fr']); - inp.datepicker('option', {dateFormat: 'DD, d MM yy', showButtonPanel:true, changeMonth:true, changeYear:true}).val('').datepicker('show'); - var dp = $('#ui-datepicker-div'); - equals($('.ui-datepicker-close', dp).text(), 'Fermer', 'Localisation - close'); - $('.ui-datepicker-close', dp).simulate('mouseover'); - equals($('.ui-datepicker-prev', dp).text(), '', 'Localisation - next'); - var month = 0; - $('.ui-datepicker-month option', dp).each(function() { - equals($(this).text(), $.datepicker.regional['fr'].monthNamesShort[month], - 'Localisation - month ' + month); - month++; - }); - var day = 1; - $('.ui-datepicker-calendar th', dp).each(function() { - equals($(this).text(), $.datepicker.regional['fr'].dayNamesMin[day], - 'Localisation - day ' + day); - day = (day + 1) % 7; - }); - inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - var date = new Date(); - equals(inp.val(), $.datepicker.regional['fr'].dayNames[date.getDay()] + ', ' + - date.getDate() + ' ' + $.datepicker.regional['fr'].monthNames[date.getMonth()] + - ' ' + date.getFullYear(), 'Localisation - formatting'); -}); - -test('noWeekends', function() { - for (var i = 1; i <= 31; i++) { - var date = new Date(2001, 1 - 1, i); - isSet($.datepicker.noWeekends(date), [(i + 1) % 7 >= 2, ''], - 'No weekends ' + date); - } -}); - -test('iso8601Week', function() { - var date = new Date(2000, 12 - 1, 31); - equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date); - date = new Date(2001, 1 - 1, 1); - equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); - date = new Date(2001, 1 - 1, 7); - equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); - date = new Date(2001, 1 - 1, 8); - equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date); - date = new Date(2003, 12 - 1, 28); - equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date); - date = new Date(2003, 12 - 1, 29); - equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); - date = new Date(2004, 1 - 1, 4); - equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); - date = new Date(2004, 1 - 1, 5); - equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date); - date = new Date(2009, 12 - 1, 28); - equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date); - date = new Date(2010, 1 - 1, 3); - equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date); - date = new Date(2010, 1 - 1, 4); - equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); - date = new Date(2010, 1 - 1, 10); - equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); -}); - -test('parseDate', function() { - init('#inp'); - ok($.datepicker.parseDate('d m y', '') == null, 'Parse date empty'); - equalsDate($.datepicker.parseDate('d m y', '3 2 01'), - new Date(2001, 2 - 1, 3), 'Parse date d m y'); - equalsDate($.datepicker.parseDate('dd mm yy', '03 02 2001'), - new Date(2001, 2 - 1, 3), 'Parse date dd mm yy'); - equalsDate($.datepicker.parseDate('d m y', '13 12 01'), - new Date(2001, 12 - 1, 13), 'Parse date d m y'); - equalsDate($.datepicker.parseDate('dd mm yy', '13 12 2001'), - new Date(2001, 12 - 1, 13), 'Parse date dd mm yy'); - equalsDate($.datepicker.parseDate('y-o', '2001-34'), - new Date(2001, 2 - 1, 3), 'Parse date y-o'); - equalsDate($.datepicker.parseDate('yy-oo', '2001-347'), - new Date(2001, 12 - 1, 13), 'Parse date yy oo'); - equalsDate($.datepicker.parseDate('oo yy', '348 2004'), - new Date(2004, 12 - 1, 13), 'Parse date oo-yy'); - equalsDate($.datepicker.parseDate('D d M y', 'Sat 3 Feb 01'), - new Date(2001, 2 - 1, 3), 'Parse date D d M y'); - equalsDate($.datepicker.parseDate('d MM DD yy', '3 February Saturday 2001'), - new Date(2001, 2 - 1, 3), 'Parse date dd MM DD yy'); - equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Saturday, February 3, 2001'), - new Date(2001, 2 - 1, 3), 'Parse date DD, MM d, yy'); - equalsDate($.datepicker.parseDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy', - 'day 3 of February (\'Saturday\'), 2001'), new Date(2001, 2 - 1, 3), - 'Parse date \'day\' d \'of\' MM (\'\'DD\'\'), yy'); - equalsDate($.datepicker.parseDate('y-m-d', '01-02-03'), - new Date(2001, 2 - 1, 3), 'Parse date y-m-d - default cutoff'); - equalsDate($.datepicker.parseDate('y-m-d', '51-02-03'), - new Date(1951, 2 - 1, 3), 'Parse date y-m-d - default cutoff'); - equalsDate($.datepicker.parseDate('y-m-d', '51-02-03', {shortYearCutoff: 80}), - new Date(2051, 2 - 1, 3), 'Parse date y-m-d - cutoff 80'); - equalsDate($.datepicker.parseDate('y-m-d', '51-02-03', {shortYearCutoff: '+60'}), - new Date(2051, 2 - 1, 3), 'Parse date y-m-d - cutoff +60'); - var fr = $.datepicker.regional['fr']; - var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, - monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; - equalsDate($.datepicker.parseDate('D d M y', 'Lun 9 Avr 01', settings), - new Date(2001, 4 - 1, 9), 'Parse date D M y with settings'); - equalsDate($.datepicker.parseDate('d MM DD yy', '9 Avril Lundi 2001', settings), - new Date(2001, 4 - 1, 9), 'Parse date d MM DD yy with settings'); - equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Lundi, Avril 9, 2001', settings), - new Date(2001, 4 - 1, 9), 'Parse date DD, MM d, yy with settings'); - equalsDate($.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy', - 'jour 9 de Avril (\'Lundi\'), 2001', settings), new Date(2001, 4 - 1, 9), - 'Parse date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings'); -}); - -test('parseDateErrors', function() { - init('#inp'); - var expectError = function(expr, value, error) { - try { - expr(); - ok(false, 'Parsed error ' + value); - } - catch (e) { - equals(e, error, 'Parsed error ' + value); - } - }; - expectError(function() { $.datepicker.parseDate(null, 'Sat 2 01'); }, - 'Sat 2 01', 'Invalid arguments'); - expectError(function() { $.datepicker.parseDate('d m y', null); }, - 'null', 'Invalid arguments'); - expectError(function() { $.datepicker.parseDate('d m y', 'Sat 2 01'); }, - 'Sat 2 01 - d m y', 'Missing number at position 0'); - expectError(function() { $.datepicker.parseDate('dd mm yy', 'Sat 2 01'); }, - 'Sat 2 01 - dd mm yy', 'Missing number at position 0'); - expectError(function() { $.datepicker.parseDate('d m y', '3 Feb 01'); }, - '3 Feb 01 - d m y', 'Missing number at position 2'); - expectError(function() { $.datepicker.parseDate('dd mm yy', '3 Feb 01'); }, - '3 Feb 01 - dd mm yy', 'Missing number at position 2'); - expectError(function() { $.datepicker.parseDate('d m y', '3 2 AD01'); }, - '3 2 AD01 - d m y', 'Missing number at position 4'); - expectError(function() { $.datepicker.parseDate('d m yy', '3 2 AD01'); }, - '3 2 AD01 - dd mm yy', 'Missing number at position 4'); - expectError(function() { $.datepicker.parseDate('y-o', '2001-D01'); }, - '2001-D01 - y-o', 'Missing number at position 5'); - expectError(function() { $.datepicker.parseDate('yy-oo', '2001-D01'); }, - '2001-D01 - yy-oo', 'Missing number at position 5'); - expectError(function() { $.datepicker.parseDate('D d M y', 'D7 3 Feb 01'); }, - 'D7 3 Feb 01 - D d M y', 'Unknown name at position 0'); - expectError(function() { $.datepicker.parseDate('D d M y', 'Sat 3 M2 01'); }, - 'Sat 3 M2 01 - D d M y', 'Unknown name at position 6'); - expectError(function() { $.datepicker.parseDate('DD, MM d, yy', 'Saturday- Feb 3, 2001'); }, - 'Saturday- Feb 3, 2001 - DD, MM d, yy', 'Unexpected literal at position 8'); - expectError(function() { $.datepicker.parseDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy', - 'day 3 of February ("Saturday"), 2001'); }, - 'day 3 of Mon2 ("Day7"), 2001', 'Unexpected literal at position 19'); - expectError(function() { $.datepicker.parseDate('d m y', '29 2 01'); }, - '29 2 01 - d m y', 'Invalid date'); - var fr = $.datepicker.regional['fr']; - var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, - monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; - expectError(function() { $.datepicker.parseDate('D d M y', 'Mon 9 Avr 01', settings); }, - 'Mon 9 Avr 01 - D d M y', 'Unknown name at position 0'); - expectError(function() { $.datepicker.parseDate('D d M y', 'Lun 9 Apr 01', settings); }, - 'Lun 9 Apr 01 - D d M y', 'Unknown name at position 6'); -}); - -test('formatDate', function() { - init('#inp'); - equals($.datepicker.formatDate('d m y', new Date(2001, 2 - 1, 3)), - '3 2 01', 'Format date d m y'); - equals($.datepicker.formatDate('dd mm yy', new Date(2001, 2 - 1, 3)), - '03 02 2001', 'Format date dd mm yy'); - equals($.datepicker.formatDate('d m y', new Date(2001, 12 - 1, 13)), - '13 12 01', 'Format date d m y'); - equals($.datepicker.formatDate('dd mm yy', new Date(2001, 12 - 1, 13)), - '13 12 2001', 'Format date dd mm yy'); - equals($.datepicker.formatDate('yy-o', new Date(2001, 2 - 1, 3)), - '2001-34', 'Format date yy-o'); - equals($.datepicker.formatDate('yy-oo', new Date(2001, 2 - 1, 3)), - '2001-034', 'Format date yy-oo'); - equals($.datepicker.formatDate('D M y', new Date(2001, 2 - 1, 3)), - 'Sat Feb 01', 'Format date D M y'); - equals($.datepicker.formatDate('DD MM yy', new Date(2001, 2 - 1, 3)), - 'Saturday February 2001', 'Format date DD MM yy'); - equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 2 - 1, 3)), - 'Saturday, February 3, 2001', 'Format date DD, MM d, yy'); - equals($.datepicker.formatDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy', - new Date(2001, 2 - 1, 3)), 'day 3 of February (\'Saturday\'), 2001', - 'Format date \'day\' d \'of\' MM (\'\'DD\'\'), yy'); - var fr = $.datepicker.regional['fr']; - var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, - monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; - equals($.datepicker.formatDate('D M y', new Date(2001, 4 - 1, 9), settings), - 'Lun Avr 01', 'Format date D M y with settings'); - equals($.datepicker.formatDate('DD MM yy', new Date(2001, 4 - 1, 9), settings), - 'Lundi Avril 2001', 'Format date DD MM yy with settings'); - equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 4 - 1, 9), settings), - 'Lundi, Avril 9, 2001', 'Format date DD, MM d, yy with settings'); - equals($.datepicker.formatDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy', - new Date(2001, 4 - 1, 9), settings), 'jour 9 de Avril (\'Lundi\'), 2001', - 'Format date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings'); -}); - -})(jQuery); diff --git a/tests/dialog.html b/tests/dialog.html deleted file mode 100644 index 954561cfc..000000000 --- a/tests/dialog.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - jQuery UI Dialog Test Suite - - - - - - - - - - - - - - - - -
      -
      Dialog Content
      -
      - - - diff --git a/tests/dialog.js b/tests/dialog.js deleted file mode 100644 index 25f8b63e9..000000000 --- a/tests/dialog.js +++ /dev/null @@ -1,723 +0,0 @@ -/* - * dialog unit tests - */ -(function($) { -// -// Dialog Test Helper Functions -// - -var defaults = { - autoOpen: true, - buttons: {}, - closeOnEscape: true, - closeText: 'close', - disabled: false, - dialogClass: undefined, - draggable: true, - height: 'auto', - maxHeight: undefined, - maxWidth: undefined, - minHeight: 150, - minWidth: 150, - modal: false, - overlay: {}, - position: 'center', - resizable: true, - stack: true, - title: '', - width: 300 -}; - -var el, - offsetBefore, offsetAfter, - heightBefore, heightAfter, - widthBefore, widthAfter, - dragged; - -function dlg() { - return el.data("dialog").element.parents(".ui-dialog:first"); -} - -function isOpen(why) { - ok(dlg().is(":visible"), why); -} - -function isNotOpen(why) { - ok(!dlg().is(":visible"), why); -} - -function drag(handle, dx, dy) { - var d = dlg(); - offsetBefore = d.offset(); - heightBefore = d.height(); - widthBefore = d.width(); - //this mouseover is to work around a limitation in resizable - //TODO: fix resizable so handle doesn't require mouseover in order to be used - $(handle, d).simulate("mouseover"); - $(handle, d).simulate("drag", { - dx: dx || 0, - dy: dy || 0 - }); - dragged = { dx: dx, dy: dy }; - offsetAfter = d.offset(); - heightAfter = d.height(); - widthAfter = d.width(); -} - -function moved(dx, dy, msg) { - msg = msg ? msg + "." : ""; - var actual = { left: offsetAfter.left, top: offsetAfter.top }; - var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy }; - same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); -} - -function shouldmove(why) { - var handle = $(".ui-dialog-titlebar", dlg()); - drag(handle, 50, 50); - moved(50, 50, why); -} - -function shouldnotmove(why) { - var handle = $(".ui-dialog-titlebar", dlg()); - drag(handle, 50, 50); - moved(0, 0, why); -} - -function resized(dw, dh, msg) { - msg = msg ? msg + "." : ""; - var actual = { width: widthAfter, height: heightAfter }; - var expected = { width: widthBefore + dw, height: heightBefore + dh }; - same(actual, expected, 'resized[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); -} - -function shouldresize(why) { - var handle = $(".ui-resizable-se", dlg()); - drag(handle, 50, 50); - resized(50, 50, why); -} - -function shouldnotresize(why) { - var handle = $(".ui-resizable-se", dlg()); - drag(handle, 50, 50); - resized(0, 0, why); -} - -function broder(el, side){ - return parseInt(el.css('border-' + side + '-width'), 10); -} - -function margin(el, side) { - return parseInt(el.css('margin-' + side), 10); -} - -// Dialog Tests -module("dialog"); - -test("init", function() { - expect(7); - - $("
      ").appendTo('body').dialog().remove(); - ok(true, '.dialog() called on element'); - - $([]).dialog().remove(); - ok(true, '.dialog() called on empty collection'); - - $('
      ').dialog().remove(); - ok(true, '.dialog() called on disconnected DOMElement - never connected'); - - $('
      ').appendTo('body').remove().dialog().remove(); - ok(true, '.dialog() called on disconnected DOMElement - removed'); - - $('
      ').dialog().dialog("foo").remove(); - ok(true, 'arbitrary method called after init'); - - el = $('
      ').dialog(); - var foo = el.data("foo.dialog"); - el.remove(); - ok(true, 'arbitrary option getter after init'); - - $('
      ').dialog().data("foo.dialog", "bar").remove(); - ok(true, 'arbitrary option setter after init'); -}); - -test("destroy", function() { - expect(6); - - $("
      ").appendTo('body').dialog().dialog("destroy").remove(); - ok(true, '.dialog("destroy") called on element'); - - $([]).dialog().dialog("destroy").remove(); - ok(true, '.dialog("destroy") called on empty collection'); - - $('
      ').dialog().dialog("destroy").remove(); - ok(true, '.dialog("destroy") called on disconnected DOMElement'); - - $('
      ').dialog().dialog("destroy").dialog("foo").remove(); - ok(true, 'arbitrary method called after destroy'); - - el = $('
      ').dialog(); - var foo = el.dialog("destroy").data("foo.dialog"); - el.remove(); - ok(true, 'arbitrary option getter after destroy'); - - $('
      ').dialog().dialog("destroy").data("foo.dialog", "bar").remove(); - ok(true, 'arbitrary option setter after destroy'); -}); - -/* -//This one takes a while to run - -test("element types", function() { - var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' - + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' - + ',acronym,code,samp,kbd,var,img,object,hr' - + ',input,button,label,select,iframe').split(','); - - $.each(typeNames, function(i) { - var typeName = typeNames[i]; - el = $(document.createElement(typeName)).appendTo('body'); - (typeName == 'table' && el.append("content")); - el.dialog(); - ok(true, '$("<' + typeName + '/>").dialog()'); - el.dialog("destroy"); - el.remove(); - }); -}); - -*/ - -test("defaults", function() { - el = $('
      ').dialog(); - $.each(defaults, function(key, val) { - var actual = el.data(key + ".dialog"), expected = val; - same(actual, expected, key); - }); - el.remove(); -}); - -test("title id", function() { - expect(3); - - var titleId; - - // reset the uuid so we know what values to expect - $.ui.dialog.uuid = 0; - - el = $('
      ').dialog(); - titleId = dlg().find('.ui-dialog-title').attr('id'); - equals(titleId, 'ui-dialog-title-1', 'auto-numbered title id'); - el.remove(); - - el = $('
      ').dialog(); - titleId = dlg().find('.ui-dialog-title').attr('id'); - equals(titleId, 'ui-dialog-title-2', 'auto-numbered title id'); - el.remove(); - - el = $('
      ').dialog(); - titleId = dlg().find('.ui-dialog-title').attr('id'); - equals(titleId, 'ui-dialog-title-foo', 'carried over title id'); - el.remove(); -}); - -test("ARIA", function() { - expect(4); - - el = $('
      ').dialog(); - - equals(dlg().attr('role'), 'dialog', 'dialog role'); - - var labelledBy = dlg().attr('aria-labelledby'); - ok(labelledBy.length > 0, 'has aria-labelledby attribute'); - equals(dlg().find('.ui-dialog-title').attr('id'), labelledBy, - 'proper aria-labelledby attribute'); - - equals(dlg().find('.ui-dialog-titlebar-close').attr('role'), 'button', - 'close link role'); - - el.remove(); -}); - -module("dialog: Options"); - -test("autoOpen", function() { - expect(2); - - el = $('
      ').dialog({ autoOpen: false }); - isNotOpen('.dialog({ autoOpen: false })'); - el.remove(); - - el = $('
      ').dialog({ autoOpen: true }); - isOpen('.dialog({ autoOpen: true })'); - el.remove(); -}); - -test("buttons", function() { - expect(17); - - var buttons = { - "Ok": function(ev, ui) { - ok(true, "button click fires callback"); - equals(this, el[0], "context of callback"); - equals(ev.target, btn[0], "event target"); - }, - "Cancel": function(ev, ui) { - ok(true, "button click fires callback"); - equals(this, el[0], "context of callback"); - equals(ev.target, btn[1], "event target"); - } - }; - - el = $('
      ').dialog({ buttons: buttons }); - var btn = $("button", dlg()); - equals(btn.length, 2, "number of buttons"); - - var i = 0; - $.each(buttons, function(key, val) { - equals(btn.eq(i).text(), key, "text of button " + (i+1)); - i++; - }); - - ok(btn.parent().hasClass('ui-dialog-buttonpane'), "buttons in container"); - btn.trigger("click"); - - var newButtons = { - "Close": function(ev, ui) { - ok(true, "button click fires callback"); - equals(this, el[0], "context of callback"); - equals(ev.target, btn[0], "event target"); - } - }; - - equals(el.data("buttons.dialog"), buttons, '.data("buttons.dialog") getter'); - el.data("buttons.dialog", newButtons); - equals(el.data("buttons.dialog"), newButtons, '.data("buttons.dialog", ...) setter'); - - btn = $("button", dlg()); - equals(btn.length, 1, "number of buttons after setter"); - btn.trigger('click'); - - i = 0; - $.each(newButtons, function(key, val) { - equals(btn.eq(i).text(), key, "text of button " + (i+1)); - i += 1; - }); - - el.remove(); -}); - -test("closeOnEscape", function() { - ok(false, 'missing test'); -}); - -test("closeText", function() { - expect(3); - - el = $('
      ').dialog(); - equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'close', - 'default close text'); - el.remove(); - - el = $('
      ').dialog({ closeText: "foo" }); - equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'foo', - 'closeText on init'); - el.remove(); - - el = $('
      ').dialog().dialog('option', 'closeText', 'bar'); - equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'bar', - 'closeText via option method'); - el.remove(); -}); - -test("dialogClass", function() { - expect(4); - - el = $('
      ').dialog(); - equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added'); - el.remove(); - - el = $('
      ').dialog({ dialogClass: "foo" }); - equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added'); - el.remove(); - - el = $('
      ').dialog({ dialogClass: "foo bar" }); - equals(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added'); - equals(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added'); - el.remove(); -}); - -test("draggable", function() { - expect(4); - - el = $('
      ').dialog({ draggable: false }); - shouldnotmove(); - el.data('draggable.dialog', true); - shouldmove(); - el.remove(); - - el = $('
      ').dialog({ draggable: true }); - shouldmove(); - el.data('draggable.dialog', false); - shouldnotmove(); - el.remove(); -}); - -test("height", function() { - expect(3); - - el = $('
      ').dialog(); - equals(dlg().height(), defaults.minHeight, "default height"); - el.remove(); - - el = $('
      ').dialog({ height: 437 }); - equals(dlg().height(), 437, "explicit height"); - el.remove(); - - el = $('
      ').dialog(); - el.data('height.dialog', 438); - equals(dlg().height(), 438, "explicit height set after init"); - el.remove(); -}); - -test("maxHeight", function() { - expect(3); - - el = $('
      ').dialog({ maxHeight: 400 }); - drag('.ui-resizable-s', 1000, 1000); - equals(heightAfter, 400, "maxHeight"); - el.remove(); - - el = $('
      ').dialog({ maxHeight: 400 }); - drag('.ui-resizable-n', -1000, -1000); - equals(heightAfter, 400, "maxHeight"); - el.remove(); - - el = $('
      ').dialog({ maxHeight: 400 }).data('maxHeight.dialog', 600); - drag('.ui-resizable-n', -1000, -1000); - equals(heightAfter, 600, "maxHeight"); - el.remove(); -}); - -test("maxWidth", function() { - expect(3); - - el = $('
      ').dialog({ maxWidth: 400 }); - drag('.ui-resizable-e', 1000, 1000); - equals(widthAfter, 400, "maxWidth"); - el.remove(); - - el = $('
      ').dialog({ maxWidth: 400 }); - drag('.ui-resizable-w', -1000, -1000); - equals(widthAfter, 400, "maxWidth"); - el.remove(); - - el = $('
      ').dialog({ maxWidth: 400 }).data('maxWidth.dialog', 600); - drag('.ui-resizable-w', -1000, -1000); - equals(widthAfter, 600, "maxWidth"); - el.remove(); -}); - -test("minHeight", function() { - expect(3); - - el = $('
      ').dialog({ minHeight: 10 }); - drag('.ui-resizable-s', -1000, -1000); - equals(heightAfter, 10, "minHeight"); - el.remove(); - - el = $('
      ').dialog({ minHeight: 10 }); - drag('.ui-resizable-n', 1000, 1000); - equals(heightAfter, 10, "minHeight"); - el.remove(); - - el = $('
      ').dialog({ minHeight: 10 }).data('minHeight.dialog', 30); - drag('.ui-resizable-n', 1000, 1000); - equals(heightAfter, 30, "minHeight"); - el.remove(); -}); - -test("minWidth", function() { - expect(3); - - el = $('
      ').dialog({ minWidth: 10 }); - drag('.ui-resizable-e', -1000, -1000); - equals(widthAfter, 10, "minWidth"); - el.remove(); - - el = $('
      ').dialog({ minWidth: 10 }); - drag('.ui-resizable-w', 1000, 1000); - equals(widthAfter, 10, "minWidth"); - el.remove(); - - el = $('
      ').dialog({ minWidth: 30 }).data('minWidth.dialog', 30); - drag('.ui-resizable-w', 1000, 1000); - equals(widthAfter, 30, "minWidth"); - el.remove(); -}); - -test("modal", function() { - ok(false, "missing test"); -}); - -test("overlay", function() { - ok(false, "missing test"); -}); - -test("position", function() { - ok(false, "missing test"); -}); - -test("resizable", function() { - expect(4); - - el = $('
      ').dialog(); - shouldresize("[default]"); - el.data('resizable.dialog', false); - shouldnotresize('disabled after init'); - el.remove(); - - el = $('
      ').dialog({ resizable: false }); - shouldnotresize("disabled in init options"); - el.data('resizable.dialog', true); - shouldresize('enabled after init'); - el.remove(); -}); - -test("stack", function() { - ok(false, "missing test"); -}); - -test("title", function() { - expect(5); - - function titleText() { - return dlg().find(".ui-dialog-title").html(); - } - - el = $('
      ').dialog(); - equals(titleText(), " ", "[default]"); - el.remove(); - - el = $('
      ').dialog(); - equals(titleText(), "foo", "title in element attribute"); - el.remove(); - - el = $('
      ').dialog({ title: 'foo' }); - equals(titleText(), "foo", "title in init options"); - el.remove(); - - el = $('
      ').dialog({ title: 'bar' }); - equals(titleText(), "bar", "title in init options should override title in element attribute"); - el.remove(); - - el = $('
      ').dialog().data('title.dialog', 'foo'); - equals(titleText(), 'foo', 'title after init'); - el.remove(); -}); - -test("width", function() { - expect(3); - - el = $('
      ').dialog(); - equals(dlg().width(), defaults.width, "default width"); - el.remove(); - - el = $('
      ').dialog({width: 437 }); - equals(dlg().width(), 437, "explicit width"); - el.data('width.dialog', 438); - equals(dlg().width(), 438, 'explicit width after init'); - el.remove(); -}); - -module("dialog: Methods"); - -test("isOpen", function() { - expect(4); - - el = $('
      ').dialog(); - equals(el.dialog('isOpen'), true, "dialog is open after init"); - el.dialog('close'); - equals(el.dialog('isOpen'), false, "dialog is closed"); - el.remove(); - - el = $('
      ').dialog({autoOpen: false}); - equals(el.dialog('isOpen'), false, "dialog is closed after init"); - el.dialog('open'); - equals(el.dialog('isOpen'), true, "dialog is open"); - el.remove(); -}); - -module("dialog: Callbacks"); - -test("open", function() { - expect(6); - - el = $("
      "); - el.dialog({ - open: function(ev, ui) { - ok(true, 'autoOpen: true fires open callback'); - equals(this, el[0], "context of callback"); - } - }); - el.remove(); - - el = $("
      "); - el.dialog({ - autoOpen: false, - open: function(ev, ui) { - ok(true, '.dialog("open") fires open callback'); - equals(this, el[0], "context of callback"); - } - }); - el.dialog("open"); - el.remove(); - - el = $('
      ').dialog({ - autoOpen: false - }); - el.bind('dialogopen', function(ev, ui) { - ok(true, 'dialog("open") fires open event'); - equals(this, el[0], 'context of event'); - }); - el.dialog('open'); - el.remove(); -}); - -test("dragStart", function() { - expect(2); - - el = $("
      "); - el.dialog({ - dragStart: function(ev, ui) { - ok(true, 'dragging fires dragStart callback'); - equals(this, el[0], "context of callback"); - } - }); - var handle = $(".ui-dialog-titlebar", dlg()); - drag(handle, 50, 50); - el.remove(); -}); - -test("drag", function() { - var fired = false; - - el = $("
      "); - el.dialog({ - drag: function(ev, ui) { - fired = true; - equals(this, el[0], "context of callback"); - } - }); - var handle = $(".ui-dialog-titlebar", dlg()); - drag(handle, 50, 50); - ok(fired, "drag fired"); - el.remove(); -}); - -test("dragStop", function() { - expect(2); - - el = $("
      "); - el.dialog({ - dragStop: function(ev, ui) { - ok(true, 'dragging fires dragStop callback'); - equals(this, el[0], "context of callback"); - } - }); - var handle = $(".ui-dialog-titlebar", dlg()); - drag(handle, 50, 50); - el.remove(); -}); - -test("resizeStart", function() { - expect(2); - - el = $("
      "); - el.dialog({ - resizeStart: function(ev, ui) { - ok(true, 'resizing fires resizeStart callback'); - equals(this, el[0], "context of callback"); - } - }); - var handle = $(".ui-resizable-se", dlg()); - drag(handle, 50, 50); - el.remove(); -}); - -test("resize", function() { - var fired = false; - - el = $("
      "); - el.dialog({ - resize: function(ev, ui) { - fired = true; - equals(this, el[0], "context of callback"); - } - }); - var handle = $(".ui-resizable-se", dlg()); - drag(handle, 50, 50); - ok(fired, "resize fired"); - el.remove(); -}); - -test("resizeStop", function() { - expect(2); - - el = $("
      "); - el.dialog({ - resizeStop: function(ev, ui) { - ok(true, 'resizing fires resizeStop callback'); - equals(this, el[0], "context of callback"); - } - }); - var handle = $(".ui-resizable-se", dlg()); - drag(handle, 50, 50); - el.remove(); -}); - -test("close", function() { - expect(4); - - el = $('
      ').dialog({ - close: function(ev, ui) { - ok(true, '.dialog("close") fires close callback'); - equals(this, el[0], "context of callback"); - } - }); - el.dialog("close"); - el.remove(); - - el = $('
      ').dialog().bind('dialogclose', function(ev, ui) { - ok(true, '.dialog("close") fires dialogclose event'); - equals(this, el[0], 'context of event'); - }); - el.dialog('close'); - el.remove(); -}); - -test("beforeclose", function() { - expect(6); - - el = $('
      ').dialog({ - beforeclose: function(ev, ui) { - ok(true, '.dialog("close") fires beforeclose callback'); - equals(this, el[0], "context of callback"); - return false; - } - }); - el.dialog('close'); - isOpen('beforeclose callback should prevent dialog from closing'); - el.remove(); - - el = $('
      ').dialog().bind('dialogbeforeclose', function(ev, ui) { - ok(true, '.dialog("close") triggers dialogbeforeclose event'); - equals(this, el[0], "context of event"); - return false; - }); - el.dialog('close'); - isOpen('dialogbeforeclose event should prevent dialog from closing'); - el.remove(); -}); - -module("dialog: Tickets"); - -})(jQuery); diff --git a/tests/draggable.html b/tests/draggable.html deleted file mode 100644 index 9cb817619..000000000 --- a/tests/draggable.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - jQuery UI Draggable Test Suite - - - - - - - - - - - - - - -
      -
      Relative
      -
      Absolute
      -
      -
      - -
      - - - diff --git a/tests/draggable.js b/tests/draggable.js deleted file mode 100644 index d5ef7fda9..000000000 --- a/tests/draggable.js +++ /dev/null @@ -1,787 +0,0 @@ -/* - * draggable unit tests - */ -(function($) { -// -// Draggable Test Helper Functions -// - -var defaults = { - appendTo: "parent", - axis: false, - cancel: ":input", - connectToSortable: false, - containment: false, - cursor: "default", - cursorAt: null, - delay: 0, - disabled: false, - distance: 1, - grid: false, - handle: false, - helper: "original", - iframeFix: false, - opacity: 1.0, - refreshPositions: false, - revert: false, - revertDuration: 500, - scroll: true, - scrollSensitivity: 20, - scrollSpeed: 20, - scope: "default", - snap: false, - snapMode: "both", - snapTolerance: 20, - stack: false, - zIndex: null -}; - -var el, offsetBefore, offsetAfter, dragged; - -var drag = function(handle, dx, dy) { - var element = el.data("draggable").element; - offsetBefore = el.offset(); - $(handle).simulate("drag", { - dx: dx || 0, - dy: dy || 0 - }); - dragged = { dx: dx, dy: dy }; - offsetAfter = el.offset(); -} - -var moved = function (dx, dy, msg) { - msg = msg ? msg + "." : ""; - var actual = { left: offsetAfter.left, top: offsetAfter.top }; - var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy }; - same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); -} - -function shouldmove(why) { - drag(el, 50, 50); - moved(50, 50, why); -} - -function shouldnotmove(why) { - drag(el, 50, 50); - moved(0, 0, why); -} - -var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } - -var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } - -// Draggable Tests -module("draggable"); - -test("init", function() { - expect(6); - - $("
      ").appendTo('body').draggable().remove(); - ok(true, '.draggable() called on element'); - - $([]).draggable(); - ok(true, '.draggable() called on empty collection'); - - $("
      ").draggable(); - ok(true, '.draggable() called on disconnected DOMElement'); - - $("
      ").draggable().draggable("foo"); - ok(true, 'arbitrary method called after init'); - - $("
      ").draggable().data("foo.draggable"); - ok(true, 'arbitrary option getter after init'); - - $("
      ").draggable().data("foo.draggable", "bar"); - ok(true, 'arbitrary option setter after init'); -}); - -test("destroy", function() { - expect(6); - - $("
      ").appendTo('body').draggable().draggable("destroy").remove(); - ok(true, '.draggable("destroy") called on element'); - - $([]).draggable().draggable("destroy"); - ok(true, '.draggable("destroy") called on empty collection'); - - $("
      ").draggable().draggable("destroy"); - ok(true, '.draggable("destroy") called on disconnected DOMElement'); - - $("
      ").draggable().draggable("destroy").draggable("foo"); - ok(true, 'arbitrary method called after destroy'); - - $("
      ").draggable().draggable("destroy").data("foo.draggable"); - ok(true, 'arbitrary option getter after destroy'); - - $("
      ").draggable().draggable("destroy").data("foo.draggable", "bar"); - ok(true, 'arbitrary option setter after destroy'); -}); - -test("enable", function() { - expect(6); - el = $("#draggable2").draggable({ disabled: true }); - shouldnotmove('.draggable({ disabled: true })'); - el.draggable("enable"); - shouldmove('.draggable("enable")'); - equals(el.data("disabled.draggable"), false, "disabled.draggable getter"); - - el.draggable("destroy"); - el.draggable({ disabled: true }); - shouldnotmove('.draggable({ disabled: true })'); - el.data("disabled.draggable", false); - equals(el.data("disabled.draggable"), false, "disabled.draggable setter"); - shouldmove('.data("disabled.draggable", false)'); -}); - -test("disable", function() { - expect(6); - el = $("#draggable2").draggable({ disabled: false }); - shouldmove('.draggable({ disabled: false })'); - el.draggable("disable"); - shouldnotmove('.draggable("disable")'); - equals(el.data("disabled.draggable"), true, "disabled.draggable getter"); - - el.draggable("destroy"); - - el.draggable({ disabled: false }); - shouldmove('.draggable({ disabled: false })'); - el.data("disabled.draggable", true); - equals(el.data("disabled.draggable"), true, "disabled.draggable setter"); - shouldnotmove('.data("disabled.draggable", true)'); -}); - -test("element types", function() { - var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' - + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' - + ',acronym,code,samp,kbd,var,img,object,hr' - + ',input,button,label,select,iframe').split(','); - - $.each(typeNames, function(i) { - var typeName = typeNames[i]; - el = $(document.createElement(typeName)).appendTo('body'); - (typeName == 'table' && el.append("content")); - el.draggable({ cancel: '' }); - drag(el, 50, 50); - moved(50, 50, "<" + typeName + ">"); - el.draggable("destroy"); - el.remove(); - }); -}); - -test("defaults", function() { - el = $('
      ').draggable(); - $.each(defaults, function(key, val) { - var actual = el.data(key + ".draggable"), expected = val; - same(actual, expected, key); - }); - el.remove(); -}); - -test("No options, relative", function() { - el = $("#draggable1").draggable(); - drag(el, 50, 50); - moved(50, 50); -}); - -test("No options, absolute", function() { - el = $("#draggable2").draggable(); - drag(el, 50, 50); - moved(50, 50); -}); - -module("draggable: Options"); - -test("{ axis: false }, default", function() { - el = $("#draggable2").draggable({ axis: false }); - drag(el, 50, 50); - moved(50, 50); -}); - -test("{ axis: 'x' }", function() { - el = $("#draggable2").draggable({ axis: "x" }); - drag(el, 50, 50); - moved(50, 0); -}); - -test("{ axis: 'y' }", function() { - el = $("#draggable2").draggable({ axis: "y" }); - drag(el, 50, 50); - moved(0, 50); -}); - -test("{ axis: ? }, unexpected", function() { - var unexpected = { - "true": true, - "{}": {}, - "[]": [], - "null": null, - "undefined": undefined, - "function() {}": function() {} - }; - $.each(unexpected, function(key, val) { - el = $("#draggable2").draggable({ axis: val }); - drag(el, 50, 50); - moved(50, 50, "axis: " + key); - el.draggable("destroy"); - }) -}); - -test("{ cancel: 'span' }", function() { - el = $("#draggable2").draggable(); - drag("#draggable2 span", 50, 50); - moved(50, 50); - - el.draggable("destroy"); - - el = $("#draggable2").draggable({ cancel: 'span' }); - drag("#draggable2 span", 50, 50); - moved(0, 0); -}); - -test("{ cancel: ? }, unexpected", function() { - var unexpected = { - "true": true, - "false": false, - "{}": {}, - "[]": [], - "null": null, - "undefined": undefined, - "function() {return '';}": function() {return '';}, - "function() {return true;}": function() {return true;}, - "function() {return false;}": function() {return false;} - }; - $.each(unexpected, function(key, val) { - el = $("#draggable2").draggable({ cancel: val }); - drag(el, 50, 50); - var expected = [50, 50]; - moved(expected[0], expected[1], "cancel: " + key); - el.draggable("destroy"); - }) -}); - -test("{ containment: 'parent' }, relative", function() { - el = $("#draggable1").draggable({ containment: 'parent' }); - var p = el.parent(), po = p.offset(); - drag(el, -100, -100); - var expected = { - left: po.left + border(p, 'left') + margin(el, 'left'), - top: po.top + border(p, 'top') + margin(el, 'top') - } - same(offsetAfter, expected, 'compare offset to parent'); -}); - -test("{ containment: 'parent' }, absolute", function() { - el = $("#draggable2").draggable({ containment: 'parent' }); - var p = el.parent(), po = p.offset(); - drag(el, -100, -100); - var expected = { - left: po.left + border(p, 'left') + margin(el, 'left'), - top: po.top + border(p, 'top') + margin(el, 'top') - } - same(offsetAfter, expected, 'compare offset to parent'); -}); - -test("{ cursor: 'move' }", function() { - - function getCursor() { return $("body").css("cursor"); } - - expect(2); - - var expected = "move", actual, before, after; - - el = $("#draggable2").draggable({ - cursor: expected, - start: function(event, ui) { - actual = getCursor(); - } - }); - - before = getCursor(); - drag("#draggable2", -1, -1); - after = getCursor(); - - equals(actual, expected, "start callback: cursor '" + expected + "'"); - equals(after, before, "after drag: cursor restored"); - -}); - -test("{ cursorAt: { left: -5, top: -5 } }", function() { - - expect(4); - - var dx = -3, dy = -3; - var ox = 5, oy = 5; - var cax = -5, cay = -5; - - var actual = null; - $("#draggable2").draggable({ - cursorAt: { left: cax, top: cay }, - drag: function(event, ui) { - actual = ui.absolutePosition; - } - }); - var el = $("#draggable2").data("draggable").element; - - var before = el.offset(); - var pos = { clientX: before.left + ox, clientY: before.top + oy }; - $("#draggable2").simulate("mousedown", pos); - pos = { clientX: pos.clientX + dx, clientY: pos.clientY + dy }; - $(document).simulate("mousemove", pos); - $(document).simulate("mousemove", pos); - $("#draggable2").simulate("mouseup", pos); - var expected = { - left: before.left + ox - cax + dx, - top: before.top + oy - cay + dy - }; - - equals(actual.left, expected.left, "Absolute: -1px left"); - equals(actual.top, expected.top, "Absolute: -1px top"); - - var actual = null; - $("#draggable1").draggable({ - cursorAt: { left: cax, top: cay }, - drag: function(event, ui) { - actual = ui.absolutePosition; - } - }); - var el = $("#draggable2").data("draggable").element; - - var before = el.offset(); - var pos = { clientX: before.left + ox, clientY: before.top + oy }; - $("#draggable2").simulate("mousedown", pos); - pos = { clientX: pos.clientX + dx, clientY: pos.clientY + dy }; - $(document).simulate("mousemove", pos); - $(document).simulate("mousemove", pos); - $("#draggable2").simulate("mouseup", pos); - var expected = { - left: before.left + ox - cax + dx, - top: before.top + oy - cay + dy - }; - - equals(actual.left, expected.left, "Relative: -1px left"); - equals(actual.top, expected.top, "Relative: -1px top"); - -}); - -test("{ distance: 10 }", function() { - - el = $("#draggable2").draggable({ distance: 10 }); - drag(el, -9, -9); - moved(0, 0, 'distance not met'); - - drag(el, -10, -10); - moved(-10, -10, 'distance met'); - - drag(el, 9, 9); - moved(0, 0, 'distance not met'); - -}); - -test("{ grid: [50, 50] }, relative", function() { - el = $("#draggable1").draggable({ grid: [50, 50] }); - drag(el, 24, 24); - moved(0, 0); - drag(el, 26, 25); - moved(50, 50); -}); - -test("{ grid: [50, 50] }, absolute", function() { - el = $("#draggable2").draggable({ grid: [50, 50] }); - drag(el, 24, 24); - moved(0, 0); - drag(el, 26, 25); - moved(50, 50); -}); - -test("{ handle: 'span' }", function() { - el = $("#draggable2").draggable({ handle: 'span' }); - - drag("#draggable2 span", 50, 50); - moved(50, 50, "drag span"); - - drag("#draggable2", 50, 50); - moved(0, 0, "drag element"); -}); - -test("{ helper: 'clone' }, relative", function() { - el = $("#draggable1").draggable({ helper: "clone" }); - drag(el, 50, 50); - moved(0, 0); -}); - -test("{ helper: 'clone' }, absolute", function() { - el = $("#draggable2").draggable({ helper: "clone" }); - drag(el, 50, 50); - moved(0, 0); -}); - -test("{ opacity: 0.5 }", function() { - - expect(1); - - var opacity = null; - el = $("#draggable2").draggable({ - opacity: 0.5, - start: function(event, ui) { - opacity = $(this).css("opacity"); - } - }); - - drag("#draggable2", -1, -1); - - equals(opacity, 0.5, "start callback: opacity is"); - -}); - -test("{ zIndex: 10 }", function() { - - expect(1); - - var expected = 10, actual; - - var zIndex = null; - el = $("#draggable2").draggable({ - zIndex: expected, - start: function(event, ui) { - actual = $(this).css("zIndex"); - } - }); - - drag("#draggable2", -1, -1); - - equals(actual, expected, "start callback: zIndex is"); - -}); - -module("draggable: Callbacks"); - -test("callbacks occurance count", function() { - - expect(3); - - var start = 0, stop = 0, dragc = 0; - el = $("#draggable2").draggable({ - start: function() { start++; }, - drag: function() { dragc++; }, - stop: function() { stop++; } - }); - - drag(el, 10, 10); - - equals(start, 1, "start callback should happen exactly once"); - equals(dragc, 3, "drag callback should happen exactly once per mousemove"); - equals(stop, 1, "stop callback should happen exactly once"); - -}); - -module("draggable: Scroll offsets"); - - -function testScroll(position) { - $("#main").css('position', position); - drag(el, 50, 50); - moved(50, 50, position+' parent'); - -} - -function setScroll(what) { - if(what) { - $(document).scrollTop(100); $(document).scrollLeft(100); - } else { - $("#main")[0].scrollTop = 100; $("#main")[0].scrollLeft = 100; - } -} - -function restoreScroll(what) { - if(what) { - $(document).scrollTop(0); $(document).scrollLeft(0); - } else { - $("#main")[0].scrollTop = 0; $("#main")[0].scrollLeft = 0; - } -} - -test("{ helper: 'original' }, relative, with scroll offset on parent", function() { - - el = $("#draggable1").draggable({ helper: "original" }); - - setScroll(); - testScroll('relative'); - - setScroll(); - testScroll('static'); - - setScroll(); - testScroll('absolute'); - - restoreScroll(); - -}); - -test("{ helper: 'original' }, relative, with scroll offset on root", function() { - - el = $("#draggable1").draggable({ helper: "original" }); - - setScroll('root'); - testScroll('relative'); - - setScroll('root'); - testScroll('static'); - - setScroll('root'); - testScroll('absolute'); - - restoreScroll('root'); - -}); - -test("{ helper: 'original' }, relative, with scroll offset on root and parent", function() { - - el = $("#draggable1").draggable({ helper: "original" }); - - setScroll(); - setScroll('root'); - testScroll('relative'); - - setScroll(); - setScroll('root'); - testScroll('static'); - - setScroll(); - setScroll('root'); - testScroll('absolute'); - - restoreScroll(); - restoreScroll('root'); - -}); - -test("{ helper: 'original' }, absolute, with scroll offset on parent", function() { - - el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" }); - - setScroll(); - testScroll('relative'); - - setScroll(); - testScroll('static'); - - setScroll(); - testScroll('absolute'); - - restoreScroll(); - -}); - -test("{ helper: 'original' }, absolute, with scroll offset on root", function() { - - el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" }); - - setScroll('root'); - testScroll('relative'); - - setScroll('root'); - testScroll('static'); - - setScroll('root'); - testScroll('absolute'); - - restoreScroll('root'); - -}); - -test("{ helper: 'original' }, absolute, with scroll offset on root and parent", function() { - - el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" }); - - setScroll(); - setScroll('root'); - testScroll('relative'); - - setScroll(); - setScroll('root'); - testScroll('static'); - - setScroll(); - setScroll('root'); - testScroll('absolute'); - - restoreScroll(); - restoreScroll('root'); - -}); - -//Fixed not for IE < 7 -if(!($.browser.msie && $.browser.version < 7)) { - - test("{ helper: 'original' }, fixed, with scroll offset on parent", function() { - - el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" }); - - setScroll(); - testScroll('relative'); - - setScroll(); - testScroll('static'); - - setScroll(); - testScroll('absolute'); - - restoreScroll(); - - }); - - test("{ helper: 'original' }, fixed, with scroll offset on root", function() { - - el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" }); - - setScroll('root'); - testScroll('relative'); - - setScroll('root'); - testScroll('static'); - - setScroll('root'); - testScroll('absolute'); - - restoreScroll('root'); - - }); - - test("{ helper: 'original' }, fixed, with scroll offset on root and parent", function() { - - el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" }); - - setScroll(); - setScroll('root'); - testScroll('relative'); - - setScroll(); - setScroll('root'); - testScroll('static'); - - setScroll(); - setScroll('root'); - testScroll('absolute'); - - restoreScroll(); - restoreScroll('root'); - - }); - -} - - - -test("{ helper: 'clone' }, absolute", function() { - - var helperOffset = null; - var origOffset = $("#draggable1").offset(); - - el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { - helperOffset = ui.helper.offset(); - } }); - - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - -}); - -test("{ helper: 'clone' }, absolute with scroll offset on parent", function() { - - setScroll(); - var helperOffset = null; - var origOffset = null; - - el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { - helperOffset = ui.helper.offset(); - } }); - - $("#main").css('position', 'relative'); - origOffset = $("#draggable1").offset(); - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - - $("#main").css('position', 'static'); - origOffset = $("#draggable1").offset(); - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - - $("#main").css('position', 'absolute'); - origOffset = $("#draggable1").offset(); - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - - restoreScroll(); - -}); - -test("{ helper: 'clone' }, absolute with scroll offset on root", function() { - - setScroll('root'); - var helperOffset = null; - var origOffset = null; - - el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { - helperOffset = ui.helper.offset(); - } }); - - $("#main").css('position', 'relative'); - origOffset = $("#draggable1").offset(); - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - - $("#main").css('position', 'static'); - origOffset = $("#draggable1").offset(); - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - - $("#main").css('position', 'absolute'); - origOffset = $("#draggable1").offset(); - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - - restoreScroll('root'); - -}); - -test("{ helper: 'clone' }, absolute with scroll offset on root and parent", function() { - - setScroll('root'); - setScroll(); - var helperOffset = null; - var origOffset = null; - - el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { - helperOffset = ui.helper.offset(); - } }); - - $("#main").css('position', 'relative'); - origOffset = $("#draggable1").offset() - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - - $("#main").css('position', 'static'); - origOffset = $("#draggable1").offset() - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - - $("#main").css('position', 'absolute'); - origOffset = $("#draggable1").offset() - drag(el, 1, 1); - same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); - - restoreScroll('root'); - restoreScroll(); - -}); - -module("draggable: behaviour"); - -test("Events should not be executed on the element if drag is initiated", function() { - //TODO: Implement missing test -}); - - -module("draggable: Tickets"); - -})(jQuery); diff --git a/tests/droppable.html b/tests/droppable.html deleted file mode 100644 index 3646767e4..000000000 --- a/tests/droppable.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - jQuery UI Droppable Test Suite - - - - - - - - - - - - - - - -
      -
      Draggable
      -
      Droppable
      -
       
      -
      - - - diff --git a/tests/droppable.js b/tests/droppable.js deleted file mode 100644 index 31915defc..000000000 --- a/tests/droppable.js +++ /dev/null @@ -1,223 +0,0 @@ -/* - * droppable unit tests - */ -(function($) { -// -// Droppable Test Helper Functions -// - -var defaults = { - accept: '*', - activeClass: null, - cssNamespace: "ui", - disabled: false, - greedy: false, - hoverClass: null, - scope: "default", - tolerance: "intersect" -}; - -var el, drg; - -function shouldBeDroppable() { - ok(false, "missing test - should be droppable"); -} - -function shouldNotBeDroppable() { - ok(false, "missing test - should not be droppable"); -} - -// Droppable Tests -module("droppable"); - -test("init", function() { - expect(6); - - $("
      ").appendTo('body').droppable().remove(); - ok(true, '.droppable() called on element'); - - $([]).droppable(); - ok(true, '.droppable() called on empty collection'); - - $("
      ").droppable(); - ok(true, '.droppable() called on disconnected DOMElement'); - - $("
      ").droppable().droppable("foo"); - ok(true, 'arbitrary method called after init'); - - $("
      ").droppable().data("foo.droppable"); - ok(true, 'arbitrary option getter after init'); - - $("
      ").droppable().data("foo.droppable", "bar"); - ok(true, 'arbitrary option setter after init'); -}); - -test("destroy", function() { - expect(6); - - $("
      ").appendTo('body').droppable().droppable("destroy").remove(); - ok(true, '.droppable("destroy") called on element'); - - $([]).droppable().droppable("destroy"); - ok(true, '.droppable("destroy") called on empty collection'); - - $("
      ").droppable().droppable("destroy"); - ok(true, '.droppable("destroy") called on disconnected DOMElement'); - - $("
      ").droppable().droppable("destroy").droppable("foo"); - ok(true, 'arbitrary method called after destroy'); - - $("
      ").droppable().droppable("destroy").data("foo.droppable"); - ok(true, 'arbitrary option getter after destroy'); - - $("
      ").droppable().droppable("destroy").data("foo.droppable", "bar"); - ok(true, 'arbitrary option setter after destroy'); -}); - -test("enable", function() { - expect(6); - el = $("#droppable1").droppable({ disabled: true }); - shouldNotBeDroppable(); - el.droppable("enable"); - shouldBeDroppable(); - equals(el.data("disabled.droppable"), false, "disabled.droppable getter"); - el.droppable("destroy"); - el.droppable({ disabled: true }); - shouldNotBeDroppable(); - el.data("disabled.droppable", false); - equals(el.data("disabled.droppable"), false, "disabled.droppable setter"); - shouldBeDroppable(); -}); - -test("disable", function() { - expect(6); - el = $("#droppable1").droppable({ disabled: false }); - shouldBeDroppable(); - el.droppable("disable"); - shouldNotBeDroppable(); - equals(el.data("disabled.droppable"), true, "disabled.droppable getter"); - el.droppable("destroy"); - el.droppable({ disabled: false }); - shouldBeDroppable(); - el.data("disabled.droppable", true); - equals(el.data("disabled.droppable"), true, "disabled.droppable setter"); - shouldNotBeDroppable(); -}); - -test("element types", function() { - var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' - + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' - + ',acronym,code,samp,kbd,var,img,object,hr' - + ',input,button,label,select,iframe').split(','); - - $.each(typeNames, function(i) { - var typeName = typeNames[i]; - el = $(document.createElement(typeName)).appendTo('body'); - (typeName == 'table' && el.append("content")); - el.droppable(); - shouldBeDroppable(); - el.droppable("destroy"); - el.remove(); - }); -}); - -test("defaults", function() { - el = $("
      ").droppable(); - $.each(defaults, function(key, val) { - var actual = el.data(key + ".droppable"), expected = val; - same(actual, expected, key); - }); - el.remove(); -}); - -test("option setting", function() { - // The plugin shouldn't modify an option value set by the user - $.each(defaults, function(key, val) { - el = $("
      ").droppable(); - el.data(key + ".droppable", val); - var actual = el.data(key + ".droppable"), expected = val; - same(actual, expected, key); - el.remove(); - }); -}); - -module("droppable: Options"); - -test("accept, selector", function() { - ok(false, "missing test"); -}); - -test("accept, fn", function() { - ok(false, "missing test"); -}); - -test("activeClass", function() { - ok(false, "missing test"); -}); - -test("cssNamespace", function() { - //cssNamespace should be appended with '-droppable' and added as className - el = $("
      ").droppable({ cssNamespace: "ui" }); - equals(el[0].className, "ui-droppable"); - el.droppable("destroy"); - - //no className should be added if cssNamepsace is null - el = $("
      ").droppable({ cssNamespace: null }); - equals(el[0].className, ""); - el.droppable("destroy"); -}); - -test("greedy", function() { - ok(false, "missing test"); -}); - -test("hoverClass", function() { - ok(false, "missing test"); -}); - -test("scope", function() { - ok(false, "missing test"); -}); - -test("tolerance, fit", function() { - ok(false, "missing test"); -}); - -test("tolerance, intersect", function() { - ok(false, "missing test"); -}); - -test("tolerance, pointer", function() { - ok(false, "missing test"); -}); - -test("tolerance, touch", function() { - ok(false, "missing test"); -}); - -module("droppable: Callbacks"); - -test("activate", function() { - ok(false, "missing test"); -}); - -test("deactivate", function() { - ok(false, "missing test"); -}); - -test("over", function() { - ok(false, "missing test"); -}); - -test("out", function() { - ok(false, "missing test"); -}); - -test("drop", function() { - ok(false, "missing test"); -}); - -module("droppable: Tickets"); - - -})(jQuery); diff --git a/tests/images/test.jpg b/tests/images/test.jpg deleted file mode 100644 index 7d8ec0996..000000000 Binary files a/tests/images/test.jpg and /dev/null differ diff --git a/tests/progressbar.html b/tests/progressbar.html deleted file mode 100644 index ddfe918b0..000000000 --- a/tests/progressbar.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - jQuery UI Progressbar Test Suite - - - - - - - - - - - - - - -
      -
      -
      - - - diff --git a/tests/progressbar.js b/tests/progressbar.js deleted file mode 100644 index 087106510..000000000 --- a/tests/progressbar.js +++ /dev/null @@ -1,68 +0,0 @@ -/* - * progressbar unit tests - */ -(function($) { -// -// Progressbar Test Helper Functions -// - -var defaults = { - disabled: false, - value: 0 -}; - -var el; - -// Progressbar Tests -module("progressbar"); - -test("init", function() { - expect(1); - - $("
      ").appendTo('body').progressbar().remove(); - ok(true, '.progressbar() called on element'); - -}); - -test("destroy", function() { - expect(1); - - $("
      ").appendTo('body').progressbar().progressbar("destroy").remove(); - ok(true, '.progressbar("destroy") called on element'); - -}); - -test("defaults", function() { - el = $('
      ').progressbar(); - $.each(defaults, function(key, val) { - var actual = el.data(key + ".progressbar"), expected = val; - same(actual, expected, key); - }); - el.remove(); -}); - -test("set defaults on init", function() { - el = $("#progressbar").progressbar({ - value: 50 - }); - - equals(el.progressbar("option", "value"), 50, "value"); -}); - -test("accessibility", function() { - expect(7); - el = $("#progressbar").progressbar(); - - equals(el.attr("role"), "progressbar", "aria role"); - equals(el.attr("aria-valuemin"), 0, "aria-valuemin"); - equals(el.attr("aria-valuemax"), 100, "aria-valuemax"); - equals(el.attr("aria-valuenow"), 0, "aria-valuenow initially"); - el.progressbar("value", 77); - equals(el.attr("aria-valuenow"), 77, "aria-valuenow"); - el.progressbar("disable"); - equals(el.attr("aria-disabled"), "true", "aria-disabled"); - el.progressbar("enable"); - equals(el.attr("aria-disabled"), "false", "enabled"); -}); - -})(jQuery); diff --git a/tests/resizable.html b/tests/resizable.html deleted file mode 100644 index 8862b7703..000000000 --- a/tests/resizable.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - jQuery UI Resizable Test Suite - - - - - - - - - - - - - - -
      -
      I'm a resizable.
      - -
      - - - diff --git a/tests/resizable.js b/tests/resizable.js deleted file mode 100644 index 98a69de5b..000000000 --- a/tests/resizable.js +++ /dev/null @@ -1,416 +0,0 @@ -/* - * resizable tests - */ -(function($) { -// -// Resizable Test Helper Functions -// - -var defaults = { - animate: false, - animateDuration: 'slow', - animateEasing: 'swing', - alsoResize: false, - aspectRatio: false, - autoHide: false, - cancel: ':input', - containment: false, - delay: 0, - disabled: false, - disableSelection: true, - distance: 1, - ghost: false, - grid: false, - handles: '???', - helper: null, - knobHandles: false, - maxHeight: null, - maxWidth: null, - minHeight: 10, - minWidth: 10, - preserveCursor: true, - preventDefault: true, - proportionallyResize: false, - transparent: false -}; - -var drag = function(el, dx, dy, complete) { - - // speed = sync -> Drag syncrhonously. - // speed = fast|slow -> Drag asyncrhonously - animated. - - //this mouseover is to work around a limitation in resizable - //TODO: fix resizable so handle doesn't require mouseover in order to be used - $(el).simulate("mouseover"); - - return $(el).simulate("drag", { - dx: dx||0, dy: dy||0, speed: 'sync', complete: complete - }); -}; - -// Resizable Tests -module("resizable"); - -test("init", function() { - expect(6); - - $("
      ").appendTo('body').resizable().remove(); - ok(true, '.resizable() called on element'); - - $([]).resizable().remove(); - ok(true, '.resizable() called on empty collection'); - - $('
      ').resizable().remove(); - ok(true, '.resizable() called on disconnected DOMElement'); - - $('
      ').resizable().resizable("foo").remove(); - ok(true, 'arbitrary method called after init'); - - el = $('
      ').resizable() - var foo = el.data("foo.resizable"); - el.remove(); - ok(true, 'arbitrary option getter after init'); - - $('
      ').resizable().data("foo.resizable", "bar").remove(); - ok(true, 'arbitrary option setter after init'); -}); - -test("destroy", function() { - expect(6); - - $("
      ").appendTo('body').resizable().resizable("destroy").remove(); - ok(true, '.resizable("destroy") called on element'); - - $([]).resizable().resizable("destroy").remove(); - ok(true, '.resizable("destroy") called on empty collection'); - - $('
      ').resizable().resizable("destroy").remove(); - ok(true, '.resizable("destroy") called on disconnected DOMElement'); - - $('
      ').resizable().resizable("destroy").resizable("foo").remove(); - ok(true, 'arbitrary method called after destroy'); - - el = $('
      ').resizable(); - var foo = el.resizable("destroy").data("foo.resizable"); - el.remove(); - ok(true, 'arbitrary option getter after destroy'); - - $('
      ').resizable().resizable("destroy").data("foo.resizable", "bar").remove(); - ok(true, 'arbitrary option setter after destroy'); -}); - -test("element types", function() { - var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' - + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' - + ',acronym,code,samp,kbd,var,img,object,hr' - + ',input,button,label,select,iframe').split(','); - - $.each(typeNames, function(i) { - var typeName = typeNames[i]; - el = $(document.createElement(typeName)).appendTo('body'); - (typeName == 'table' && el.append("content")); - el.resizable(); - ok(true, '$("<' + typeName + '/>").resizable()'); - el.resizable("destroy"); - el.remove(); - }); -}); - -test("defaults", function() { - el = $('
      ').resizable(); - $.each(defaults, function(key, val) { - var actual = el.data(key + ".resizable"), expected = val; - same(actual, expected, key); - }); - el.remove(); -}); - -test("n", function() { - expect(2); - - var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ handles: 'all' }); - - drag(handle, 0, -50); - equals( target.height(), 150, "compare height" ); - - drag(handle, 0, 50); - equals( target.height(), 100, "compare height" ); -}); - -test("s", function() { - expect(2); - - var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ handles: 'all' }); - - drag(handle, 0, 50); - equals( target.height(), 150, "compare height" ); - - drag(handle, 0, -50); - equals( target.height(), 100, "compare height" ); -}); - -test("e", function() { - expect(2); - - var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ handles: 'all' }); - - drag(handle, 50); - equals( target.width(), 150, "compare width"); - - drag(handle, -50); - equals( target.width(), 100, "compare width" ); -}); - -test("w", function() { - expect(2); - - var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ handles: 'all' }); - - drag(handle, -50); - equals( target.width(), 150, "compare width" ); - - drag(handle, 50); - equals( target.width(), 100, "compare width" ); -}); - -test("ne", function() { - expect(4); - - var handle = '.ui-resizable-ne', target = $('#resizable1').css({ overflow: 'hidden' }).resizable({ handles: 'all' }); - - drag(handle, -50, -50); - equals( target.width(), 50, "compare width" ); - equals( target.height(), 150, "compare height" ); - - drag(handle, 50, 50); - equals( target.width(), 100, "compare width" ); - equals( target.height(), 100, "compare height" ); -}); - -test("se", function() { - expect(4); - - var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all' }); - - drag(handle, 50, 50); - equals( target.width(), 150, "compare width" ); - equals( target.height(), 150, "compare height" ); - - drag(handle, -50, -50); - equals( target.width(), 100, "compare width" ); - equals( target.height(), 100, "compare height" ); -}); - -test("sw", function() { - expect(4); - - var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all' }); - - drag(handle, -50, -50); - equals( target.width(), 150, "compare width" ); - equals( target.height(), 50, "compare height" ); - - drag(handle, 50, 50); - equals( target.width(), 100, "compare width" ); - equals( target.height(), 100, "compare height" ); -}); - -test("nw", function() { - expect(4); - - var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all' }); - - drag(handle, -50, -50); - equals( target.width(), 150, "compare width" ); - equals( target.height(), 150, "compare height" ); - - drag(handle, 50, 50); - equals( target.width(), 100, "compare width" ); - equals( target.height(), 100, "compare height" ); -}); - -module("resizable: Options"); - -test("aspectRatio: 'preserve' (e)", function() { - expect(4); - - var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - - drag(handle, 80); - equals( target.width(), 130, "compare maxWidth"); - equals( target.height(), 130, "compare maxHeight"); - - drag(handle, -130); - equals( target.width(), 70, "compare minWidth"); - equals( target.height(), 70, "compare minHeight"); -}); - -test("aspectRatio: 'preserve' (w)", function() { - expect(4); - - var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - - drag(handle, -80); - equals( target.width(), 130, "compare maxWidth"); - equals( target.height(), 130, "compare maxHeight"); - - drag(handle, 130); - equals( target.width(), 70, "compare minWidth"); - equals( target.height(), 70, "compare minHeight"); -}); - -test("aspectRatio: 'preserve' (n)", function() { - expect(4); - - var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - - drag(handle, 0, -80); - equals( target.width(), 130, "compare maxWidth"); - equals( target.height(), 130, "compare maxHeight"); - - drag(handle, 0, 80); - equals( target.width(), 70, "compare minWidth"); - equals( target.height(), 70, "compare minHeight"); -}); - -test("aspectRatio: 'preserve' (s)", function() { - expect(4); - - var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - - drag(handle, 0, 80); - equals( target.width(), 130, "compare maxWidth"); - equals( target.height(), 130, "compare maxHeight"); - - drag(handle, 0, -80); - equals( target.width(), 70, "compare minWidth"); - equals( target.height(), 70, "compare minHeight"); -}); - -test("aspectRatio: 'preserve' (se)", function() { - expect(4); - - var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - - drag(handle, 80, 80); - equals( target.width(), 130, "compare maxWidth"); - equals( target.height(), 130, "compare maxHeight"); - - drag(handle, -80, -80); - equals( target.width(), 70, "compare minWidth"); - equals( target.height(), 70, "compare minHeight"); -}); - -test("aspectRatio: 'preserve' (sw)", function() { - expect(4); - - var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - - drag(handle, -80, 80); - equals( target.width(), 130, "compare maxWidth"); - equals( target.height(), 130, "compare maxHeight"); - - drag(handle, 80, -80); - equals( target.width(), 70, "compare minWidth"); - equals( target.height(), 70, "compare minHeight"); -}); - -test("aspectRatio: 'preserve' (ne)", function() { - expect(4); - - var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - - drag(handle, 80, -80); - equals( target.width(), 130, "compare maxWidth"); - equals( target.height(), 130, "compare maxHeight"); - - drag(handle, -80, 80); - equals( target.width(), 70, "compare minWidth"); - equals( target.height(), 70, "compare minHeight"); -}); - -test("grid", function() { - expect(4); - - var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', grid: [0, 20] }); - - drag(handle, 3, 9); - equals( target.width(), 103, "compare width"); - equals( target.height(), 100, "compare height"); - - drag(handle, 15, 11); - equals( target.width(), 118, "compare width"); - equals( target.height(), 120, "compare height"); -}); - -test("grid (wrapped)", function() { - expect(4); - - var handle = '.ui-resizable-se', target = $('#resizable2').resizable({ handles: 'all', grid: [0, 20] }); - - drag(handle, 3, 9); - equals( target.width(), 103, "compare width"); - equals( target.height(), 100, "compare height"); - - drag(handle, 15, 11); - equals( target.width(), 118, "compare width"); - equals( target.height(), 120, "compare height"); -}); - -test("ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { - expect(4); - - var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); - - drag(handle, -50, -50); - equals( target.width(), 60, "compare minWidth" ); - equals( target.height(), 60, "compare minHeight" ); - - drag(handle, 70, 70); - equals( target.width(), 100, "compare maxWidth" ); - equals( target.height(), 100, "compare maxHeight" ); -}); - -test("ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { - expect(4); - - var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); - - drag(handle, 50, -50); - equals( target.width(), 60, "compare minWidth" ); - equals( target.height(), 60, "compare minHeight" ); - - drag(handle, -70, 70); - equals( target.width(), 100, "compare maxWidth" ); - equals( target.height(), 100, "compare maxHeight" ); -}); - -test("ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { - expect(4); - - var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); - - drag(handle, -50, 50); - equals( target.width(), 60, "compare minWidth" ); - equals( target.height(), 60, "compare minHeight" ); - - drag(handle, 70, -70); - equals( target.width(), 100, "compare maxWidth" ); - equals( target.height(), 100, "compare maxHeight" ); -}); - -test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { - expect(4); - - var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); - - drag(handle, 70, 70); - equals( target.width(), 60, "compare minWidth" ); - equals( target.height(), 60, "compare minHeight" ); - - drag(handle, -70, -70); - equals( target.width(), 100, "compare maxWidth" ); - equals( target.height(), 100, "compare maxHeight" ); -}); - -})(jQuery); diff --git a/tests/selectable.html b/tests/selectable.html deleted file mode 100644 index 6f83d2bac..000000000 --- a/tests/selectable.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - jQuery UI Selectable Test Suite - - - - - - - - - - - - - - -
      -
        -
      • Item 1
      • -
      • Item 2
      • -
      • Item 3
      • -
      • Item 4
      • -
      • Item 5
      • -
      -
      - - - diff --git a/tests/selectable.js b/tests/selectable.js deleted file mode 100644 index df23626ca..000000000 --- a/tests/selectable.js +++ /dev/null @@ -1,196 +0,0 @@ -/* - * selectable unit tests - */ -(function($) { -// -// Selectable Test Helper Functions -// - -var defaults = { - autoRefresh: true, - disabled: false, - filter: '*' -}; - -var el; - -var drag = function(dx, dy) { - var off = el.offset(), pos = { clientX: off.left, clientY: off.top }; - el.simulate("mousedown", pos); - $(document).simulate("mousemove", pos); - pos.clientX += dx; - pos.clientY += dy; - $(document).simulate("mousemove", pos); - $(document).simulate("mouseup", pos); -} - -var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } - -var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } - -// Selectable Tests -module("selectable"); - -test("init", function() { - expect(6); - - $("
      ").appendTo('body').selectable().remove(); - ok(true, '.selectable() called on element'); - - $([]).selectable().remove(); - ok(true, '.selectable() called on empty collection'); - - $("
      ").selectable().remove(); - ok(true, '.selectable() called on disconnected DOMElement'); - - $("
      ").selectable().selectable("foo").remove(); - ok(true, 'arbitrary method called after init'); - - el = $("
      ").selectable() - var foo = el.data("foo.selectable"); - el.remove(); - ok(true, 'arbitrary option getter after init'); - - $("
      ").selectable().data("foo.selectable", "bar").remove(); - ok(true, 'arbitrary option setter after init'); -}); - -test("destroy", function() { - expect(6); - - $("
      ").appendTo('body').selectable().selectable("destroy").remove(); - ok(true, '.selectable("destroy") called on element'); - - $([]).selectable().selectable("destroy").remove(); - ok(true, '.selectable("destroy") called on empty collection'); - - $("
      ").selectable().selectable("destroy").remove(); - ok(true, '.selectable("destroy") called on disconnected DOMElement'); - - $("
      ").selectable().selectable("destroy").selectable("foo").remove(); - ok(true, 'arbitrary method called after destroy'); - - el = $("
      ").selectable(); - var foo = el.selectable("destroy").data("foo.selectable"); - el.remove(); - ok(true, 'arbitrary option getter after destroy'); - - $("
      ").selectable().selectable("destroy").data("foo.selectable", "bar").remove(); - ok(true, 'arbitrary option setter after destroy'); -}); - -test("defaults", function() { - el = $('
      ').selectable(); - $.each(defaults, function(key, val) { - var actual = el.data(key + ".selectable"), expected = val; - same(actual, expected, key); - }); - el.remove(); -}); - -module("selectable: Options"); - -test("autoRefresh", function() { - expect(3); - el = $("#selectable1"); - var actual, sel = $("*", el), selected = function() { actual += 1 }; - - actual = 0; - el = $("#selectable1").selectable({ autoRefresh: false, selected: selected }); - sel.hide(); - drag(1000, 1000); - equals(actual, sel.length); - el.selectable("destroy"); - - actual = 0; - sel.show(); - el = $("#selectable1").selectable({ autoRefresh: true, selected: selected }); - sel.hide(); - drag(1000, 1000); - equals(actual, 0); - sel.show(); - drag(1000, 1000); - equals(actual, sel.length); - el.selectable("destroy"); - sel.show(); -}); - -test("filter", function() { - expect(2); - el = $("#selectable1"); - var actual, sel = $("*", el), selected = function() { actual += 1 }; - - actual = 0; - el = $("#selectable1").selectable({ filter: '.special', selected: selected }); - drag(1000, 1000); - ok(sel.length != 1, "this test assumes more than 1 selectee"); - equals(actual, 1); - el.selectable("destroy"); -}); - -module("selectable: Methods"); - -test("disable", function() { - expect(2); - var fired = false; - - el = $("#selectable1"); - el.selectable({ - disabled: false, - start: function() { fired = true; } - }); - el.simulate("drag", 20, 20); - equals(fired, true, "start fired"); - el.selectable("disable"); - fired = false; - el.simulate("drag", 20, 20); - equals(fired, false, "start fired"); - el.selectable("destroy"); -}); - -test("enable", function() { - expect(2); - var fired = false; - - el = $("#selectable1"); - el.selectable({ - disabled: true, - start: function() { fired = true; } - }); - el.simulate("drag", 20, 20); - equals(fired, false, "start fired"); - el.selectable("enable"); - el.simulate("drag", 20, 20); - equals(fired, true, "start fired"); - el.selectable("destroy"); -}); - -module("selectable: Callbacks"); - -test("start", function() { - expect(2); - el = $("#selectable1"); - el.selectable({ - start: function(ev, ui) { - ok(true, "drag fired start callback"); - equals(this, el[0], "context of callback"); - } - }); - el.simulate("drag", 20, 20); -}); - -test("stop", function() { - expect(2); - el = $("#selectable1"); - el.selectable({ - start: function(ev, ui) { - ok(true, "drag fired stop callback"); - equals(this, el[0], "context of callback"); - } - }); - el.simulate("drag", 20, 20); -}); - -module("selectable: Tickets"); - -})(jQuery); diff --git a/tests/simulate/jquery.simulate.js b/tests/simulate/jquery.simulate.js deleted file mode 100644 index d52140bb8..000000000 --- a/tests/simulate/jquery.simulate.js +++ /dev/null @@ -1,152 +0,0 @@ -/* - * jquery.simulate - simulate browser mouse and keyboard events - * - * Copyright (c) 2009 Eduardo Lundgren (eduardolundgren@gmail.com) - * and Richard D. Worth (rdworth@gmail.com) - * - * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) - * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. - * - */ - -;(function($) { - -$.fn.extend({ - simulate: function(type, options) { - return this.each(function() { - var opt = $.extend({}, $.simulate.defaults, options || {}); - new $.simulate(this, type, opt); - }); - } -}); - -$.simulate = function(el, type, options) { - this.target = el; - this.options = options; - - if (/^drag$/.test(type)) { - this[type].apply(this, [this.target, options]); - } else { - this.simulateEvent(el, type, options); - } -} - -$.extend($.simulate.prototype, { - simulateEvent: function(el, type, options) { - var evt = this.createEvent(type, options); - this.dispatchEvent(el, type, evt, options); - return evt; - }, - createEvent: function(type, options) { - if (/^mouse(over|out|down|up|move)|(dbl)?click$/.test(type)) { - return this.mouseEvent(type, options); - } else if (/^key(up|down|press)$/.test(type)) { - return this.keyboardEvent(type, options); - } - }, - mouseEvent: function(type, options) { - var evt; - var e = $.extend({ - bubbles: true, cancelable: (type != "mousemove"), view: window, detail: 0, - screenX: 0, screenY: 0, clientX: 0, clientY: 0, - ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, - button: 0, relatedTarget: undefined - }, options); - - var relatedTarget = $(e.relatedTarget)[0]; - - if ($.isFunction(document.createEvent)) { - evt = document.createEvent("MouseEvents"); - evt.initMouseEvent(type, e.bubbles, e.cancelable, e.view, e.detail, - e.screenX, e.screenY, e.clientX, e.clientY, - e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, - e.button, e.relatedTarget || document.body.parentNode); - } else if (document.createEventObject) { - evt = document.createEventObject(); - $.extend(evt, e); - evt.button = { 0:1, 1:4, 2:2 }[evt.button] || evt.button; - } - return evt; - }, - keyboardEvent: function(type, options) { - var evt; - - var e = $.extend({ bubbles: true, cancelable: true, view: window, - ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, - keyCode: 0, charCode: 0 - }, options); - - if ($.isFunction(document.createEvent)) { - try { - evt = document.createEvent("KeyEvents"); - evt.initKeyEvent(type, e.bubbles, e.cancelable, e.view, - e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, - e.keyCode, e.charCode); - } catch(err) { - evt = document.createEvent("Events"); - evt.initEvent(type, e.bubbles, e.cancelable); - $.extend(evt, { view: e.view, - ctrlKey: e.ctrlKey, altKey: e.altKey, shiftKey: e.shiftKey, metaKey: e.metaKey, - keyCode: e.keyCode, charCode: e.charCode - }); - } - } else if (document.createEventObject) { - evt = document.createEventObject(); - $.extend(evt, e); - } - if ($.browser.msie || $.browser.opera) { - evt.keyCode = (e.charCode > 0) ? e.charCode : e.keyCode; - evt.charCode = undefined; - } - return evt; - }, - - dispatchEvent: function(el, type, evt) { - if (el.dispatchEvent) { - el.dispatchEvent(evt); - } else if (el.fireEvent) { - el.fireEvent('on' + type, evt); - } - return evt; - }, - - drag: function(el) { - var self = this, center = this.findCenter(this.target), - options = this.options, x = Math.floor(center.x), y = Math.floor(center.y), - dx = options.dx || 0, dy = options.dy || 0, target = this.target; - var coord = { clientX: x, clientY: y }; - this.simulateEvent(target, "mousedown", coord); - coord = { clientX: x + 1, clientY: y + 1 }; - this.simulateEvent(document, "mousemove", coord); - coord = { clientX: x + dx, clientY: y + dy }; - this.simulateEvent(document, "mousemove", coord); - this.simulateEvent(document, "mousemove", coord); - this.simulateEvent(target, "mouseup", coord); - }, - findCenter: function(el) { - var el = $(this.target), o = el.offset(); - return { - x: o.left + el.outerWidth() / 2, - y: o.top + el.outerHeight() / 2 - }; - } -}); - -$.extend($.simulate, { - defaults: { - speed: 'sync' - }, - VK_TAB: 9, - VK_ENTER: 13, - VK_ESC: 27, - VK_PGUP: 33, - VK_PGDN: 34, - VK_END: 35, - VK_HOME: 36, - VK_LEFT: 37, - VK_UP: 38, - VK_RIGHT: 39, - VK_DOWN: 40 -}); - -})(jQuery); diff --git a/tests/slider.html b/tests/slider.html deleted file mode 100644 index e21705be8..000000000 --- a/tests/slider.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - jQuery UI Slider Test Suite - - - - - - - - - - - - - - -
      -
      -
      -
      -
      -
      - - - diff --git a/tests/slider.js b/tests/slider.js deleted file mode 100644 index 34d29b4fd..000000000 --- a/tests/slider.js +++ /dev/null @@ -1,396 +0,0 @@ -/* - * slider unit tests - */ -(function($) { -// -// Slider Test Helper Functions -// - -var defaults = { - max: 100, - min: 0, - orientation: 'horizontal', - step: 1, - value: 0 -}; - -var el, options; - -function handle() { - return el.find(".ui-slider-handle"); -} - -// Slider Tests -module("slider"); - -test("init", function() { - expect(6); - - $("
      ").appendTo('body').slider().remove(); - ok(true, '.slider() called on element'); - - $([]).slider().remove(); - ok(true, '.slider() called on empty collection'); - - $('
      ').slider().remove(); - ok(true, '.slider() called on disconnected DOMElement'); - - $('
      ').slider().slider("foo").remove(); - ok(true, 'arbitrary method called after init'); - - el = $('
      ').slider(); - var foo = el.data("foo.slider"); - el.remove(); - ok(true, 'arbitrary option getter after init'); - - $('
      ').slider().data("foo.slider", "bar").remove(); - ok(true, 'arbitrary option setter after init'); -}); - -test("destroy", function() { - expect(8); - - $("
      ").appendTo('body').slider().slider("destroy").remove(); - ok(true, '.slider("destroy") called on element'); - - $([]).slider().slider("destroy").remove(); - ok(true, '.slider("destroy") called on empty collection'); - - $('
      ').appendTo('body').remove().slider().slider("destroy").remove(); - ok(true, '.slider("destroy") called on disconnected DOMElement'); - - $('
      ').slider().slider("destroy").slider("foo").remove(); - ok(true, 'arbitrary method called after destroy'); - - el = $('
      ').slider(); - var foo = el.slider("destroy").data("foo.slider"); - el.remove(); - ok(true, 'arbitrary option getter (.data) after destroy'); - - el = $('
      ').slider(); - var foo = el.slider("destroy").slider("option", "foo"); - el.remove(); - ok(true, 'arbitrary option getter (.slider option method) after destroy'); - - $('
      ').slider().slider("destroy").data("foo.slider", "bar").remove(); - ok(true, 'arbitrary option setter (.data) after destroy'); - - $('
      ').slider().slider("destroy").slider("options", "foo", "bar").remove(); - ok(true, 'arbitrary option setter (.slider option method) after destroy'); -}); - -test("defaults", function() { - el = $('
      ').slider(); - $.each(defaults, function(key, val) { - var actual = el.data(key + ".slider"), expected = val; - same(actual, expected, key); - }); - el.remove(); -}); - -module("slider"); - -test("keydown HOME on handle sets value to min", function() { - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", 0); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); - equals(el.slider("value"), options.min); - - el.slider('destroy'); - - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", 0); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); - equals(el.slider("value"), options.min); - - el.slider('destroy'); -}); - -test("keydown END on handle sets value to max", function() { - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", 0); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); - equals(el.slider("value"), options.max); - - el.slider('destroy'); - - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", 0); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); - equals(el.slider("value"), options.max); - - el.slider('destroy'); -}); - -test("keydown UP on handle increases value by step, not greater than max", function() { - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", options.max - options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); - equals(el.slider("value"), options.max); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); - equals(el.slider("value"), options.max); - - el.slider("destroy"); - - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", options.max - options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); - equals(el.slider("value"), options.max); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); - equals(el.slider("value"), options.max); - - el.slider("destroy"); -}); - -test("keydown RIGHT on handle increases value by step, not greater than max", function() { - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", options.max - options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); - equals(el.slider("value"), options.max); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); - equals(el.slider("value"), options.max); - - el.slider("destroy"); - - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", options.max - options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); - equals(el.slider("value"), options.max); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); - equals(el.slider("value"), options.max); - - el.slider("destroy"); -}); - -test("keydown DOWN on handle decreases value by step, not less than min", function() { - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", options.min + options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); - equals(el.slider("value"), options.min); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); - equals(el.slider("value"), options.min); - - el.slider("destroy"); - - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", options.min + options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); - equals(el.slider("value"), options.min); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); - equals(el.slider("value"), options.min); - - el.slider("destroy"); -}); - -test("keydown LEFT on handle decreases value by step, not less than min", function() { - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", options.min + options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); - equals(el.slider("value"), options.min); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); - equals(el.slider("value"), options.min); - - el.slider("destroy"); - - el = $('
      '); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", options.min + options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); - equals(el.slider("value"), options.min); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); - equals(el.slider("value"), options.min); - - el.slider("destroy"); -}); - -module("slider: Options"); - -test("orientation", function() { - el = $('
      '); - - options = { - max: 2, - min: -2, - orientation: 'vertical', - value: 1 - }; - - var percentVal = (options.value - options.min) / (options.max - options.min) * 100; - - el.slider(options).slider("option", "orientation", "horizontal"); - ok(el.is('.ui-slider-horizontal'), "horizontal slider has class .ui-slider-horizontal"); - ok(!el.is('.ui-slider-vertical'), "horizontal slider does not have class .ui-slider-vertical"); - equals(handle().css('left'), percentVal + '%', "horizontal slider handle is positioned with left: %"); - - el.slider('destroy'); - - options = { - max: 2, - min: -2, - orientation: 'horizontal', - value: -1 - }; - - var percentVal = (options.value - options.min) / (options.max - options.min) * 100; - - el.slider(options).slider("option", "orientation", "vertical"); - ok(el.is('.ui-slider-vertical'), "vertical slider has class .ui-slider-vertical"); - ok(!el.is('.ui-slider-horizontal'), "vertical slider does not have class .ui-slider-horizontal"); - equals(handle().css('bottom'), percentVal + '%', "vertical slider handle is positioned with bottom: %"); - - el.slider('destroy'); - -}); - -test("max", function() { - el = $('
      '); - - options = { - max: 37, - min: 6, - orientation: 'horizontal', - step: 1, - value: 50 - }; - - el.slider(options); - ok(el.slider("option", "value") == options.value, "value option is not contained by max"); - ok(el.slider("value") == options.max, "value method is contained by max"); - el.slider('destroy'); - -}); - -test("min", function() { - el = $('
      '); - - options = { - max: 37, - min: 6, - orientation: 'vertical', - step: 1, - value: 2 - }; - - el.slider(options); - ok(el.slider("option", "value") == options.value, "value option is not contained by min"); - ok(el.slider("value") == options.min, "value method is contained by min"); - el.slider('destroy'); - -}); - -})(jQuery); diff --git a/tests/sortable.html b/tests/sortable.html deleted file mode 100644 index 190aa5763..000000000 --- a/tests/sortable.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - jQuery UI Sortable Test Suite - - - - - - - - - - - - - - -
      -
        -
      • Item 1
      • -
      • Item 2
      • -
      • Item 3
      • -
      • Item 4
      • -
      • Item 5
      • -
      -
      - - - diff --git a/tests/sortable.js b/tests/sortable.js deleted file mode 100644 index c913ed86d..000000000 --- a/tests/sortable.js +++ /dev/null @@ -1,148 +0,0 @@ -/* - * sortable unit tests - */ -(function($) { -// -// Sortable Test Helper Functions -// - -var defaults = { - appendTo: "parent", - cancel: ":input", - delay: 0, - disabled: false, - distance: 1, - dropOnEmpty: true, - helper: "original", - items: "> *", - scroll: true, - scrollSensitivity: 20, - scrollSpeed: 20, - tolerance: "guess", - zIndex: 1000 -}; - -var el, offsetBefore, offsetAfter, dragged; - -var drag = function(handle, dx, dy) { - offsetBefore = $(handle).offset(); - $(handle).simulate("drag", { - dx: dx || 0, - dy: dy || 0 - }); - dragged = { dx: dx, dy: dy }; - offsetAfter = $(handle).offset(); -} - -var sort = function(handle, dx, dy, index, msg) { - drag(handle, dx, dy); - equals($(handle).parent().children().index(handle), index, msg); -} - -var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } -var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } - -// Sortable Tests -module("sortable"); - -test("init", function() { - expect(6); - - $("
      ").appendTo('body').sortable().remove(); - ok(true, '.sortable() called on element'); - - $([]).sortable(); - ok(true, '.sortable() called on empty collection'); - - $("
      ").sortable(); - ok(true, '.sortable() called on disconnected DOMElement'); - - $("
      ").sortable().sortable("foo"); - ok(true, 'arbitrary method called after init'); - - $("
      ").sortable().data("foo.sortable"); - ok(true, 'arbitrary option getter after init'); - - $("
      ").sortable().data("foo.sortable", "bar"); - ok(true, 'arbitrary option setter after init'); -}); - -test("destroy", function() { - expect(6); - - $("
      ").appendTo('body').sortable().sortable("destroy").remove(); - ok(true, '.sortable("destroy") called on element'); - - $([]).sortable().sortable("destroy"); - ok(true, '.sortable("destroy") called on empty collection'); - - $("
      ").sortable().sortable("destroy"); - ok(true, '.sortable("destroy") called on disconnected DOMElement'); - - $("
      ").sortable().sortable("destroy").sortable("foo"); - ok(true, 'arbitrary method called after destroy'); - - $("
      ").sortable().sortable("destroy").data("foo.sortable"); - ok(true, 'arbitrary option getter after destroy'); - - $("
      ").sortable().sortable("destroy").data("foo.sortable", "bar"); - ok(true, 'arbitrary option setter after destroy'); -}); - -test("enable", function() { - expect(4); - el = $("#sortable").sortable({ disabled: true }); - - sort($("li", el)[0], 0, 40, 0, '.sortable({ disabled: true })'); - - el.sortable("enable"); - equals(el.data("disabled.sortable"), false, "disabled.sortable getter"); - - el.sortable("destroy"); - el.sortable({ disabled: true }); - el.data("disabled.sortable", false); - equals(el.data("disabled.sortable"), false, "disabled.sortable setter"); - - sort($("li", el)[0], 0, 40, 2, '.data("disabled.sortable", false)'); -}); - -test("disable", function() { - expect(5); - el = $("#sortable").sortable({ disabled: false }); - sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })'); - - el.sortable("disable"); - sort($("li", el)[0], 0, 40, 0, 'disabled.sortable getter'); - - el.sortable("destroy"); - - el.sortable({ disabled: false }); - sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })'); - el.data("disabled.sortable", true); - equals(el.data("disabled.sortable"), true, "disabled.sortable setter"); - sort($("li", el)[0], 0, 40, 0, '.data("disabled.sortable", true)'); -}); - -test("defaults", function() { - el = $('
      ').sortable(); - $.each(defaults, function(key, val) { - var actual = el.data(key + ".sortable"), expected = val; - same(actual, expected, key); - }); - el.remove(); -}); - -test("#3019: Stop fires too early", function() { - - var helper = null; - el = $("#sortable").sortable({ stop: function(event, ui) { - helper = ui.helper; - }}); - - sort($("li", el)[0], 0, 40, 2, 'Dragging the sortable'); - equals(helper, null, "helper should be false"); - -}); - - -})(jQuery); diff --git a/tests/tabs.html b/tests/tabs.html deleted file mode 100644 index eb0224212..000000000 --- a/tests/tabs.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - jQuery UI Tabs Test Suite - - - - - - - - - - - - - - - - -
      - -
      -
        -
      • 1
      • -
      • 2
      • -
      • 3
      • -
      -
      -
      -
      -
      -
      -
        -
      • 1
      • -
      • 2
      • -
      -
      -
      -
      - -
      - - - diff --git a/tests/tabs.js b/tests/tabs.js deleted file mode 100644 index 41d59f060..000000000 --- a/tests/tabs.js +++ /dev/null @@ -1,243 +0,0 @@ -/* - * tabs unit tests - */ -(function($) { -// -// Tabs Test Helper Functions -// - -var defaults = { - ajaxOptions: null, - cache: false, - cookie: null, - deselectable: false, - deselectableClass: 'ui-tabs-deselectable', - disabled: [], - disabledClass: 'ui-state-disabled', - event: 'click', - fx: null, - hideClass: 'ui-tabs-hide', - idPrefix: 'ui-tabs-', - loadingClass: 'ui-tabs-loading', - navClass: 'ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all', - panelClass: 'ui-tabs-panel ui-widget-content ui-corner-bottom', - panelTemplate: '
      ', - selectedClass: 'ui-tabs-selected ui-state-active', - spinner: 'Loading…', - tabTemplate: '
    1. #{label}
    2. ' -}; - -var el; - -// need to wait a bit for the pseudo animation... -function defer(defered, ms) { - var queue = defer.queue || (defer.queue = []); - if (!queue.length) stop(); - queue.push(defered); - setTimeout(function() { - queue.shift()(); - if (!queue.length) start(); - }, ms || 100); -} - -module('tabs'); - - test('init', function() { - expect(9); - - var el = $('#tabs1').tabs(); // new markup requires to tabify wrapper again... - ok(true, '.tabs() called on element'); - - el.tabs('destroy').tabs({ selected: 1 }); - - 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-state-default.ui-corner-top'), 'attach classes to inactive li'); - ok( $('li:eq(1)', el).is('.ui-tabs-selected.ui-state-active.ui-corner-top'), 'attach classes to active li'); - equals( el.data('selected.tabs'), 1, 'selected.tabs set' ); - equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 1, 'second tab active'); - equals( $('div', el).index( $('div.ui-tabs-hide', '#tabs1') ), 0, 'first panel should be hidden' ); - - }); - - test('destroy', function() { - expect(0); - - }); - - test("defaults", function() { - el = $('#tabs1 > ul').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); - - var el = $('#tabs1 > ul').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 = $('#tabs2 > ul').tabs({ selected: 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); - - }); - - -module('tabs: Options'); - - test('select: null', function() { - expect(3); - - var el = $('#tabs1 > ul'); - - el.tabs({ selected: null }); - equals( el.data('selected.tabs'), null, 'option set' ); - equals( $('li.ui-tabs-selected', el).length, 0, 'all tabs should be deselected' ); - equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' ); - - // TODO select == null with cookie - // TODO select == null with select method - - }); - - test('deselectable: true', function() { - expect(7); - - var el = $('#tabs1 > ul'); - - el.tabs({ deselectable: true }); - equals( el.data('deselectable.tabs'), true, 'option set' ); - equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once'); - equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 0, 'class "ui-tabs-deselectable" attached to first tab'); - - el.tabs('select', 1); - equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once'); - equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 1, 'class "ui-tabs-deselectable" attached to second tab'); - - el.tabs('select', 1); - equals( $('li.ui-tabs-deselectable', el).length, 0, 'class "ui-tabs-deselectable" not attached'); - defer(function() { - equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' ); - }); - - }); - - test('cookie', function() { - expect(5); - - var el = $('#tabs1 > ul'); - var cookieName = 'ui-tabs-' + $.data(el[0]); - $.cookie(cookieName, null); // blank state - var cookie = function() { - return parseInt($.cookie(cookieName), 10); - }; - - el.tabs({ cookie: {} }); - equals(cookie(), 0, 'initial cookie value, no cookie given'); - - el.tabs('destroy'); - el.tabs({ selected: 1, cookie: {} }); - equals(cookie(), 1, 'initial cookie value, given selected'); - - el.tabs('select', 2); - equals(cookie(), 2, 'cookie value after tabs select'); - - el.tabs('destroy'); - $.cookie(cookieName, 1); - el.tabs({ cookie: {} }); - equals(cookie(), 1, 'initial cookie value, from existing cookie'); - - el.tabs('destroy'); - ok($.cookie(cookieName) === null, 'erase cookie after destroy'); - - }); - - -module('tabs: Tickets'); - - test('id containing colon, #????', function() { - expect(4); - - var el = $('#tabs2 > ul').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); - defer(function() { - 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'); - - var el = $('#tabs2 > ul').tabs(); - equals(inlineStyle('height'), expected, 'init should not remove inline style'); - - el.tabs('select', 1); - defer(function() { - equals(inlineStyle('height'), expected, 'show tab should not remove inline style'); - - el.tabs('select', 0); - defer(function() { - equals(inlineStyle('height'), expected, 'hide tab should not remove inline style'); - }); - - }); - - }); - -// test('', function() { -// expect(0); -// -// }); - -})(jQuery); diff --git a/tests/testsuite.css b/tests/testsuite.css deleted file mode 100644 index b278cc6d9..000000000 --- a/tests/testsuite.css +++ /dev/null @@ -1,4 +0,0 @@ -@import url("qunit/testsuite.css"); -html { border: 0; } -.xerror, .error, .ui-tabs-hide { display: none } -#main { position: absolute; top: -10000px; left: -10000px; } diff --git a/tests/testsuite.js b/tests/testsuite.js deleted file mode 100644 index 2ad60cbab..000000000 --- a/tests/testsuite.js +++ /dev/null @@ -1,10 +0,0 @@ -$(function() { - -$('body').prepend( - '

      ' + document.title + '

      ' + - '' + - '

      ' + - '
        ' -); - -}); diff --git a/tests/ui.html b/tests/ui.html deleted file mode 100644 index b29834cc4..000000000 --- a/tests/ui.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - jQuery UI Test Suite - - - - - - - - - - - - - - - - - - - - - - - - -
        - -
        - - - diff --git a/tests/ui.js b/tests/ui.js deleted file mode 100644 index 03bbf405e..000000000 --- a/tests/ui.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * common UI unit tests - */ -(function($) { - -var plugins = [ - "accordion", - "datepicker", - "dialog", - "draggable", - "droppable", - "progressbar", - "resizable", - "selectable", - "slider", - "sortable", - "tabs" -]; - -module("version"); - -test("core", function() { - equals($.ui.version, "@VERSION", "$.ui.version"); -}); - -$(plugins).each(function() { - var pluginName = this; - test(pluginName, function() { - if ($.ui[pluginName]) - equals($.ui[pluginName].version, "@VERSION", "$.ui." + pluginName + ".version"); - else - ok(false, "$.ui." + pluginName + " undefined."); - }); -}); - -})(jQuery); diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html new file mode 100644 index 000000000..51553d330 --- /dev/null +++ b/tests/unit/accordion/accordion.html @@ -0,0 +1,96 @@ + + + + jQuery UI Accordion Test Suite + + + + + + + + + + + + + + +
        + +
        +
        + There is one obvious advantage: +
        +

        + You've seen it coming! +
        + Buy now and get nothing for free! +
        + Well, at least no free beer. Perhaps a bear, if you can afford it. +

        +
        +
        +
        + Now that you've got... +
        +

        + your bear, you have to admit it! +
        + No, we aren't selling bears. +

        +

        + We could talk about renting one. +

        +
        +
        +
        + Rent one bear, ... +
        +

        + get two for three beer. +

        +

        + And now, for something completely different. +

        +
        +
        +
        + + + +
        + + + diff --git a/tests/unit/accordion/accordion.js b/tests/unit/accordion/accordion.js new file mode 100644 index 000000000..d9f8c4b64 --- /dev/null +++ b/tests/unit/accordion/accordion.js @@ -0,0 +1,150 @@ +/* + * 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").parent().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( 90, $('#navigation div:first').height() ); + equals( 126, $('#navigation div:eq(1)').height() ); + equals( 54, $('#navigation div:last').height() ); + $('#navigation').accordion("destroy").accordion({ autoHeight: true }); + equals( 126, $('#navigation div:first').height() ); + equals( 126, $('#navigation div:eq(1)').height() ); + equals( 126, $('#navigation div:last').height() ); +}); + +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, alwaysOpen:false", function() { + var ac = $('#list1').accordion({alwaysOpen: false}).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, alwaysOpen:true", 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, + alwaysOpen: false + }); + equals( $("#list1 a.selected").size(), 0, "no headers selected" ); +}); + +test("accordionchange event, open closed and close again", function() { + expect(8); + $("#list1").accordion({ + active: false, + alwaysOpen: false + }) + .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/all/all.html b/tests/unit/all/all.html new file mode 100644 index 000000000..358cc3e52 --- /dev/null +++ b/tests/unit/all/all.html @@ -0,0 +1,226 @@ + + + + jQuery UI All Tests + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

        jQuery UI All Tests

        + +

        + +

        Run individual testsuites or doubleclick a test below

        + + +
          + +
          + +

          + +
          Relative
          +
          Absolute
          + +
          +
          +
          +
          + +
          + There is one obvious advantage: +
          +

          + You've seen it coming!
          + Buy now and get nothing for free!
          + Well, at least no free beer. Perhaps a bear, if you can afford it. +

          +
          + Now that you've got... +
          +

          + your bear, you have to admit it!
          + No, we aren't selling bears. +

          +

          + We could talk about renting one. +

          +
          + Rent one bear, ... +
          +

          + get two for three beer. +

          +

          + And now, for something completely different. +

          +
          +
          + + +
          +
          Red
          +
          + Fancy stuff about red thingies. +
          +
          Green
          +
          + Green! Green! Green! +
          +
          Blue
          +
          + Cool kids are blue. +
          +
          + +
          +
          +
          Tennis
          +
          + One ball, two players. Lots of fun. +
          +
          +
          +
          Soccer
          +
          + One ball, 22 players. Lots of fun. +
          +
          +
          +
          Baseball
          +
          + Well, one ball, some guys running around, some guys hitting others with a stick.
          + Sounds like fun, doesn't it? +
          +
          + Well, apart from the running part. +
          +
          +
          + +
          I'm a resizable.
          + + + +
            +
          • Item 1
          • +
          • Item 2
          • +
          • Item 3
          • +
          • Item 4
          • +
          • Item 5
          • +
          + +
            +
          • Item 1
          • +
          • Item 2
          • +
          • Item 3
          • +
          • Item 4
          • +
          • Item 5
          • +
          + +

          + + + +
          + +
          +
            +
          • 1
          • +
          • 2
          • +
          • 3
          • +
          +
          +
          +
          +
          +
          +
            +
          • 1
          • +
          • 2
          • +
          +
          +
          +
          + +
          + + \ No newline at end of file diff --git a/tests/unit/all/all_2.html b/tests/unit/all/all_2.html new file mode 100644 index 000000000..0645acb83 --- /dev/null +++ b/tests/unit/all/all_2.html @@ -0,0 +1,82 @@ + + + + jQuery UI All Tests + + + + + + + + + + + + + + + + + + + + + + + + + + + +

          jQuery UI All Tests

          + +

          + +

          Run individual testsuites or doubleclick a test below

          +
            +
          + +
            + +
            + +
            + + + \ No newline at end of file diff --git a/tests/unit/core/core.html b/tests/unit/core/core.html new file mode 100644 index 000000000..c8d88c88a --- /dev/null +++ b/tests/unit/core/core.html @@ -0,0 +1,63 @@ + + + + jQuery UI Core Test Suite + + + + + + + + + + + + + +
            +
            + + + + + + + + + anchor + anchor +
            +
            + + + + + + + + +
            +
            + + + + +
            +
            + + + + +
            +
            +
            + + + diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js new file mode 100644 index 000000000..4be475486 --- /dev/null +++ b/tests/unit/core/core.js @@ -0,0 +1,78 @@ +/* + * core unit tests + */ +(function($) { + +module("selectors"); + +test("tabbable - enabled elements", function() { + expect(10); + + ok( $('#input1-1').is(':tabbable'), 'input, no type'); + ok( $('#input1-2').is(':tabbable'), 'input, type text'); + ok( $('#input1-3').is(':tabbable'), 'input, type checkbox'); + ok( $('#input1-4').is(':tabbable'), 'input, type radio'); + ok( $('#input1-5').is(':tabbable'), 'input, type button'); + ok(!$('#input1-6').is(':tabbable'), 'input, type hidden'); + ok( $('#input1-7').is(':tabbable'), 'select'); + ok( $('#input1-8').is(':tabbable'), 'textarea'); + ok( $('#anchor1-1').is(':tabbable'), 'anchor with href'); + ok(!$('#anchor1-2').is(':tabbable'), 'anchor without href'); +}); + +test("tabbable - disabled elements", function() { + expect(8); + + ok(!$('#input2-1').is(':tabbable'), 'input, no type'); + ok(!$('#input2-2').is(':tabbable'), 'input, type text'); + ok(!$('#input2-3').is(':tabbable'), 'input, type checkbox'); + ok(!$('#input2-4').is(':tabbable'), 'input, type radio'); + ok(!$('#input2-5').is(':tabbable'), 'input, type button'); + ok(!$('#input2-6').is(':tabbable'), 'input, type hidden'); + ok(!$('#input2-7').is(':tabbable'), 'select'); + ok(!$('#input2-8').is(':tabbable'), 'textarea'); +}); + +test("tabbable - hidden styles", function() { + expect(6); + + ok(!$('#input3-1').is(':tabbable'), 'input, hidden wrapper - display: none'); + ok(!$('#anchor3-1').is(':tabbable'), 'anchor, hidden wrapper - display: none'); + ok(!$('#input3-2').is(':tabbable'), 'input, hidden wrapper - visibility: hidden'); + ok(!$('#anchor3-2').is(':tabbable'), 'anchor, hidden wrapper - visibility: hidden'); + ok(!$('#input3-3').is(':tabbable'), 'input, display: none'); + ok(!$('#input3-4').is(':tabbable'), 'input, visibility: hidden'); +}); + +test("tabbable - tabindex", function() { + expect(4); + + ok( $('#input4-1').is(':tabbable'), 'input, tabindex 0'); + ok( $('#input4-2').is(':tabbable'), 'input, tabindex 10'); + ok(!$('#input4-3').is(':tabbable'), 'input, tabindex -1'); + ok(!$('#input4-4').is(':tabbable'), 'input, tabindex -50'); +}); + +module('jQuery extensions'); + +test("attr - aria", function() { + expect(6); + + var el = $('#aria'); + + ok(!el.attr('role'), 'role is empty via attr'); + equals(el.attr('role', 'tablist').attr('role'), 'tablist', 'role is tablist'); + + equals(el.attr('aria-expanded'), undefined, 'aria expanded is undefined'); + + el.attr('aria-expanded', true); + equals(el.attr('aria-expanded'), 'true', 'aria expanded is true'); + + el.removeAttr('aria-expanded'); + equals(el.attr('aria-expanded'), undefined, 'aria expanded is undefined after removing'); + + el.attr('aria-expanded', false); + equals(el.attr('aria-expanded'), 'false', 'aria expanded is false'); +}); + +})(jQuery); diff --git a/tests/unit/datepicker/datepicker.html b/tests/unit/datepicker/datepicker.html new file mode 100644 index 000000000..a17b08e90 --- /dev/null +++ b/tests/unit/datepicker/datepicker.html @@ -0,0 +1,30 @@ + + + + jQuery UI Datepicker Test Suite + + + + + + + + + + + + + + + + + + +
            +

            +
            + + + diff --git a/tests/unit/datepicker/datepicker.js b/tests/unit/datepicker/datepicker.js new file mode 100644 index 000000000..dadb5a997 --- /dev/null +++ b/tests/unit/datepicker/datepicker.js @@ -0,0 +1,1387 @@ +/* + * datepicker unit tests + */ +(function($) { + +module('datepicker'); + +function equalsDate(d1, d2, message) { + if (!d1 || !d2) { + ok(false, message + ' - missing date'); + return; + } + d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()); + d2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()); + equals(d1.toString(), d2.toString(), message); +} + +function equalsDateArray(a1, a2, message) { + if (!a1 || !a2) { + ok(false, message + ' - missing dates'); + return; + } + a1[0] = (a1[0] ? new Date(a1[0].getFullYear(), a1[0].getMonth(), a1[0].getDate()) : ''); + a1[1] = (a1[1] ? new Date(a1[1].getFullYear(), a1[1].getMonth(), a1[1].getDate()) : ''); + a2[0] = (a2[0] ? new Date(a2[0].getFullYear(), a2[0].getMonth(), a2[0].getDate()) : ''); + a2[1] = (a2[1] ? new Date(a2[1].getFullYear(), a2[1].getMonth(), a2[1].getDate()) : ''); + same(a1, a2, message); +} + +function init(id, options) { + $.datepicker.setDefaults($.datepicker.regional['']); + var inp = $(id); + inp.datepicker($.extend({duration: ''}, options || {})); + return inp; +} + +var PROP_NAME = 'datepicker'; + +test('setDefaults', function() { + var inp = init('#inp'); + var dp = $('#ui-datepicker-div'); + ok(!dp.is(':visible'), 'Initially invisible'); + ok(inp.is('.hasDatepicker'), 'Marker class set'); + ok($($.datepicker.dpDiv).html() == '', 'Content empty'); + inp.datepicker('show'); + ok($($.datepicker.dpDiv).html() != '', 'Content present'); + inp.datepicker('hide'); + equals($.datepicker._defaults.showOn, 'focus', 'Initial showOn'); + $.datepicker.setDefaults({showOn: 'button'}); + equals($.datepicker._defaults.showOn, 'button', 'Change default showOn'); + $.datepicker.setDefaults({showOn: 'focus'}); + equals($.datepicker._defaults.showOn, 'focus', 'Restore showOn'); +}); + +test('destroy', function() { + var inp = init('#inp'); + ok(inp.is('.hasDatepicker'), 'Default - marker class set'); + ok($.data(inp[0], PROP_NAME), 'Default - instance present'); + ok(inp.next().is('#alt'), 'Default - button absent'); + inp.datepicker('destroy'); + inp = $('#inp'); + ok(!inp.is('.hasDatepicker'), 'Default - marker class cleared'); + ok(!$.data(inp[0], PROP_NAME), 'Default - instance absent'); + ok(inp.next().is('#alt'), 'Default - button absent'); + // With button + inp= init('#inp', {showOn: 'both'}); + ok(inp.is('.hasDatepicker'), 'Button - marker class set'); + ok($.data(inp[0], PROP_NAME), 'Button - instance present'); + ok(inp.next().text() == '...', 'Button - button added'); + inp.datepicker('destroy'); + inp = $('#inp'); + ok(!inp.is('.hasDatepicker'), 'Button - marker class cleared'); + ok(!$.data(inp[0], PROP_NAME), 'Button - instance absent'); + ok(inp.next().is('#alt'), 'Button - button removed'); + // With append text + inp = init('#inp', {appendText: 'Testing'}); + ok(inp.is('.hasDatepicker'), 'Append - marker class set'); + ok($.data(inp[0], PROP_NAME), 'Append - instance present'); + ok(inp.next().text() == 'Testing', 'Append - append text added'); + inp.datepicker('destroy'); + inp = $('#inp'); + ok(!inp.is('.hasDatepicker'), 'Append - marker class cleared'); + ok(!$.data(inp[0], PROP_NAME), 'Append - instance absent'); + ok(inp.next().is('#alt'), 'Append - append text removed'); + // With both + inp= init('#inp', {showOn: 'both', buttonImageOnly: true, + buttonImage: 'img/calendar.gif', appendText: 'Testing'}); + ok(inp.is('.hasDatepicker'), 'Both - marker class set'); + ok($.data(inp[0], PROP_NAME), 'Both - instance present'); + ok(inp.next()[0].nodeName.toLowerCase() == 'img', 'Both - button added'); + ok(inp.next().next().text() == 'Testing', 'Both - append text added'); + inp.datepicker('destroy'); + inp = $('#inp'); + ok(!inp.is('.hasDatepicker'), 'Both - marker class cleared'); + ok(!$.data(inp[0], PROP_NAME), 'Both - instance absent'); + ok(inp.next().is('#alt'), 'Both - button and append text absent'); + // Inline + var inl = init('#inl'); + ok(inl.is('.hasDatepicker'), 'Inline - marker class set'); + ok(inl.html() != '', 'Inline - datepicker present'); + ok($.data(inl[0], PROP_NAME), 'Inline - instance present'); + ok(inl.next().length == 0 || inl.next().is('p'), 'Inline - button absent'); + inl.datepicker('destroy'); + inl = $('#inl'); + ok(!inl.is('.hasDatepicker'), 'Inline - marker class cleared'); + ok(inl.html() == '', 'Inline - datepicker absent'); + ok(!$.data(inl[0], PROP_NAME), 'Inline - instance absent'); + ok(inl.next().length == 0 || inl.next().is('p'), 'Inline - button absent'); +}); + +test('option', function() { + var inp = init('#inp'); + var inst = $.data(inp[0], PROP_NAME); + equals(inst.settings.showOn, null, 'Initial setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn'); + inp.datepicker('option', 'showOn', 'button'); + equals(inst.settings.showOn, 'button', 'Change setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'button', 'Change instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); + inp.datepicker('option', {showOn: 'both'}); + equals(inst.settings.showOn, 'both', 'Change setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'both', 'Change instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); + inp.datepicker('option', 'showOn', undefined); + equals(inst.settings.showOn, null, 'Clear setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); +}); + +test('change', function() { + var inp = init('#inp'); + var inst = $.data(inp[0], PROP_NAME); + equals(inst.settings.showOn, null, 'Initial setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn'); + inp.datepicker('change', 'showOn', 'button'); + equals(inst.settings.showOn, 'button', 'Change setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'button', 'Change instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); + inp.datepicker('change', {showOn: 'both'}); + equals(inst.settings.showOn, 'both', 'Change setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'both', 'Change instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); + inp.datepicker('change', 'showOn', undefined); + equals(inst.settings.showOn, null, 'Clear setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); +}); + +test('invocation', function() { + var inp = init('#inp'); + var dp = $('#ui-datepicker-div'); + var body = $('body'); + // On focus + var button = inp.siblings('button'); + ok(button.length == 0, 'Focus - button absent'); + var image = inp.siblings('img'); + ok(image.length == 0, 'Focus - image absent'); + inp.focus(); + ok(dp.is(':visible'), 'Focus - rendered on focus'); + inp.simulate('keydown', {keyCode: $.simulate.VK_ESC}); + ok(!dp.is(':visible'), 'Focus - hidden on exit'); + inp.focus(); + ok(dp.is(':visible'), 'Focus - rendered on focus'); + body.simulate('mousedown', {}); + ok(!dp.is(':visible'), 'Focus - hidden on external click'); + inp.datepicker('hide').datepicker('destroy'); + // On button + inp = init('#inp', {showOn: 'button', buttonText: 'Popup'}); + ok(!dp.is(':visible'), 'Button - initially hidden'); + button = inp.siblings('button'); + image = inp.siblings('img'); + ok(button.length == 1, 'Button - button present'); + ok(image.length == 0, 'Button - image absent'); + equals(button.text(), 'Popup', 'Button - button text'); + inp.focus(); + ok(!dp.is(':visible'), 'Button - not rendered on focus'); + button.click(); + ok(dp.is(':visible'), 'Button - rendered on button click'); + button.click(); + ok(!dp.is(':visible'), 'Button - hidden on second button click'); + inp.datepicker('hide').datepicker('destroy'); + // On image button + inp = init('#inp', {showOn: 'button', buttonImageOnly: true, + buttonImage: 'img/calendar.gif', buttonText: 'Cal'}); + ok(!dp.is(':visible'), 'Image button - initially hidden'); + button = inp.siblings('button'); + ok(button.length == 0, 'Image button - button absent'); + image = inp.siblings('img'); + ok(image.length == 1, 'Image button - image present'); + equals(image.attr('src'), 'img/calendar.gif', 'Image button - image source'); + equals(image.attr('title'), 'Cal', 'Image button - image text'); + inp.focus(); + ok(!dp.is(':visible'), 'Image button - not rendered on focus'); + image.click(); + ok(dp.is(':visible'), 'Image button - rendered on image click'); + image.click(); + ok(!dp.is(':visible'), 'Image button - hidden on second image click'); + inp.datepicker('hide').datepicker('destroy'); + // On both + inp = init('#inp', {showOn: 'both', buttonImage: 'img/calendar.gif'}); + ok(!dp.is(':visible'), 'Both - initially hidden'); + button = inp.siblings('button'); + ok(button.length == 1, 'Both - button present'); + image = inp.siblings('img'); + ok(image.length == 0, 'Both - image absent'); + image = button.children('img'); + ok(image.length == 1, 'Both - button image present'); + inp.focus(); + ok(dp.is(':visible'), 'Both - rendered on focus'); + body.simulate('mousedown', {}); + ok(!dp.is(':visible'), 'Both - hidden on external click'); + button.click(); + ok(dp.is(':visible'), 'Both - rendered on button click'); + button.click(); + ok(!dp.is(':visible'), 'Both - hidden on second button click'); + inp.datepicker('hide').datepicker('destroy'); +}); + +test('baseStructure', function() { + var dp = $('#ui-datepicker-div'); + var inp = init('#inp'); + inp.focus(); + var iframe = ($.browser.msie && parseInt($.browser.version) < 7); + ok(dp.is(':visible'), 'Structure - datepicker visible'); + ok(!dp.is('.ui-datepicker-rtl'), 'Structure - not right-to-left'); + ok(!dp.is('.ui-datepicker-multi'), 'Structure - not multi-month'); + equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure - child count'); + + var header = dp.children(':first'); + ok(header.is('div.ui-datepicker-header'), 'Structure - header division'); + equals(header.children().length, 3, 'Structure - header child count'); + ok(header.children(':first').is('a.ui-datepicker-prev') && header.children(':first').html() != '', 'Structure - prev link'); + ok(header.children(':eq(1)').is('a.ui-datepicker-next') && header.children(':eq(1)').html() != '', 'Structure - next link'); + + var title = header.children(':last'); + ok(title.is('div.ui-datepicker-title') && title.html() != '','Structure - title division'); + equals(title.children().length, 2, 'Structure - title child count'); + ok(title.children(':first').is('span.ui-datepicker-month') && title.children(':first').text() != '', 'Structure - month text') + ok(title.children(':last').is('span.ui-datepicker-year') && title.children(':last').text() != '', 'Structure - year text') + + var table = dp.children(':eq(1)'); + ok(table.is('table.ui-datepicker-calendar'), 'Structure - month table'); + ok(table.children(':first').is('thead'), 'Structure - month table thead'); + var thead = table.children(':first').children(':first'); + ok(thead.is('tr'), 'Structure - month table title row'); + equals(thead.find('th').length, 7, 'Structure - month table title cells'); + ok(table.children(':eq(1)').is('tbody'), 'Structure - month table body'); + ok(table.children(':eq(1)').children('tr').length >= 4, 'Structure - month table week count'); + var week = table.children(':eq(1)').children(':first'); + ok(week.is('tr'), 'Structure - month table week row'); + equals(week.children().length, 7, 'Structure - week child count'); + ok(week.children(':first').is('td.ui-datepicker-week-end'), 'Structure - month table first day cell'); + ok(week.children(':last').is('td.ui-datepicker-week-end'), 'Structure - month table second day cell'); + ok(dp.children('iframe').length == (iframe ? 1 : 0), 'Structure - iframe'); + inp.datepicker('hide').datepicker('destroy'); + + // Editable month/year and button panel + inp = init('#inp', {changeMonth: true, changeYear: true, showButtonPanel: true}); + inp.focus(); + + var title = dp.find('div.ui-datepicker-title'); + ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure - month selector'); + ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure - year selector'); + + var panel = dp.children(':last'); + ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure - button panel division'); + equals(panel.children().length, 2, 'Structure - button panel child count'); + ok(panel.children(':first').is('button.ui-datepicker-current'), 'Structure - today button'); + ok(panel.children(':last').is('button.ui-datepicker-close'), 'Structure - close button'); + inp.datepicker('hide').datepicker('destroy'); + + // Multi-month 2 + inp = init('#inp', {numberOfMonths: 2}); + inp.focus(); + ok(dp.is('.ui-datepicker-multi'), 'Structure multi [2] - multi-month'); + equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure multi [2] - child count'); + month = dp.children(':first'); + ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi [2] - first month division'); + month = dp.children(':eq(1)'); + ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi [2] - second month division'); + inp.datepicker('hide').datepicker('destroy'); + + // Multi-month [2, 2] + inp = init('#inp', {numberOfMonths: [2, 2]}); + inp.focus(); + ok(dp.is('.ui-datepicker-multi'), 'Structure multi - multi-month'); + equals(dp.children().length, 4 + (iframe ? 1 : 0), 'Structure multi [2,2] - child count'); + month = dp.children(':first'); + ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - first month division'); + month = dp.children(':eq(1)'); + ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - second month division'); + month = dp.children(':eq(2)'); + ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - third month division'); + month = dp.children(':eq(3)'); + ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - fourth month division'); + inp.datepicker('hide').datepicker('destroy'); + + // Inline + var inl = init('#inl'); + dp = inl.children(); + ok(dp.is('.ui-datepicker-inline'), 'Structure inline - main div'); + ok(!dp.is('.ui-datepicker-rtl'), 'Structure inline - not right-to-left'); + ok(!dp.is('.ui-datepicker-multi'), 'Structure inline - not multi-month'); + equals(dp.children().length, 2, 'Structure inline - child count'); + var header = dp.children(':first'); + ok(header.is('div.ui-datepicker-header'), 'Structure inline - header division'); + equals(header.children().length, 3, 'Structure inline - header child count'); + var table = month.children(':eq(1)'); + ok(table.is('table.ui-datepicker-calendar'), 'Structure inline - month table'); + ok(table.children(':first').is('thead'), 'Structure inline - month table thead'); + ok(table.children(':eq(1)').is('tbody'), 'Structure inline - month table body'); + inl.datepicker('destroy'); + + // Inline multi-month + inl = init('#inl', {numberOfMonths: 2}); + dp = inl.children(); + ok(dp.is('.ui-datepicker-inline') && dp.is('.ui-datepicker-multi'), 'Structure inline multi - main div'); + equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure multi - child count'); + month = dp.children(':first'); + ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-first'), 'Structure multi - first month division'); + month = dp.children(':eq(1)'); + ok(month.is('div.ui-datepicker-group') && month.is('div.ui-datepicker-group-last'), 'Structure multi - second month division'); + inl.datepicker('destroy'); +}); + +test('customStructure', function() { + var dp = $('#ui-datepicker-div'); + // Check right-to-left localisation + var inp = init('#inp', $.datepicker.regional['he']); + inp.data('showButtonPanel.datepicker',true); + inp.focus(); + var iframe = ($.browser.msie && parseInt($.browser.version) < 7); + ok(dp.is('.ui-datepicker-rtl'), 'Structure RTL - right-to-left'); + var header = dp.children(':first'); + ok(header.is('div.ui-datepicker-header'), 'Structure RTL - header division'); + equals(header.children().length, 3, 'Structure RTL - header child count'); + ok(header.children(':first').is('a.ui-datepicker-next'), 'Structure RTL - prev link'); + ok(header.children(':eq(1)').is('a.ui-datepicker-prev'), 'Structure RTL - next link'); + var panel = dp.children(':last'); + ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure RTL - button division'); + equals(panel.children().length, 2, 'Structure RTL - button panel child count'); + ok(panel.children(':first').is('button.ui-datepicker-close'), 'Structure RTL - close button'); + ok(panel.children(':last').is('button.ui-datepicker-current'), 'Structure RTL - today button'); + inp.datepicker('hide').datepicker('destroy'); + + // Hide prev/next + inp = init('#inp', {hideIfNoPrevNext: true, minDate: new Date(2008, 2 - 1, 4), maxDate: new Date(2008, 2 - 1, 14)}); + inp.val('02/10/2008').focus(); + var header = dp.children(':first'); + ok(header.is('div.ui-datepicker-header'), 'Structure hide prev/next - header division'); + equals(header.children().length, 1, 'Structure hide prev/next - links child count'); + ok(header.children(':first').is('div.ui-datepicker-title'), 'Structure hide prev/next - title division'); + inp.datepicker('hide').datepicker('destroy'); + + // Changeable Month with read-only year + inp = init('#inp', {changeMonth: true}); + inp.focus(); + var title = dp.children(':first').children(':last'); + equals(title.children().length, 2, 'Structure changeable month - title child count'); + ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure changeable month - month selector'); + ok(title.children(':last').is('span.ui-datepicker-year'), 'Structure changeable month - read-only year'); + inp.datepicker('hide').datepicker('destroy'); + + // Changeable year with read-only month + inp = init('#inp', {changeYear: true}); + inp.focus(); + var title = dp.children(':first').children(':last'); + equals(title.children().length, 2, 'Structure changeable year - title child count'); + ok(title.children(':first').is('span.ui-datepicker-month'), 'Structure changeable year - read-only month'); + ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure changeable year - year selector'); + inp.datepicker('hide').datepicker('destroy'); + + // Read-only first day of week + inp = init('#inp', {changeFirstDay: false}); + inp.focus(); + var thead = dp.find('.ui-datepicker-calendar thead tr'); + equals(thead.children().length, 7, 'Structure read-only first day - thead child count'); + equals(thead.find('a').length, 0, 'Structure read-only first day - thead links count'); + inp.datepicker('hide').datepicker('destroy'); +}); + +test('enableDisable', function() { + var inp = init('#inp'); + ok(!inp.datepicker('isDisabled'), 'Enable/disable - initially marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable - field initially enabled'); + inp.datepicker('disable'); + ok(inp.datepicker('isDisabled'), 'Enable/disable - now marked as disabled'); + ok(inp[0].disabled, 'Enable/disable - field now disabled'); + inp.datepicker('enable'); + ok(!inp.datepicker('isDisabled'), 'Enable/disable - now marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable - field now enabled'); + inp.datepicker('destroy'); + // With a button + inp = init('#inp', {showOn: 'button'}); + ok(!inp.datepicker('isDisabled'), 'Enable/disable button - initially marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable button - field initially enabled'); + ok(!inp.next('button')[0].disabled, 'Enable/disable button - button initially enabled'); + inp.datepicker('disable'); + ok(inp.datepicker('isDisabled'), 'Enable/disable button - now marked as disabled'); + ok(inp[0].disabled, 'Enable/disable button - field now disabled'); + ok(inp.next('button')[0].disabled, 'Enable/disable button - button now disabled'); + inp.datepicker('enable'); + ok(!inp.datepicker('isDisabled'), 'Enable/disable button - now marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable button - field now enabled'); + ok(!inp.next('button')[0].disabled, 'Enable/disable button - button now enabled'); + inp.datepicker('destroy'); + // With an image button + inp = init('#inp', {showOn: 'button', buttonImageOnly: true, + buttonImage: 'img/calendar.gif'}); + ok(!inp.datepicker('isDisabled'), 'Enable/disable image - initially marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable image - field initially enabled'); + ok(inp.next('img').css('opacity') == 1, 'Enable/disable image - image initially enabled'); + inp.datepicker('disable'); + ok(inp.datepicker('isDisabled'), 'Enable/disable image - now marked as disabled'); + ok(inp[0].disabled, 'Enable/disable image - field now disabled'); + ok(inp.next('img').css('opacity') != 1, 'Enable/disable image - image now disabled'); + inp.datepicker('enable'); + ok(!inp.datepicker('isDisabled'), 'Enable/disable image - now marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable image - field now enabled'); + ok(inp.next('img').css('opacity') == 1, 'Enable/disable image - image now enabled'); + inp.datepicker('destroy'); + // Inline + var inl = init('#inl'); + var dp = $('.ui-datepicker-inline', inl); + ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - initially marked as enabled'); + ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visually disabled initially'); + inl.datepicker('disable'); + ok(inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as disabled'); + ok(dp.children().is('.ui-state-disabled'), 'Enable/disable inline - visually disabled'); + inl.datepicker('enable'); + ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as enabled'); + ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visiually disabled'); + inl.datepicker('destroy'); +}); + +test('keystrokes', function() { + var inp = init('#inp'); + var date = new Date(); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke enter'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Keystroke enter - preset'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+home'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); + ok(inp.datepicker('getDate') == null, 'Keystroke ctrl+end'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + ok(inp.datepicker('getDate') == null, 'Keystroke esc'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Keystroke esc - preset'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Keystroke esc - abandoned'); + // Moving by day or week + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_LEFT}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 1); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+left'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_LEFT}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 1); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke left'); + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_RIGHT}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 1); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+right'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_RIGHT}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 1); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke right'); + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_UP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 7); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+up'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_UP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 7); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke up'); + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 7); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+down'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_DOWN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 7); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke down'); + // Moving by month or year + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 4), + 'Keystroke pgup'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 4), + 'Keystroke pgdn'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 4), + 'Keystroke ctrl+pgup'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 4), + 'Keystroke ctrl+pgdn'); + // Check for moving to short months + inp.val('03/31/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29), + 'Keystroke pgup - Feb'); + inp.val('01/30/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29), + 'Keystroke pgdn - Feb'); + inp.val('02/29/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 28), + 'Keystroke ctrl+pgup - Feb'); + inp.val('02/29/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 28), + 'Keystroke ctrl+pgdn - Feb'); + // Goto current + inp.datepicker('option', {gotoCurrent: true}). + datepicker('hide').val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Keystroke ctrl+home'); + // Change steps + inp.datepicker('option', {stepMonths: 2, gotoCurrent: false}). + datepicker('hide').val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2007, 12 - 1, 4), + 'Keystroke pgup step 2'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 4 - 1, 4), + 'Keystroke pgdn step 2'); +}); + +test('mouse', function() { + var inp = init('#inp'); + var dp = $('#ui-datepicker-div'); + var date = new Date(); + inp.val('').datepicker('show'); + $('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {}); + date.setDate(10); + equalsDate(inp.datepicker('getDate'), date, 'Mouse click'); + inp.val('02/04/2008').datepicker('show'); + $('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 12), + 'Mouse click - preset'); + inp.val('02/04/2008').datepicker('show'); + inp.val('').datepicker('show'); + $('button.ui-datepicker-close', dp).simulate('click', {}); + ok(inp.datepicker('getDate') == null, 'Mouse click - close'); + inp.val('02/04/2008').datepicker('show'); + $('button.ui-datepicker-close', dp).simulate('click', {}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Mouse click - close + preset'); + inp.val('02/04/2008').datepicker('show'); + $('a.ui-datepicker-prev', dp).simulate('click', {}); + $('button.ui-datepicker-close', dp).simulate('click', {}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Mouse click - abandoned'); + // Current/previous/next + inp.val('02/04/2008').datepicker('option', {showButtonPanel: true}).datepicker('show'); + $('.ui-datepicker-current', dp).simulate('click', {}); + $('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {}); + date.setDate(14); + equalsDate(inp.datepicker('getDate'), date, 'Mouse click - current'); + inp.val('02/04/2008').datepicker('show'); + $('.ui-datepicker-prev', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click'); + equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 16), + 'Mouse click - previous'); + inp.val('02/04/2008').datepicker('show'); + $('.ui-datepicker-next', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click'); + equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 18), + 'Mouse click - next'); + // Previous/next with minimum/maximum + inp.datepicker('option', {minDate: new Date(2008, 2 - 1, 2), + maxDate: new Date(2008, 2 - 1, 26)}).val('02/04/2008').datepicker('show'); + $('.ui-datepicker-prev', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click'); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 16), + 'Mouse click - previous + min/max'); + inp.val('02/04/2008').datepicker('show'); + $('.ui-datepicker-next', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click'); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 18), + 'Mouse click - next + min/max'); + // Inline + var inl = init('#inl'); + var dp = $('.ui-datepicker-inline', inl); + var date = new Date(); + inl.datepicker('setDate', date); + $('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {}); + date.setDate(10); + equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline'); + inl.datepicker('option', {showButtonPanel: true}).datepicker('setDate', new Date(2008, 2 - 1, 4)); + $('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {}); + equalsDate(inl.datepicker('getDate'), new Date(2008, 2 - 1, 12), 'Mouse click inline - preset'); + inl.datepicker('option', {showButtonPanel: true}); + $('.ui-datepicker-current', dp).simulate('click', {}); + $('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {}); + date.setDate(14); + equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline - current'); + inl.datepicker('setDate', new Date(2008, 2 - 1, 4)); + $('.ui-datepicker-prev', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click'); + equalsDate(inl.datepicker('getDate'), new Date(2008, 1 - 1, 16), + 'Mouse click inline - previous'); + inl.datepicker('setDate', new Date(2008, 2 - 1, 4)); + $('.ui-datepicker-next', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click'); + equalsDate(inl.datepicker('getDate'), new Date(2008, 3 - 1, 18), + 'Mouse click inline - next'); +}); + +test('defaultDate', function() { + var inp = init('#inp'); + var date = new Date(); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Default date null'); + // numeric values + inp.datepicker('option', {defaultDate: -2}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 2); + equalsDate(inp.datepicker('getDate'), date, 'Default date -2'); + inp.datepicker('option', {defaultDate: 3}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 5); + equalsDate(inp.datepicker('getDate'), date, 'Default date 3'); + inp.datepicker('option', {defaultDate: 1 / 0}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 3); + equalsDate(inp.datepicker('getDate'), date, 'Default date Infinity'); + inp.datepicker('option', {defaultDate: 1 / 'a'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Default date NaN'); + // string values + inp.datepicker('option', {defaultDate: '-1d'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 1); + equalsDate(inp.datepicker('getDate'), date, 'Default date -1d'); + inp.datepicker('option', {defaultDate: '+3D'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 4); + equalsDate(inp.datepicker('getDate'), date, 'Default date +3D'); + inp.datepicker('option', {defaultDate: ' -2 w '}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = new Date(); + date.setDate(date.getDate() - 14); + equalsDate(inp.datepicker('getDate'), date, 'Default date -2 w'); + inp.datepicker('option', {defaultDate: '+1 W'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 21); + equalsDate(inp.datepicker('getDate'), date, 'Default date +1 W'); + inp.datepicker('option', {defaultDate: ' -1 m '}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = new Date(); + date.setMonth(date.getMonth() - 1); + equalsDate(inp.datepicker('getDate'), date, 'Default date -1 m'); + inp.datepicker('option', {defaultDate: '+2M'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setMonth(date.getMonth() + 3); + equalsDate(inp.datepicker('getDate'), date, 'Default date +2M'); + inp.datepicker('option', {defaultDate: '-2y'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = new Date(); + date.setFullYear(date.getFullYear() - 2); + equalsDate(inp.datepicker('getDate'), date, 'Default date -2y'); + inp.datepicker('option', {defaultDate: '+1 Y '}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setFullYear(date.getFullYear() + 3); + equalsDate(inp.datepicker('getDate'), date, 'Default date +1 Y'); + inp.datepicker('option', {defaultDate: '+1M +10d'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = new Date(); + date.setMonth(date.getMonth() + 1); + date.setDate(date.getDate() + 10); + equalsDate(inp.datepicker('getDate'), date, 'Default date +1M +10d'); + date = new Date(2007, 1 - 1, 26); + inp.datepicker('option', {defaultDate: date}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Default date 01/26/2007'); +}); + +test('miscellaneous', function() { + var dp = $('#ui-datepicker-div'); + var inp = init('#inp'); + // Year range + var genRange = function(start, offset) { + var range = ''; + for (var i = start; i < start + offset; i++) { + range += i; + } + return range; + }; + inp.val('02/04/2008').datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), '2008', 'Year range - read-only default'); + inp.datepicker('hide').datepicker('option', {changeYear: true}).datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), genRange(new Date().getFullYear() - 10, 21), 'Year range - changeable default'); + inp.datepicker('hide').datepicker('option', {yearRange: '-6:+2', changeYear: true}).datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), genRange(new Date().getFullYear() - 6, 9), 'Year range - -6:+2'); + inp.datepicker('hide').datepicker('option', {yearRange: '2000:2010', changeYear: true}).datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), genRange(2000, 11), 'Year range - 2000:2010'); + + // Navigation as date format + inp.datepicker('option', {showButtonPanel: true}); + equals(dp.find('.ui-datepicker-prev').text(), 'Prev', 'Navigation prev - default'); + equals(dp.find('.ui-datepicker-current').text(), 'Today', 'Navigation current - default'); + equals(dp.find('.ui-datepicker-next').text(), 'Next', 'Navigation next - default'); + inp.datepicker('hide').datepicker('option', {navigationAsDateFormat: true, prevText: '< M', currentText: 'MM', nextText: 'M >'}).val('02/04/2008').datepicker('show'); + var longNames = $.datepicker.regional[''].monthNames; + var shortNames = $.datepicker.regional[''].monthNamesShort; + var date = new Date(); + equals(dp.find('.ui-datepicker-prev').text(), '< ' + shortNames[0], 'Navigation prev - as date format'); + equals(dp.find('.ui-datepicker-current').text(), + longNames[date.getMonth()], 'Navigation current - as date format'); + equals(dp.find('.ui-datepicker-next').text(), + shortNames[2] + ' >', 'Navigation next - as date format'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}); + equals(dp.find('.ui-datepicker-prev').text(), + '< ' + shortNames[1], 'Navigation prev - as date format + pgdn'); + equals(dp.find('.ui-datepicker-current').text(), + longNames[date.getMonth()], 'Navigation current - as date format + pgdn'); + equals(dp.find('.ui-datepicker-next').text(), + shortNames[3] + ' >', 'Navigation next - as date format + pgdn'); + inp.datepicker('hide').datepicker('option', {gotoCurrent: true}). + val('02/04/2008').datepicker('show'); + equals(dp.find('.ui-datepicker-prev').text(), + '< ' + shortNames[0], 'Navigation prev - as date format + goto current'); + equals(dp.find('.ui-datepicker-current').text(), + longNames[1], 'Navigation current - as date format + goto current'); + equals(dp.find('.ui-datepicker-next').text(), + shortNames[2] + ' >', 'Navigation next - as date format + goto current'); +}); + +test('minMax', function() { + var inp = init('#inp'); + var lastYear = new Date(2007, 6 - 1, 4); + var nextYear = new Date(2009, 6 - 1, 4); + var minDate = new Date(2008, 2 - 1, 29); + var maxDate = new Date(2008, 12 - 1, 7); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), lastYear, + 'Min/max - null, null - ctrl+pgup'); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), nextYear, + 'Min/max - null, null - ctrl+pgdn'); + inp.datepicker('option', {minDate: minDate}). + datepicker('hide').val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), minDate, + 'Min/max - 02/29/2008, null - ctrl+pgup'); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), nextYear, + 'Min/max - 02/29/2008, null - ctrl+pgdn'); + inp.datepicker('option', {maxDate: maxDate}). + datepicker('hide').val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), minDate, + 'Min/max - 02/29/2008, 12/07/2008 - ctrl+pgup'); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), maxDate, + 'Min/max - 02/29/2008, 12/07/2008 - ctrl+pgdn'); + inp.datepicker('option', {minDate: null}). + datepicker('hide').val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), lastYear, + 'Min/max - null, 12/07/2008 - ctrl+pgup'); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), maxDate, + 'Min/max - null, 12/07/2008 - ctrl+pgdn'); + // Relative dates + var date = new Date(); + date.setDate(date.getDate() - 7); + inp.datepicker('option', {minDate: '-1w', maxDate: '+1 M +10 D '}). + datepicker('hide').val('').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, + 'Min/max - -1w, +1 M +10 D - ctrl+pgup'); + date = new Date(); + date.setMonth(date.getMonth() + 1); + date.setDate(date.getDate() + 10); + inp.val('').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, + 'Min/max - -1w, +1 M +10 D - ctrl+pgdn'); +}); + +test('setDate', function() { + var inp = init('#inp'); + var date1 = new Date(2008, 6 - 1, 4); + var date2 = new Date(); + ok(inp.datepicker('getDate') == null, 'Set date - default'); + inp.datepicker('setDate', date1); + equalsDate(inp.datepicker('getDate'), date1, 'Set date - 2008-06-04'); + date1 = new Date(); + date1.setDate(date1.getDate() + 7); + inp.datepicker('setDate', +7); + equalsDate(inp.datepicker('getDate'), date1, 'Set date - +7'); + date2.setFullYear(date2.getFullYear() + 2); + inp.datepicker('setDate', '+2y'); + equalsDate(inp.datepicker('getDate'), date2, 'Set date - +2y'); + inp.datepicker('setDate', date1, date2); + equalsDate(inp.datepicker('getDate'), date1, 'Set date - two dates'); + inp.datepicker('setDate'); + ok(inp.datepicker('getDate') == null, 'Set date - null'); + // Inline + var inl = init('#inl'); + date1 = new Date(2008, 6 - 1, 4); + date2 = new Date(); + equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - default'); + inl.datepicker('setDate', date1); + equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - 2008-06-04'); + date1 = new Date(); + date1.setDate(date1.getDate() + 7); + inl.datepicker('setDate', +7); + equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - +7'); + date2.setFullYear(date2.getFullYear() + 2); + inl.datepicker('setDate', '+2y'); + equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - +2y'); + inl.datepicker('setDate', date1, date2); + equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - two dates'); + inl.datepicker('setDate'); + ok(inl.datepicker('getDate') == null, 'Set date inline - null'); + // Alternate field + var alt = $('#alt'); + inp.datepicker('option', {altField: '#alt', altFormat: 'yy-mm-dd'}); + date1 = new Date(2008, 6 - 1, 4); + inp.datepicker('setDate', date1); + equals(inp.val(), '06/04/2008', 'Set date alternate - 06/04/2008'); + equals(alt.val(), '2008-06-04', 'Set date alternate - 2008-06-04'); +}); + +test('altField', function() { + var inp = init('#inp'); + var alt = $('#alt'); + // No alternate field set + alt.val(''); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(inp.val(), '06/04/2008', 'Alt field - dp - enter'); + equals(alt.val(), '', 'Alt field - alt not set'); + // Alternate field set + alt.val(''); + inp.datepicker('option', {altField: '#alt', altFormat: 'yy-mm-dd'}). + val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(inp.val(), '06/04/2008', 'Alt field - dp - enter'); + equals(alt.val(), '2008-06-04', 'Alt field - alt - enter'); + // Move from initial date + alt.val(''); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(inp.val(), '07/04/2008', 'Alt field - dp - pgdn'); + equals(alt.val(), '2008-07-04', 'Alt field - alt - pgdn'); + // Alternate field set - closed + alt.val(''); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equals(inp.val(), '06/04/2008', 'Alt field - dp - pgdn/esc'); + equals(alt.val(), '', 'Alt field - alt - pgdn/esc'); + // Clear date and alternate + alt.val(''); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); + equals(inp.val(), '', 'Alt field - dp - ctrl+end'); + equals(alt.val(), '', 'Alt field - alt - ctrl+end'); +}); + +test('daylightSaving', function() { + var inp = init('#inp'); + var dp = $('#ui-datepicker-div'); + ok(true, 'Daylight saving - ' + new Date()); + // Australia, Sydney - AM change, southern hemisphere + inp.val('04/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(6) a', dp).simulate('click'); + equals(inp.val(), '04/05/2008', 'Daylight saving - Australia 04/05/2008'); + inp.val('04/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(7) a', dp).simulate('click'); + equals(inp.val(), '04/06/2008', 'Daylight saving - Australia 04/06/2008'); + inp.val('04/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(8) a', dp).simulate('click'); + equals(inp.val(), '04/07/2008', 'Daylight saving - Australia 04/07/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(6) a', dp).simulate('click'); + equals(inp.val(), '10/04/2008', 'Daylight saving - Australia 10/04/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(7) a', dp).simulate('click'); + equals(inp.val(), '10/05/2008', 'Daylight saving - Australia 10/05/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(8) a', dp).simulate('click'); + equals(inp.val(), '10/06/2008', 'Daylight saving - Australia 10/06/2008'); + // Brasil, Brasilia - midnight change, southern hemisphere + inp.val('02/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(20) a', dp).simulate('click'); + equals(inp.val(), '02/16/2008', 'Daylight saving - Brasil 02/16/2008'); + inp.val('02/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(21) a', dp).simulate('click'); + equals(inp.val(), '02/17/2008', 'Daylight saving - Brasil 02/17/2008'); + inp.val('02/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(22) a', dp).simulate('click'); + equals(inp.val(), '02/18/2008', 'Daylight saving - Brasil 02/18/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(13) a', dp).simulate('click'); + equals(inp.val(), '10/11/2008', 'Daylight saving - Brasil 10/11/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(14) a', dp).simulate('click'); + equals(inp.val(), '10/12/2008', 'Daylight saving - Brasil 10/12/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(15) a', dp).simulate('click'); + equals(inp.val(), '10/13/2008', 'Daylight saving - Brasil 10/13/2008'); + // Lebanon, Beirut - midnight change, northern hemisphere + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(34) a', dp).simulate('click'); + equals(inp.val(), '03/29/2008', 'Daylight saving - Lebanon 03/29/2008'); + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(35) a', dp).simulate('click'); + equals(inp.val(), '03/30/2008', 'Daylight saving - Lebanon 03/30/2008'); + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(36) a', dp).simulate('click'); + equals(inp.val(), '03/31/2008', 'Daylight saving - Lebanon 03/31/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(27) a', dp).simulate('click'); + equals(inp.val(), '10/25/2008', 'Daylight saving - Lebanon 10/25/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(28) a', dp).simulate('click'); + equals(inp.val(), '10/26/2008', 'Daylight saving - Lebanon 10/26/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(29) a', dp).simulate('click'); + equals(inp.val(), '10/27/2008', 'Daylight saving - Lebanon 10/27/2008'); + // US, Eastern - AM change, northern hemisphere + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(13) a', dp).simulate('click'); + equals(inp.val(), '03/08/2008', 'Daylight saving - US 03/08/2008'); + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(14) a', dp).simulate('click'); + equals(inp.val(), '03/09/2008', 'Daylight saving - US 03/09/2008'); + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(15) a', dp).simulate('click'); + equals(inp.val(), '03/10/2008', 'Daylight saving - US 03/10/2008'); + inp.val('11/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(6) a', dp).simulate('click'); + equals(inp.val(), '11/01/2008', 'Daylight saving - US 11/01/2008'); + inp.val('11/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(7) a', dp).simulate('click'); + equals(inp.val(), '11/02/2008', 'Daylight saving - US 11/02/2008'); + inp.val('11/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(8) a', dp).simulate('click'); + equals(inp.val(), '11/03/2008', 'Daylight saving - US 11/03/2008'); +}); + +var beforeShowThis = null; +var beforeShowInput = null; +var beforeShowInst = null; + +function beforeAll(input, inst) { + beforeShowThis = this; + beforeShowInput = input; + beforeShowInst = inst; + return {currentText: 'Current'}; +} + +var beforeShowDayThis = null; +var beforeShowDayOK = true; + +function beforeDay(date) { + beforeShowDayThis = this; + beforeShowDayOK &= (date > new Date(2008, 1 - 1, 26) && + date < new Date(2008, 3 - 1, 6)); + return [(date.getDate() % 2 == 0), (date.getDate() % 10 == 0 ? 'day10' : ''), + (date.getDate() % 3 == 0 ? 'Divisble by 3' : '')]; +} + +function calcWeek(date) { + var doy = date.getDate() + 6; + for (var m = date.getMonth() - 1; m >= 0; m--) + doy += $.datepicker._getDaysInMonth(date.getFullYear(), m); + // Simple count from 01/01 starting at week 1 + return Math.floor(doy / 7); +} + +test('callbacks', function() { + // Before show + var inp = init('#inp', {beforeShow: beforeAll}); + var inst = $.data(inp[0], 'datepicker'); + equals($.datepicker._get(inst, 'currentText'), 'Today', 'Before show - initial'); + inp.val('02/04/2008').datepicker('show'); + equals($.datepicker._get(inst, 'currentText'), 'Current', 'Before show - changed'); + ok(beforeShowThis.id == inp[0].id, 'Before show - this OK'); + ok(beforeShowInput.id == inp[0].id, 'Before show - input OK'); + isObj(beforeShowInst, inst, 'Before show - inst OK'); + inp.datepicker('hide').datepicker('destroy'); + // Before show day + inp = init('#inp', {beforeShowDay: beforeDay}); + var dp = $('#ui-datepicker-div'); + inp.val('02/04/2008').datepicker('show'); + ok(beforeShowDayThis.id == inp[0].id, 'Before show day - this OK'); + ok(beforeShowDayOK, 'Before show day - dates OK'); + var day20 = dp.find('.ui-datepicker-calendar td:contains("20")'); + var day21 = dp.find('.ui-datepicker-calendar td:contains("21")'); + ok(!day20.is('.ui-datepicker-unselectable'), 'Before show day - unselectable 20'); + ok(day21.is('.ui-datepicker-unselectable'), 'Before show day - unselectable 21'); + ok(day20.is('.day10'), 'Before show day - CSS 20'); + ok(!day21.is('.day10'), 'Before show day - CSS 21'); + ok(day20.attr('title') == '', 'Before show day - title 20'); + ok(day21.attr('title') == 'Divisble by 3', 'Before show day - title 21'); + inp.datepicker('hide').datepicker('destroy'); +}); + +var selectedThis = null; +var selectedDate = null; +var selectedInst = null; + +function callback(date, inst) { + selectedThis = this; + selectedDate = date; + selectedInst = inst; +} + +function callback2(year, month, inst) { + selectedThis = this; + selectedDate = year + '/' + month; + selectedInst = inst; +} + +test('events', function() { + var inp = init('#inp', {onSelect: callback}); + var date = new Date(); + // onSelect + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(selectedThis, inp[0], 'Callback selected this'); + equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback selected inst'); + equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), + 'Callback selected date'); + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 7); + equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), + 'Callback selected date - ctrl+down'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), + 'Callback selected date - esc'); + // onChangeMonthYear + inp.datepicker('option', {onChangeMonthYear: callback2, onSelect: null}). + val('').datepicker('show'); + var newMonthYear = function(date) { + return date.getFullYear() + '/' + (date.getMonth() + 1); + }; + date = new Date(); + date.setDate(1); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGUP}); + date.setMonth(date.getMonth() - 1); + equals(selectedThis, inp[0], 'Callback change month/year this'); + equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback change month/year inst'); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - pgup'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}); + date.setMonth(date.getMonth() + 1); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - pgdn'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}); + date.setFullYear(date.getFullYear() - 1); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - ctrl+pgup'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}); + date.setFullYear(date.getFullYear() + 1); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - ctrl+home'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}); + date.setFullYear(date.getFullYear() + 1); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - ctrl+pgdn'); + inp.datepicker('setDate', new Date(2007, 1 - 1, 26)); + equals(selectedDate, '2007/1', 'Callback change month/year date - setDate'); + selectedDate = null; + inp.datepicker('setDate', new Date(2007, 1 - 1, 12)); + ok(selectedDate == null, 'Callback change month/year date - setDate no change'); + // onChangeMonthYear step by 2 + inp.datepicker('option', {stepMonths: 2}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGUP}); + date.setMonth(date.getMonth() - 14); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year by 2 date - pgup'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}); + date.setMonth(date.getMonth() - 12); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year by 2 date - ctrl+pgup'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}); + date.setMonth(date.getMonth() + 2); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year by 2 date - pgdn'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}); + date.setMonth(date.getMonth() + 12); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year by 2 date - ctrl+pgdn'); + // onClose + inp.datepicker('option', {onClose: callback, onChangeMonthYear: null, stepMonths: 1}). + val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equals(selectedThis, inp[0], 'Callback close this'); + equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback close inst'); + equals(selectedDate, '', 'Callback close date - esc'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', new Date()), + 'Callback close date - enter'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equals(selectedDate, '02/04/2008', 'Callback close date - preset'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); + equals(selectedDate, '', 'Callback close date - ctrl+end'); +}); + +test('localisation', function() { + var inp = init('#inp', $.datepicker.regional['fr']); + inp.datepicker('option', {dateFormat: 'DD, d MM yy', showButtonPanel:true, changeMonth:true, changeYear:true}).val('').datepicker('show'); + var dp = $('#ui-datepicker-div'); + equals($('.ui-datepicker-close', dp).text(), 'Fermer', 'Localisation - close'); + $('.ui-datepicker-close', dp).simulate('mouseover'); + equals($('.ui-datepicker-prev', dp).text(), '', 'Localisation - next'); + var month = 0; + $('.ui-datepicker-month option', dp).each(function() { + equals($(this).text(), $.datepicker.regional['fr'].monthNamesShort[month], + 'Localisation - month ' + month); + month++; + }); + var day = 1; + $('.ui-datepicker-calendar th', dp).each(function() { + equals($(this).text(), $.datepicker.regional['fr'].dayNamesMin[day], + 'Localisation - day ' + day); + day = (day + 1) % 7; + }); + inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + var date = new Date(); + equals(inp.val(), $.datepicker.regional['fr'].dayNames[date.getDay()] + ', ' + + date.getDate() + ' ' + $.datepicker.regional['fr'].monthNames[date.getMonth()] + + ' ' + date.getFullYear(), 'Localisation - formatting'); +}); + +test('noWeekends', function() { + for (var i = 1; i <= 31; i++) { + var date = new Date(2001, 1 - 1, i); + isSet($.datepicker.noWeekends(date), [(i + 1) % 7 >= 2, ''], + 'No weekends ' + date); + } +}); + +test('iso8601Week', function() { + var date = new Date(2000, 12 - 1, 31); + equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date); + date = new Date(2001, 1 - 1, 1); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2001, 1 - 1, 7); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2001, 1 - 1, 8); + equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date); + date = new Date(2003, 12 - 1, 28); + equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date); + date = new Date(2003, 12 - 1, 29); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2004, 1 - 1, 4); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2004, 1 - 1, 5); + equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date); + date = new Date(2009, 12 - 1, 28); + equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date); + date = new Date(2010, 1 - 1, 3); + equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date); + date = new Date(2010, 1 - 1, 4); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2010, 1 - 1, 10); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); +}); + +test('parseDate', function() { + init('#inp'); + ok($.datepicker.parseDate('d m y', '') == null, 'Parse date empty'); + equalsDate($.datepicker.parseDate('d m y', '3 2 01'), + new Date(2001, 2 - 1, 3), 'Parse date d m y'); + equalsDate($.datepicker.parseDate('dd mm yy', '03 02 2001'), + new Date(2001, 2 - 1, 3), 'Parse date dd mm yy'); + equalsDate($.datepicker.parseDate('d m y', '13 12 01'), + new Date(2001, 12 - 1, 13), 'Parse date d m y'); + equalsDate($.datepicker.parseDate('dd mm yy', '13 12 2001'), + new Date(2001, 12 - 1, 13), 'Parse date dd mm yy'); + equalsDate($.datepicker.parseDate('y-o', '2001-34'), + new Date(2001, 2 - 1, 3), 'Parse date y-o'); + equalsDate($.datepicker.parseDate('yy-oo', '2001-347'), + new Date(2001, 12 - 1, 13), 'Parse date yy oo'); + equalsDate($.datepicker.parseDate('oo yy', '348 2004'), + new Date(2004, 12 - 1, 13), 'Parse date oo-yy'); + equalsDate($.datepicker.parseDate('D d M y', 'Sat 3 Feb 01'), + new Date(2001, 2 - 1, 3), 'Parse date D d M y'); + equalsDate($.datepicker.parseDate('d MM DD yy', '3 February Saturday 2001'), + new Date(2001, 2 - 1, 3), 'Parse date dd MM DD yy'); + equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Saturday, February 3, 2001'), + new Date(2001, 2 - 1, 3), 'Parse date DD, MM d, yy'); + equalsDate($.datepicker.parseDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy', + 'day 3 of February (\'Saturday\'), 2001'), new Date(2001, 2 - 1, 3), + 'Parse date \'day\' d \'of\' MM (\'\'DD\'\'), yy'); + equalsDate($.datepicker.parseDate('y-m-d', '01-02-03'), + new Date(2001, 2 - 1, 3), 'Parse date y-m-d - default cutoff'); + equalsDate($.datepicker.parseDate('y-m-d', '51-02-03'), + new Date(1951, 2 - 1, 3), 'Parse date y-m-d - default cutoff'); + equalsDate($.datepicker.parseDate('y-m-d', '51-02-03', {shortYearCutoff: 80}), + new Date(2051, 2 - 1, 3), 'Parse date y-m-d - cutoff 80'); + equalsDate($.datepicker.parseDate('y-m-d', '51-02-03', {shortYearCutoff: '+60'}), + new Date(2051, 2 - 1, 3), 'Parse date y-m-d - cutoff +60'); + var fr = $.datepicker.regional['fr']; + var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, + monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; + equalsDate($.datepicker.parseDate('D d M y', 'Lun 9 Avr 01', settings), + new Date(2001, 4 - 1, 9), 'Parse date D M y with settings'); + equalsDate($.datepicker.parseDate('d MM DD yy', '9 Avril Lundi 2001', settings), + new Date(2001, 4 - 1, 9), 'Parse date d MM DD yy with settings'); + equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Lundi, Avril 9, 2001', settings), + new Date(2001, 4 - 1, 9), 'Parse date DD, MM d, yy with settings'); + equalsDate($.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy', + 'jour 9 de Avril (\'Lundi\'), 2001', settings), new Date(2001, 4 - 1, 9), + 'Parse date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings'); +}); + +test('parseDateErrors', function() { + init('#inp'); + var expectError = function(expr, value, error) { + try { + expr(); + ok(false, 'Parsed error ' + value); + } + catch (e) { + equals(e, error, 'Parsed error ' + value); + } + }; + expectError(function() { $.datepicker.parseDate(null, 'Sat 2 01'); }, + 'Sat 2 01', 'Invalid arguments'); + expectError(function() { $.datepicker.parseDate('d m y', null); }, + 'null', 'Invalid arguments'); + expectError(function() { $.datepicker.parseDate('d m y', 'Sat 2 01'); }, + 'Sat 2 01 - d m y', 'Missing number at position 0'); + expectError(function() { $.datepicker.parseDate('dd mm yy', 'Sat 2 01'); }, + 'Sat 2 01 - dd mm yy', 'Missing number at position 0'); + expectError(function() { $.datepicker.parseDate('d m y', '3 Feb 01'); }, + '3 Feb 01 - d m y', 'Missing number at position 2'); + expectError(function() { $.datepicker.parseDate('dd mm yy', '3 Feb 01'); }, + '3 Feb 01 - dd mm yy', 'Missing number at position 2'); + expectError(function() { $.datepicker.parseDate('d m y', '3 2 AD01'); }, + '3 2 AD01 - d m y', 'Missing number at position 4'); + expectError(function() { $.datepicker.parseDate('d m yy', '3 2 AD01'); }, + '3 2 AD01 - dd mm yy', 'Missing number at position 4'); + expectError(function() { $.datepicker.parseDate('y-o', '2001-D01'); }, + '2001-D01 - y-o', 'Missing number at position 5'); + expectError(function() { $.datepicker.parseDate('yy-oo', '2001-D01'); }, + '2001-D01 - yy-oo', 'Missing number at position 5'); + expectError(function() { $.datepicker.parseDate('D d M y', 'D7 3 Feb 01'); }, + 'D7 3 Feb 01 - D d M y', 'Unknown name at position 0'); + expectError(function() { $.datepicker.parseDate('D d M y', 'Sat 3 M2 01'); }, + 'Sat 3 M2 01 - D d M y', 'Unknown name at position 6'); + expectError(function() { $.datepicker.parseDate('DD, MM d, yy', 'Saturday- Feb 3, 2001'); }, + 'Saturday- Feb 3, 2001 - DD, MM d, yy', 'Unexpected literal at position 8'); + expectError(function() { $.datepicker.parseDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy', + 'day 3 of February ("Saturday"), 2001'); }, + 'day 3 of Mon2 ("Day7"), 2001', 'Unexpected literal at position 19'); + expectError(function() { $.datepicker.parseDate('d m y', '29 2 01'); }, + '29 2 01 - d m y', 'Invalid date'); + var fr = $.datepicker.regional['fr']; + var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, + monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; + expectError(function() { $.datepicker.parseDate('D d M y', 'Mon 9 Avr 01', settings); }, + 'Mon 9 Avr 01 - D d M y', 'Unknown name at position 0'); + expectError(function() { $.datepicker.parseDate('D d M y', 'Lun 9 Apr 01', settings); }, + 'Lun 9 Apr 01 - D d M y', 'Unknown name at position 6'); +}); + +test('formatDate', function() { + init('#inp'); + equals($.datepicker.formatDate('d m y', new Date(2001, 2 - 1, 3)), + '3 2 01', 'Format date d m y'); + equals($.datepicker.formatDate('dd mm yy', new Date(2001, 2 - 1, 3)), + '03 02 2001', 'Format date dd mm yy'); + equals($.datepicker.formatDate('d m y', new Date(2001, 12 - 1, 13)), + '13 12 01', 'Format date d m y'); + equals($.datepicker.formatDate('dd mm yy', new Date(2001, 12 - 1, 13)), + '13 12 2001', 'Format date dd mm yy'); + equals($.datepicker.formatDate('yy-o', new Date(2001, 2 - 1, 3)), + '2001-34', 'Format date yy-o'); + equals($.datepicker.formatDate('yy-oo', new Date(2001, 2 - 1, 3)), + '2001-034', 'Format date yy-oo'); + equals($.datepicker.formatDate('D M y', new Date(2001, 2 - 1, 3)), + 'Sat Feb 01', 'Format date D M y'); + equals($.datepicker.formatDate('DD MM yy', new Date(2001, 2 - 1, 3)), + 'Saturday February 2001', 'Format date DD MM yy'); + equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 2 - 1, 3)), + 'Saturday, February 3, 2001', 'Format date DD, MM d, yy'); + equals($.datepicker.formatDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy', + new Date(2001, 2 - 1, 3)), 'day 3 of February (\'Saturday\'), 2001', + 'Format date \'day\' d \'of\' MM (\'\'DD\'\'), yy'); + var fr = $.datepicker.regional['fr']; + var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, + monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; + equals($.datepicker.formatDate('D M y', new Date(2001, 4 - 1, 9), settings), + 'Lun Avr 01', 'Format date D M y with settings'); + equals($.datepicker.formatDate('DD MM yy', new Date(2001, 4 - 1, 9), settings), + 'Lundi Avril 2001', 'Format date DD MM yy with settings'); + equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 4 - 1, 9), settings), + 'Lundi, Avril 9, 2001', 'Format date DD, MM d, yy with settings'); + equals($.datepicker.formatDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy', + new Date(2001, 4 - 1, 9), settings), 'jour 9 de Avril (\'Lundi\'), 2001', + 'Format date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings'); +}); + +})(jQuery); diff --git a/tests/unit/dialog/dialog.html b/tests/unit/dialog/dialog.html new file mode 100644 index 000000000..184430ec7 --- /dev/null +++ b/tests/unit/dialog/dialog.html @@ -0,0 +1,26 @@ + + + + jQuery UI Dialog Test Suite + + + + + + + + + + + + + + + + +
            +
            Dialog Content
            +
            + + + diff --git a/tests/unit/dialog/dialog.js b/tests/unit/dialog/dialog.js new file mode 100644 index 000000000..ff537174b --- /dev/null +++ b/tests/unit/dialog/dialog.js @@ -0,0 +1,723 @@ +/* + * dialog unit tests + */ +(function($) { +// +// Dialog Test Helper Functions +// + +var defaults = { + autoOpen: true, + buttons: {}, + closeOnEscape: true, + closeText: 'close', + disabled: false, + dialogClass: undefined, + draggable: true, + height: 'auto', + maxHeight: undefined, + maxWidth: undefined, + minHeight: 150, + minWidth: 150, + modal: false, + overlay: {}, + position: 'center', + resizable: true, + stack: true, + title: '', + width: 300 +}; + +var el, + offsetBefore, offsetAfter, + heightBefore, heightAfter, + widthBefore, widthAfter, + dragged; + +function dlg() { + return el.data("dialog").element.parents(".ui-dialog:first"); +} + +function isOpen(why) { + ok(dlg().is(":visible"), why); +} + +function isNotOpen(why) { + ok(!dlg().is(":visible"), why); +} + +function drag(handle, dx, dy) { + var d = dlg(); + offsetBefore = d.offset(); + heightBefore = d.height(); + widthBefore = d.width(); + //this mouseover is to work around a limitation in resizable + //TODO: fix resizable so handle doesn't require mouseover in order to be used + $(handle, d).simulate("mouseover"); + $(handle, d).simulate("drag", { + dx: dx || 0, + dy: dy || 0 + }); + dragged = { dx: dx, dy: dy }; + offsetAfter = d.offset(); + heightAfter = d.height(); + widthAfter = d.width(); +} + +function moved(dx, dy, msg) { + msg = msg ? msg + "." : ""; + var actual = { left: offsetAfter.left, top: offsetAfter.top }; + var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy }; + same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); +} + +function shouldmove(why) { + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, 50); + moved(50, 50, why); +} + +function shouldnotmove(why) { + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, 50); + moved(0, 0, why); +} + +function resized(dw, dh, msg) { + msg = msg ? msg + "." : ""; + var actual = { width: widthAfter, height: heightAfter }; + var expected = { width: widthBefore + dw, height: heightBefore + dh }; + same(actual, expected, 'resized[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); +} + +function shouldresize(why) { + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + resized(50, 50, why); +} + +function shouldnotresize(why) { + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + resized(0, 0, why); +} + +function broder(el, side){ + return parseInt(el.css('border-' + side + '-width'), 10); +} + +function margin(el, side) { + return parseInt(el.css('margin-' + side), 10); +} + +// Dialog Tests +module("dialog"); + +test("init", function() { + expect(7); + + $("
            ").appendTo('body').dialog().remove(); + ok(true, '.dialog() called on element'); + + $([]).dialog().remove(); + ok(true, '.dialog() called on empty collection'); + + $('
            ').dialog().remove(); + ok(true, '.dialog() called on disconnected DOMElement - never connected'); + + $('
            ').appendTo('body').remove().dialog().remove(); + ok(true, '.dialog() called on disconnected DOMElement - removed'); + + $('
            ').dialog().dialog("foo").remove(); + ok(true, 'arbitrary method called after init'); + + el = $('
            ').dialog(); + var foo = el.data("foo.dialog"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $('
            ').dialog().data("foo.dialog", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(6); + + $("
            ").appendTo('body').dialog().dialog("destroy").remove(); + ok(true, '.dialog("destroy") called on element'); + + $([]).dialog().dialog("destroy").remove(); + ok(true, '.dialog("destroy") called on empty collection'); + + $('
            ').dialog().dialog("destroy").remove(); + ok(true, '.dialog("destroy") called on disconnected DOMElement'); + + $('
            ').dialog().dialog("destroy").dialog("foo").remove(); + ok(true, 'arbitrary method called after destroy'); + + el = $('
            ').dialog(); + var foo = el.dialog("destroy").data("foo.dialog"); + el.remove(); + ok(true, 'arbitrary option getter after destroy'); + + $('
            ').dialog().dialog("destroy").data("foo.dialog", "bar").remove(); + ok(true, 'arbitrary option setter after destroy'); +}); + +/* +//This one takes a while to run + +test("element types", function() { + var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' + + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' + + ',acronym,code,samp,kbd,var,img,object,hr' + + ',input,button,label,select,iframe').split(','); + + $.each(typeNames, function(i) { + var typeName = typeNames[i]; + el = $(document.createElement(typeName)).appendTo('body'); + (typeName == 'table' && el.append("content")); + el.dialog(); + ok(true, '$("<' + typeName + '/>").dialog()'); + el.dialog("destroy"); + el.remove(); + }); +}); + +*/ + +test("defaults", function() { + el = $('
            ').dialog(); + $.each(defaults, function(key, val) { + var actual = el.data(key + ".dialog"), expected = val; + same(actual, expected, key); + }); + el.remove(); +}); + +test("title id", function() { + expect(3); + + var titleId; + + // reset the uuid so we know what values to expect + $.ui.dialog.uuid = 0; + + el = $('
            ').dialog(); + titleId = dlg().find('.ui-dialog-title').attr('id'); + equals(titleId, 'ui-dialog-title-1', 'auto-numbered title id'); + el.remove(); + + el = $('
            ').dialog(); + titleId = dlg().find('.ui-dialog-title').attr('id'); + equals(titleId, 'ui-dialog-title-2', 'auto-numbered title id'); + el.remove(); + + el = $('
            ').dialog(); + titleId = dlg().find('.ui-dialog-title').attr('id'); + equals(titleId, 'ui-dialog-title-foo', 'carried over title id'); + el.remove(); +}); + +test("ARIA", function() { + expect(4); + + el = $('
            ').dialog(); + + equals(dlg().attr('role'), 'dialog', 'dialog role'); + + var labelledBy = dlg().attr('aria-labelledby'); + ok(labelledBy.length > 0, 'has aria-labelledby attribute'); + equals(dlg().find('.ui-dialog-title').attr('id'), labelledBy, + 'proper aria-labelledby attribute'); + + equals(dlg().find('.ui-dialog-titlebar-close').attr('role'), 'button', + 'close link role'); + + el.remove(); +}); + +module("dialog: Options"); + +test("autoOpen", function() { + expect(2); + + el = $('
            ').dialog({ autoOpen: false }); + isNotOpen('.dialog({ autoOpen: false })'); + el.remove(); + + el = $('
            ').dialog({ autoOpen: true }); + isOpen('.dialog({ autoOpen: true })'); + el.remove(); +}); + +test("buttons", function() { + expect(17); + + var buttons = { + "Ok": function(ev, ui) { + ok(true, "button click fires callback"); + equals(this, el[0], "context of callback"); + equals(ev.target, btn[0], "event target"); + }, + "Cancel": function(ev, ui) { + ok(true, "button click fires callback"); + equals(this, el[0], "context of callback"); + equals(ev.target, btn[1], "event target"); + } + }; + + el = $('
            ').dialog({ buttons: buttons }); + var btn = $("button", dlg()); + equals(btn.length, 2, "number of buttons"); + + var i = 0; + $.each(buttons, function(key, val) { + equals(btn.eq(i).text(), key, "text of button " + (i+1)); + i++; + }); + + ok(btn.parent().hasClass('ui-dialog-buttonpane'), "buttons in container"); + btn.trigger("click"); + + var newButtons = { + "Close": function(ev, ui) { + ok(true, "button click fires callback"); + equals(this, el[0], "context of callback"); + equals(ev.target, btn[0], "event target"); + } + }; + + equals(el.data("buttons.dialog"), buttons, '.data("buttons.dialog") getter'); + el.data("buttons.dialog", newButtons); + equals(el.data("buttons.dialog"), newButtons, '.data("buttons.dialog", ...) setter'); + + btn = $("button", dlg()); + equals(btn.length, 1, "number of buttons after setter"); + btn.trigger('click'); + + i = 0; + $.each(newButtons, function(key, val) { + equals(btn.eq(i).text(), key, "text of button " + (i+1)); + i += 1; + }); + + el.remove(); +}); + +test("closeOnEscape", function() { + ok(false, 'missing test'); +}); + +test("closeText", function() { + expect(3); + + el = $('
            ').dialog(); + equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'close', + 'default close text'); + el.remove(); + + el = $('
            ').dialog({ closeText: "foo" }); + equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'foo', + 'closeText on init'); + el.remove(); + + el = $('
            ').dialog().dialog('option', 'closeText', 'bar'); + equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'bar', + 'closeText via option method'); + el.remove(); +}); + +test("dialogClass", function() { + expect(4); + + el = $('
            ').dialog(); + equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added'); + el.remove(); + + el = $('
            ').dialog({ dialogClass: "foo" }); + equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added'); + el.remove(); + + el = $('
            ').dialog({ dialogClass: "foo bar" }); + equals(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added'); + equals(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added'); + el.remove(); +}); + +test("draggable", function() { + expect(4); + + el = $('
            ').dialog({ draggable: false }); + shouldnotmove(); + el.data('draggable.dialog', true); + shouldmove(); + el.remove(); + + el = $('
            ').dialog({ draggable: true }); + shouldmove(); + el.data('draggable.dialog', false); + shouldnotmove(); + el.remove(); +}); + +test("height", function() { + expect(3); + + el = $('
            ').dialog(); + equals(dlg().height(), defaults.minHeight, "default height"); + el.remove(); + + el = $('
            ').dialog({ height: 437 }); + equals(dlg().height(), 437, "explicit height"); + el.remove(); + + el = $('
            ').dialog(); + el.data('height.dialog', 438); + equals(dlg().height(), 438, "explicit height set after init"); + el.remove(); +}); + +test("maxHeight", function() { + expect(3); + + el = $('
            ').dialog({ maxHeight: 400 }); + drag('.ui-resizable-s', 1000, 1000); + equals(heightAfter, 400, "maxHeight"); + el.remove(); + + el = $('
            ').dialog({ maxHeight: 400 }); + drag('.ui-resizable-n', -1000, -1000); + equals(heightAfter, 400, "maxHeight"); + el.remove(); + + el = $('
            ').dialog({ maxHeight: 400 }).data('maxHeight.dialog', 600); + drag('.ui-resizable-n', -1000, -1000); + equals(heightAfter, 600, "maxHeight"); + el.remove(); +}); + +test("maxWidth", function() { + expect(3); + + el = $('
            ').dialog({ maxWidth: 400 }); + drag('.ui-resizable-e', 1000, 1000); + equals(widthAfter, 400, "maxWidth"); + el.remove(); + + el = $('
            ').dialog({ maxWidth: 400 }); + drag('.ui-resizable-w', -1000, -1000); + equals(widthAfter, 400, "maxWidth"); + el.remove(); + + el = $('
            ').dialog({ maxWidth: 400 }).data('maxWidth.dialog', 600); + drag('.ui-resizable-w', -1000, -1000); + equals(widthAfter, 600, "maxWidth"); + el.remove(); +}); + +test("minHeight", function() { + expect(3); + + el = $('
            ').dialog({ minHeight: 10 }); + drag('.ui-resizable-s', -1000, -1000); + equals(heightAfter, 10, "minHeight"); + el.remove(); + + el = $('
            ').dialog({ minHeight: 10 }); + drag('.ui-resizable-n', 1000, 1000); + equals(heightAfter, 10, "minHeight"); + el.remove(); + + el = $('
            ').dialog({ minHeight: 10 }).data('minHeight.dialog', 30); + drag('.ui-resizable-n', 1000, 1000); + equals(heightAfter, 30, "minHeight"); + el.remove(); +}); + +test("minWidth", function() { + expect(3); + + el = $('
            ').dialog({ minWidth: 10 }); + drag('.ui-resizable-e', -1000, -1000); + equals(widthAfter, 10, "minWidth"); + el.remove(); + + el = $('
            ').dialog({ minWidth: 10 }); + drag('.ui-resizable-w', 1000, 1000); + equals(widthAfter, 10, "minWidth"); + el.remove(); + + el = $('
            ').dialog({ minWidth: 30 }).data('minWidth.dialog', 30); + drag('.ui-resizable-w', 1000, 1000); + equals(widthAfter, 30, "minWidth"); + el.remove(); +}); + +test("modal", function() { + ok(false, "missing test"); +}); + +test("overlay", function() { + ok(false, "missing test"); +}); + +test("position", function() { + ok(false, "missing test"); +}); + +test("resizable", function() { + expect(4); + + el = $('
            ').dialog(); + shouldresize("[default]"); + el.data('resizable.dialog', false); + shouldnotresize('disabled after init'); + el.remove(); + + el = $('
            ').dialog({ resizable: false }); + shouldnotresize("disabled in init options"); + el.data('resizable.dialog', true); + shouldresize('enabled after init'); + el.remove(); +}); + +test("stack", function() { + ok(false, "missing test"); +}); + +test("title", function() { + expect(5); + + function titleText() { + return dlg().find(".ui-dialog-title").html(); + } + + el = $('
            ').dialog(); + equals(titleText(), " ", "[default]"); + el.remove(); + + el = $('
            ').dialog(); + equals(titleText(), "foo", "title in element attribute"); + el.remove(); + + el = $('
            ').dialog({ title: 'foo' }); + equals(titleText(), "foo", "title in init options"); + el.remove(); + + el = $('
            ').dialog({ title: 'bar' }); + equals(titleText(), "bar", "title in init options should override title in element attribute"); + el.remove(); + + el = $('
            ').dialog().data('title.dialog', 'foo'); + equals(titleText(), 'foo', 'title after init'); + el.remove(); +}); + +test("width", function() { + expect(3); + + el = $('
            ').dialog(); + equals(dlg().width(), defaults.width, "default width"); + el.remove(); + + el = $('
            ').dialog({width: 437 }); + equals(dlg().width(), 437, "explicit width"); + el.data('width.dialog', 438); + equals(dlg().width(), 438, 'explicit width after init'); + el.remove(); +}); + +module("dialog: Methods"); + +test("isOpen", function() { + expect(4); + + el = $('
            ').dialog(); + equals(el.dialog('isOpen'), true, "dialog is open after init"); + el.dialog('close'); + equals(el.dialog('isOpen'), false, "dialog is closed"); + el.remove(); + + el = $('
            ').dialog({autoOpen: false}); + equals(el.dialog('isOpen'), false, "dialog is closed after init"); + el.dialog('open'); + equals(el.dialog('isOpen'), true, "dialog is open"); + el.remove(); +}); + +module("dialog: Callbacks"); + +test("open", function() { + expect(6); + + el = $("
            "); + el.dialog({ + open: function(ev, ui) { + ok(true, 'autoOpen: true fires open callback'); + equals(this, el[0], "context of callback"); + } + }); + el.remove(); + + el = $("
            "); + el.dialog({ + autoOpen: false, + open: function(ev, ui) { + ok(true, '.dialog("open") fires open callback'); + equals(this, el[0], "context of callback"); + } + }); + el.dialog("open"); + el.remove(); + + el = $('
            ').dialog({ + autoOpen: false + }); + el.bind('dialogopen', function(ev, ui) { + ok(true, 'dialog("open") fires open event'); + equals(this, el[0], 'context of event'); + }); + el.dialog('open'); + el.remove(); +}); + +test("dragStart", function() { + expect(2); + + el = $("
            "); + el.dialog({ + dragStart: function(ev, ui) { + ok(true, 'dragging fires dragStart callback'); + equals(this, el[0], "context of callback"); + } + }); + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("drag", function() { + var fired = false; + + el = $("
            "); + el.dialog({ + drag: function(ev, ui) { + fired = true; + equals(this, el[0], "context of callback"); + } + }); + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, 50); + ok(fired, "drag fired"); + el.remove(); +}); + +test("dragStop", function() { + expect(2); + + el = $("
            "); + el.dialog({ + dragStop: function(ev, ui) { + ok(true, 'dragging fires dragStop callback'); + equals(this, el[0], "context of callback"); + } + }); + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("resizeStart", function() { + expect(2); + + el = $("
            "); + el.dialog({ + resizeStart: function(ev, ui) { + ok(true, 'resizing fires resizeStart callback'); + equals(this, el[0], "context of callback"); + } + }); + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("resize", function() { + var fired = false; + + el = $("
            "); + el.dialog({ + resize: function(ev, ui) { + fired = true; + equals(this, el[0], "context of callback"); + } + }); + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + ok(fired, "resize fired"); + el.remove(); +}); + +test("resizeStop", function() { + expect(2); + + el = $("
            "); + el.dialog({ + resizeStop: function(ev, ui) { + ok(true, 'resizing fires resizeStop callback'); + equals(this, el[0], "context of callback"); + } + }); + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("close", function() { + expect(4); + + el = $('
            ').dialog({ + close: function(ev, ui) { + ok(true, '.dialog("close") fires close callback'); + equals(this, el[0], "context of callback"); + } + }); + el.dialog("close"); + el.remove(); + + el = $('
            ').dialog().bind('dialogclose', function(ev, ui) { + ok(true, '.dialog("close") fires dialogclose event'); + equals(this, el[0], 'context of event'); + }); + el.dialog('close'); + el.remove(); +}); + +test("beforeclose", function() { + expect(6); + + el = $('
            ').dialog({ + beforeclose: function(ev, ui) { + ok(true, '.dialog("close") fires beforeclose callback'); + equals(this, el[0], "context of callback"); + return false; + } + }); + el.dialog('close'); + isOpen('beforeclose callback should prevent dialog from closing'); + el.remove(); + + el = $('
            ').dialog().bind('dialogbeforeclose', function(ev, ui) { + ok(true, '.dialog("close") triggers dialogbeforeclose event'); + equals(this, el[0], "context of event"); + return false; + }); + el.dialog('close'); + isOpen('dialogbeforeclose event should prevent dialog from closing'); + el.remove(); +}); + +module("dialog: Tickets"); + +})(jQuery); diff --git a/tests/unit/draggable/draggable.html b/tests/unit/draggable/draggable.html new file mode 100644 index 000000000..2d129c9d6 --- /dev/null +++ b/tests/unit/draggable/draggable.html @@ -0,0 +1,28 @@ + + + + jQuery UI Draggable Test Suite + + + + + + + + + + + + + + +
            +
            Relative
            +
            Absolute
            +
            +
            + +
            + + + diff --git a/tests/unit/draggable/draggable.js b/tests/unit/draggable/draggable.js new file mode 100644 index 000000000..d5ef7fda9 --- /dev/null +++ b/tests/unit/draggable/draggable.js @@ -0,0 +1,787 @@ +/* + * draggable unit tests + */ +(function($) { +// +// Draggable Test Helper Functions +// + +var defaults = { + appendTo: "parent", + axis: false, + cancel: ":input", + connectToSortable: false, + containment: false, + cursor: "default", + cursorAt: null, + delay: 0, + disabled: false, + distance: 1, + grid: false, + handle: false, + helper: "original", + iframeFix: false, + opacity: 1.0, + refreshPositions: false, + revert: false, + revertDuration: 500, + scroll: true, + scrollSensitivity: 20, + scrollSpeed: 20, + scope: "default", + snap: false, + snapMode: "both", + snapTolerance: 20, + stack: false, + zIndex: null +}; + +var el, offsetBefore, offsetAfter, dragged; + +var drag = function(handle, dx, dy) { + var element = el.data("draggable").element; + offsetBefore = el.offset(); + $(handle).simulate("drag", { + dx: dx || 0, + dy: dy || 0 + }); + dragged = { dx: dx, dy: dy }; + offsetAfter = el.offset(); +} + +var moved = function (dx, dy, msg) { + msg = msg ? msg + "." : ""; + var actual = { left: offsetAfter.left, top: offsetAfter.top }; + var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy }; + same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); +} + +function shouldmove(why) { + drag(el, 50, 50); + moved(50, 50, why); +} + +function shouldnotmove(why) { + drag(el, 50, 50); + moved(0, 0, why); +} + +var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } + +var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } + +// Draggable Tests +module("draggable"); + +test("init", function() { + expect(6); + + $("
            ").appendTo('body').draggable().remove(); + ok(true, '.draggable() called on element'); + + $([]).draggable(); + ok(true, '.draggable() called on empty collection'); + + $("
            ").draggable(); + ok(true, '.draggable() called on disconnected DOMElement'); + + $("
            ").draggable().draggable("foo"); + ok(true, 'arbitrary method called after init'); + + $("
            ").draggable().data("foo.draggable"); + ok(true, 'arbitrary option getter after init'); + + $("
            ").draggable().data("foo.draggable", "bar"); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(6); + + $("
            ").appendTo('body').draggable().draggable("destroy").remove(); + ok(true, '.draggable("destroy") called on element'); + + $([]).draggable().draggable("destroy"); + ok(true, '.draggable("destroy") called on empty collection'); + + $("
            ").draggable().draggable("destroy"); + ok(true, '.draggable("destroy") called on disconnected DOMElement'); + + $("
            ").draggable().draggable("destroy").draggable("foo"); + ok(true, 'arbitrary method called after destroy'); + + $("
            ").draggable().draggable("destroy").data("foo.draggable"); + ok(true, 'arbitrary option getter after destroy'); + + $("
            ").draggable().draggable("destroy").data("foo.draggable", "bar"); + ok(true, 'arbitrary option setter after destroy'); +}); + +test("enable", function() { + expect(6); + el = $("#draggable2").draggable({ disabled: true }); + shouldnotmove('.draggable({ disabled: true })'); + el.draggable("enable"); + shouldmove('.draggable("enable")'); + equals(el.data("disabled.draggable"), false, "disabled.draggable getter"); + + el.draggable("destroy"); + el.draggable({ disabled: true }); + shouldnotmove('.draggable({ disabled: true })'); + el.data("disabled.draggable", false); + equals(el.data("disabled.draggable"), false, "disabled.draggable setter"); + shouldmove('.data("disabled.draggable", false)'); +}); + +test("disable", function() { + expect(6); + el = $("#draggable2").draggable({ disabled: false }); + shouldmove('.draggable({ disabled: false })'); + el.draggable("disable"); + shouldnotmove('.draggable("disable")'); + equals(el.data("disabled.draggable"), true, "disabled.draggable getter"); + + el.draggable("destroy"); + + el.draggable({ disabled: false }); + shouldmove('.draggable({ disabled: false })'); + el.data("disabled.draggable", true); + equals(el.data("disabled.draggable"), true, "disabled.draggable setter"); + shouldnotmove('.data("disabled.draggable", true)'); +}); + +test("element types", function() { + var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' + + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' + + ',acronym,code,samp,kbd,var,img,object,hr' + + ',input,button,label,select,iframe').split(','); + + $.each(typeNames, function(i) { + var typeName = typeNames[i]; + el = $(document.createElement(typeName)).appendTo('body'); + (typeName == 'table' && el.append("content")); + el.draggable({ cancel: '' }); + drag(el, 50, 50); + moved(50, 50, "<" + typeName + ">"); + el.draggable("destroy"); + el.remove(); + }); +}); + +test("defaults", function() { + el = $('
            ').draggable(); + $.each(defaults, function(key, val) { + var actual = el.data(key + ".draggable"), expected = val; + same(actual, expected, key); + }); + el.remove(); +}); + +test("No options, relative", function() { + el = $("#draggable1").draggable(); + drag(el, 50, 50); + moved(50, 50); +}); + +test("No options, absolute", function() { + el = $("#draggable2").draggable(); + drag(el, 50, 50); + moved(50, 50); +}); + +module("draggable: Options"); + +test("{ axis: false }, default", function() { + el = $("#draggable2").draggable({ axis: false }); + drag(el, 50, 50); + moved(50, 50); +}); + +test("{ axis: 'x' }", function() { + el = $("#draggable2").draggable({ axis: "x" }); + drag(el, 50, 50); + moved(50, 0); +}); + +test("{ axis: 'y' }", function() { + el = $("#draggable2").draggable({ axis: "y" }); + drag(el, 50, 50); + moved(0, 50); +}); + +test("{ axis: ? }, unexpected", function() { + var unexpected = { + "true": true, + "{}": {}, + "[]": [], + "null": null, + "undefined": undefined, + "function() {}": function() {} + }; + $.each(unexpected, function(key, val) { + el = $("#draggable2").draggable({ axis: val }); + drag(el, 50, 50); + moved(50, 50, "axis: " + key); + el.draggable("destroy"); + }) +}); + +test("{ cancel: 'span' }", function() { + el = $("#draggable2").draggable(); + drag("#draggable2 span", 50, 50); + moved(50, 50); + + el.draggable("destroy"); + + el = $("#draggable2").draggable({ cancel: 'span' }); + drag("#draggable2 span", 50, 50); + moved(0, 0); +}); + +test("{ cancel: ? }, unexpected", function() { + var unexpected = { + "true": true, + "false": false, + "{}": {}, + "[]": [], + "null": null, + "undefined": undefined, + "function() {return '';}": function() {return '';}, + "function() {return true;}": function() {return true;}, + "function() {return false;}": function() {return false;} + }; + $.each(unexpected, function(key, val) { + el = $("#draggable2").draggable({ cancel: val }); + drag(el, 50, 50); + var expected = [50, 50]; + moved(expected[0], expected[1], "cancel: " + key); + el.draggable("destroy"); + }) +}); + +test("{ containment: 'parent' }, relative", function() { + el = $("#draggable1").draggable({ containment: 'parent' }); + var p = el.parent(), po = p.offset(); + drag(el, -100, -100); + var expected = { + left: po.left + border(p, 'left') + margin(el, 'left'), + top: po.top + border(p, 'top') + margin(el, 'top') + } + same(offsetAfter, expected, 'compare offset to parent'); +}); + +test("{ containment: 'parent' }, absolute", function() { + el = $("#draggable2").draggable({ containment: 'parent' }); + var p = el.parent(), po = p.offset(); + drag(el, -100, -100); + var expected = { + left: po.left + border(p, 'left') + margin(el, 'left'), + top: po.top + border(p, 'top') + margin(el, 'top') + } + same(offsetAfter, expected, 'compare offset to parent'); +}); + +test("{ cursor: 'move' }", function() { + + function getCursor() { return $("body").css("cursor"); } + + expect(2); + + var expected = "move", actual, before, after; + + el = $("#draggable2").draggable({ + cursor: expected, + start: function(event, ui) { + actual = getCursor(); + } + }); + + before = getCursor(); + drag("#draggable2", -1, -1); + after = getCursor(); + + equals(actual, expected, "start callback: cursor '" + expected + "'"); + equals(after, before, "after drag: cursor restored"); + +}); + +test("{ cursorAt: { left: -5, top: -5 } }", function() { + + expect(4); + + var dx = -3, dy = -3; + var ox = 5, oy = 5; + var cax = -5, cay = -5; + + var actual = null; + $("#draggable2").draggable({ + cursorAt: { left: cax, top: cay }, + drag: function(event, ui) { + actual = ui.absolutePosition; + } + }); + var el = $("#draggable2").data("draggable").element; + + var before = el.offset(); + var pos = { clientX: before.left + ox, clientY: before.top + oy }; + $("#draggable2").simulate("mousedown", pos); + pos = { clientX: pos.clientX + dx, clientY: pos.clientY + dy }; + $(document).simulate("mousemove", pos); + $(document).simulate("mousemove", pos); + $("#draggable2").simulate("mouseup", pos); + var expected = { + left: before.left + ox - cax + dx, + top: before.top + oy - cay + dy + }; + + equals(actual.left, expected.left, "Absolute: -1px left"); + equals(actual.top, expected.top, "Absolute: -1px top"); + + var actual = null; + $("#draggable1").draggable({ + cursorAt: { left: cax, top: cay }, + drag: function(event, ui) { + actual = ui.absolutePosition; + } + }); + var el = $("#draggable2").data("draggable").element; + + var before = el.offset(); + var pos = { clientX: before.left + ox, clientY: before.top + oy }; + $("#draggable2").simulate("mousedown", pos); + pos = { clientX: pos.clientX + dx, clientY: pos.clientY + dy }; + $(document).simulate("mousemove", pos); + $(document).simulate("mousemove", pos); + $("#draggable2").simulate("mouseup", pos); + var expected = { + left: before.left + ox - cax + dx, + top: before.top + oy - cay + dy + }; + + equals(actual.left, expected.left, "Relative: -1px left"); + equals(actual.top, expected.top, "Relative: -1px top"); + +}); + +test("{ distance: 10 }", function() { + + el = $("#draggable2").draggable({ distance: 10 }); + drag(el, -9, -9); + moved(0, 0, 'distance not met'); + + drag(el, -10, -10); + moved(-10, -10, 'distance met'); + + drag(el, 9, 9); + moved(0, 0, 'distance not met'); + +}); + +test("{ grid: [50, 50] }, relative", function() { + el = $("#draggable1").draggable({ grid: [50, 50] }); + drag(el, 24, 24); + moved(0, 0); + drag(el, 26, 25); + moved(50, 50); +}); + +test("{ grid: [50, 50] }, absolute", function() { + el = $("#draggable2").draggable({ grid: [50, 50] }); + drag(el, 24, 24); + moved(0, 0); + drag(el, 26, 25); + moved(50, 50); +}); + +test("{ handle: 'span' }", function() { + el = $("#draggable2").draggable({ handle: 'span' }); + + drag("#draggable2 span", 50, 50); + moved(50, 50, "drag span"); + + drag("#draggable2", 50, 50); + moved(0, 0, "drag element"); +}); + +test("{ helper: 'clone' }, relative", function() { + el = $("#draggable1").draggable({ helper: "clone" }); + drag(el, 50, 50); + moved(0, 0); +}); + +test("{ helper: 'clone' }, absolute", function() { + el = $("#draggable2").draggable({ helper: "clone" }); + drag(el, 50, 50); + moved(0, 0); +}); + +test("{ opacity: 0.5 }", function() { + + expect(1); + + var opacity = null; + el = $("#draggable2").draggable({ + opacity: 0.5, + start: function(event, ui) { + opacity = $(this).css("opacity"); + } + }); + + drag("#draggable2", -1, -1); + + equals(opacity, 0.5, "start callback: opacity is"); + +}); + +test("{ zIndex: 10 }", function() { + + expect(1); + + var expected = 10, actual; + + var zIndex = null; + el = $("#draggable2").draggable({ + zIndex: expected, + start: function(event, ui) { + actual = $(this).css("zIndex"); + } + }); + + drag("#draggable2", -1, -1); + + equals(actual, expected, "start callback: zIndex is"); + +}); + +module("draggable: Callbacks"); + +test("callbacks occurance count", function() { + + expect(3); + + var start = 0, stop = 0, dragc = 0; + el = $("#draggable2").draggable({ + start: function() { start++; }, + drag: function() { dragc++; }, + stop: function() { stop++; } + }); + + drag(el, 10, 10); + + equals(start, 1, "start callback should happen exactly once"); + equals(dragc, 3, "drag callback should happen exactly once per mousemove"); + equals(stop, 1, "stop callback should happen exactly once"); + +}); + +module("draggable: Scroll offsets"); + + +function testScroll(position) { + $("#main").css('position', position); + drag(el, 50, 50); + moved(50, 50, position+' parent'); + +} + +function setScroll(what) { + if(what) { + $(document).scrollTop(100); $(document).scrollLeft(100); + } else { + $("#main")[0].scrollTop = 100; $("#main")[0].scrollLeft = 100; + } +} + +function restoreScroll(what) { + if(what) { + $(document).scrollTop(0); $(document).scrollLeft(0); + } else { + $("#main")[0].scrollTop = 0; $("#main")[0].scrollLeft = 0; + } +} + +test("{ helper: 'original' }, relative, with scroll offset on parent", function() { + + el = $("#draggable1").draggable({ helper: "original" }); + + setScroll(); + testScroll('relative'); + + setScroll(); + testScroll('static'); + + setScroll(); + testScroll('absolute'); + + restoreScroll(); + +}); + +test("{ helper: 'original' }, relative, with scroll offset on root", function() { + + el = $("#draggable1").draggable({ helper: "original" }); + + setScroll('root'); + testScroll('relative'); + + setScroll('root'); + testScroll('static'); + + setScroll('root'); + testScroll('absolute'); + + restoreScroll('root'); + +}); + +test("{ helper: 'original' }, relative, with scroll offset on root and parent", function() { + + el = $("#draggable1").draggable({ helper: "original" }); + + setScroll(); + setScroll('root'); + testScroll('relative'); + + setScroll(); + setScroll('root'); + testScroll('static'); + + setScroll(); + setScroll('root'); + testScroll('absolute'); + + restoreScroll(); + restoreScroll('root'); + +}); + +test("{ helper: 'original' }, absolute, with scroll offset on parent", function() { + + el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll(); + testScroll('relative'); + + setScroll(); + testScroll('static'); + + setScroll(); + testScroll('absolute'); + + restoreScroll(); + +}); + +test("{ helper: 'original' }, absolute, with scroll offset on root", function() { + + el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll('root'); + testScroll('relative'); + + setScroll('root'); + testScroll('static'); + + setScroll('root'); + testScroll('absolute'); + + restoreScroll('root'); + +}); + +test("{ helper: 'original' }, absolute, with scroll offset on root and parent", function() { + + el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll(); + setScroll('root'); + testScroll('relative'); + + setScroll(); + setScroll('root'); + testScroll('static'); + + setScroll(); + setScroll('root'); + testScroll('absolute'); + + restoreScroll(); + restoreScroll('root'); + +}); + +//Fixed not for IE < 7 +if(!($.browser.msie && $.browser.version < 7)) { + + test("{ helper: 'original' }, fixed, with scroll offset on parent", function() { + + el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll(); + testScroll('relative'); + + setScroll(); + testScroll('static'); + + setScroll(); + testScroll('absolute'); + + restoreScroll(); + + }); + + test("{ helper: 'original' }, fixed, with scroll offset on root", function() { + + el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll('root'); + testScroll('relative'); + + setScroll('root'); + testScroll('static'); + + setScroll('root'); + testScroll('absolute'); + + restoreScroll('root'); + + }); + + test("{ helper: 'original' }, fixed, with scroll offset on root and parent", function() { + + el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll(); + setScroll('root'); + testScroll('relative'); + + setScroll(); + setScroll('root'); + testScroll('static'); + + setScroll(); + setScroll('root'); + testScroll('absolute'); + + restoreScroll(); + restoreScroll('root'); + + }); + +} + + + +test("{ helper: 'clone' }, absolute", function() { + + var helperOffset = null; + var origOffset = $("#draggable1").offset(); + + el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { + helperOffset = ui.helper.offset(); + } }); + + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + +}); + +test("{ helper: 'clone' }, absolute with scroll offset on parent", function() { + + setScroll(); + var helperOffset = null; + var origOffset = null; + + el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { + helperOffset = ui.helper.offset(); + } }); + + $("#main").css('position', 'relative'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'static'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'absolute'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + restoreScroll(); + +}); + +test("{ helper: 'clone' }, absolute with scroll offset on root", function() { + + setScroll('root'); + var helperOffset = null; + var origOffset = null; + + el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { + helperOffset = ui.helper.offset(); + } }); + + $("#main").css('position', 'relative'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'static'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'absolute'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + restoreScroll('root'); + +}); + +test("{ helper: 'clone' }, absolute with scroll offset on root and parent", function() { + + setScroll('root'); + setScroll(); + var helperOffset = null; + var origOffset = null; + + el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { + helperOffset = ui.helper.offset(); + } }); + + $("#main").css('position', 'relative'); + origOffset = $("#draggable1").offset() + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'static'); + origOffset = $("#draggable1").offset() + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'absolute'); + origOffset = $("#draggable1").offset() + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + restoreScroll('root'); + restoreScroll(); + +}); + +module("draggable: behaviour"); + +test("Events should not be executed on the element if drag is initiated", function() { + //TODO: Implement missing test +}); + + +module("draggable: Tickets"); + +})(jQuery); diff --git a/tests/unit/droppable/droppable.html b/tests/unit/droppable/droppable.html new file mode 100644 index 000000000..3881adf1d --- /dev/null +++ b/tests/unit/droppable/droppable.html @@ -0,0 +1,27 @@ + + + + jQuery UI Droppable Test Suite + + + + + + + + + + + + + + + +
            +
            Draggable
            +
            Droppable
            +
             
            +
            + + + diff --git a/tests/unit/droppable/droppable.js b/tests/unit/droppable/droppable.js new file mode 100644 index 000000000..31915defc --- /dev/null +++ b/tests/unit/droppable/droppable.js @@ -0,0 +1,223 @@ +/* + * droppable unit tests + */ +(function($) { +// +// Droppable Test Helper Functions +// + +var defaults = { + accept: '*', + activeClass: null, + cssNamespace: "ui", + disabled: false, + greedy: false, + hoverClass: null, + scope: "default", + tolerance: "intersect" +}; + +var el, drg; + +function shouldBeDroppable() { + ok(false, "missing test - should be droppable"); +} + +function shouldNotBeDroppable() { + ok(false, "missing test - should not be droppable"); +} + +// Droppable Tests +module("droppable"); + +test("init", function() { + expect(6); + + $("
            ").appendTo('body').droppable().remove(); + ok(true, '.droppable() called on element'); + + $([]).droppable(); + ok(true, '.droppable() called on empty collection'); + + $("
            ").droppable(); + ok(true, '.droppable() called on disconnected DOMElement'); + + $("
            ").droppable().droppable("foo"); + ok(true, 'arbitrary method called after init'); + + $("
            ").droppable().data("foo.droppable"); + ok(true, 'arbitrary option getter after init'); + + $("
            ").droppable().data("foo.droppable", "bar"); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(6); + + $("
            ").appendTo('body').droppable().droppable("destroy").remove(); + ok(true, '.droppable("destroy") called on element'); + + $([]).droppable().droppable("destroy"); + ok(true, '.droppable("destroy") called on empty collection'); + + $("
            ").droppable().droppable("destroy"); + ok(true, '.droppable("destroy") called on disconnected DOMElement'); + + $("
            ").droppable().droppable("destroy").droppable("foo"); + ok(true, 'arbitrary method called after destroy'); + + $("
            ").droppable().droppable("destroy").data("foo.droppable"); + ok(true, 'arbitrary option getter after destroy'); + + $("
            ").droppable().droppable("destroy").data("foo.droppable", "bar"); + ok(true, 'arbitrary option setter after destroy'); +}); + +test("enable", function() { + expect(6); + el = $("#droppable1").droppable({ disabled: true }); + shouldNotBeDroppable(); + el.droppable("enable"); + shouldBeDroppable(); + equals(el.data("disabled.droppable"), false, "disabled.droppable getter"); + el.droppable("destroy"); + el.droppable({ disabled: true }); + shouldNotBeDroppable(); + el.data("disabled.droppable", false); + equals(el.data("disabled.droppable"), false, "disabled.droppable setter"); + shouldBeDroppable(); +}); + +test("disable", function() { + expect(6); + el = $("#droppable1").droppable({ disabled: false }); + shouldBeDroppable(); + el.droppable("disable"); + shouldNotBeDroppable(); + equals(el.data("disabled.droppable"), true, "disabled.droppable getter"); + el.droppable("destroy"); + el.droppable({ disabled: false }); + shouldBeDroppable(); + el.data("disabled.droppable", true); + equals(el.data("disabled.droppable"), true, "disabled.droppable setter"); + shouldNotBeDroppable(); +}); + +test("element types", function() { + var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' + + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' + + ',acronym,code,samp,kbd,var,img,object,hr' + + ',input,button,label,select,iframe').split(','); + + $.each(typeNames, function(i) { + var typeName = typeNames[i]; + el = $(document.createElement(typeName)).appendTo('body'); + (typeName == 'table' && el.append("content")); + el.droppable(); + shouldBeDroppable(); + el.droppable("destroy"); + el.remove(); + }); +}); + +test("defaults", function() { + el = $("
            ").droppable(); + $.each(defaults, function(key, val) { + var actual = el.data(key + ".droppable"), expected = val; + same(actual, expected, key); + }); + el.remove(); +}); + +test("option setting", function() { + // The plugin shouldn't modify an option value set by the user + $.each(defaults, function(key, val) { + el = $("
            ").droppable(); + el.data(key + ".droppable", val); + var actual = el.data(key + ".droppable"), expected = val; + same(actual, expected, key); + el.remove(); + }); +}); + +module("droppable: Options"); + +test("accept, selector", function() { + ok(false, "missing test"); +}); + +test("accept, fn", function() { + ok(false, "missing test"); +}); + +test("activeClass", function() { + ok(false, "missing test"); +}); + +test("cssNamespace", function() { + //cssNamespace should be appended with '-droppable' and added as className + el = $("
            ").droppable({ cssNamespace: "ui" }); + equals(el[0].className, "ui-droppable"); + el.droppable("destroy"); + + //no className should be added if cssNamepsace is null + el = $("
            ").droppable({ cssNamespace: null }); + equals(el[0].className, ""); + el.droppable("destroy"); +}); + +test("greedy", function() { + ok(false, "missing test"); +}); + +test("hoverClass", function() { + ok(false, "missing test"); +}); + +test("scope", function() { + ok(false, "missing test"); +}); + +test("tolerance, fit", function() { + ok(false, "missing test"); +}); + +test("tolerance, intersect", function() { + ok(false, "missing test"); +}); + +test("tolerance, pointer", function() { + ok(false, "missing test"); +}); + +test("tolerance, touch", function() { + ok(false, "missing test"); +}); + +module("droppable: Callbacks"); + +test("activate", function() { + ok(false, "missing test"); +}); + +test("deactivate", function() { + ok(false, "missing test"); +}); + +test("over", function() { + ok(false, "missing test"); +}); + +test("out", function() { + ok(false, "missing test"); +}); + +test("drop", function() { + ok(false, "missing test"); +}); + +module("droppable: Tickets"); + + +})(jQuery); diff --git a/tests/unit/progressbar/progressbar.html b/tests/unit/progressbar/progressbar.html new file mode 100644 index 000000000..c6d9becfb --- /dev/null +++ b/tests/unit/progressbar/progressbar.html @@ -0,0 +1,24 @@ + + + + jQuery UI Progressbar Test Suite + + + + + + + + + + + + + + +
            +
            +
            + + + diff --git a/tests/unit/progressbar/progressbar.js b/tests/unit/progressbar/progressbar.js new file mode 100644 index 000000000..087106510 --- /dev/null +++ b/tests/unit/progressbar/progressbar.js @@ -0,0 +1,68 @@ +/* + * progressbar unit tests + */ +(function($) { +// +// Progressbar Test Helper Functions +// + +var defaults = { + disabled: false, + value: 0 +}; + +var el; + +// Progressbar Tests +module("progressbar"); + +test("init", function() { + expect(1); + + $("
            ").appendTo('body').progressbar().remove(); + ok(true, '.progressbar() called on element'); + +}); + +test("destroy", function() { + expect(1); + + $("
            ").appendTo('body').progressbar().progressbar("destroy").remove(); + ok(true, '.progressbar("destroy") called on element'); + +}); + +test("defaults", function() { + el = $('
            ').progressbar(); + $.each(defaults, function(key, val) { + var actual = el.data(key + ".progressbar"), expected = val; + same(actual, expected, key); + }); + el.remove(); +}); + +test("set defaults on init", function() { + el = $("#progressbar").progressbar({ + value: 50 + }); + + equals(el.progressbar("option", "value"), 50, "value"); +}); + +test("accessibility", function() { + expect(7); + el = $("#progressbar").progressbar(); + + equals(el.attr("role"), "progressbar", "aria role"); + equals(el.attr("aria-valuemin"), 0, "aria-valuemin"); + equals(el.attr("aria-valuemax"), 100, "aria-valuemax"); + equals(el.attr("aria-valuenow"), 0, "aria-valuenow initially"); + el.progressbar("value", 77); + equals(el.attr("aria-valuenow"), 77, "aria-valuenow"); + el.progressbar("disable"); + equals(el.attr("aria-disabled"), "true", "aria-disabled"); + el.progressbar("enable"); + equals(el.attr("aria-disabled"), "false", "enabled"); +}); + +})(jQuery); diff --git a/tests/unit/resizable/images/test.jpg b/tests/unit/resizable/images/test.jpg new file mode 100644 index 000000000..7d8ec0996 Binary files /dev/null and b/tests/unit/resizable/images/test.jpg differ diff --git a/tests/unit/resizable/resizable.html b/tests/unit/resizable/resizable.html new file mode 100644 index 000000000..5d2889884 --- /dev/null +++ b/tests/unit/resizable/resizable.html @@ -0,0 +1,25 @@ + + + + jQuery UI Resizable Test Suite + + + + + + + + + + + + + + +
            +
            I'm a resizable.
            + +
            + + + diff --git a/tests/unit/resizable/resizable.js b/tests/unit/resizable/resizable.js new file mode 100644 index 000000000..98a69de5b --- /dev/null +++ b/tests/unit/resizable/resizable.js @@ -0,0 +1,416 @@ +/* + * resizable tests + */ +(function($) { +// +// Resizable Test Helper Functions +// + +var defaults = { + animate: false, + animateDuration: 'slow', + animateEasing: 'swing', + alsoResize: false, + aspectRatio: false, + autoHide: false, + cancel: ':input', + containment: false, + delay: 0, + disabled: false, + disableSelection: true, + distance: 1, + ghost: false, + grid: false, + handles: '???', + helper: null, + knobHandles: false, + maxHeight: null, + maxWidth: null, + minHeight: 10, + minWidth: 10, + preserveCursor: true, + preventDefault: true, + proportionallyResize: false, + transparent: false +}; + +var drag = function(el, dx, dy, complete) { + + // speed = sync -> Drag syncrhonously. + // speed = fast|slow -> Drag asyncrhonously - animated. + + //this mouseover is to work around a limitation in resizable + //TODO: fix resizable so handle doesn't require mouseover in order to be used + $(el).simulate("mouseover"); + + return $(el).simulate("drag", { + dx: dx||0, dy: dy||0, speed: 'sync', complete: complete + }); +}; + +// Resizable Tests +module("resizable"); + +test("init", function() { + expect(6); + + $("
            ").appendTo('body').resizable().remove(); + ok(true, '.resizable() called on element'); + + $([]).resizable().remove(); + ok(true, '.resizable() called on empty collection'); + + $('
            ').resizable().remove(); + ok(true, '.resizable() called on disconnected DOMElement'); + + $('
            ').resizable().resizable("foo").remove(); + ok(true, 'arbitrary method called after init'); + + el = $('
            ').resizable() + var foo = el.data("foo.resizable"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $('
            ').resizable().data("foo.resizable", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(6); + + $("
            ").appendTo('body').resizable().resizable("destroy").remove(); + ok(true, '.resizable("destroy") called on element'); + + $([]).resizable().resizable("destroy").remove(); + ok(true, '.resizable("destroy") called on empty collection'); + + $('
            ').resizable().resizable("destroy").remove(); + ok(true, '.resizable("destroy") called on disconnected DOMElement'); + + $('
            ').resizable().resizable("destroy").resizable("foo").remove(); + ok(true, 'arbitrary method called after destroy'); + + el = $('
            ').resizable(); + var foo = el.resizable("destroy").data("foo.resizable"); + el.remove(); + ok(true, 'arbitrary option getter after destroy'); + + $('
            ').resizable().resizable("destroy").data("foo.resizable", "bar").remove(); + ok(true, 'arbitrary option setter after destroy'); +}); + +test("element types", function() { + var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' + + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' + + ',acronym,code,samp,kbd,var,img,object,hr' + + ',input,button,label,select,iframe').split(','); + + $.each(typeNames, function(i) { + var typeName = typeNames[i]; + el = $(document.createElement(typeName)).appendTo('body'); + (typeName == 'table' && el.append("content")); + el.resizable(); + ok(true, '$("<' + typeName + '/>").resizable()'); + el.resizable("destroy"); + el.remove(); + }); +}); + +test("defaults", function() { + el = $('
            ').resizable(); + $.each(defaults, function(key, val) { + var actual = el.data(key + ".resizable"), expected = val; + same(actual, expected, key); + }); + el.remove(); +}); + +test("n", function() { + expect(2); + + var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, 0, -50); + equals( target.height(), 150, "compare height" ); + + drag(handle, 0, 50); + equals( target.height(), 100, "compare height" ); +}); + +test("s", function() { + expect(2); + + var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, 0, 50); + equals( target.height(), 150, "compare height" ); + + drag(handle, 0, -50); + equals( target.height(), 100, "compare height" ); +}); + +test("e", function() { + expect(2); + + var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, 50); + equals( target.width(), 150, "compare width"); + + drag(handle, -50); + equals( target.width(), 100, "compare width" ); +}); + +test("w", function() { + expect(2); + + var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, -50); + equals( target.width(), 150, "compare width" ); + + drag(handle, 50); + equals( target.width(), 100, "compare width" ); +}); + +test("ne", function() { + expect(4); + + var handle = '.ui-resizable-ne', target = $('#resizable1').css({ overflow: 'hidden' }).resizable({ handles: 'all' }); + + drag(handle, -50, -50); + equals( target.width(), 50, "compare width" ); + equals( target.height(), 150, "compare height" ); + + drag(handle, 50, 50); + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); +}); + +test("se", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, 50, 50); + equals( target.width(), 150, "compare width" ); + equals( target.height(), 150, "compare height" ); + + drag(handle, -50, -50); + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); +}); + +test("sw", function() { + expect(4); + + var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, -50, -50); + equals( target.width(), 150, "compare width" ); + equals( target.height(), 50, "compare height" ); + + drag(handle, 50, 50); + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); +}); + +test("nw", function() { + expect(4); + + var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, -50, -50); + equals( target.width(), 150, "compare width" ); + equals( target.height(), 150, "compare height" ); + + drag(handle, 50, 50); + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); +}); + +module("resizable: Options"); + +test("aspectRatio: 'preserve' (e)", function() { + expect(4); + + var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, -130); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (w)", function() { + expect(4); + + var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, -80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 130); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (n)", function() { + expect(4); + + var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 0, -80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 0, 80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (s)", function() { + expect(4); + + var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 0, 80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 0, -80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (se)", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 80, 80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, -80, -80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (sw)", function() { + expect(4); + + var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, -80, 80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 80, -80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (ne)", function() { + expect(4); + + var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 80, -80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, -80, 80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("grid", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', grid: [0, 20] }); + + drag(handle, 3, 9); + equals( target.width(), 103, "compare width"); + equals( target.height(), 100, "compare height"); + + drag(handle, 15, 11); + equals( target.width(), 118, "compare width"); + equals( target.height(), 120, "compare height"); +}); + +test("grid (wrapped)", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable2').resizable({ handles: 'all', grid: [0, 20] }); + + drag(handle, 3, 9); + equals( target.width(), 103, "compare width"); + equals( target.height(), 100, "compare height"); + + drag(handle, 15, 11); + equals( target.width(), 118, "compare width"); + equals( target.height(), 120, "compare height"); +}); + +test("ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + drag(handle, -50, -50); + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, 70, 70); + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); +}); + +test("ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + expect(4); + + var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + drag(handle, 50, -50); + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, -70, 70); + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); +}); + +test("ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + expect(4); + + var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + drag(handle, -50, 50); + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, 70, -70); + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); +}); + +test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + expect(4); + + var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + drag(handle, 70, 70); + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, -70, -70); + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); +}); + +})(jQuery); diff --git a/tests/unit/selectable/selectable.html b/tests/unit/selectable/selectable.html new file mode 100644 index 000000000..e35d28ad1 --- /dev/null +++ b/tests/unit/selectable/selectable.html @@ -0,0 +1,30 @@ + + + + jQuery UI Selectable Test Suite + + + + + + + + + + + + + + +
            +
              +
            • Item 1
            • +
            • Item 2
            • +
            • Item 3
            • +
            • Item 4
            • +
            • Item 5
            • +
            +
            + + + diff --git a/tests/unit/selectable/selectable.js b/tests/unit/selectable/selectable.js new file mode 100644 index 000000000..df23626ca --- /dev/null +++ b/tests/unit/selectable/selectable.js @@ -0,0 +1,196 @@ +/* + * selectable unit tests + */ +(function($) { +// +// Selectable Test Helper Functions +// + +var defaults = { + autoRefresh: true, + disabled: false, + filter: '*' +}; + +var el; + +var drag = function(dx, dy) { + var off = el.offset(), pos = { clientX: off.left, clientY: off.top }; + el.simulate("mousedown", pos); + $(document).simulate("mousemove", pos); + pos.clientX += dx; + pos.clientY += dy; + $(document).simulate("mousemove", pos); + $(document).simulate("mouseup", pos); +} + +var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } + +var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } + +// Selectable Tests +module("selectable"); + +test("init", function() { + expect(6); + + $("
            ").appendTo('body').selectable().remove(); + ok(true, '.selectable() called on element'); + + $([]).selectable().remove(); + ok(true, '.selectable() called on empty collection'); + + $("
            ").selectable().remove(); + ok(true, '.selectable() called on disconnected DOMElement'); + + $("
            ").selectable().selectable("foo").remove(); + ok(true, 'arbitrary method called after init'); + + el = $("
            ").selectable() + var foo = el.data("foo.selectable"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $("
            ").selectable().data("foo.selectable", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(6); + + $("
            ").appendTo('body').selectable().selectable("destroy").remove(); + ok(true, '.selectable("destroy") called on element'); + + $([]).selectable().selectable("destroy").remove(); + ok(true, '.selectable("destroy") called on empty collection'); + + $("
            ").selectable().selectable("destroy").remove(); + ok(true, '.selectable("destroy") called on disconnected DOMElement'); + + $("
            ").selectable().selectable("destroy").selectable("foo").remove(); + ok(true, 'arbitrary method called after destroy'); + + el = $("
            ").selectable(); + var foo = el.selectable("destroy").data("foo.selectable"); + el.remove(); + ok(true, 'arbitrary option getter after destroy'); + + $("
            ").selectable().selectable("destroy").data("foo.selectable", "bar").remove(); + ok(true, 'arbitrary option setter after destroy'); +}); + +test("defaults", function() { + el = $('
            ').selectable(); + $.each(defaults, function(key, val) { + var actual = el.data(key + ".selectable"), expected = val; + same(actual, expected, key); + }); + el.remove(); +}); + +module("selectable: Options"); + +test("autoRefresh", function() { + expect(3); + el = $("#selectable1"); + var actual, sel = $("*", el), selected = function() { actual += 1 }; + + actual = 0; + el = $("#selectable1").selectable({ autoRefresh: false, selected: selected }); + sel.hide(); + drag(1000, 1000); + equals(actual, sel.length); + el.selectable("destroy"); + + actual = 0; + sel.show(); + el = $("#selectable1").selectable({ autoRefresh: true, selected: selected }); + sel.hide(); + drag(1000, 1000); + equals(actual, 0); + sel.show(); + drag(1000, 1000); + equals(actual, sel.length); + el.selectable("destroy"); + sel.show(); +}); + +test("filter", function() { + expect(2); + el = $("#selectable1"); + var actual, sel = $("*", el), selected = function() { actual += 1 }; + + actual = 0; + el = $("#selectable1").selectable({ filter: '.special', selected: selected }); + drag(1000, 1000); + ok(sel.length != 1, "this test assumes more than 1 selectee"); + equals(actual, 1); + el.selectable("destroy"); +}); + +module("selectable: Methods"); + +test("disable", function() { + expect(2); + var fired = false; + + el = $("#selectable1"); + el.selectable({ + disabled: false, + start: function() { fired = true; } + }); + el.simulate("drag", 20, 20); + equals(fired, true, "start fired"); + el.selectable("disable"); + fired = false; + el.simulate("drag", 20, 20); + equals(fired, false, "start fired"); + el.selectable("destroy"); +}); + +test("enable", function() { + expect(2); + var fired = false; + + el = $("#selectable1"); + el.selectable({ + disabled: true, + start: function() { fired = true; } + }); + el.simulate("drag", 20, 20); + equals(fired, false, "start fired"); + el.selectable("enable"); + el.simulate("drag", 20, 20); + equals(fired, true, "start fired"); + el.selectable("destroy"); +}); + +module("selectable: Callbacks"); + +test("start", function() { + expect(2); + el = $("#selectable1"); + el.selectable({ + start: function(ev, ui) { + ok(true, "drag fired start callback"); + equals(this, el[0], "context of callback"); + } + }); + el.simulate("drag", 20, 20); +}); + +test("stop", function() { + expect(2); + el = $("#selectable1"); + el.selectable({ + start: function(ev, ui) { + ok(true, "drag fired stop callback"); + equals(this, el[0], "context of callback"); + } + }); + el.simulate("drag", 20, 20); +}); + +module("selectable: Tickets"); + +})(jQuery); diff --git a/tests/unit/slider/slider.html b/tests/unit/slider/slider.html new file mode 100644 index 000000000..c4a30168a --- /dev/null +++ b/tests/unit/slider/slider.html @@ -0,0 +1,27 @@ + + + + jQuery UI Slider Test Suite + + + + + + + + + + + + + + +
            +
            +
            +
            +
            +
            + + + diff --git a/tests/unit/slider/slider.js b/tests/unit/slider/slider.js new file mode 100644 index 000000000..34d29b4fd --- /dev/null +++ b/tests/unit/slider/slider.js @@ -0,0 +1,396 @@ +/* + * slider unit tests + */ +(function($) { +// +// Slider Test Helper Functions +// + +var defaults = { + max: 100, + min: 0, + orientation: 'horizontal', + step: 1, + value: 0 +}; + +var el, options; + +function handle() { + return el.find(".ui-slider-handle"); +} + +// Slider Tests +module("slider"); + +test("init", function() { + expect(6); + + $("
            ").appendTo('body').slider().remove(); + ok(true, '.slider() called on element'); + + $([]).slider().remove(); + ok(true, '.slider() called on empty collection'); + + $('
            ').slider().remove(); + ok(true, '.slider() called on disconnected DOMElement'); + + $('
            ').slider().slider("foo").remove(); + ok(true, 'arbitrary method called after init'); + + el = $('
            ').slider(); + var foo = el.data("foo.slider"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $('
            ').slider().data("foo.slider", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(8); + + $("
            ").appendTo('body').slider().slider("destroy").remove(); + ok(true, '.slider("destroy") called on element'); + + $([]).slider().slider("destroy").remove(); + ok(true, '.slider("destroy") called on empty collection'); + + $('
            ').appendTo('body').remove().slider().slider("destroy").remove(); + ok(true, '.slider("destroy") called on disconnected DOMElement'); + + $('
            ').slider().slider("destroy").slider("foo").remove(); + ok(true, 'arbitrary method called after destroy'); + + el = $('
            ').slider(); + var foo = el.slider("destroy").data("foo.slider"); + el.remove(); + ok(true, 'arbitrary option getter (.data) after destroy'); + + el = $('
            ').slider(); + var foo = el.slider("destroy").slider("option", "foo"); + el.remove(); + ok(true, 'arbitrary option getter (.slider option method) after destroy'); + + $('
            ').slider().slider("destroy").data("foo.slider", "bar").remove(); + ok(true, 'arbitrary option setter (.data) after destroy'); + + $('
            ').slider().slider("destroy").slider("options", "foo", "bar").remove(); + ok(true, 'arbitrary option setter (.slider option method) after destroy'); +}); + +test("defaults", function() { + el = $('
            ').slider(); + $.each(defaults, function(key, val) { + var actual = el.data(key + ".slider"), expected = val; + same(actual, expected, key); + }); + el.remove(); +}); + +module("slider"); + +test("keydown HOME on handle sets value to min", function() { + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); + equals(el.slider("value"), options.min); + + el.slider('destroy'); + + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); + equals(el.slider("value"), options.min); + + el.slider('destroy'); +}); + +test("keydown END on handle sets value to max", function() { + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); + equals(el.slider("value"), options.max); + + el.slider('destroy'); + + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); + equals(el.slider("value"), options.max); + + el.slider('destroy'); +}); + +test("keydown UP on handle increases value by step, not greater than max", function() { + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); + + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); +}); + +test("keydown RIGHT on handle increases value by step, not greater than max", function() { + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); + + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); +}); + +test("keydown DOWN on handle decreases value by step, not less than min", function() { + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); + + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); +}); + +test("keydown LEFT on handle decreases value by step, not less than min", function() { + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); + + el = $('
            '); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); +}); + +module("slider: Options"); + +test("orientation", function() { + el = $('
            '); + + options = { + max: 2, + min: -2, + orientation: 'vertical', + value: 1 + }; + + var percentVal = (options.value - options.min) / (options.max - options.min) * 100; + + el.slider(options).slider("option", "orientation", "horizontal"); + ok(el.is('.ui-slider-horizontal'), "horizontal slider has class .ui-slider-horizontal"); + ok(!el.is('.ui-slider-vertical'), "horizontal slider does not have class .ui-slider-vertical"); + equals(handle().css('left'), percentVal + '%', "horizontal slider handle is positioned with left: %"); + + el.slider('destroy'); + + options = { + max: 2, + min: -2, + orientation: 'horizontal', + value: -1 + }; + + var percentVal = (options.value - options.min) / (options.max - options.min) * 100; + + el.slider(options).slider("option", "orientation", "vertical"); + ok(el.is('.ui-slider-vertical'), "vertical slider has class .ui-slider-vertical"); + ok(!el.is('.ui-slider-horizontal'), "vertical slider does not have class .ui-slider-horizontal"); + equals(handle().css('bottom'), percentVal + '%', "vertical slider handle is positioned with bottom: %"); + + el.slider('destroy'); + +}); + +test("max", function() { + el = $('
            '); + + options = { + max: 37, + min: 6, + orientation: 'horizontal', + step: 1, + value: 50 + }; + + el.slider(options); + ok(el.slider("option", "value") == options.value, "value option is not contained by max"); + ok(el.slider("value") == options.max, "value method is contained by max"); + el.slider('destroy'); + +}); + +test("min", function() { + el = $('
            '); + + options = { + max: 37, + min: 6, + orientation: 'vertical', + step: 1, + value: 2 + }; + + el.slider(options); + ok(el.slider("option", "value") == options.value, "value option is not contained by min"); + ok(el.slider("value") == options.min, "value method is contained by min"); + el.slider('destroy'); + +}); + +})(jQuery); diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html new file mode 100644 index 000000000..5c45144bc --- /dev/null +++ b/tests/unit/sortable/sortable.html @@ -0,0 +1,30 @@ + + + + jQuery UI Sortable Test Suite + + + + + + + + + + + + + + +
            +
              +
            • Item 1
            • +
            • Item 2
            • +
            • Item 3
            • +
            • Item 4
            • +
            • Item 5
            • +
            +
            + + + diff --git a/tests/unit/sortable/sortable.js b/tests/unit/sortable/sortable.js new file mode 100644 index 000000000..c913ed86d --- /dev/null +++ b/tests/unit/sortable/sortable.js @@ -0,0 +1,148 @@ +/* + * sortable unit tests + */ +(function($) { +// +// Sortable Test Helper Functions +// + +var defaults = { + appendTo: "parent", + cancel: ":input", + delay: 0, + disabled: false, + distance: 1, + dropOnEmpty: true, + helper: "original", + items: "> *", + scroll: true, + scrollSensitivity: 20, + scrollSpeed: 20, + tolerance: "guess", + zIndex: 1000 +}; + +var el, offsetBefore, offsetAfter, dragged; + +var drag = function(handle, dx, dy) { + offsetBefore = $(handle).offset(); + $(handle).simulate("drag", { + dx: dx || 0, + dy: dy || 0 + }); + dragged = { dx: dx, dy: dy }; + offsetAfter = $(handle).offset(); +} + +var sort = function(handle, dx, dy, index, msg) { + drag(handle, dx, dy); + equals($(handle).parent().children().index(handle), index, msg); +} + +var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } +var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } + +// Sortable Tests +module("sortable"); + +test("init", function() { + expect(6); + + $("
            ").appendTo('body').sortable().remove(); + ok(true, '.sortable() called on element'); + + $([]).sortable(); + ok(true, '.sortable() called on empty collection'); + + $("
            ").sortable(); + ok(true, '.sortable() called on disconnected DOMElement'); + + $("
            ").sortable().sortable("foo"); + ok(true, 'arbitrary method called after init'); + + $("
            ").sortable().data("foo.sortable"); + ok(true, 'arbitrary option getter after init'); + + $("
            ").sortable().data("foo.sortable", "bar"); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(6); + + $("
            ").appendTo('body').sortable().sortable("destroy").remove(); + ok(true, '.sortable("destroy") called on element'); + + $([]).sortable().sortable("destroy"); + ok(true, '.sortable("destroy") called on empty collection'); + + $("
            ").sortable().sortable("destroy"); + ok(true, '.sortable("destroy") called on disconnected DOMElement'); + + $("
            ").sortable().sortable("destroy").sortable("foo"); + ok(true, 'arbitrary method called after destroy'); + + $("
            ").sortable().sortable("destroy").data("foo.sortable"); + ok(true, 'arbitrary option getter after destroy'); + + $("
            ").sortable().sortable("destroy").data("foo.sortable", "bar"); + ok(true, 'arbitrary option setter after destroy'); +}); + +test("enable", function() { + expect(4); + el = $("#sortable").sortable({ disabled: true }); + + sort($("li", el)[0], 0, 40, 0, '.sortable({ disabled: true })'); + + el.sortable("enable"); + equals(el.data("disabled.sortable"), false, "disabled.sortable getter"); + + el.sortable("destroy"); + el.sortable({ disabled: true }); + el.data("disabled.sortable", false); + equals(el.data("disabled.sortable"), false, "disabled.sortable setter"); + + sort($("li", el)[0], 0, 40, 2, '.data("disabled.sortable", false)'); +}); + +test("disable", function() { + expect(5); + el = $("#sortable").sortable({ disabled: false }); + sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })'); + + el.sortable("disable"); + sort($("li", el)[0], 0, 40, 0, 'disabled.sortable getter'); + + el.sortable("destroy"); + + el.sortable({ disabled: false }); + sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })'); + el.data("disabled.sortable", true); + equals(el.data("disabled.sortable"), true, "disabled.sortable setter"); + sort($("li", el)[0], 0, 40, 0, '.data("disabled.sortable", true)'); +}); + +test("defaults", function() { + el = $('
            ').sortable(); + $.each(defaults, function(key, val) { + var actual = el.data(key + ".sortable"), expected = val; + same(actual, expected, key); + }); + el.remove(); +}); + +test("#3019: Stop fires too early", function() { + + var helper = null; + el = $("#sortable").sortable({ stop: function(event, ui) { + helper = ui.helper; + }}); + + sort($("li", el)[0], 0, 40, 2, 'Dragging the sortable'); + equals(helper, null, "helper should be false"); + +}); + + +})(jQuery); diff --git a/tests/unit/tabs/tabs.html b/tests/unit/tabs/tabs.html new file mode 100644 index 000000000..57ddb6680 --- /dev/null +++ b/tests/unit/tabs/tabs.html @@ -0,0 +1,44 @@ + + + + jQuery UI Tabs Test Suite + + + + + + + + + + + + + + + +
            + +
            +
              +
            • 1
            • +
            • 2
            • +
            • 3
            • +
            +
            +
            +
            +
            +
            +
              +
            • 1
            • +
            • 2
            • +
            +
            +
            +
            + +
            + + + diff --git a/tests/unit/tabs/tabs.js b/tests/unit/tabs/tabs.js new file mode 100644 index 000000000..41d59f060 --- /dev/null +++ b/tests/unit/tabs/tabs.js @@ -0,0 +1,243 @@ +/* + * tabs unit tests + */ +(function($) { +// +// Tabs Test Helper Functions +// + +var defaults = { + ajaxOptions: null, + cache: false, + cookie: null, + deselectable: false, + deselectableClass: 'ui-tabs-deselectable', + disabled: [], + disabledClass: 'ui-state-disabled', + event: 'click', + fx: null, + hideClass: 'ui-tabs-hide', + idPrefix: 'ui-tabs-', + loadingClass: 'ui-tabs-loading', + navClass: 'ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all', + panelClass: 'ui-tabs-panel ui-widget-content ui-corner-bottom', + panelTemplate: '
            ', + selectedClass: 'ui-tabs-selected ui-state-active', + spinner: 'Loading…', + tabTemplate: '
          1. #{label}
          2. ' +}; + +var el; + +// need to wait a bit for the pseudo animation... +function defer(defered, ms) { + var queue = defer.queue || (defer.queue = []); + if (!queue.length) stop(); + queue.push(defered); + setTimeout(function() { + queue.shift()(); + if (!queue.length) start(); + }, ms || 100); +} + +module('tabs'); + + test('init', function() { + expect(9); + + var el = $('#tabs1').tabs(); // new markup requires to tabify wrapper again... + ok(true, '.tabs() called on element'); + + el.tabs('destroy').tabs({ selected: 1 }); + + 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-state-default.ui-corner-top'), 'attach classes to inactive li'); + ok( $('li:eq(1)', el).is('.ui-tabs-selected.ui-state-active.ui-corner-top'), 'attach classes to active li'); + equals( el.data('selected.tabs'), 1, 'selected.tabs set' ); + equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 1, 'second tab active'); + equals( $('div', el).index( $('div.ui-tabs-hide', '#tabs1') ), 0, 'first panel should be hidden' ); + + }); + + test('destroy', function() { + expect(0); + + }); + + test("defaults", function() { + el = $('#tabs1 > ul').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); + + var el = $('#tabs1 > ul').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 = $('#tabs2 > ul').tabs({ selected: 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); + + }); + + +module('tabs: Options'); + + test('select: null', function() { + expect(3); + + var el = $('#tabs1 > ul'); + + el.tabs({ selected: null }); + equals( el.data('selected.tabs'), null, 'option set' ); + equals( $('li.ui-tabs-selected', el).length, 0, 'all tabs should be deselected' ); + equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' ); + + // TODO select == null with cookie + // TODO select == null with select method + + }); + + test('deselectable: true', function() { + expect(7); + + var el = $('#tabs1 > ul'); + + el.tabs({ deselectable: true }); + equals( el.data('deselectable.tabs'), true, 'option set' ); + equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once'); + equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 0, 'class "ui-tabs-deselectable" attached to first tab'); + + el.tabs('select', 1); + equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once'); + equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 1, 'class "ui-tabs-deselectable" attached to second tab'); + + el.tabs('select', 1); + equals( $('li.ui-tabs-deselectable', el).length, 0, 'class "ui-tabs-deselectable" not attached'); + defer(function() { + equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' ); + }); + + }); + + test('cookie', function() { + expect(5); + + var el = $('#tabs1 > ul'); + var cookieName = 'ui-tabs-' + $.data(el[0]); + $.cookie(cookieName, null); // blank state + var cookie = function() { + return parseInt($.cookie(cookieName), 10); + }; + + el.tabs({ cookie: {} }); + equals(cookie(), 0, 'initial cookie value, no cookie given'); + + el.tabs('destroy'); + el.tabs({ selected: 1, cookie: {} }); + equals(cookie(), 1, 'initial cookie value, given selected'); + + el.tabs('select', 2); + equals(cookie(), 2, 'cookie value after tabs select'); + + el.tabs('destroy'); + $.cookie(cookieName, 1); + el.tabs({ cookie: {} }); + equals(cookie(), 1, 'initial cookie value, from existing cookie'); + + el.tabs('destroy'); + ok($.cookie(cookieName) === null, 'erase cookie after destroy'); + + }); + + +module('tabs: Tickets'); + + test('id containing colon, #????', function() { + expect(4); + + var el = $('#tabs2 > ul').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); + defer(function() { + 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'); + + var el = $('#tabs2 > ul').tabs(); + equals(inlineStyle('height'), expected, 'init should not remove inline style'); + + el.tabs('select', 1); + defer(function() { + equals(inlineStyle('height'), expected, 'show tab should not remove inline style'); + + el.tabs('select', 0); + defer(function() { + equals(inlineStyle('height'), expected, 'hide tab should not remove inline style'); + }); + + }); + + }); + +// test('', function() { +// expect(0); +// +// }); + +})(jQuery); diff --git a/tests/unit/testsuite.css b/tests/unit/testsuite.css new file mode 100644 index 000000000..f1961ff47 --- /dev/null +++ b/tests/unit/testsuite.css @@ -0,0 +1,4 @@ +@import url("../../external/qunit/testsuite.css"); +html { border: 0; } +.xerror, .error, .ui-tabs-hide { display: none } +#main { position: absolute; top: -10000px; left: -10000px; } diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js new file mode 100644 index 000000000..2ad60cbab --- /dev/null +++ b/tests/unit/testsuite.js @@ -0,0 +1,10 @@ +$(function() { + +$('body').prepend( + '

            ' + document.title + '

            ' + + '' + + '

            ' + + '
              ' +); + +}); -- cgit v1.2.3