You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by gt...@apache.org on 2012/11/28 22:35:04 UTC
[2/2] js commit: Better code coverage for blackberry qnx unit tests
Better code coverage for blackberry qnx unit tests
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/fdfefbf2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/fdfefbf2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/fdfefbf2
Branch: refs/heads/master
Commit: fdfefbf243bf0fac2d0540aec6be04dfc65c22e9
Parents: 53110dc
Author: Gord Tanner <gt...@gmail.com>
Authored: Wed Nov 28 16:31:07 2012 -0500
Committer: Gord Tanner <gt...@gmail.com>
Committed: Wed Nov 28 16:34:05 2012 -0500
----------------------------------------------------------------------
test/blackberry/qnx/test.capture.js | 196 +++++++++++++++++-------
test/blackberry/qnx/test.compass.js | 2 +-
test/blackberry/qnx/test.fileTransfer.js | 4 -
test/blackberry/qnx/test.magnetometer.js | 16 +-
4 files changed, 147 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/fdfefbf2/test/blackberry/qnx/test.capture.js
----------------------------------------------------------------------
diff --git a/test/blackberry/qnx/test.capture.js b/test/blackberry/qnx/test.capture.js
index f134434..2c73f91 100644
--- a/test/blackberry/qnx/test.capture.js
+++ b/test/blackberry/qnx/test.capture.js
@@ -50,79 +50,162 @@ describe("blackberry qnx capture", function () {
});
});
- describe("captureImage", function(){
- it('should call the capture function', function(){
- var args = [{ limit: -9 }, "nothingness"],
- win = jasmine.createSpy('win'),
- fail = jasmine.createSpy('fail');
-
- capture.captureImage(args, win, fail);
- expect(win).toHaveBeenCalled();
-
- });
-
- it('should call success function', function(){
- var args = [""],
- win = jasmine.createSpy('win'),
- fail = jasmine.createSpy('fail');
-
- capture.captureImage(args, win, fail);
- expect(win).toHaveBeenCalledWith([]);
- });
-
- it('should return No Result', function(){
- var args = [""],
- win = jasmine.createSpy('win'),
- fail = jasmine.createSpy('fail');
-
- expect(capture.captureImage(args, win, fail)).toEqual({
- status: cordova.callbackStatus.NO_RESULT,
- message: "WebWorks Is On It"
+ function testCapture(method, action) {
+ describe(method, function(){
+ beforeEach(function () {
+ global.blackberry = {
+ invoke: {
+ card: {
+ invokeCamera: jasmine.createSpy('blackberry.invoke.card.invokeCamera')
+ }
+ }
+ };
});
- });
- });
- describe("captureVideo", function(){
- it('should call the capture function', function(){
- var args = [{ limit: -9 }, "nothingness"],
- win = jasmine.createSpy('win'),
- fail = jasmine.createSpy('fail');
+ afterEach(function () {
+ delete global.blackberry;
+ });
- capture.captureVideo(args, win, fail);
- expect(win).toHaveBeenCalled();
- });
+ it('should return No Result', function(){
+ var args = [{limit: 0}],
+ win = jasmine.createSpy('win'),
+ fail = jasmine.createSpy('fail');
- it('should call success function', function(){
- var args = [""],
- win = jasmine.createSpy('win'),
- fail = jasmine.createSpy('fail');
+ expect(capture[method](args, win, fail)).toEqual({
+ status: cordova.callbackStatus.NO_RESULT,
+ message: "WebWorks Is On It"
+ });
+ });
- capture.captureVideo(args, win, fail);
- expect(win).toHaveBeenCalledWith([]);
- });
+ describe("when the limit is 0 or less", function () {
+ it('calls the win callback with an empty array', function(){
+ var args = [{ limit: -9 }],
+ win = jasmine.createSpy('win'),
+ fail = jasmine.createSpy('fail');
- it('should return No Result', function(){
- var args = [""],
- win = jasmine.createSpy('win'),
- fail = jasmine.createSpy('fail');
+ capture[method](args, win, fail);
+ expect(win).toHaveBeenCalled();
+ });
+ });
- expect(capture.captureVideo(args, win, fail)).toEqual({
- status: cordova.callbackStatus.NO_RESULT,
- message: "WebWorks Is On It"
+ describe("when the limit is greater than 0", function () {
+ var win, fail;
+
+ beforeEach(function () {
+ win = jasmine.createSpy("win");
+ fail = jasmine.createSpy("fail");
+ });
+
+ it("calls the invokeCamera method", function () {
+ capture[method]([{limit: 1}], win, fail);
+ expect(blackberry.invoke.card.invokeCamera).toHaveBeenCalledWith(action,
+ jasmine.any(Function),
+ jasmine.any(Function),
+ jasmine.any(Function));
+ });
+
+ describe("inside the invokeCamera callback", function () {
+ var onsave;
+
+ beforeEach(function () {
+ window.webkitRequestFileSystem = jasmine.createSpy("window.webkitRequestFileSystem");
+ global.blackberry.io = { sandbox: true };
+
+ capture[method]([{limit: 1}], win, fail);
+ onsave = blackberry.invoke.card.invokeCamera.mostRecentCall.args[1];
+ });
+
+ afterEach(function () {
+ delete window.webkitRequestFileSystem;
+ });
+
+ it("sets the sandbox to false", function () {
+ onsave();
+ expect(blackberry.io.sandbox).toBe(false);
+ });
+
+ it("calls webkitRequestFileSystem", function () {
+ onsave();
+ expect(window.webkitRequestFileSystem).toHaveBeenCalledWith(
+ window.PERSISTENT,
+ 1024,
+ jasmine.any(Function),
+ fail);
+ });
+
+ describe("in the webkitRequestFileSystem callback", function () {
+ var callback,
+ fs = { root: { getFile: jasmine.createSpy("getFile") } };
+
+ beforeEach(function () {
+ onsave('/foo/bar/baz.gif');
+ callback = window.webkitRequestFileSystem.mostRecentCall.args[2];
+ });
+
+ it("calls getfile on the provided filesystem", function () {
+ callback(fs);
+ expect(fs.root.getFile).toHaveBeenCalledWith('/foo/bar/baz.gif',
+ {},
+ jasmine.any(Function),
+ fail);
+ });
+
+ it("calls the file method of the fileEntity", function () {
+ var fe = { file: jasmine.createSpy('file') };
+ callback(fs);
+ fs.root.getFile.mostRecentCall.args[2](fe);
+ expect(fe.file).toHaveBeenCalledWith(jasmine.any(Function), fail);
+ });
+
+ describe("in the file callback", function () {
+ var fe = {
+ file: jasmine.createSpy('file'),
+ fullPath: 'file://this/is/the/full/path/eh.png'
+ },
+ fileCB;
+
+ beforeEach(function () {
+ callback(fs);
+ fs.root.getFile.mostRecentCall.args[2](fe);
+ fileCB = fe.file.mostRecentCall.args[0];
+ });
+
+ it("sets the fullPath of the file object", function () {
+ var file = {};
+ fileCB(file);
+ expect(file.fullPath).toBe(fe.fullPath);
+ });
+
+ it("calls the win callback with an array containing the file", function () {
+ var file = {};
+ fileCB(file);
+ expect(win).toHaveBeenCalledWith([file]);
+ });
+
+ it("resets the value of blackberry.io.sandbox", function () {
+ var file = {};
+ fileCB(file);
+ expect(blackberry.io.sandbox).toBe(true);
+ });
+ });
+ });
+ });
});
});
- });
+ }
+ testCapture('captureImage', 'photo');
+ testCapture('captureVideo', 'video');
describe("captureAudio", function(){
- it('should call the audio capture', function(){
-
- var args = "arguments",
+ it('should call the fail callback', function(){
+ var args = {},
win = jasmine.createSpy('win'),
fail = jasmine.createSpy('fail');
capture.captureAudio(args, win, fail);
expect(fail).toHaveBeenCalled();
+ expect(win).not.toHaveBeenCalled();
});
it('should return no result', function(){
@@ -136,5 +219,4 @@ describe("blackberry qnx capture", function () {
});
});
});
-
});
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/fdfefbf2/test/blackberry/qnx/test.compass.js
----------------------------------------------------------------------
diff --git a/test/blackberry/qnx/test.compass.js b/test/blackberry/qnx/test.compass.js
index 445b8ff..870a0a4 100644
--- a/test/blackberry/qnx/test.compass.js
+++ b/test/blackberry/qnx/test.compass.js
@@ -19,7 +19,7 @@
*
*/
-describe("blackberry qnx compass", function () {
+xdescribe("blackberry qnx compass", function () {
var compass = require('cordova/plugin/qnx/compass'),
cordova = require('cordova'),
exec = require('cordova/exec'),
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/fdfefbf2/test/blackberry/qnx/test.fileTransfer.js
----------------------------------------------------------------------
diff --git a/test/blackberry/qnx/test.fileTransfer.js b/test/blackberry/qnx/test.fileTransfer.js
index 723e0a8..dd33f77 100644
--- a/test/blackberry/qnx/test.fileTransfer.js
+++ b/test/blackberry/qnx/test.fileTransfer.js
@@ -51,7 +51,6 @@ describe("blackberry qnx fileTransfer", function () {
status: cordova.callbackStatus.NO_RESULT,
message: "async"
});
-
});
});
@@ -67,9 +66,6 @@ describe("blackberry qnx fileTransfer", function () {
status: cordova.callbackStatus.NO_RESULT,
message: "async"
});
-
});
});
-
-
});
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/fdfefbf2/test/blackberry/qnx/test.magnetometer.js
----------------------------------------------------------------------
diff --git a/test/blackberry/qnx/test.magnetometer.js b/test/blackberry/qnx/test.magnetometer.js
index 48ded12..2f8e583 100644
--- a/test/blackberry/qnx/test.magnetometer.js
+++ b/test/blackberry/qnx/test.magnetometer.js
@@ -38,30 +38,29 @@ describe("blackberry qnx magnetometer", function () {
it('should remove the event listener', function(){
magnetometer.start();
- expect(window.removeEventListener).toHaveBeenCalled();
+ expect(window.removeEventListener).toHaveBeenCalledWith("deviceorientation", jasmine.any(Function));
});
it('should add an event listener', function(){
magnetometer.start();
- expect(window.addEventListener).toHaveBeenCalled();
+ expect(window.addEventListener).toHaveBeenCalledWith("deviceorientation", jasmine.any(Function));
});
- it('should grab the magnetometer', function(){
+ it('call the win callback with the data from the event', function(){
var win = jasmine.createSpy('win');
magnetometer.start({}, win);
window.addEventListener.mostRecentCall.args[1]({
- alpha: 0,
+ alpha: 60,
timeStamp: "bout that time, eh chap?"
});
expect(win).toHaveBeenCalledWith({
- magneticHeading: 360,
- trueHeading: 360,
+ magneticHeading: 300,
+ trueHeading: 300,
headingAccuracy: 0,
timestamp: "bout that time, eh chap?"
});
-
});
});
@@ -75,8 +74,7 @@ describe("blackberry qnx magnetometer", function () {
it('should remove the event listener', function(){
magnetometer.stop();
- expect(window.removeEventListener).toHaveBeenCalled();
+ expect(window.removeEventListener).toHaveBeenCalledWith("deviceorientation", jasmine.any(Function));
});
});
-
});