overleaf/services/web/test/frontend/shared/hooks/use-recaptcha.spec.tsx
Tim Down e60885aa88 Merge pull request #19347 from overleaf/td-bs5-cypress-css
Move CSS loading in Cypress to individual test spec files

GitOrigin-RevId: 92bb5167cfa81b0bd54acc724efb23b397421ccb
2024-07-25 08:05:16 +00:00

38 lines
1 KiB
TypeScript

import '../../helpers/bootstrap-3'
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')
})
})