Cordova plugin unit tests [Device, NetworkStatus]

Reviewed by Bryan Higgins <[email protected]>
Tested by Tracy Li <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/eb75c14b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/eb75c14b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/eb75c14b

Branch: refs/heads/master
Commit: eb75c14b71da3228a3d9929aab3886b24ea5a90a
Parents: c42ba50
Author: jkeshavarzi <[email protected]>
Authored: Fri Mar 22 10:17:48 2013 -0400
Committer: Bryan Higgins <[email protected]>
Committed: Fri May 3 10:13:29 2013 -0400

----------------------------------------------------------------------
 .../project/plugins/NetworkStatus/index.js         |    4 +-
 blackberry10/bin/test/plugins/Device/index.js      |   68 +++++++++
 .../bin/test/plugins/NetworkStatus/index.js        |  109 +++++++++++++++
 blackberry10/scripts/test.js                       |    3 +-
 4 files changed, 181 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/eb75c14b/blackberry10/bin/templates/project/plugins/NetworkStatus/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/NetworkStatus/index.js 
b/blackberry10/bin/templates/project/plugins/NetworkStatus/index.js
index f96efe9..ae6cdf2 100644
--- a/blackberry10/bin/templates/project/plugins/NetworkStatus/index.js
+++ b/blackberry10/bin/templates/project/plugins/NetworkStatus/index.js
@@ -44,8 +44,8 @@ function mapConnectionType(con) {
 function currentConnectionType() {
     try {
         //possible for webplatform to throw pps exception
-        return mapConnectionType(qnx.webplatform.device.activeConnection || { 
type : 'none' });
-    } 
+        return 
mapConnectionType(window.qnx.webplatform.device.activeConnection || { type : 
'none' });
+    }
     catch (e) {
         return 'unknown';
     }

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/eb75c14b/blackberry10/bin/test/plugins/Device/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/plugins/Device/index.js 
b/blackberry10/bin/test/plugins/Device/index.js
new file mode 100644
index 0000000..bdfcfa4
--- /dev/null
+++ b/blackberry10/bin/test/plugins/Device/index.js
@@ -0,0 +1,68 @@
+/*
+* Copyright 2013 Research In Motion Limited.
+*
+* Licensed 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.
+*/
+var _apiDir = __dirname + "./../../../templates/project/plugins/Device/",
+index;
+
+describe("Device", function () {
+    beforeEach(function () {
+        index = require(_apiDir + "index");
+    });
+
+    afterEach(function () {
+        index = null;
+    });
+
+    describe("getDeviceInfo", function () {
+        beforeEach(function () {
+            GLOBAL.window = {
+                qnx: {
+                    webplatform: {
+                        device: {
+                        }
+                    }
+                }
+            };
+        });
+
+        afterEach(function () {
+            delete GLOBAL.window;
+        });
+
+        it("calls success with the Device info", function () {
+            var mockedDevice = {
+                scmBundle: "1.0.0.0",
+                modelName: "q10",
+                devicePin: (new Date()).getTime()
+            },
+            success = jasmine.createSpy().andCallFake(function (deviceInfo) {
+                expect(deviceInfo.platform).toEqual("blackberry10");
+                expect(deviceInfo.version).toEqual(mockedDevice.scmBundle);
+                expect(deviceInfo.model).toEqual(mockedDevice.modelName);
+                expect(deviceInfo.name).toEqual(mockedDevice.modelName);
+                expect(deviceInfo.uuid).toEqual(mockedDevice.devicePin);
+                expect(deviceInfo.cordova).toBeDefined();
+            }),
+            fail = jasmine.createSpy();
+
+            window.qnx.webplatform.device = mockedDevice;
+
+            index.getDeviceInfo(success, fail);
+
+            expect(success).toHaveBeenCalled();
+            expect(fail).not.toHaveBeenCalled();
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/eb75c14b/blackberry10/bin/test/plugins/NetworkStatus/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/plugins/NetworkStatus/index.js 
b/blackberry10/bin/test/plugins/NetworkStatus/index.js
new file mode 100644
index 0000000..87f6f0b
--- /dev/null
+++ b/blackberry10/bin/test/plugins/NetworkStatus/index.js
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 Research In Motion Limited.
+*
+* Licensed 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.
+*/
+var _apiDir = __dirname + 
"./../../../templates/project/plugins/NetworkStatus/",
+index;
+
+describe("NetworkStatus", function () {
+    beforeEach(function () {
+        index = require(_apiDir + "index");
+    });
+
+    afterEach(function () {
+        index = null;
+    });
+
+    describe("getConnectionInfo", function () {
+        beforeEach(function () {
+            GLOBAL.window = {
+                qnx: {
+                    webplatform: {
+                        device: {
+                        }
+                    }
+                }
+            };
+        });
+
+        afterEach(function () {
+            delete GLOBAL.window;
+        });
+
+        function testConnection(expectedResult, mockedType, mockedTechnology) {
+            var mockedDevice = {
+                activeConnection: {
+                    type: mockedType,
+                    technology: mockedTechnology
+                }
+            },
+            success = jasmine.createSpy(),
+            fail = jasmine.createSpy();
+
+            if (mockedType) {
+                window.qnx.webplatform.device = mockedDevice;
+            }
+
+            index.getConnectionInfo(success, fail);
+
+            expect(success).toHaveBeenCalledWith(expectedResult);
+            expect(fail).not.toHaveBeenCalled();
+        }
+
+        it("calls success with a wired connection", function () {
+            testConnection("ethernet", "wired");
+        });
+
+        it("calls success with a wifi connection", function () {
+            testConnection("wifi", "wifi");
+        });
+
+        it("calls success with no connection", function () {
+            testConnection("none", "none");
+        });
+
+        it("calls success with a cellular edge connection", function () {
+            testConnection("2g", "cellular", "edge");
+        });
+
+        it("calls success with a cellular gsm connection", function () {
+            testConnection("2g", "cellular", "gsm");
+        });
+
+        it("calls success with a cellular evdo connection", function () {
+            testConnection("3g", "cellular", "evdo");
+        });
+
+        it("calls success with a cellular umts connection", function () {
+            testConnection("3g", "cellular", "umts");
+        });
+
+        it("calls success with a lte connection", function () {
+            testConnection("4g", "cellular", "lte");
+        });
+
+        it("calls success with a cellular connection", function () {
+            testConnection("cellular", "cellular");
+        });
+
+        it("defaults to none if no connection is found", function () {
+            testConnection("none");
+        });
+
+        it("defaults to unknown if connection type doesn't exist", function () 
{
+            testConnection("unknown", "fakeConnectionType");
+        });
+
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/eb75c14b/blackberry10/scripts/test.js
----------------------------------------------------------------------
diff --git a/blackberry10/scripts/test.js b/blackberry10/scripts/test.js
index e8d1e3f..05408c1 100644
--- a/blackberry10/scripts/test.js
+++ b/blackberry10/scripts/test.js
@@ -25,7 +25,8 @@ module.exports = function (done, custom) {
         specs = [
             "framework/test",
             "bin/test/cordova/integration",
-            "bin/test/cordova/unit"
+            "bin/test/cordova/unit",
+            "bin/test/plugins"
         ];
         key = {};
 

Reply via email to