r3601 committed - button: unit test coverage

r3601 committed - button: unit test coverage

Revision: 3601
Author: joern.zaefferer
Date: Sun Jan 3 10:09:25 2010
Log: button: unit test coverage
http://code.google.com/p/jquery-ui/source/detail?r=3601
Modified:
/branches/dev/tests/unit/button/button.html
/branches/dev/tests/unit/button/button_core.js
/branches/dev/tests/unit/button/button_events.js
/branches/dev/tests/unit/button/button_methods.js
/branches/dev/tests/unit/button/button_options.js
=======================================
--- /branches/dev/tests/unit/button/button.html    Sun Jan 3 05:20:44 2010
+++ /branches/dev/tests/unit/button/button.html    Sun Jan 3 10:09:25 2010
@@ -25,8 +25,13 @@
<div id="main">
-    <button id="button">Label</button>
-
+    <div><button id="button">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>
@@ -34,6 +39,13 @@
            <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>
=======================================
--- /branches/dev/tests/unit/button/button_core.js    Sun Jan 3 05:20:44 2010
+++ /branches/dev/tests/unit/button/button_core.js    Sun Jan 3 10:09:25 2010
@@ -7,6 +7,27 @@
module("button: core");
-
+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, no form", function() {
+    $(":radio").button();
+    assert(":first", ":eq(1)", ":last");
+    $("#radio0 .ui-button:first").click();
+    assert(":first", ":eq(1)", ":last");
+});
+
+test("radio, form", function() {
+    $(":radio").button();
+    assert(":first", ":eq(1)", ":last");
+    $("#radio1 .ui-button:first").click();
+    assert(":first", ":first", ":last");
+
+    $("#radio2 .ui-button:first").click();
+    assert(":first", ":first", ":first");
+});
})(jQuery);
=======================================
--- /branches/dev/tests/unit/button/button_events.js    Sun Jan 3 05:20:44
2010
+++ /branches/dev/tests/unit/button/button_events.js    Sun Jan 3 10:09:25
2010
@@ -5,19 +5,13 @@
module("button: events");
-test("search", function() {
-});
-
-test("open", function() {
-});
-
-test("focus", function() {
-});
-
-test("close", function() {
-});
-
-test("change", function() {
+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);
=======================================
--- /branches/dev/tests/unit/button/button_methods.js    Sun Jan 3 05:20:44
2010
+++ /branches/dev/tests/unit/button/button_methods.js    Sun Jan 3 10:09:25
2010
@@ -7,11 +7,12 @@
module("button: methods");
test("destroy", function() {
-    // events, classes, aria attributes
-})
-
-test("search", function() {
-
-})
+    var beforeHtml = $("#button").html()
+        beforeClasses = $("#button").attr("class");
+    var afterHtml = $("#button").button().button("destroy").html()
+        afterClasses = $("#button").attr("class");
+    same( beforeHtml, afterHtml );
+    same( beforeClasses, afterClasses );
+});
})(jQuery);
=======================================
--- /branches/dev/tests/unit/button/button_options.js    Sun Jan 3 05:20:44
2010
+++ /branches/dev/tests/unit/button/button_options.js    Sun Jan 3 10:09:25
2010
@@ -5,9 +5,28 @@
module("button: options");
-test("text", function() {
+test("text false without icon", function() {
+    $("#button").button({
+        text: false
+    });
+    ok( $("#button").is(".ui-button-text-only:not(.ui-button-icon-only)") );
});
+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)")
);
+});
+
+test("label, default", function() {
+    $("#button").button();
+    same( "Label", $("#button").text() );
+});
+
test("label", function() {
    $("#button").button({
        label: "xxx"
@@ -16,6 +35,14 @@
});
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)")
);
});
})(jQuery);
--