Unit testing blackberry specific platform code - added tests for qnx manager - added tests for blackberry exec - added symlink for blackberry exec - added a platform for the test platform
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/97995336 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/97995336 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/97995336 Branch: refs/heads/master Commit: 97995336f692cdec462388209fb328dce78fb7a0 Parents: e67e1a8 Author: Gord Tanner <[email protected]> Authored: Wed Nov 7 14:54:17 2012 -0500 Committer: Gord Tanner <[email protected]> Committed: Wed Nov 7 14:54:17 2012 -0500 ---------------------------------------------------------------------- lib/blackberry/exec.js | 1 - lib/test/blackberryexec.js | 1 + lib/test/platform.js | 27 +++++ test/blackberry/qnx/test.manager.js | 56 ++++++++++ test/blackberry/test.exec.js | 162 ++++++++++++++++++++++++++++++ 5 files changed, 246 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/97995336/lib/blackberry/exec.js ---------------------------------------------------------------------- diff --git a/lib/blackberry/exec.js b/lib/blackberry/exec.js index 8a27baf..7ef7344 100644 --- a/lib/blackberry/exec.js +++ b/lib/blackberry/exec.js @@ -54,7 +54,6 @@ module.exports = function(success, fail, service, action, args) { catch (e) { console.log("Error in success callback: "+cordova.callbackId+" = "+e); } - } return v.message; } else if (v.status == cordova.callbackStatus.NO_RESULT) { http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/97995336/lib/test/blackberryexec.js ---------------------------------------------------------------------- diff --git a/lib/test/blackberryexec.js b/lib/test/blackberryexec.js new file mode 120000 index 0000000..f00795f --- /dev/null +++ b/lib/test/blackberryexec.js @@ -0,0 +1 @@ +../blackberry/exec.js \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/97995336/lib/test/platform.js ---------------------------------------------------------------------- diff --git a/lib/test/platform.js b/lib/test/platform.js new file mode 100644 index 0000000..2688ddd --- /dev/null +++ b/lib/test/platform.js @@ -0,0 +1,27 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +module.exports = { + id: "test platform", + runtime: function () {}, + initialize: function () {}, + objects: {} +}; http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/97995336/test/blackberry/qnx/test.manager.js ---------------------------------------------------------------------- diff --git a/test/blackberry/qnx/test.manager.js b/test/blackberry/qnx/test.manager.js new file mode 100644 index 0000000..5e5571a --- /dev/null +++ b/test/blackberry/qnx/test.manager.js @@ -0,0 +1,56 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +describe("blackberry qnx manager", function () { + var manager = require('cordova/plugin/qnx/manager'); + + it("calls the plugin", function () { + var device = require('cordova/plugin/qnx/device'), + win = jasmine.createSpy('win'), + fail = jasmine.createSpy('fail'), + args = {}; + + spyOn(device, "getDeviceInfo"); + + manager.exec(win, fail, "Device", "getDeviceInfo", args); + expect(device.getDeviceInfo).toHaveBeenCalledWith(args, win, fail); + }); + + it("returns the result of the plugin", function () { + var camera = require('cordova/plugin/qnx/camera'); + spyOn(camera, "takePicture").andReturn("duckface"); + expect(manager.exec(null, null, "Camera", "takePicture")).toBe("duckface"); + }); + + it("returns class not found when no plugin", function () { + expect(manager.exec(null, null, "Ruby", "method_missing")).toEqual({ + status: cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION, + message: "Class Ruby cannot be found" + }); + }); + + it("returns invalid action when no action", function () { + expect(manager.exec(null, null, "Camera", "makePonies")).toEqual({ + status: cordova.callbackStatus.INVALID_ACTION, + message: "Action not found: makePonies" + }); + }); +}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/97995336/test/blackberry/test.exec.js ---------------------------------------------------------------------- diff --git a/test/blackberry/test.exec.js b/test/blackberry/test.exec.js new file mode 100644 index 0000000..755b067 --- /dev/null +++ b/test/blackberry/test.exec.js @@ -0,0 +1,162 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +describe("blackberry exec", function () { + var exec = require('cordova/blackberryexec'), + cordova = require('cordova'); + + it("calls the managers exec for the given runtime", function () { + var platform = require('cordova/platform'), + manager = require('cordova/plugin/qnx/manager'), + win = jasmine.createSpy("win"), + fail = jasmine.createSpy("fail"), + args = {}; + + spyOn(platform, "runtime").andReturn("qnx"); + spyOn(manager, "exec"); + + exec(win, fail, "foo", "bar", args); + + expect(manager.exec).toHaveBeenCalledWith(win, fail, "foo", "bar", args); + }); + + describe("when the callback status is ok", function () { + var platform = require('cordova/platform'), + manager = require('cordova/plugin/qnx/manager'); + + beforeEach(function () { + spyOn(platform, "runtime").andReturn("qnx"); + spyOn(manager, "exec").andReturn({ + status: cordova.callbackStatus.OK, + message: "sometimes I drink from the milk carton" + }); + }); + + it("returns the message", function () { + expect(exec(null, null)).toBe("sometimes I drink from the milk carton"); + }); + + it("calls the success callback with the message", function () { + var success = jasmine.createSpy("success"); + exec(success); + expect(success).toHaveBeenCalledWith("sometimes I drink from the milk carton"); + }); + + it("doesn't call the error callback", function () { + var error = jasmine.createSpy("error"); + exec(null, error); + expect(error).not.toHaveBeenCalled(); + }); + + it("logs any errors from the success callback", function () { + spyOn(console, "log"); + + var success = jasmine.createSpy("success").andThrow("oh noes!"); + cordova.callbackId = 1; + exec(success); + + expect(console.log).toHaveBeenCalledWith("Error in success callback: 1 = oh noes!"); + }); + + it("still returns the message even if there was an exception in success", function () { + spyOn(console, "log"); + var success = jasmine.createSpy("success").andThrow("oh noes!"); + expect(exec(success)).toBe("sometimes I drink from the milk carton"); + }); + }); + + describe("when the callback status is no_result", function () { + var platform = require('cordova/platform'), + manager = require('cordova/plugin/qnx/manager'); + + beforeEach(function () { + spyOn(platform, "runtime").andReturn("qnx"); + spyOn(manager, "exec").andReturn({ + status: cordova.callbackStatus.NO_RESULT, + message: "I know what you did last summer" + }); + }); + + it("returns undefined", function () { + expect(exec()).not.toBeDefined(); + }); + + it("doesn't call the success callback", function () { + var success = jasmine.createSpy("success"); + exec(success); + expect(success).not.toHaveBeenCalled(); + }); + + it("doesn't call the error callback", function () { + var error = jasmine.createSpy("error"); + exec(null, error); + expect(error).not.toHaveBeenCalled(); + }); + }); + + describe("when the callback status is anything else", function () { + var platform = require('cordova/platform'), + manager = require('cordova/plugin/qnx/manager'); + + beforeEach(function () { + spyOn(console, "log"); + spyOn(platform, "runtime").andReturn("qnx"); + spyOn(manager, "exec").andReturn({ + status: "poop", + message: "the bed" + }); + }); + + it("returns null", function () { + expect(exec()).toBeNull(); + }); + + it("logs the status and message", function () { + exec(); + expect(console.log).toHaveBeenCalledWith("Error: Status=poop Message=the bed"); + }); + + it("calls the fail callback with the message", function () { + var fail = jasmine.createSpy("fail"); + exec(null, fail); + expect(fail).toHaveBeenCalledWith("the bed"); + }); + + it("doesn't call the success callback", function () { + var success = jasmine.createSpy("success"); + exec(success); + expect(success).not.toHaveBeenCalled(); + }); + + it("logs the exception from the error callback", function () { + var error = jasmine.createSpy("error").andThrow("aww snap"); + cordova.callbackId = 1; + exec(null, error); + + expect(console.log).toHaveBeenCalledWith("Error in error callback: 1 = aww snap"); + }); + + it("still returns null when there is an error", function () { + var error = jasmine.createSpy("error").andThrow("aww snap"); + expect(exec(null, error)).toBeNull(); + }); + }); +});
