Skip to content

Commit c52dc1e

Browse files
committed
test(ui): stabilize OIDC credential error coverage
1 parent 0ba2970 commit c52dc1e

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

packages/ui/src/components/ConfigureSSO/steps/ConfigureStep/__tests__/ConfigureStep.test.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { render, screen } from '@/test/utils';
77
import { CardStateProvider, useCardState } from '@/ui/elements/contexts';
88

99
import type { EnterpriseConnectionProviderType } from '../../../types';
10+
import { Wizard } from '../../../elements/Wizard';
1011

1112
// The dispatch reads `organizationEnterpriseConnection.provider`. The nested
1213
// sub-flows also read `enterpriseConnection` (via `Step.Footer.Reset`), which is
@@ -50,6 +51,7 @@ vi.mock('../../../ConfigureSSOContext', () => ({
5051

5152
import { ConfigureProviderStep, resolveConfigureSteps } from '../index';
5253
import { OidcCustomConfigureSteps } from '../oidc';
54+
import { OidcCredentialsStep } from '../oidc/shared/OidcCredentialsStep';
5355
import {
5456
SamlCustomConfigureSteps,
5557
SamlGoogleConfigureSteps,
@@ -104,6 +106,23 @@ describe('ConfigureProviderStep', () => {
104106
{ wrapper },
105107
);
106108

109+
const renderCredentialsStep = (wrapper: React.ComponentType<{ children?: React.ReactNode }>) =>
110+
render(
111+
<Flow.Root flow='configureSSO'>
112+
<CardStateProvider>
113+
<Wizard
114+
steps={[{ id: 'credentials' }]}
115+
initialStepId='credentials'
116+
>
117+
<Wizard.Match id='credentials'>
118+
<OidcCredentialsStep mode='discoveryUrl' />
119+
</Wizard.Match>
120+
</Wizard>
121+
</CardStateProvider>
122+
</Flow.Root>,
123+
{ wrapper },
124+
);
125+
107126
it('renders the OIDC configure steps for a custom OAuth provider key without throwing', async () => {
108127
contextState.provider = 'oauth_custom_clerk_dev';
109128
contextState.enterpriseConnection = {
@@ -329,8 +348,7 @@ describe('ConfigureProviderStep', () => {
329348
contextState.provider = 'oidc_clerk_dev';
330349
contextState.enterpriseConnection = { id: 'ent_123', oauthConfig: null };
331350
updateConnection.mockReset();
332-
updateConnection.mockResolvedValueOnce({});
333-
updateConnection.mockRejectedValueOnce(
351+
updateConnection.mockRejectedValue(
334352
new ClerkAPIResponseError('Error', {
335353
data: [
336354
{
@@ -351,25 +369,21 @@ describe('ConfigureProviderStep', () => {
351369
);
352370
const { wrapper } = await createFixtures();
353371

354-
const { userEvent } = renderStep(wrapper);
355-
356-
await userEvent.click(await screen.findByRole('button', { name: 'Continue' }));
357-
await userEvent.type(
358-
screen.getByRole('textbox', { name: 'Discovery endpoint' }),
359-
'https://idp.example/.well-known/openid-configuration',
360-
);
361-
await userEvent.click(screen.getByRole('button', { name: 'Continue' }));
372+
const { userEvent } = renderCredentialsStep(wrapper);
362373

363-
const clientId = await screen.findByRole('textbox', { name: 'Client ID' });
364-
const clientSecret = screen.getByLabelText('Client secret');
374+
const clientId = screen.getByRole('textbox');
375+
const clientSecret = document.querySelector<HTMLInputElement>('input[name="clientSecret"]');
376+
expect(clientSecret).not.toBeNull();
365377
await userEvent.type(clientId, 'client_123');
366-
await userEvent.type(clientSecret, 'secret_456');
378+
await userEvent.type(clientSecret!, 'secret_456');
367379
await userEvent.click(screen.getByRole('button', { name: 'Continue' }));
368380

369-
expect(await screen.findByText('Client ID is invalid.')).toBeInTheDocument();
370-
expect(await screen.findByText('Client secret is invalid.')).toBeInTheDocument();
371-
expect(clientId).toHaveAttribute('aria-describedby', 'error-clientId');
372-
expect(clientSecret).toHaveAttribute('aria-describedby', 'error-clientSecret');
381+
await vi.waitFor(() => {
382+
expect(document.getElementById('error-clientId')).toHaveTextContent('Client ID is invalid.');
383+
expect(document.getElementById('error-clientSecret')).toHaveTextContent('Client secret is invalid.');
384+
expect(clientId).toHaveAttribute('aria-describedby', 'error-clientId');
385+
expect(clientSecret).toHaveAttribute('aria-describedby', 'error-clientSecret');
386+
});
373387
});
374388

375389
it('selects manual mode when an existing connection has manual endpoints without a discovery URL', async () => {

0 commit comments

Comments
 (0)