Skip to content

Commit 0e3f54a

Browse files
committed
fix: Fix webapp tests
1 parent c17e718 commit 0e3f54a

File tree

11 files changed

+70
-44
lines changed

11 files changed

+70
-44
lines changed

packages/webapp-libs/webapp-generative-ai/jest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export default {
1212
},
1313
},
1414
moduleNameMapper: {
15-
'react-markdown': '<rootDir>/../../../node_modules/react-markdown/react-markdown.min.js',
15+
'react-markdown': '<rootDir>/../webapp-core/src/tests/mocks/reactMarkdown.tsx',
16+
'remark-gfm': '<rootDir>/../webapp-core/src/tests/mocks/remarkGfm.ts',
1617
},
1718
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
1819
coverageReporters: ['lcov'],

packages/webapp-libs/webapp-tenants/src/components/tenantInvitationForm/tenantInvitationForm.component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@sb/webapp-core/components/ui/card';
1313
import { cn } from '@sb/webapp-core/lib/utils';
1414
import { Check, ChevronDown, UserPlus } from 'lucide-react';
15-
import { useCallback, useEffect, useRef, useState } from 'react';
15+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
1616
import { FormattedMessage, useIntl } from 'react-intl';
1717

1818
import { useCurrentTenant } from '../../providers';
@@ -91,7 +91,8 @@ export const TenantInvitationForm = ({ initialData, onSubmit, error, loading }:
9191
handleFormSubmit,
9292
} = useTenantInvitationForm({ initialData, onSubmit, error });
9393

94-
const selectedRoleIds = watch('organizationRoleIds') || [];
94+
const watchedRoleIds = watch('organizationRoleIds');
95+
const selectedRoleIds = useMemo(() => watchedRoleIds || [], [watchedRoleIds]);
9596

9697
// Close dropdown when clicking outside
9798
useEffect(() => {

packages/webapp-libs/webapp-tenants/src/hooks/useGenerateTenantPath/useGenerateTenantPath.hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const useGenerateTenantPath = () => {
3535
return useCallback(
3636
(path: string, params: Record<string, string | number> = {}) =>
3737
generatePath(generateLocalePath('') + getTenantPath(path), { tenantId, ...params }),
38-
[tenantId]
38+
[tenantId, generateLocalePath]
3939
);
4040
};
4141

packages/webapp-libs/webapp-tenants/src/hooks/usePermissionCheck/usePermissionCheck.hook.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export const usePermissionCheck = (
2929
) => {
3030
const { data: currentTenant } = useCurrentTenant();
3131
const tenantId = currentTenant?.id ?? '';
32-
const permissionsArray = Array.isArray(permissions) ? permissions : [permissions];
32+
const permissionsArray = useMemo(
33+
() => (Array.isArray(permissions) ? permissions : [permissions]),
34+
[permissions]
35+
);
3336

3437
const { data, loading, error, refetch } = useQuery(currentUserPermissionsQuery, {
3538
variables: { tenantId },

packages/webapp-libs/webapp-tenants/src/providers/currentTenantProvider/currentTenantProvider.component.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ export const CurrentTenantProvider = ({ children }: CurrentTenantProviderProps)
4040

4141
useEffect(() => {
4242
if (currentTenant && userId) {
43-
parsedStoredState[userId] = currentTenant.id;
44-
setCurrentTenantStorageState(parsedStoredState);
43+
const { parsedStoredState: state } = parseStoredState(storedState, userId);
44+
state[userId] = currentTenant.id;
45+
setCurrentTenantStorageState(state);
4546
}
46-
}, [currentTenant?.id, userId]);
47+
}, [currentTenant, storedState, userId]);
4748

4849
const value = useMemo(
4950
() => ({ data: currentTenant || null }),
50-
[currentTenant?.id, currentMembership?.role, currentTenant?.name, currentTenant?.actionLoggingEnabled]
51+
[currentTenant]
5152
);
5253

5354
return <currentTenantContext.Provider value={value}>{children}</currentTenantContext.Provider>;

packages/webapp-libs/webapp-tenants/src/routes/tenantInvitation/tenantInvitation.component.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const TenantInvitation = () => {
6666
},
6767
},
6868
});
69-
}, [token]);
69+
}, [token, commitAcceptMutation, tenant, tenantMembershipId]);
7070

7171
const [commitDeclineMutation, { loading: declineLoading }] = useMutation(declineTenantInvitationMutation, {
7272
onCompleted: () => {
@@ -87,7 +87,7 @@ export const TenantInvitation = () => {
8787
},
8888
},
8989
});
90-
}, [token]);
90+
}, [token, commitDeclineMutation, tenant, tenantMembershipId]);
9191

9292
let redirectPath: string | null = null;
9393

@@ -101,7 +101,7 @@ export const TenantInvitation = () => {
101101
if (redirectPath) {
102102
navigate(redirectPath);
103103
}
104-
}, [redirectPath]);
104+
}, [redirectPath, navigate]);
105105

106106
if (!tenant || redirectPath) {
107107
return null;

packages/webapp-libs/webapp-tenants/src/routes/tenantSettings/tenantSecuritySettings/components/__tests__/auditLogCard.component.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const TENANT_ID = 'tenant-audit-1';
2424
const createMockAuditLog = (overrides = {}) => ({
2525
id: 'log-1',
2626
eventType: 'sso_login_success',
27+
eventTypeLabel: 'SSO login success',
2728
eventDescription: 'User signed in via SSO',
2829
userEmail: 'user@example.com',
2930
connectionName: 'Okta',
@@ -131,7 +132,7 @@ describe('AuditLogCard: Component', () => {
131132
it('should show failed event with failed styling', async () => {
132133
mockedApiClient.get.mockResolvedValue({
133134
data: {
134-
logs: [createMockAuditLog({ success: false, eventType: 'sso_login_failed' })],
135+
logs: [createMockAuditLog({ success: false, eventType: 'sso_login_failed', eventTypeLabel: 'SSO login failed' })],
135136
totalCount: 1,
136137
totalPages: 1,
137138
currentPage: 1,

packages/webapp-libs/webapp-tenants/src/routes/tenantSettings/tenantSecuritySettings/components/__tests__/directorySyncCard.component.spec.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const TENANT_ID = 'tenant-scim-1';
1717

1818
const createSSOConnectionsMock = (connections: { id: string; name: string; connectionType: string; status: string }[]) =>
1919
composeMockedQueryResult(TenantSecuritySsoConnectionsQueryDocument, {
20+
variables: { tenantId: TENANT_ID },
2021
data: {
2122
ssoConnections: {
2223
edges: connections.map((node) => ({ node })),
@@ -28,6 +29,7 @@ const createSCIMTokensMock = (
2829
tokens: { id: string; name: string; tokenPrefix: string; isActive: boolean; createdAt: string; lastUsedAt: string | null; requestCount: number }[]
2930
) =>
3031
composeMockedQueryResult(TenantScimTokensQueryDocument, {
32+
variables: { tenantId: TENANT_ID },
3133
data: {
3234
scimTokens: {
3335
edges: tokens.map((node) => ({ node })),
@@ -79,36 +81,39 @@ describe('DirectorySyncCard: Component', () => {
7981
});
8082

8183
it('should show ready to configure when SSO active but no tokens', async () => {
82-
renderComponent(true, {
84+
const { waitForApolloMocks } = renderComponent(true, {
8385
connections: [{ id: '1', name: 'Okta', connectionType: 'saml', status: 'active' }],
8486
});
87+
await waitForApolloMocks();
8588

8689
expect(await screen.findByText(/ready to configure directory sync/i)).toBeInTheDocument();
8790
expect(await screen.findByRole('button', { name: /generate SCIM token/i })).toBeInTheDocument();
8891
});
8992

9093
it('should show compatible identity providers', async () => {
91-
renderComponent(true, {
94+
const { waitForApolloMocks } = renderComponent(true, {
9295
connections: [{ id: '1', name: 'Okta', connectionType: 'saml', status: 'active' }],
9396
});
97+
await waitForApolloMocks();
9498

9599
expect(await screen.findByText(/compatible identity providers/i)).toBeInTheDocument();
96100
expect(screen.getByText('Okta')).toBeInTheDocument();
97101
expect(screen.getByText('Azure AD')).toBeInTheDocument();
98102
});
99103

100104
it('should open generate token modal when button clicked', async () => {
101-
renderComponent(true, {
105+
const { waitForApolloMocks } = renderComponent(true, {
102106
connections: [{ id: '1', name: 'Okta', connectionType: 'saml', status: 'active' }],
103107
});
108+
await waitForApolloMocks();
104109

105110
await userEvent.click(await screen.findByRole('button', { name: /generate SCIM token/i }));
106111

107112
expect(await screen.findByLabelText(/token name/i)).toBeInTheDocument();
108113
});
109114

110115
it('should display SCIM endpoint and token list when tokens exist', async () => {
111-
renderComponent(true, {
116+
const { waitForApolloMocks } = renderComponent(true, {
112117
connections: [{ id: '1', name: 'Okta', connectionType: 'saml', status: 'active' }],
113118
tokens: [
114119
{
@@ -122,6 +127,7 @@ describe('DirectorySyncCard: Component', () => {
122127
},
123128
],
124129
});
130+
await waitForApolloMocks();
125131

126132
expect(await screen.findByText(/SCIM endpoint URL/i)).toBeInTheDocument();
127133
expect(await screen.findByText('Okta SCIM')).toBeInTheDocument();

packages/webapp-libs/webapp-tenants/src/routes/tenantSettings/tenantSecuritySettings/components/__tests__/passkeysCard.component.spec.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const createMockPasskey = (overrides = {}) => ({
3939

4040
const createTenantPasskeysMock = (passkeys: ReturnType<typeof createMockPasskey>[]) =>
4141
composeMockedQueryResult(TenantPasskeysQueryDocument, {
42-
variables: { search: undefined },
42+
variables: { tenantId: TENANT_ID, search: undefined },
4343
data: { tenantPasskeys: passkeys },
4444
});
4545

@@ -106,30 +106,34 @@ describe('PasskeysCard: Component', () => {
106106
});
107107

108108
it('should render search input when passkeys exist', async () => {
109-
renderComponent(true, [createMockPasskey()]);
109+
const { waitForApolloMocks } = renderComponent(true, [createMockPasskey()]);
110+
await waitForApolloMocks();
110111

111112
expect(await screen.findByPlaceholderText(/search by user name or email/i)).toBeInTheDocument();
112113
});
113114

114115
it('should show user info for admin view', async () => {
115-
renderComponent(true, [
116+
const { waitForApolloMocks } = renderComponent(true, [
116117
createMockPasskey({ userName: 'Admin User', userEmail: 'admin@company.com' }),
117118
]);
119+
await waitForApolloMocks();
118120

119121
expect(await screen.findByText('Admin User')).toBeInTheDocument();
120122
});
121123

122124
it('should show Device badge for platform authenticator', async () => {
123-
renderComponent(true, [createMockPasskey({ authenticatorType: 'platform' })]);
125+
const { waitForApolloMocks } = renderComponent(true, [createMockPasskey({ authenticatorType: 'platform' })]);
126+
await waitForApolloMocks();
124127

125128
expect(await screen.findByText('Device')).toBeInTheDocument();
126129
});
127130

128131
it('should show search input when passkeys exist', async () => {
129-
renderComponent(true, [
132+
const { waitForApolloMocks } = renderComponent(true, [
130133
createMockPasskey({ name: 'MacBook', id: '1' }),
131134
createMockPasskey({ name: 'iPhone', id: '2' }),
132135
]);
136+
await waitForApolloMocks();
133137

134138
const searchInput = await screen.findByPlaceholderText(/search by user name or email/i);
135139
expect(searchInput).toBeInTheDocument();

packages/webapp-libs/webapp-tenants/src/routes/tenantSettings/tenantSecuritySettings/components/__tests__/ssoConnectionCard.component.spec.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ const createMockConnection = (overrides = {}) => ({
3030
...overrides,
3131
});
3232

33-
const createSSOConnectionsMock = (connections: ReturnType<typeof createMockConnection>[]) =>
34-
composeMockedQueryResult(TenantSecuritySsoConnectionsQueryDocument, {
35-
data: {
36-
ssoConnections: {
37-
edges: connections.map((node) => ({ node })),
38-
},
39-
},
40-
});
41-
4233
const createSSOConnectionsMock = (connections: ReturnType<typeof createMockConnection>[]) =>
4334
composeMockedQueryResult(TenantSecuritySsoConnectionsQueryDocument, {
4435
variables: { tenantId: 'tenant-1' },

0 commit comments

Comments
 (0)