mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
687b56f18e
[web] Reset recaptcha every time GitOrigin-RevId: 6db3571ad6dad3611c748a2d92dce47002a16a77
37 lines
996 B
TypeScript
37 lines
996 B
TypeScript
import { useRecaptcha } from '@/shared/hooks/use-recaptcha'
|
|
import * as ReactGoogleRecaptcha from 'react-google-recaptcha'
|
|
|
|
const ReCaptcha = () => {
|
|
const { ref: recaptchaRef, getReCaptchaToken } = useRecaptcha()
|
|
|
|
const handleClick = async () => {
|
|
await getReCaptchaToken()
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<ReactGoogleRecaptcha.ReCAPTCHA
|
|
ref={recaptchaRef}
|
|
size="invisible"
|
|
sitekey="123456"
|
|
badge="inline"
|
|
/>
|
|
<button onClick={handleClick}>Click</button>
|
|
</>
|
|
)
|
|
}
|
|
|
|
describe('useRecaptcha', function () {
|
|
it('should reset the captcha', function () {
|
|
cy.spy(ReactGoogleRecaptcha.ReCAPTCHA.prototype, 'reset').as('resetSpy')
|
|
cy.spy(ReactGoogleRecaptcha.ReCAPTCHA.prototype, 'executeAsync').as(
|
|
'executeAsyncSpy'
|
|
)
|
|
|
|
cy.mount(<ReCaptcha />)
|
|
|
|
cy.findByRole('button', { name: /click/i }).click()
|
|
cy.get('@resetSpy').should('have.been.calledOnce')
|
|
cy.get('@executeAsyncSpy').should('have.been.calledOnce')
|
|
})
|
|
})
|