From 84e0ce168f109fbd5482c6c1ba09bbbb55592888 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Thu, 15 Apr 2010 09:45:35 +0200 Subject: Tooltip: Unit tests for tooltip and a fix to pass through event objects to triggered events --- tests/unit/tooltip/tooltip.html | 43 +++++++++++++++++++++++++++ tests/unit/tooltip/tooltip_core.js | 11 +++++++ tests/unit/tooltip/tooltip_defaults.js | 16 ++++++++++ tests/unit/tooltip/tooltip_events.js | 54 ++++++++++++++++++++++++++++++++++ tests/unit/tooltip/tooltip_methods.js | 23 +++++++++++++++ tests/unit/tooltip/tooltip_options.js | 39 ++++++++++++++++++++++++ tests/unit/tooltip/tooltip_tickets.js | 10 +++++++ 7 files changed, 196 insertions(+) create mode 100644 tests/unit/tooltip/tooltip.html create mode 100644 tests/unit/tooltip/tooltip_core.js create mode 100644 tests/unit/tooltip/tooltip_defaults.js create mode 100644 tests/unit/tooltip/tooltip_events.js create mode 100644 tests/unit/tooltip/tooltip_methods.js create mode 100644 tests/unit/tooltip/tooltip_options.js create mode 100644 tests/unit/tooltip/tooltip_tickets.js (limited to 'tests/unit/tooltip') diff --git a/tests/unit/tooltip/tooltip.html b/tests/unit/tooltip/tooltip.html new file mode 100644 index 000000000..37bfeafce --- /dev/null +++ b/tests/unit/tooltip/tooltip.html @@ -0,0 +1,43 @@ + + + + + jQuery UI Tooltip Test Suite + + + + + + + + + + + + + + + + + + + + + + + +

jQuery UI Tooltip Test Suite

+

+

+
    +
+ +
+
+ anchor + +
+
+ + + diff --git a/tests/unit/tooltip/tooltip_core.js b/tests/unit/tooltip/tooltip_core.js new file mode 100644 index 000000000..247927df4 --- /dev/null +++ b/tests/unit/tooltip/tooltip_core.js @@ -0,0 +1,11 @@ +/* + * tooltip_core.js + */ + + +(function($) { + +module("tooltip: core"); + + +})(jQuery); diff --git a/tests/unit/tooltip/tooltip_defaults.js b/tests/unit/tooltip/tooltip_defaults.js new file mode 100644 index 000000000..bcdcd4307 --- /dev/null +++ b/tests/unit/tooltip/tooltip_defaults.js @@ -0,0 +1,16 @@ +/* + * tooltip_defaults.js + */ + +var tooltip_defaults = { + disabled: false, + content: $.ui.tooltip.prototype.options.content, + tooltipClass: "ui-widget-content", + position: { + my: "left center", + at: "right center", + offset: "15 0" + } +}; + +commonWidgetTests('tooltip', { defaults: tooltip_defaults }); diff --git a/tests/unit/tooltip/tooltip_events.js b/tests/unit/tooltip/tooltip_events.js new file mode 100644 index 000000000..51c56b62e --- /dev/null +++ b/tests/unit/tooltip/tooltip_events.js @@ -0,0 +1,54 @@ +/* + * tooltip_events.js + */ +(function($) { + +module("tooltip: events"); + +test("programmatic triggers", function() { + expect(2); + var e = $("#tooltipped1").tooltip({ + open: function(event, ui) { + same( event.type, "tooltipopen" ); + }, + close: function(event, ui) { + same( event.type, "tooltipclose" ); + } + }); + e.tooltip("open").tooltip("close"); + e.tooltip("destroy"); +}); + +test("mouse events", function() { + expect(4); + var e = $("#tooltipped1").tooltip({ + open: function(event, ui) { + same( event.type, "tooltipopen" ); + same( event.originalEvent.type, "mouseenter" ); + }, + close: function(event, ui) { + same( event.type, "tooltipclose" ); + same( event.originalEvent.type, "mouseleave" ); + } + }); + e.trigger("mouseover").trigger("mouseout"); + e.tooltip("destroy"); +}); + +test("focus events", function() { + expect(4); + var e = $("#tooltipped1").tooltip({ + open: function(event, ui) { + same( event.type, "tooltipopen" ); + same( event.originalEvent.type, "focus" ); + }, + close: function(event, ui) { + same( event.type, "tooltipclose" ); + same( event.originalEvent.type, "blur" ); + } + }); + e.trigger("focus").trigger("blur"); + e.tooltip("destroy"); +}); + +})(jQuery); diff --git a/tests/unit/tooltip/tooltip_methods.js b/tests/unit/tooltip/tooltip_methods.js new file mode 100644 index 000000000..867923dd0 --- /dev/null +++ b/tests/unit/tooltip/tooltip_methods.js @@ -0,0 +1,23 @@ +/* + * tooltip_methods.js + */ +(function($) { + + +module("tooltip: methods"); + +test("destroy", function() { + var beforeHtml = $("#tooltipped1").parent().html(); + var afterHtml = $("#tooltipped1").tooltip().tooltip("destroy").parent().html(); + equal( afterHtml, beforeHtml ); +}); + +test("open", function() { + var e = $("#tooltipped1").tooltip(); + ok( $(".ui-tooltip").is(":hidden") ); + e.tooltip("open"); + ok( $(".ui-tooltip").is(":visible") ); + $(":ui-tooltip").tooltip("destroy"); +}); + +})(jQuery); diff --git a/tests/unit/tooltip/tooltip_options.js b/tests/unit/tooltip/tooltip_options.js new file mode 100644 index 000000000..e0262a947 --- /dev/null +++ b/tests/unit/tooltip/tooltip_options.js @@ -0,0 +1,39 @@ +/* + * tooltip_options.js + */ +(function($) { + +module("tooltip: options"); + +function contentTest(name, expected, impl) { + test(name, function() { + $("#tooltipped1").tooltip({ + content: impl + }).tooltip("open"); + same( $(".ui-tooltip").text(), expected ); + $(":ui-tooltip").tooltip("destroy"); + }); +} + +contentTest("content: default", "anchortitle"); +contentTest("content: return string", "customstring", function() { + return "customstring"; +}); +contentTest("content: callback string", "customstring2", function(response) { + response("customstring2"); +}); + +test("tooltipClass, default", function() { + $("#tooltipped1").tooltip().tooltip("open"); + same( $(".ui-tooltip").attr("class"), "ui-tooltip ui-widget ui-corner-all ui-widget-content"); + $(":ui-tooltip").tooltip("destroy"); +}); +test("tooltipClass, custom", function() { + $("#tooltipped1").tooltip({ + tooltipClass: "pretty fancy" + }).tooltip("open"); + same( $(".ui-tooltip").attr("class"), "ui-tooltip ui-widget ui-corner-all pretty fancy"); + $(":ui-tooltip").tooltip("destroy"); +}); + +})(jQuery); diff --git a/tests/unit/tooltip/tooltip_tickets.js b/tests/unit/tooltip/tooltip_tickets.js new file mode 100644 index 000000000..5d6d0ef86 --- /dev/null +++ b/tests/unit/tooltip/tooltip_tickets.js @@ -0,0 +1,10 @@ +/* + * tooltip_tickets.js + */ +(function($) { + +module("tooltip: tickets"); + + + +})(jQuery); -- cgit v1.2.3