Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit 04b6c5a

Browse files
nicocrmgortok
authored andcommitted
Add instagram mock (#1262)
1 parent db29fba commit 04b6c5a

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

src/mocks/instagram.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @ngdoc service
3+
* @name ngCordovaMocks.cordovaInstagram
4+
*
5+
* @description
6+
* A service for testing instagram features
7+
* in an app build with ngCordova.
8+
**/
9+
ngCordovaMocks.factory('$cordovaInstagram', ['$q', function ($q) {
10+
var throwsError = false;
11+
var returnIsInstalled = true;
12+
13+
return {
14+
15+
/**
16+
* @ngdoc property
17+
* @name throwsError
18+
* @propertyOf ngCordovaMocks.cordovaInstagram
19+
*
20+
* @description
21+
* A flag that signals whether a promise should be rejected or not.
22+
* This property should only be used in automated tests.
23+
**/
24+
throwsError: throwsError,
25+
26+
/**
27+
* @ngdoc property
28+
* @name returnIsInstalled
29+
* @propertyOf ngCordovaMocks.cordovaInstagram
30+
*
31+
* @description
32+
* A flag that signals whether the mock should simulate that the instagram app
33+
* is installed or not.
34+
* This property should only be used in automated tests.
35+
**/
36+
returnIsInstalled: returnIsInstalled,
37+
38+
share: function (options) {
39+
if(this.throwsError) {
40+
return $q.reject('an error occurred');
41+
}
42+
return $q.when(true);
43+
},
44+
45+
46+
isInstalled: function () {
47+
if(this.throwsError) {
48+
return $q.reject('an error occurred');
49+
}
50+
return $q.when(this.returnIsInstalled);
51+
}
52+
}
53+
}]);

test/mocks/instagram.spec.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
describe('ngCordovaMocks', function() {
2+
beforeEach(function() {
3+
module('ngCordovaMocks');
4+
});
5+
6+
describe('cordovaInstagram', function () {
7+
var $rootScope = null;
8+
var $cordovaInstagram = null;
9+
var shareOptions = {};
10+
11+
beforeEach(inject(function (_$cordovaInstagram_, _$rootScope_) {
12+
$cordovaInstagram = _$cordovaInstagram_;
13+
$rootScope = _$rootScope_;
14+
}));
15+
16+
it('should share', function (done) {
17+
$cordovaInstagram.share(shareOptions)
18+
.then(
19+
function() { expect(true).toBe(true); },
20+
function() { expect(false).toBe(true); }
21+
)
22+
.finally(done)
23+
;
24+
25+
$rootScope.$digest();
26+
});
27+
28+
it('should throw an error while sharing.', function(done) {
29+
$cordovaInstagram.throwsError = true;
30+
$cordovaInstagram.share(shareOptions)
31+
.then(
32+
function() { expect(true).toBe(false); },
33+
function() { expect(true).toBe(true); }
34+
)
35+
.finally(done)
36+
;
37+
38+
$rootScope.$digest();
39+
});
40+
41+
it('should return is installed', function (done) {
42+
$cordovaInstagram.isInstalled()
43+
.then(
44+
function(isInstalled) { expect(isInstalled).toBe(true); },
45+
function() { expect(false).toBe(true); }
46+
)
47+
.finally(done)
48+
;
49+
50+
$rootScope.$digest();
51+
});
52+
53+
it('should throw an error while checking isInstalled.', function(done) {
54+
$cordovaInstagram.throwsError = true;
55+
$cordovaInstagram.isInstalled()
56+
.then(
57+
function() { expect(true).toBe(false); },
58+
function() { expect(true).toBe(true); }
59+
)
60+
.finally(done)
61+
;
62+
63+
$rootScope.$digest();
64+
});
65+
66+
it('should return isInstalled as false', function(done) {
67+
$cordovaInstagram.returnIsInstalled = false;
68+
$cordovaInstagram.isInstalled()
69+
.then(
70+
function(isInstalled) { expect(isInstalled).toBe(false); },
71+
function() { expect(true).toBe(true); }
72+
)
73+
.finally(done)
74+
;
75+
76+
$rootScope.$digest();
77+
});
78+
});
79+
});

0 commit comments

Comments
 (0)