This repository has been archived by the owner on Aug 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from felixmosh/generate-link-ondemand
Improvement: Generate recaptcha script on demand. closes #175
- Loading branch information
Showing
7 changed files
with
264 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function ProviderDriver() { | ||
var _this = this; | ||
var mockModules = { | ||
$window: {} | ||
}; | ||
|
||
module(mockModules); // mock all the properties | ||
|
||
this.given = { | ||
recaptchaLoaded: function (recaptchaMock) { | ||
mockModules.$window.grecaptcha = recaptchaMock; | ||
return _this; | ||
} | ||
}; | ||
|
||
this.when = { | ||
created: function () { | ||
module(function (vcRecaptchaServiceProvider) { | ||
_this.provider = vcRecaptchaServiceProvider; | ||
}); | ||
|
||
inject(); // needed for angular-mocks to kick off | ||
|
||
return _this; | ||
}, | ||
callingCreate: function () { | ||
inject(function (vcRecaptchaService, $rootScope) { | ||
vcRecaptchaService.create(null, {}); | ||
$rootScope.$digest(); | ||
}); | ||
|
||
return this; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
describe('provider', function () { | ||
'use strict'; | ||
|
||
var driver, | ||
recaptchaMock, | ||
key; | ||
|
||
beforeEach(module('vcRecaptcha')); | ||
|
||
beforeEach(function () { | ||
driver = new ProviderDriver(); | ||
driver.given.recaptchaLoaded(recaptchaMock = jasmine.createSpyObj('recaptchaMock', ['render'])) | ||
.when.created(); | ||
|
||
driver.provider.setSiteKey(key = '1234567890123456789012345678901234567890'); | ||
}); | ||
|
||
it('should setDefaults', function () { | ||
var modifiedKey = key.substring(0, 39) + 'x'; | ||
|
||
driver.provider.setDefaults({key: modifiedKey}); | ||
|
||
driver.when.callingCreate(); | ||
|
||
var callArgs = recaptchaMock.render.calls.mostRecent().args[1]; | ||
|
||
expect(callArgs).toEqual(jasmine.objectContaining({sitekey: modifiedKey})); | ||
}); | ||
|
||
it('should setSiteKey', function () { | ||
driver.provider.setSiteKey(key); | ||
|
||
driver.when.callingCreate(); | ||
|
||
var callArgs = recaptchaMock.render.calls.mostRecent().args[1]; | ||
|
||
expect(callArgs).toEqual(jasmine.objectContaining({sitekey: key})); | ||
}); | ||
|
||
it('should setTheme', function () { | ||
var theme = 'theme'; | ||
driver.provider.setTheme(theme); | ||
|
||
driver.when.callingCreate(); | ||
|
||
var callArgs = recaptchaMock.render.calls.mostRecent().args[1]; | ||
|
||
expect(callArgs).toEqual(jasmine.objectContaining({theme: theme})); | ||
}); | ||
|
||
it('should setStoken', function () { | ||
var stoken = 'stoken'; | ||
driver.provider.setStoken(stoken); | ||
|
||
driver.when.callingCreate(); | ||
|
||
var callArgs = recaptchaMock.render.calls.mostRecent().args[1]; | ||
|
||
expect(callArgs).toEqual(jasmine.objectContaining({stoken: stoken})); | ||
}); | ||
|
||
it('should setSize', function () { | ||
var size = 'size'; | ||
driver.provider.setSize(size); | ||
|
||
driver.when.callingCreate(); | ||
|
||
var callArgs = recaptchaMock.render.calls.mostRecent().args[1]; | ||
|
||
expect(callArgs).toEqual(jasmine.objectContaining({size: size})); | ||
}); | ||
|
||
it('should setType', function () { | ||
var type = 'type'; | ||
driver.provider.setType(type); | ||
|
||
driver.when.callingCreate(); | ||
|
||
var callArgs = recaptchaMock.render.calls.mostRecent().args[1]; | ||
|
||
expect(callArgs).toEqual(jasmine.objectContaining({type: type})); | ||
}); | ||
|
||
it('should setLang', function () { | ||
var lang = 'en'; | ||
driver.provider.setLang(lang); | ||
|
||
driver.when.callingCreate(); | ||
|
||
var callArgs = recaptchaMock.render.calls.mostRecent().args[1]; | ||
|
||
expect(callArgs).toEqual(jasmine.objectContaining({hl: lang})); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function ServiceDriver() { | ||
var _this = this; | ||
var mockModules = { | ||
$window: {}, | ||
$document: {} | ||
}; | ||
|
||
module(mockModules); // mock all the properties | ||
|
||
this.given = { | ||
apiLoaded: function (mockRecaptcha) { | ||
mockModules.$window.grecaptcha = mockRecaptcha; | ||
|
||
return _this; | ||
}, | ||
onLoadFunctionName: function (funcName) { | ||
module(function (vcRecaptchaServiceProvider) { | ||
vcRecaptchaServiceProvider.setOnLoadFunctionName(funcName); | ||
}); | ||
return _this; | ||
}, | ||
mockDocument: function (mockDocument) { | ||
mockModules.$document.get = mockDocument.get; | ||
|
||
return _this; | ||
} | ||
}; | ||
|
||
this.when = { | ||
created: function () { | ||
inject(function (vcRecaptchaService) { | ||
_this.service = vcRecaptchaService; | ||
}) | ||
}, | ||
notifyThatApiLoaded: function () { | ||
mockModules.$window.vcRecaptchaApiLoaded(); | ||
return _this; | ||
} | ||
}; | ||
} | ||
|
||
ServiceDriver.prototype.applyChanges = function () { | ||
inject(function ($rootScope) { | ||
$rootScope.$digest(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters