Skip to content
This repository was archived by the owner on Aug 17, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
size: '=?',
type: '=?',
lang: '=?',
badge: '=?',
tabindex: '=?',
required: '=?',
onCreate: '&',
Expand Down Expand Up @@ -52,6 +53,7 @@
lang: scope.lang || attrs.lang || null,
tabindex: scope.tabindex || attrs.tabindex || null,
size: scope.size || attrs.size || null,
badge: scope.badge || attrs.badge || null,
'expired-callback': expired

}).then(function (widgetId) {
Expand Down
19 changes: 19 additions & 0 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@
config.lang = lang;
};

/**
* Sets the reCaptcha badge position which will be used by default if not specified in a specific directive instance.
*
* @param badge The reCaptcha badge position.
*/
provider.setBadge = function(badge){
config.badge = badge;
};

/**
* Sets the reCaptcha configuration values which will be used by default is not specified in a specific directive instance.
*
Expand Down Expand Up @@ -159,6 +168,7 @@
conf.size = conf.size || config.size;
conf.type = conf.type || config.type;
conf.hl = conf.lang || config.lang;
conf.badge = conf.badge || config.badge;

if (!conf.sitekey || conf.sitekey.length !== 40) {
throwNoKeyException();
Expand All @@ -182,6 +192,15 @@
$rootScope.$broadcast('reCaptchaReset', widgetId);
},

/**
* Executes the reCaptcha
*/
execute: function (widgetId) {
validateRecaptchaInstance();

recaptcha.execute(widgetId);
},

/**
* Get/Set reCaptcha language
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/provider_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,16 @@ describe('provider', function () {

expect(callArgs).toEqual(jasmine.objectContaining({hl: lang}));
});

it('should setBadge', function () {
var badge = 'bottomright';
driver.provider.setBadge(badge);

driver.when.callingCreate();

var callArgs = recaptchaMock.render.calls.mostRecent().args[1];

expect(callArgs).toEqual(jasmine.objectContaining({badge: badge}));
});

});
13 changes: 11 additions & 2 deletions tests/service_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('service', function () {

beforeEach(function () {
driver
.given.apiLoaded(grecaptchaMock = jasmine.createSpyObj('grecaptcha', ['render', 'getResponse', 'reset']))
.given.apiLoaded(grecaptchaMock = jasmine.createSpyObj('grecaptcha', ['render', 'getResponse', 'reset','execute']))
.when.created();
});

Expand All @@ -30,7 +30,8 @@ describe('service', function () {
stoken: undefined,
size: undefined,
type: undefined,
hl: undefined
hl: undefined,
badge: undefined
};

driver.when.notifyThatApiLoaded();
Expand All @@ -53,6 +54,14 @@ describe('service', function () {
expect(grecaptchaMock.reset).toHaveBeenCalledWith(_widgetId);
});

it('should call execute', function () {
var _widgetId = 123;

driver.service.execute(_widgetId);

expect(grecaptchaMock.execute).toHaveBeenCalledWith(_widgetId);
});

it('should call getResponse', function () {
var _widgetId = 123;

Expand Down