Permalink
Browse files

Update interface and add tests

  • Loading branch information...
vbortone committed Jan 18, 2013
1 parent c11d0c9 commit 5aa600bcad86e4189b6fec7b7a6a1e8ebea0258e
Showing with 124 additions and 49 deletions.
  1. +78 −1 bootbox/bootbox-tests.ts
  2. +46 −48 bootbox/bootbox.d.ts
View
@@ -1 +1,78 @@
-// Tests for Bootbox
+// QUnit Tests for Bootbox 3.0
+/// <reference path="bootbox.d.ts" />
+/// <reference path="../qunit/qunit.d.ts" />
+
+test("Bootbox alert with message", function () {
+ ok(bootbox.alert("Are we ok?"), "Passed!");
+});
+
+test("Bootbox alert with message and custom text in button", function () {
+ ok(bootbox.alert("Are we ok with Test button?", "Test"), "Passed!");
+});
+
+asyncTest("Bootbox alert with message and callback", function() {
+ bootbox.alert("Are we ok with callback?", function() {
+ ok(true, "Callback called!");
+ start();
+ });
+});
+
+asyncTest("Bootbox alert with message and callback and custom text", function() {
+ bootbox.alert("Are we ok with callback and custom button?", "Test", function() {
+ ok(true, "Callback called!");
+ start();
+ });
+});
+
+asyncTest("Bootbox confirm (ok) with message and callback", function() {
+ bootbox.confirm("Click ok to pass test", function(result) {
+ ok(result, "Callback called!");
+ start();
+ });
+});
+
+asyncTest("Bootbox confirm (cancel) with message and callback", function() {
+ bootbox.confirm("Click cancel to pass test", function(result) {
+ ok(!result, "Callback called!");
+ start();
+ });
+});
+
+asyncTest("Bootbox confirm (confirm?) with message and callback and custom text", function() {
+ bootbox.confirm("Click confirm to pass test", "Cancel?", "Confirm?", function(result) {
+ ok(result, "Callback called!");
+ start();
+ });
+});
+
+asyncTest("Bootbox confirm (cancel?) with message and callback and custom text", function() {
+ bootbox.confirm("Click cancel to pass test", "Cancel?", "Confirm?", function(result) {
+ ok(!result, "Callback called!");
+ start();
+ });
+});
+
+test("Bootbox prompt with message", function () {
+ ok(bootbox.prompt("Are we ok?"), "Passed!");
+});
+
+asyncTest("Bootbox prompt with message and callback", function() {
+ bootbox.prompt("Enter 'ok' to pass test", function(result) {
+ equal(result.toLowerCase(), "ok", "Callback called!");
+ start();
+ });
+});
+
+asyncTest("Bootbox prompt with message and callback and custom text", function() {
+ bootbox.prompt("Enter 'ok' to pass test", "Cancel?", "Confirm?", function(result) {
+ equal(result.toLowerCase(), "ok", "Callback called!");
+ start();
+ });
+});
+
+asyncTest("Bootbox prompt with message and callback and custom text and default value", function() {
+ bootbox.prompt("Keep default value and click ok", "Cancel?", "Confirm?", function(result) {
+ equal(result, "Test Value", "Callback called!");
+ start();
+ }, "Test Value");
+});
View
@@ -1,49 +1,47 @@
-// Type definitions for Bootbox 3.0.0
-// Project: https://github.com/makeusabrew/bootbox
-// Definitions by: Vincent Bortone <https://github.com/vbortone/>
-// Definitions: https://github.com/borisyankov/DefinitelyTyped
-
-/// <reference path="../jquery/jquery.d.ts"/>
-/// <reference path="../bootstrap/bootstrap.d.ts"/>
-
-interface BootboxLocale {
- OK: string;
- CANCEL: string;
- CONFIRM: string;
-}
-
-interface BootboxIcons {
- OK: any;
- CANCEL: any;
- CONFIRM: any;
-}
-
-interface BootboxHandler {
- label: string;
- class: string;
- callback: () => void;
- callback: (result: bool) => void;
- callback: (result: string) => void;
-}
-
-interface BootboxOption {
- header: string;
- headerCloseButton: bool;
-}
-
-interface BootboxStatic {
- alert(message: string, customButtonText?: string, callback?: () => void): void;
- confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: bool) => void): void;
- prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void;
- dialog(message: string, handlers?: BootboxHandler[], options?: any): void;
- dialog(message: string, handler?: BootboxHandler): void;
- hideAll(): void;
- animate(shouldAnimate: bool): void;
- backdrop(backdropValue: string): void;
- classes(customCssClasses: string): void;
- setIcons(icons: BootboxIcons): void;
- setLocale(localeName: string): void;
- addLocale(localeName: string, translations: BootboxLocale) : void;
-}
-
+// Type definitions for Bootbox 3.0.0
+// Project: https://github.com/makeusabrew/bootbox
+// Definitions by: Vincent Bortone <https://github.com/vbortone/>
+// Definitions: https://github.com/borisyankov/DefinitelyTyped
+
+interface BootboxLocale {
+ OK: string;
+ CANCEL: string;
+ CONFIRM: string;
+}
+
+interface BootboxIcons {
+ OK: any;
+ CANCEL: any;
+ CONFIRM: any;
+}
+
+interface BootboxHandler {
+ label: string;
+ class: string;
+ callback: (result?: any) => void;
+}
+
+interface BootboxOption {
+ header: string;
+ headerCloseButton: bool;
+}
+
+interface BootboxStatic {
+ alert(message: string, callback: () => void): void;
+ alert(message: string, customButtonText?: string, callback?: () => void): void;
+ confirm(message: string, callback: (result: bool) => void): void;
+ confirm(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: bool) => void): void;
+ prompt(message: string, callback: (result: string) => void, defaultValue?: string): void;
+ prompt(message: string, cancelButtonText?: string, confirmButtonText?: string, callback?: (result: string) => void, defaultValue?: string): void;
+ dialog(message: string, handlers?: BootboxHandler[], options?: any): void;
+ dialog(message: string, handler?: BootboxHandler): void;
+ hideAll(): void;
+ animate(shouldAnimate: bool): void;
+ backdrop(backdropValue: string): void;
+ classes(customCssClasses: string): void;
+ setIcons(icons: BootboxIcons): void;
+ setLocale(localeName: string): void;
+ addLocale(localeName: string, translations: BootboxLocale) : void;
+}
+
declare var bootbox : BootboxStatic;

0 comments on commit 5aa600b

Please sign in to comment.