|
| 1 | +describe('ngCordovaMocks', function() { |
| 2 | + |
| 3 | + beforeEach(function() { |
| 4 | + module('ngCordovaMocks'); |
| 5 | + }); |
| 6 | + |
| 7 | + describe('webIntent', function () { |
| 8 | + var $webIntent = null; |
| 9 | + var $rootScope = null; |
| 10 | + var spy = {}; |
| 11 | + |
| 12 | + //beforeEach(module('ngCordova.plugins.webIntent')); |
| 13 | + |
| 14 | + beforeEach(inject(function (_$webIntent_, _$rootScope_) { |
| 15 | + $webIntent = _$webIntent_; |
| 16 | + $rootScope = _$rootScope_; |
| 17 | + |
| 18 | + spy.success = jasmine.createSpy('success'); |
| 19 | + spy.fail = function() {};//jasmine.createSpy('fail'); |
| 20 | + |
| 21 | + spyOn(spy, 'fail').and.callThrough(); |
| 22 | + })); |
| 23 | + |
| 24 | + it('should return actionSend on actionSend', function() { |
| 25 | + expect($webIntent.actionSend()).toBe("actionSend"); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should return actionView on actionView', function() { |
| 29 | + expect($webIntent.actionView()).toBe("actionView"); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should return extraText on extraText', function() { |
| 33 | + expect($webIntent.extraText()).toBe("extraText"); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should return extraSubject on extraSubject', function() { |
| 37 | + expect($webIntent.extraSubject()).toBe("extraSubject"); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should return extraStream on extraStream', function() { |
| 41 | + expect($webIntent.extraStream()).toBe("extraStream"); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should return extraEmail on extraEmail', function() { |
| 45 | + expect($webIntent.extraEmail()).toBe("extraEmail"); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should return actionCall on actionCall', function() { |
| 49 | + expect($webIntent.actionCall()).toBe("actionCall"); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should return actionSendTo on actionSendTo', function() { |
| 53 | + expect($webIntent.actionSendTo()).toBe("actionSendTo"); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('startActivity', function() { |
| 57 | + it('should call the success callback', function(done) { |
| 58 | + $webIntent.startActivity("myFile") |
| 59 | + .then(spy.success).catch(spy.fail).then(function() { |
| 60 | + expect(spy.success).toHaveBeenCalled(); |
| 61 | + expect(spy.fail).not.toHaveBeenCalled(); |
| 62 | + }).finally(done); |
| 63 | + |
| 64 | + $rootScope.$apply(); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should call the fail callback', function(done) { |
| 68 | + $webIntent.throwsError = true; |
| 69 | + $webIntent.startActivity("myFile") |
| 70 | + .then(spy.success).catch(spy.fail).then(function() { |
| 71 | + expect(spy.fail).toHaveBeenCalled(); |
| 72 | + expect(spy.success).not.toHaveBeenCalled(); |
| 73 | + }).finally(done); |
| 74 | + $rootScope.$apply(); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + describe('hasExtra', function() { |
| 79 | + it('should call the success callback', function(done) { |
| 80 | + $webIntent.hasExtra("extraText") |
| 81 | + .then(spy.success).catch(spy.fail).then(function() { |
| 82 | + expect(spy.success).toHaveBeenCalledWith($webIntent.has); |
| 83 | + expect(spy.fail).not.toHaveBeenCalled(); |
| 84 | + }).finally(done); |
| 85 | + |
| 86 | + $rootScope.$apply(); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should call the fail callback', function(done) { |
| 90 | + $webIntent.throwsError = true; |
| 91 | + $webIntent.hasExtra("extraText") |
| 92 | + .then(spy.success).catch(spy.fail).then(function() { |
| 93 | + expect(spy.fail).toHaveBeenCalled(); |
| 94 | + expect(spy.success).not.toHaveBeenCalled(); |
| 95 | + }).finally(done); |
| 96 | + $rootScope.$apply(); |
| 97 | + }); |
| 98 | + }); |
| 99 | + |
| 100 | + describe('getExtra', function() { |
| 101 | + it('should call the success callback', function(done) { |
| 102 | + $webIntent.getExtra("extraText") |
| 103 | + .then(spy.success).catch(spy.fail).then(function() { |
| 104 | + expect(spy.success).toHaveBeenCalledWith($webIntent.url); |
| 105 | + expect(spy.fail).not.toHaveBeenCalled(); |
| 106 | + }).finally(done); |
| 107 | + |
| 108 | + $rootScope.$apply(); |
| 109 | + }); |
| 110 | + |
| 111 | + it('should call the fail callback', function(done) { |
| 112 | + $webIntent.throwsError = true; |
| 113 | + $webIntent.getExtra("extraText") |
| 114 | + .then(spy.success).catch(spy.fail).then(function() { |
| 115 | + expect(spy.fail).toHaveBeenCalled(); |
| 116 | + expect(spy.success).not.toHaveBeenCalled(); |
| 117 | + }).finally(done); |
| 118 | + $rootScope.$apply(); |
| 119 | + }); |
| 120 | + }); |
| 121 | + |
| 122 | + describe('getUri', function() { |
| 123 | + it('should call the success callback', function(done) { |
| 124 | + $webIntent.getUri() |
| 125 | + .then(spy.success).catch(spy.fail).then(function() { |
| 126 | + expect(spy.success).toHaveBeenCalledWith($webIntent.url); |
| 127 | + expect(spy.fail).not.toHaveBeenCalled(); |
| 128 | + }).finally(done); |
| 129 | + |
| 130 | + $rootScope.$apply(); |
| 131 | + }); |
| 132 | + |
| 133 | + it('should call the fail callback', function(done) { |
| 134 | + $webIntent.throwsError = true; |
| 135 | + $webIntent.getUri() |
| 136 | + .then(spy.success).catch(spy.fail).then(function() { |
| 137 | + expect(spy.fail).toHaveBeenCalled(); |
| 138 | + expect(spy.success).not.toHaveBeenCalled(); |
| 139 | + }).finally(done); |
| 140 | + $rootScope.$apply(); |
| 141 | + }); |
| 142 | + }); |
| 143 | + |
| 144 | + describe('onNewIntent', function() { |
| 145 | + it('should call the success callback', function() { |
| 146 | + $webIntent.onNewIntent(spy.success); |
| 147 | + $webIntent.newIntent(); |
| 148 | + |
| 149 | + expect(spy.success).toHaveBeenCalled(); |
| 150 | + }); |
| 151 | + }); |
| 152 | + |
| 153 | + describe('sendBroadcast', function() { |
| 154 | + it('should call the success callback', function(done) { |
| 155 | + $webIntent.sendBroadcast() |
| 156 | + .then(spy.success).catch(spy.fail).then(function() { |
| 157 | + expect(spy.success).toHaveBeenCalled(); |
| 158 | + expect(spy.fail).not.toHaveBeenCalled(); |
| 159 | + }).finally(done); |
| 160 | + |
| 161 | + $rootScope.$apply(); |
| 162 | + }); |
| 163 | + |
| 164 | + it('should call the fail callback', function(done) { |
| 165 | + $webIntent.throwsError = true; |
| 166 | + $webIntent.sendBroadcast() |
| 167 | + .then(spy.success).catch(spy.fail).then(function() { |
| 168 | + expect(spy.fail).toHaveBeenCalled(); |
| 169 | + expect(spy.success).not.toHaveBeenCalled(); |
| 170 | + }).finally(done); |
| 171 | + $rootScope.$apply(); |
| 172 | + }); |
| 173 | + }); |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + }); |
| 178 | +}); |
0 commit comments