Skip to content

Commit

Permalink
Merge branch 'master' into iamrisk-3591
Browse files Browse the repository at this point in the history
  • Loading branch information
TSLarson authored Jul 3, 2024
2 parents 93fca5e + 70c1872 commit 6a1e23e
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`Arkose should match the snapshot 1`] = `
>
<div
className="auth0-lock-arkose"
id=""
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`Auth0 V2 should match the snapshot 1`] = `
>
<div
className="auth0-lock-auth0-v2"
id=""
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`friendly captcha should match the snapshot 1`] = `
>
<div
className="auth0-lock-friendly-captcha"
id=""
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`hCaptcha should match the snapshot 1`] = `
>
<div
className="auth0-lock-hcaptcha"
id="h-captcha"
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`Recaptcha Enterprise should match the snapshot 1`] = `
>
<div
className="auth0-lock-recaptchav2"
id=""
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`Recaptcha v2 should match the snapshot 1`] = `
>
<div
className="auth0-lock-recaptchav2"
id=""
/>
</div>
`;
12 changes: 11 additions & 1 deletion src/__tests__/field/captcha/third_party_captcha.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,24 @@ describe('ThirdPartyCaptcha', () => {
});

it('should call render with the correct renderParams', () => {
const renderParams = global.window.hcaptcha.render.mock.calls[0][1];
const renderCalls = global.window.hcaptcha.render.mock.calls;
const renderParams = renderCalls[0][1];
expect(renderParams).toEqual({
sitekey: 'mySiteKey',
callback: expect.any(Function),
'expired-callback': expect.any(Function),
'error-callback': expect.any(Function)
});
expect(renderCalls.length).toEqual(1);
});

it('should call render on update', () => {
act(() => {
wrapper.setState();
const renderCalls = global.window.hcaptcha.render.mock.calls;
expect(renderCalls.length).toEqual(1);
})
})
});

describe('auth0_v2', () => {
Expand Down
14 changes: 13 additions & 1 deletion src/field/captcha/third_party_captcha.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ const providerDomPrefix = (provider) => {
}
};

const providerComponentId = (provider) => {
if (provider === HCAPTCHA_PROVIDER) {
return 'h-captcha';
} else {
return '';
}
};

const loadScript = (url, attributes) => {
var script = document.createElement('script');
for (var attr in attributes) {
Expand Down Expand Up @@ -301,7 +309,7 @@ export class ThirdPartyCaptcha extends React.Component {
: `auth0-lock-${providerDomPrefix(this.props.provider)}-block auth0-lock-${providerDomPrefix(this.props.provider)}-block-error`
}
>
<div className={`auth0-lock-${providerDomPrefix(this.props.provider) === 'recaptcha' ? 'recaptchav2' : providerDomPrefix(this.props.provider)}`} ref={this.ref} />
<div className={`auth0-lock-${providerDomPrefix(this.props.provider) === 'recaptcha' ? 'recaptchav2' : providerDomPrefix(this.props.provider)}`} id={providerComponentId(this.props.provider)} ref={this.ref} />
</div>
);
}
Expand All @@ -315,9 +323,13 @@ export class ThirdPartyCaptcha extends React.Component {
}

componentDidUpdate(prevProps, prevState) {
let hCaptchaComponent = document.getElementById("h-captcha");
if (prevProps.value !== this.props.value && this.props.value === '') {
this.reset();
}
if (this.props.provider === HCAPTCHA_PROVIDER && hCaptchaComponent && window[this.props.provider]) {
window[this.props.provider].render('h-captcha', this.getRenderParams());
}
}
}

Expand Down

0 comments on commit 6a1e23e

Please sign in to comment.