|
| 1 | +import { screen, waitFor } from '@testing-library/react'; |
| 2 | +import userEvent from '@testing-library/user-event'; |
| 3 | +import React from 'react'; |
| 4 | +import { vi, describe, it, expect, beforeEach } from 'vitest'; |
| 5 | + |
| 6 | +import type { SamlpConfigureFormHandle } from '@/components/auth0/my-organization/shared/idp-management/sso-provider-create/provider-configure/samlp-sso-configure-form'; |
| 7 | +import { SamlpProviderForm } from '@/components/auth0/my-organization/shared/idp-management/sso-provider-create/provider-configure/samlp-sso-configure-form'; |
| 8 | +import { createMockI18nService, renderWithProviders } from '@/tests/utils'; |
| 9 | + |
| 10 | +describe('SamlpProviderForm', () => { |
| 11 | + beforeEach(() => { |
| 12 | + vi.clearAllMocks(); |
| 13 | + |
| 14 | + createMockI18nService().translator('idp_management.create_sso_provider.provider_configure'); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('binding method', () => { |
| 18 | + describe('URN format', () => { |
| 19 | + it('should use full SAML URN format for default binding method value', async () => { |
| 20 | + const formRef = React.createRef<SamlpConfigureFormHandle>(); |
| 21 | + renderWithProviders(<SamlpProviderForm ref={formRef} idpConfig={null} />); |
| 22 | + |
| 23 | + await waitFor(() => { |
| 24 | + const data = formRef.current?.getData(); |
| 25 | + expect(data?.bindingMethod).toBe('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should preserve initial binding method value with full URN format', async () => { |
| 30 | + const formRef = React.createRef<SamlpConfigureFormHandle>(); |
| 31 | + const initialData = { |
| 32 | + bindingMethod: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', |
| 33 | + metadataUrl: 'https://example.com/metadata', |
| 34 | + }; |
| 35 | + |
| 36 | + renderWithProviders( |
| 37 | + <SamlpProviderForm ref={formRef} idpConfig={null} initialData={initialData} />, |
| 38 | + ); |
| 39 | + |
| 40 | + await waitFor(() => { |
| 41 | + const data = formRef.current?.getData(); |
| 42 | + expect(data?.bindingMethod).toBe('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'); |
| 43 | + }); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('rendering', () => { |
| 48 | + it('should render binding method field in advanced settings', async () => { |
| 49 | + const user = userEvent.setup(); |
| 50 | + renderWithProviders(<SamlpProviderForm idpConfig={null} />); |
| 51 | + |
| 52 | + const accordionTrigger = screen.getByRole('button', { |
| 53 | + name: 'fields.samlp.advanced_settings.title', |
| 54 | + }); |
| 55 | + await user.click(accordionTrigger); |
| 56 | + |
| 57 | + expect( |
| 58 | + screen.getByText('fields.samlp.advanced_settings.request_protocol_binding.label'), |
| 59 | + ).toBeInTheDocument(); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + describe('advanced settings', () => { |
| 65 | + describe('sign request', () => { |
| 66 | + it('should render signature algorithm fields when sign request is enabled', async () => { |
| 67 | + const user = userEvent.setup(); |
| 68 | + renderWithProviders(<SamlpProviderForm idpConfig={null} />); |
| 69 | + |
| 70 | + expect( |
| 71 | + screen.queryByText('fields.samlp.advanced_settings.sign_request_algorithm.label'), |
| 72 | + ).not.toBeInTheDocument(); |
| 73 | + |
| 74 | + const accordionTrigger = screen.getByRole('button', { |
| 75 | + name: 'fields.samlp.advanced_settings.title', |
| 76 | + }); |
| 77 | + await user.click(accordionTrigger); |
| 78 | + |
| 79 | + const checkbox = screen.getByRole('checkbox'); |
| 80 | + await user.click(checkbox); |
| 81 | + |
| 82 | + expect( |
| 83 | + screen.getByText('fields.samlp.advanced_settings.sign_request_algorithm.label'), |
| 84 | + ).toBeInTheDocument(); |
| 85 | + expect( |
| 86 | + screen.getByText('fields.samlp.advanced_settings.sign_request_algorithm_digest.label'), |
| 87 | + ).toBeInTheDocument(); |
| 88 | + }); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + describe('form dirty state', () => { |
| 93 | + it('should call onFormDirty when form becomes dirty', async () => { |
| 94 | + const user = userEvent.setup(); |
| 95 | + const onFormDirty = vi.fn(); |
| 96 | + renderWithProviders(<SamlpProviderForm idpConfig={null} onFormDirty={onFormDirty} />); |
| 97 | + |
| 98 | + const metadataUrlField = screen.getByPlaceholderText( |
| 99 | + 'fields.samlp.meta_data_url.placeholder', |
| 100 | + ); |
| 101 | + await user.type(metadataUrlField, 'https://example.com/metadata'); |
| 102 | + |
| 103 | + await waitFor(() => { |
| 104 | + expect(onFormDirty).toHaveBeenLastCalledWith(true); |
| 105 | + }); |
| 106 | + }); |
| 107 | + }); |
| 108 | +}); |
0 commit comments