Permalink
Browse files

More generic cleaning on event removal

  • Loading branch information...
Sergey Golod
Sergey Golod committed Apr 20, 2012
1 parent a250622 commit 4acfb29f58f595d98f6a94d07d3561f98bd8b8c0
Showing with 32 additions and 4 deletions.
  1. +8 −2 ext/blackberry.event/index.js
  2. +3 −2 lib/pps/ppsEvents.js
  3. +21 −0 test/functional/blackberry.event.js
@@ -31,8 +31,11 @@ var _event = requireLocal("lib/event"),
eventName: "StateOfCharge",
paramName: "level",
fieldValue: null,
+ reset: function () {
+ this.setFieldValue(null);
+ },
setFieldValue: function (value) {
- this.fieldValue = this.formatValue(value);
+ this.fieldValue = value ? this.formatValue(value) : value;
},
formatValue: function (str) {
return parseInt(str, 10);
@@ -68,8 +71,11 @@ var _event = requireLocal("lib/event"),
eventName: "StateOfCharge",
paramName: "level",
fieldValue: null,
+ reset: function () {
+ this.setFieldValue(null);
+ },
setFieldValue: function (value) {
- this.fieldValue = this.formatValue(value);
+ this.fieldValue = value ? this.formatValue(value) : value;
},
formatValue: function (str) {
return parseInt(str, 10);
View
@@ -118,14 +118,15 @@ module.exports = {
}
},
removeEventListener: function (eventMapObj) {
+ // When removing event listener closing all instances of ppsUtills and reseting all items of fieldNameArr array.
if (eventMapObj) {
eventMapObj.eventDetailsArr.forEach(function (eventDetailsObj) {
if (eventDetailsObj.ppsUtils) {
eventDetailsObj.ppsUtils.close();
}
eventDetailsObj.fieldNameArr.forEach(function (fieldNameObj) {
- if (fieldNameObj.setFieldValue) {
- fieldNameObj.setFieldValue(null);
+ if (fieldNameObj.reset) {
+ fieldNameObj.reset();
}
});
});
@@ -237,6 +237,27 @@ describe("blackberry.event", function () {
expect(onBatteryLow).not.toHaveBeenCalled();
});
});
+
+ it("should trigger callback for low event when re-entering threshold after adding event lister after all were removed", function () {
+
+ window.confirm("[Device]Drain the battery to level lower than 15%. [SIM]Set 'StateOfCharge' in battery PPS Object to level lower than 15%");
+ blackberry.event.removeEventListener('batterylow', onBatteryLow);
+ window.confirm("[Device]Charge the battery to level higher or equal to 15%. [SIM]Set 'StateOfCharge' in battery PPS Object to level higher or equal to 15");
+ window.confirm("[Device]Drain the battery to level lower than 15%. [SIM]Set 'StateOfCharge' in battery PPS Object to level lower than 15%");
+ blackberry.event.addEventListener('batterylow', onBatteryLow);
+
+ waitsFor(function () {
+ return onBatteryLow.callCount;
+ }, "event never fired", waitForTimeout);
+
+ runs(function () {
+ expect(onBatteryLow).toHaveBeenCalledWith(jasmine.any(Object));
+ expect(onBatteryLow.mostRecentCall.args[0].level).toBeDefined();
+ expect(onBatteryLow.mostRecentCall.args[0].isPlugged).toBeDefined();
+ });
+ });
+
+
});
describe("batterycritical", function () {

0 comments on commit 4acfb29

Please sign in to comment.