aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/button
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2010-01-07 03:19:50 +0000
committerScott González <scott.gonzalez@gmail.com>2010-01-07 03:19:50 +0000
commit90fb45dffafc2e891b1ebca948ad33e6b94de112 (patch)
tree6bd09ea116ef2cdd86ec0fa70bf740617f67d441 /tests/unit/button
parent975b02a82cdff29fd8469bfe4324472c2ae3f954 (diff)
downloadjquery-ui-90fb45dffafc2e891b1ebca948ad33e6b94de112.tar.gz
jquery-ui-90fb45dffafc2e891b1ebca948ad33e6b94de112.zip
Merged in /branches/dev r3251:3620 (excluding autocomplete, modal, tooltip, menu; including menu static tests).
Diffstat (limited to 'tests/unit/button')
-rw-r--r--tests/unit/button/button.html56
-rw-r--r--tests/unit/button/button_core.js70
-rw-r--r--tests/unit/button/button_defaults.js15
-rw-r--r--tests/unit/button/button_events.js17
-rw-r--r--tests/unit/button/button_methods.js15
-rw-r--r--tests/unit/button/button_options.js69
-rw-r--r--tests/unit/button/button_tickets.js10
7 files changed, 252 insertions, 0 deletions
diff --git a/tests/unit/button/button.html b/tests/unit/button/button.html
new file mode 100644
index 000000000..5017c9bc6
--- /dev/null
+++ b/tests/unit/button/button.html
@@ -0,0 +1,56 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <title>jQuery UI Button Test Suite</title>
+
+ <script type="text/javascript" src="../../../jquery-1.3.2.js"></script>
+ <script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script>
+ <script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script>
+ <script type="text/javascript" src="../../../ui/jquery.ui.button.js"></script>
+
+ <link type="text/css" href="../testsuite.css" rel="stylesheet" />
+ <script type="text/javascript" src="../../../external/testrunner-r6588.js"></script>
+ <script type="text/javascript" src="../../jquery.simulate.js"></script>
+ <script type="text/javascript" src="../testsuite.js"></script>
+
+ <script type="text/javascript" src="button_core.js"></script>
+ <script type="text/javascript" src="button_defaults.js"></script>
+ <script type="text/javascript" src="button_events.js"></script>
+ <script type="text/javascript" src="button_methods.js"></script>
+ <script type="text/javascript" src="button_options.js"></script>
+ <script type="text/javascript" src="button_tickets.js"></script>
+
+</head>
+<body>
+
+<div id="main">
+
+ <div><button id="button" class="foo">Label</button></div>
+
+ <div id="radio0" style="margin-top: 2em;">
+ <input type="radio" id="radio01" name="radio" checked="checked" /><label for="radio01">Choice 1</label>
+ <input type="radio" id="radio02" name="radio" /><label for="radio02">Choice 2</label>
+ <input type="radio" id="radio03" name="radio" /><label for="radio03">Choice 3</label>
+ </div>
+ <form>
+ <div id="radio1" style="margin-top: 2em;">
+ <input type="radio" id="radio11" name="radio" /><label for="radio11">Choice 1</label>
+ <input type="radio" id="radio12" name="radio" checked="checked" /><label for="radio12">Choice 2</label>
+ <input type="radio" id="radio13" name="radio" /><label for="radio13">Choice 3</label>
+ </div>
+ </form>
+ <form>
+ <div id="radio2" style="margin-top: 2em;">
+ <input type="radio" id="radio21" name="radio" /><label for="radio21">Choice 1</label>
+ <input type="radio" id="radio22" name="radio" /><label for="radio22">Choice 2</label>
+ <input type="radio" id="radio23" name="radio" checked="checked" /><label for="radio23">Choice 3</label>
+ </div>
+ </form>
+
+ <input type="checkbox" id="check" /><label for="check">Toggle</label>
+
+ <div><input id="submit" type="submit" value="Label" /></div>
+</div>
+
+</body>
+</html>
diff --git a/tests/unit/button/button_core.js b/tests/unit/button/button_core.js
new file mode 100644
index 000000000..12016627f
--- /dev/null
+++ b/tests/unit/button/button_core.js
@@ -0,0 +1,70 @@
+/*
+ * button_core.js
+ */
+
+
+(function($) {
+
+module("button: core");
+
+test("checkbox", function() {
+ var input = $("#check");
+ label = $("label[for=check]");
+ ok( input.is(":visble") );
+ ok( label.is(":not(.ui-button)") );
+ input.button();
+ ok( input.is(":hidden") );
+ ok( label.is(".ui-button") );
+});
+
+test("radios", function() {
+ var inputs = $("#radio0 input");
+ labels = $("#radio0 label");
+ ok( inputs.is(":visble") );
+ ok( labels.is(":not(.ui-button)") );
+ inputs.button();
+ ok( inputs.is(":hidden") );
+ ok( labels.is(".ui-button") );
+});
+
+function assert(noForm, form1, form2) {
+ ok( $("#radio0 .ui-button" + noForm).is(".ui-state-active") );
+ ok( $("#radio1 .ui-button" + form1).is(".ui-state-active") );
+ ok( $("#radio2 .ui-button" + form2).is(".ui-state-active") );
+}
+
+test("radio groups", function() {
+ $(":radio").button();
+ assert(":eq(0)", ":eq(1)", ":eq(2)");
+
+ // click outside of forms
+ $("#radio0 .ui-button:eq(1)").click();
+ assert(":eq(1)", ":eq(1)", ":eq(2)");
+
+ // click in first form
+ $("#radio1 .ui-button:eq(0)").click();
+ assert(":eq(1)", ":eq(0)", ":eq(2)");
+
+ // click in second form
+ $("#radio2 .ui-button:eq(0)").click();
+ assert(":eq(1)", ":eq(0)", ":eq(0)");
+});
+
+test("input type submit, don't create child elements", function() {
+ var input = $("#submit")
+ same( input.children().length, 0 );
+ input.button();
+ same( input.children().length, 0 );
+});
+
+test("buttonset", function() {
+ var set = $("#radio1").buttonset();
+ ok( set.is(".ui-button-set") );
+ same( set.children(".ui-button").length, 3 );
+ same( set.children("input:radio:hidden").length, 3 );
+ ok( set.children("label:eq(0)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") );
+ ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") );
+ ok( set.children("label:eq(2)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") );
+});
+
+})(jQuery);
diff --git a/tests/unit/button/button_defaults.js b/tests/unit/button/button_defaults.js
new file mode 100644
index 000000000..f0152e3c2
--- /dev/null
+++ b/tests/unit/button/button_defaults.js
@@ -0,0 +1,15 @@
+/*
+ * button_defaults.js
+ */
+
+var button_defaults = {
+ disabled: false,
+ text: true,
+ label: null,
+ icons: {
+ primary: null,
+ secondary: null
+ }
+};
+
+commonWidgetTests('button', { defaults: button_defaults });
diff --git a/tests/unit/button/button_events.js b/tests/unit/button/button_events.js
new file mode 100644
index 000000000..17f505458
--- /dev/null
+++ b/tests/unit/button/button_events.js
@@ -0,0 +1,17 @@
+/*
+ * button_events.js
+ */
+(function($) {
+
+module("button: events");
+
+test("click-through", function() {
+ expect(2);
+ var set = $("#radio1").buttonset();
+ set.find("input:first").click(function() {
+ ok( true );
+ });
+ ok( set.find("label:first").click().is(".ui-button") );
+});
+
+})(jQuery);
diff --git a/tests/unit/button/button_methods.js b/tests/unit/button/button_methods.js
new file mode 100644
index 000000000..a162a8930
--- /dev/null
+++ b/tests/unit/button/button_methods.js
@@ -0,0 +1,15 @@
+/*
+ * button_methods.js
+ */
+(function($) {
+
+
+module("button: methods");
+
+test("destroy", function() {
+ var beforeHtml = $("#button").parent().html();
+ var afterHtml = $("#button").button().button("destroy").parent().html();
+ same( beforeHtml, afterHtml );
+});
+
+})(jQuery);
diff --git a/tests/unit/button/button_options.js b/tests/unit/button/button_options.js
new file mode 100644
index 000000000..f44679a34
--- /dev/null
+++ b/tests/unit/button/button_options.js
@@ -0,0 +1,69 @@
+/*
+ * button_options.js
+ */
+(function($) {
+
+module("button: options");
+
+test("text false without icon", function() {
+ $("#button").button({
+ text: false
+ });
+ ok( $("#button").is(".ui-button-text-only:not(.ui-button-icon-only)") );
+
+ $("#button").button("destroy");
+});
+
+test("text false with icon", function() {
+ $("#button").button({
+ text: false,
+ icons: {
+ primary: "iconclass"
+ }
+ });
+ ok( $("#button").is(".ui-button-icon-only:not(.ui-button-text):has(span.ui-icon.iconclass)") );
+
+ $("#button").button("destroy");
+});
+
+test("label, default", function() {
+ $("#button").button();
+ same( $("#button").text(), "Label" );
+
+ $("#button").button("destroy");
+});
+
+test("label", function() {
+ $("#button").button({
+ label: "xxx"
+ });
+ same( $("#button").text(), "xxx" );
+
+ $("#button").button("destroy");
+});
+
+test("label default with input type submit", function() {
+ same( $("#submit").button().val(), "Label" );
+});
+
+test("label with input type submit", function() {
+ var label = $("#submit").button({
+ label: "xxx"
+ }).val();
+ same( label, "xxx" );
+});
+
+test("icons", function() {
+ $("#button").button({
+ text: false,
+ icons: {
+ primary: "iconclass",
+ secondary: "iconclass2"
+ }
+ });
+ ok( $("#button").is(":has(span.ui-icon.ui-button-icon-primary.iconclass):has(span.ui-icon.ui-button-icon-secondary.iconclass2)") );
+
+ $("#button").button("destroy");
+});
+
+})(jQuery);
diff --git a/tests/unit/button/button_tickets.js b/tests/unit/button/button_tickets.js
new file mode 100644
index 000000000..d3b981e21
--- /dev/null
+++ b/tests/unit/button/button_tickets.js
@@ -0,0 +1,10 @@
+/*
+ * button_tickets.js
+ */
+(function($) {
+
+module("button: tickets");
+
+
+
+})(jQuery);