Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CB-2679 Add prompt to Notification API for js

- added a native prompt method to Notification API
- added 2 jasmine unit tests for new prompt method
- note that the prompt method expects an Array for buttonLabels
  • Loading branch information...
commit bbf1562d4934b1331ffb263424b6ae054cedeb71 1 parent c6edd57
@jamesjong jamesjong authored agrieve committed
Showing with 35 additions and 0 deletions.
  1. +18 −0 lib/common/plugin/notification.js
  2. +17 −0 test/test.notification.js
View
18 lib/common/plugin/notification.js
@@ -78,6 +78,24 @@ module.exports = {
},
/**
+ * Open a native prompt dialog, with a customizable title and button text.
+ * The following results are returned to the result callback:
+ * buttonIndex Index number of the button selected.
+ * input1 The text entered in the prompt dialog box.
+ *
+ * @param {String} message Dialog message to display (default: "Prompt message")
+ * @param {Function} resultCallback The callback that is called when user clicks on a button.
+ * @param {String} title Title of the dialog (default: "Prompt")
+ * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"])
+ */
+ prompt: function(message, resultCallback, title, buttonLabels) {
+ var _message = (message || "Prompt message");
+ var _title = (title || "Prompt");
+ var _buttonLabels = (buttonLabels || ["OK","Cancel"]);
+ exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels]);
+ },
+
+ /**
* Causes the device to vibrate.
*
* @param {Integer} mills The number of milliseconds to vibrate for.
View
17 test/test.notification.js
@@ -57,6 +57,23 @@ describe("notification", function () {
});
});
+ describe("when prompting", function () {
+ it("defaults the title to Prompt, the message to Prompt message and the buttons to OK,Cancel", function () {
+ notification.prompt();
+ expect(exec).toHaveBeenCalledWith(
+ undefined, null, "Notification", "prompt",
+ ["Prompt message", "Prompt", ['OK','Cancel']]);
+ });
+
+ it("passes the provided params to the exec method", function () {
+ var cb = jasmine.createSpy();
+ notification.prompt("baby prompt me one more time!", cb, "oh baby baby", ["Yes", "No"]);
+ expect(exec).toHaveBeenCalledWith(
+ cb, null, "Notification", "prompt",
+ ["baby prompt me one more time!", "oh baby baby", ['Yes','No']]);
+ });
+ });
+
it("causes the device to vibrate", function () {
notification.vibrate(1000);
expect(exec).toHaveBeenCalledWith(

0 comments on commit bbf1562

Please sign in to comment.
Something went wrong with that request. Please try again.