Skip to content

Commit 34d5e0c

Browse files
committed
Add invisible props and execute method
1 parent cbfe092 commit 34d5e0c

3 files changed

Lines changed: 76 additions & 51 deletions

File tree

src/recaptcha-wrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ const globalName = "grecaptcha";
1111
export default makeAsyncScriptLoader(ReCAPTCHA, URL, {
1212
callbackName: callbackName,
1313
globalName: globalName,
14-
exposeFuncs: ["getValue", "reset"],
14+
exposeFuncs: ["getValue", "reset", "execute"],
1515
});

src/recaptcha.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const ReCAPTCHA = React.createClass({
1010
type: PropTypes.oneOf(["image", "audio"]),
1111
tabindex: PropTypes.number,
1212
onExpired: PropTypes.func,
13-
size: PropTypes.oneOf(["compact", "normal"]),
13+
size: PropTypes.oneOf(["compact", "normal", "invisible"]),
1414
stoken: PropTypes.string,
1515
},
1616

@@ -34,6 +34,15 @@ const ReCAPTCHA = React.createClass({
3434
return null;
3535
},
3636

37+
execute() {
38+
const { grecaptcha } = this.props;
39+
const { widgetId } = this.state;
40+
41+
if (grecaptcha && widgetId !== undefined) {
42+
return grecaptcha.execute(widgetId);
43+
}
44+
},
45+
3746
reset() {
3847
if (this.props.grecaptcha && this.state.widgetId !== undefined) {
3948
this.props.grecaptcha.reset(this.state.widgetId);

test/recaptcha-spec.js

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,71 @@ import ReactTestUtils from "react-addons-test-utils";
44
import ReCAPTCHA from "../src/recaptcha";
55

66
describe("ReCAPTCHA", () => {
7-
it("Rendered Component should be a div", () => {
8-
let instance = ReactTestUtils.renderIntoDocument(
9-
<ReCAPTCHA sitekey="xxx" />
10-
);
11-
assert.equal(ReactDOM.findDOMNode(instance).nodeName, "DIV");
12-
});
13-
it("Rendered Component should contained passed props", () => {
14-
let props = {
15-
className: "TheClassName",
16-
id: "superdefinedId",
17-
};
18-
let instance = ReactTestUtils.renderIntoDocument(
19-
<ReCAPTCHA sitekey="xxx" {...props} />
20-
);
21-
assert.equal(ReactDOM.findDOMNode(instance).id, props.id);
22-
assert.match(ReactDOM.findDOMNode(instance).className, new RegExp(props.className));
23-
});
7+
it("Rendered Component should be a div", () => {
8+
let instance = ReactTestUtils.renderIntoDocument(
9+
<ReCAPTCHA sitekey="xxx" />
10+
);
11+
assert.equal(ReactDOM.findDOMNode(instance).nodeName, "DIV");
12+
});
13+
it("Rendered Component should contained passed props", () => {
14+
let props = {
15+
className: "TheClassName",
16+
id: "superdefinedId",
17+
};
18+
let instance = ReactTestUtils.renderIntoDocument(
19+
<ReCAPTCHA sitekey="xxx" {...props} />
20+
);
21+
assert.equal(ReactDOM.findDOMNode(instance).id, props.id);
22+
assert.match(ReactDOM.findDOMNode(instance).className, new RegExp(props.className));
23+
});
2424

25-
it("should call grecaptcha.render, when it is already loaded", (done) => {
26-
let grecaptchaMock = {
27-
render(node, options) {
28-
assert.isNotNull(node);
29-
assert.equal(options.sitekey, "xxx");
30-
done();
31-
},
32-
};
33-
let instance = ReactTestUtils.renderIntoDocument(
34-
<ReCAPTCHA sitekey="xxx" grecaptcha={grecaptchaMock} />
35-
);
36-
assert.ok(instance);
37-
});
38-
it("reset, should call grecaptcha.reset with the widget id", (done) => {
39-
let grecaptchaMock = {
40-
render() {
41-
return "someWidgetId";
42-
},
25+
it("should call grecaptcha.render, when it is already loaded", (done) => {
26+
let grecaptchaMock = {
27+
render(node, options) {
28+
assert.isNotNull(node);
29+
assert.equal(options.sitekey, "xxx");
30+
done();
31+
},
32+
};
33+
let instance = ReactTestUtils.renderIntoDocument(
34+
<ReCAPTCHA sitekey="xxx" grecaptcha={grecaptchaMock} />
35+
);
36+
assert.ok(instance);
37+
});
38+
it("reset, should call grecaptcha.reset with the widget id", (done) => {
39+
let grecaptchaMock = {
40+
render() {
41+
return "someWidgetId";
42+
},
4343

44-
reset(widgetId) {
45-
assert.isNotNull(widgetId);
46-
done();
47-
},
48-
};
49-
let instance = ReactTestUtils.renderIntoDocument(
50-
<ReCAPTCHA sitekey="xxx" grecaptcha={grecaptchaMock} />
51-
);
52-
instance.reset();
53-
});
54-
describe("Expired", () => {
55-
it("should call onChange with null when response is expired");
56-
it("should call onExpired when response is expired");
57-
});
44+
reset(widgetId) {
45+
assert.isNotNull(widgetId);
46+
done();
47+
},
48+
};
49+
let instance = ReactTestUtils.renderIntoDocument(
50+
<ReCAPTCHA sitekey="xxx" grecaptcha={grecaptchaMock} />
51+
);
52+
instance.reset();
53+
});
54+
it("execute, should call grecaptcha.execute with the widget id", (done) => {
55+
let grecaptchaMock = {
56+
render() {
57+
return "someWidgetId";
58+
},
59+
60+
execute(widgetId) {
61+
assert.isNotNull(widgetId);
62+
done();
63+
},
64+
};
65+
let instance = ReactTestUtils.renderIntoDocument(
66+
<ReCAPTCHA sitekey="xxx" size="invisible" grecaptcha={grecaptchaMock} />
67+
);
68+
instance.execute();
69+
});
70+
describe("Expired", () => {
71+
it("should call onChange with null when response is expired");
72+
it("should call onExpired when response is expired");
73+
});
5874
});

0 commit comments

Comments
 (0)