Skip to content

Commit 8160c52

Browse files
author
Adrian Marquez
committed
feat: reenable unit tests
1 parent a043278 commit 8160c52

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

src/__tests__/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Running Plugin Tests
2+
3+
1. Use your existing cordova app, or create a new one.
4+
2. Add this plugins:
5+
```
6+
cordova plugin add cordova-plugin-test-framework
7+
cordova plugin add plugins/branch-cordova-sdk/src/__tests__
8+
```
9+
3. Change the start page in `config.xml` with `<content src="cdvtests/index.html" />` or navigate to `cdvtests/index.html` from within your app.
10+
4. That's it.

src/__tests__/index.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ var _typeof =
1414
: typeof obj;
1515
};
1616

17+
var sessionInitialized = false;
18+
19+
function initSession(done) {
20+
return new Promise(function promise(resolve, reject) {
21+
if (sessionInitialized) {
22+
return resolve();
23+
}
24+
25+
window.Branch.initSession().then(function() {
26+
sessionInitialized = true;
27+
resolve();
28+
});
29+
});
30+
}
31+
1732
/**
1833
* Branch.IO Cordova Plugin Unit-Test
1934
* ----------------------------------
@@ -67,7 +82,7 @@ exports.defineAutoTests = function() {
6782

6883
describe("Branch.getLatestReferringParams()", function() {
6984
beforeEach(function(done) {
70-
window.Branch.initSession().then(function() {
85+
initSession().then(function() {
7186
done();
7287
});
7388
}, 3000);
@@ -87,7 +102,7 @@ exports.defineAutoTests = function() {
87102

88103
describe("Branch.getFirstReferringParams()", function() {
89104
beforeEach(function(done) {
90-
window.Branch.initSession().then(function() {
105+
initSession().then(function() {
91106
done();
92107
});
93108
}, 3000);
@@ -106,7 +121,7 @@ exports.defineAutoTests = function() {
106121

107122
describe("Branch.setIdentity()", function() {
108123
beforeEach(function(done) {
109-
window.Branch.initSession().then(function() {
124+
initSession().then(function() {
110125
done();
111126
});
112127
}, 3000);
@@ -128,7 +143,7 @@ exports.defineAutoTests = function() {
128143
var branchUniversalObj;
129144

130145
beforeEach(function(done) {
131-
window.Branch.initSession().then(function() {
146+
initSession().then(function() {
132147
var properties = {
133148
canonicalIdentifier: "testbed",
134149
title: "testbed",
@@ -149,9 +164,7 @@ exports.defineAutoTests = function() {
149164
"should execute register view",
150165
function(done) {
151166
branchUniversalObj.registerView().then(function(res) {
152-
expect(typeof res === "undefined" ? "undefined" : _typeof(res)).toBe(
153-
"object"
154-
);
167+
expect(typeof res).not.toBe("undefined");
155168
done();
156169
});
157170
},
@@ -192,7 +205,7 @@ exports.defineAutoTests = function() {
192205

193206
describe("Branch.userCompletedAction()", function() {
194207
beforeEach(function(done) {
195-
window.Branch.initSession().then(function() {
208+
initSession().then(function() {
196209
done();
197210
});
198211
}, 3000);
@@ -209,7 +222,7 @@ exports.defineAutoTests = function() {
209222

210223
describe("Branch.loadRewards()", function() {
211224
beforeEach(function(done) {
212-
window.Branch.initSession().then(function() {
225+
initSession().then(function() {
213226
done();
214227
});
215228
}, 3000);
@@ -237,7 +250,7 @@ exports.defineAutoTests = function() {
237250

238251
describe("Branch.redeemRewards()", function() {
239252
beforeEach(function(done) {
240-
window.Branch.initSession().then(function() {
253+
initSession().then(function() {
241254
done();
242255
});
243256
}, 3000);
@@ -265,7 +278,7 @@ exports.defineAutoTests = function() {
265278

266279
describe("Branch.creditHistory()", function() {
267280
beforeEach(function(done) {
268-
window.Branch.initSession().then(function() {
281+
initSession().then(function() {
269282
done();
270283
});
271284
}, 3000);

src/__tests__/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "branch-cordova-sdk-tests",
3+
"version": "1.0.0",
4+
"description": "Branch Metrics Cordova SDK Tests",
5+
"cordova": {
6+
"id": "branch-cordova-sdk-tests",
7+
"platforms": []
8+
},
9+
"license": "MIT"
10+
}

src/__tests__/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ SOFTWARE.
3131
<name>branch-cordova-sdk-tests</name>
3232
<license>Apache 2.0</license>
3333

34-
<js-module src="tests.js" name="tests"></js-module>
34+
<js-module src="index.js" name="tests"></js-module>
3535

3636
</plugin>

src/android/io/branch/BranchSDK.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ private void registerView(int instanceIdx, CallbackContext callbackContext) {
570570

571571
branchUniversalWrapper.branchUniversalObj.registerView(new RegisterViewStatusListener(callbackContext));
572572

573+
callbackContext.success("Success");
574+
573575
}
574576

575577
/**

0 commit comments

Comments
 (0)