|
| 1 | +/** |
| 2 | + * |
| 3 | + * Copyright © 2026 Ping Identity Corporation. All right reserved. |
| 4 | + * |
| 5 | + * This software may be modified and distributed under the terms |
| 6 | + * of the MIT license. See the LICENSE file for details. |
| 7 | + * |
| 8 | + **/ |
| 9 | + |
| 10 | +import { FRStep, CallbackType } from '@forgerock/javascript-sdk'; |
| 11 | +import { expect, within } from 'storybook/test'; |
| 12 | + |
| 13 | +import { |
| 14 | + visibleGrecaptchaEnterprise, |
| 15 | + invisibleGrecaptchaEnterprise, |
| 16 | +} from './recaptcha-enterprise.mock'; |
| 17 | +import RecaptchaEnterprise from './recaptcha-enterprise.story.svelte'; |
| 18 | +import { captchaStore } from '$core/captcha.store'; |
| 19 | +import { journeyStore } from '$journey/journey.store'; |
| 20 | + |
| 21 | +function mockGrecaptchaEnterprise() { |
| 22 | + window.grecaptcha = { |
| 23 | + enterprise: { |
| 24 | + ready: (cb) => cb(), |
| 25 | + render: () => 'widget-id', |
| 26 | + execute: async () => 'enterprise-token', |
| 27 | + reset: () => undefined, |
| 28 | + getResponse: () => 'enterprise-token', |
| 29 | + }, |
| 30 | + }; |
| 31 | +} |
| 32 | + |
| 33 | +export default { |
| 34 | + argTypes: { |
| 35 | + callback: { control: false }, |
| 36 | + }, |
| 37 | + component: RecaptchaEnterprise, |
| 38 | + parameters: { |
| 39 | + layout: 'fullscreen', |
| 40 | + }, |
| 41 | + title: 'Callbacks/ReCaptchaEnterprise', |
| 42 | +}; |
| 43 | + |
| 44 | +export const VisibleEnterprise = { |
| 45 | + args: { |
| 46 | + callback: new FRStep(visibleGrecaptchaEnterprise).getCallbackOfType( |
| 47 | + CallbackType.ReCaptchaEnterpriseCallback, |
| 48 | + ), |
| 49 | + }, |
| 50 | + play: async () => { |
| 51 | + mockGrecaptchaEnterprise(); |
| 52 | + captchaStore.set({ mode: 'normal' }); |
| 53 | + }, |
| 54 | +}; |
| 55 | + |
| 56 | +export const InvisibleEnterprise = { |
| 57 | + args: { |
| 58 | + callback: new FRStep(invisibleGrecaptchaEnterprise).getCallbackOfType( |
| 59 | + CallbackType.ReCaptchaEnterpriseCallback, |
| 60 | + ), |
| 61 | + }, |
| 62 | + play: async () => { |
| 63 | + mockGrecaptchaEnterprise(); |
| 64 | + captchaStore.set({ mode: 'invisible' }); |
| 65 | + journeyStore.update((v) => ({ ...v, recaptchaAction: 'LOGIN' })); |
| 66 | + }, |
| 67 | +}; |
| 68 | + |
| 69 | +export const InvisibleEnterpriseError = { |
| 70 | + args: { ...InvisibleEnterprise.args }, |
| 71 | + play: async ({ canvasElement }) => { |
| 72 | + mockGrecaptchaEnterprise(); |
| 73 | + captchaStore.set({ mode: 'invisible' }); |
| 74 | + window.frHandleCaptchaInvisibleError?.(); |
| 75 | + const canvas = within(canvasElement); |
| 76 | + await expect(canvas.findByText(/CAPTCHA verification failed/i)).resolves.toBeInTheDocument(); |
| 77 | + }, |
| 78 | +}; |
0 commit comments