Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better code coverage for blackberry qnx unit tests

  • Loading branch information...
commit fdfefbf243bf0fac2d0540aec6be04dfc65c22e9 1 parent 53110dc
@gtanner gtanner authored
View
196 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 () {
});
});
});
-
});
View
2  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'),
View
4 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"
});
-
});
});
-
-
});
View
16 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));
});
});
-
});
Please sign in to comment.
Something went wrong with that request. Please try again.