diff --git a/src/recaptcha-wrapper.js b/src/recaptcha-wrapper.js index 5bedb2f..eeab57d 100644 --- a/src/recaptcha-wrapper.js +++ b/src/recaptcha-wrapper.js @@ -11,5 +11,5 @@ const globalName = "grecaptcha"; export default makeAsyncScriptLoader(ReCAPTCHA, URL, { callbackName: callbackName, globalName: globalName, - exposeFuncs: ["getValue", "reset"], + exposeFuncs: ["getValue", "reset", "execute"], }); diff --git a/src/recaptcha.js b/src/recaptcha.js index 400e978..ac71b7d 100644 --- a/src/recaptcha.js +++ b/src/recaptcha.js @@ -10,7 +10,7 @@ const ReCAPTCHA = React.createClass({ type: PropTypes.oneOf(["image", "audio"]), tabindex: PropTypes.number, onExpired: PropTypes.func, - size: PropTypes.oneOf(["compact", "normal"]), + size: PropTypes.oneOf(["compact", "normal", "invisible"]), stoken: PropTypes.string, }, @@ -34,6 +34,15 @@ const ReCAPTCHA = React.createClass({ return null; }, + execute() { + const { grecaptcha } = this.props; + const { widgetId } = this.state; + + if (grecaptcha && widgetId !== undefined) { + return grecaptcha.execute(widgetId); + } + }, + reset() { if (this.props.grecaptcha && this.state.widgetId !== undefined) { this.props.grecaptcha.reset(this.state.widgetId); diff --git a/test/recaptcha-spec.js b/test/recaptcha-spec.js index 707b9c9..a38109c 100644 --- a/test/recaptcha-spec.js +++ b/test/recaptcha-spec.js @@ -4,55 +4,71 @@ import ReactTestUtils from "react-addons-test-utils"; import ReCAPTCHA from "../src/recaptcha"; describe("ReCAPTCHA", () => { - it("Rendered Component should be a div", () => { - let instance = ReactTestUtils.renderIntoDocument( - - ); - assert.equal(ReactDOM.findDOMNode(instance).nodeName, "DIV"); - }); - it("Rendered Component should contained passed props", () => { - let props = { - className: "TheClassName", - id: "superdefinedId", - }; - let instance = ReactTestUtils.renderIntoDocument( - - ); - assert.equal(ReactDOM.findDOMNode(instance).id, props.id); - assert.match(ReactDOM.findDOMNode(instance).className, new RegExp(props.className)); - }); + it("Rendered Component should be a div", () => { + let instance = ReactTestUtils.renderIntoDocument( + + ); + assert.equal(ReactDOM.findDOMNode(instance).nodeName, "DIV"); + }); + it("Rendered Component should contained passed props", () => { + let props = { + className: "TheClassName", + id: "superdefinedId", + }; + let instance = ReactTestUtils.renderIntoDocument( + + ); + assert.equal(ReactDOM.findDOMNode(instance).id, props.id); + assert.match(ReactDOM.findDOMNode(instance).className, new RegExp(props.className)); + }); - it("should call grecaptcha.render, when it is already loaded", (done) => { - let grecaptchaMock = { - render(node, options) { - assert.isNotNull(node); - assert.equal(options.sitekey, "xxx"); - done(); - }, - }; - let instance = ReactTestUtils.renderIntoDocument( - - ); - assert.ok(instance); - }); - it("reset, should call grecaptcha.reset with the widget id", (done) => { - let grecaptchaMock = { - render() { - return "someWidgetId"; - }, + it("should call grecaptcha.render, when it is already loaded", (done) => { + let grecaptchaMock = { + render(node, options) { + assert.isNotNull(node); + assert.equal(options.sitekey, "xxx"); + done(); + }, + }; + let instance = ReactTestUtils.renderIntoDocument( + + ); + assert.ok(instance); + }); + it("reset, should call grecaptcha.reset with the widget id", (done) => { + let grecaptchaMock = { + render() { + return "someWidgetId"; + }, - reset(widgetId) { - assert.isNotNull(widgetId); - done(); - }, - }; - let instance = ReactTestUtils.renderIntoDocument( - - ); - instance.reset(); - }); - describe("Expired", () => { - it("should call onChange with null when response is expired"); - it("should call onExpired when response is expired"); - }); + reset(widgetId) { + assert.isNotNull(widgetId); + done(); + }, + }; + let instance = ReactTestUtils.renderIntoDocument( + + ); + instance.reset(); + }); + it("execute, should call grecaptcha.execute with the widget id", (done) => { + let grecaptchaMock = { + render() { + return "someWidgetId"; + }, + + execute(widgetId) { + assert.isNotNull(widgetId); + done(); + }, + }; + let instance = ReactTestUtils.renderIntoDocument( + + ); + instance.execute(); + }); + describe("Expired", () => { + it("should call onChange with null when response is expired"); + it("should call onExpired when response is expired"); + }); });