Skip to content

Commit eb755b9

Browse files
committed
chore: update tests
1 parent 2f69a67 commit eb755b9

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

packages/clerk-js/src/ui/components/OrganizationProfile/MemberListTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const RoleSelect = (props: {
196196
textWrap: 'nowrap',
197197
}))
198198
}
199-
isDisabled={isDisabled || !selectedRole}
199+
isDisabled={isDisabled || (!!value && fetchedRoles.length > 0 && !selectedRole)}
200200
>
201201
{selectedRole?.label || selectedRole?.value ? (
202202
<Flex

packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationMembers.test.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,69 @@ describe('OrganizationMembers', () => {
474474
expect(fixtures.clerk.organization?.getMemberships).toHaveBeenCalled();
475475
expect(getByText('You')).toBeInTheDocument();
476476
});
477+
it('disables the role select when the membership role does not map to fetched roles', async () => {
478+
const membersList: OrganizationMembershipResource[] = [
479+
createFakeMember({ id: '1', orgId: '1', role: 'admin', identifier: 'test_user1' }),
480+
createFakeMember({
481+
id: '2',
482+
orgId: '1',
483+
role: 'org:managed_admin',
484+
roleName: 'Managed Admin',
485+
identifier: 'test_user2',
486+
}),
487+
];
488+
const { wrapper, fixtures } = await createFixtures(f => {
489+
f.withOrganizations();
490+
f.withUser({
491+
id: '1',
492+
email_addresses: ['test@clerk.com'],
493+
organization_memberships: [{ name: 'Org1', id: '1' }],
494+
});
495+
});
496+
497+
fixtures.clerk.organization?.getMemberships.mockReturnValue(
498+
Promise.resolve({
499+
data: membersList,
500+
total_count: 2,
501+
}),
502+
);
503+
fixtures.clerk.organization?.getRoles.mockResolvedValue({
504+
total_count: 2,
505+
data: [
506+
{
507+
pathRoot: '',
508+
reload: jest.fn(),
509+
id: 'member',
510+
key: 'member',
511+
name: 'Member',
512+
description: '',
513+
permissions: [],
514+
createdAt: new Date(),
515+
updatedAt: new Date(),
516+
},
517+
{
518+
pathRoot: '',
519+
reload: jest.fn(),
520+
id: 'admin',
521+
key: 'admin',
522+
name: 'Admin',
523+
description: '',
524+
permissions: [],
525+
createdAt: new Date(),
526+
updatedAt: new Date(),
527+
},
528+
],
529+
});
530+
531+
const { container, getByText, getByRole } = render(<OrganizationMembers />, { wrapper });
532+
533+
await waitForLoadingCompleted(container);
534+
535+
expect(fixtures.clerk.organization?.getMemberships).toHaveBeenCalled();
536+
expect(getByText('You')).toBeInTheDocument();
537+
expect(getByText('Managed Admin')).toBeInTheDocument();
538+
await waitFor(() => expect(getByRole('button', { name: 'Managed Admin' })).toBeDisabled());
539+
});
477540

478541
describe('InviteMembersScreen', () => {
479542
it('shows the invite screen when user clicks on Invite button', async () => {

packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type FakeMemberParams = {
1616
id: string;
1717
orgId: string;
1818
role?: OrganizationCustomRoleKey;
19+
roleName?: string;
1920
identifier?: string;
2021
firstName?: string;
2122
lastName?: string;
@@ -30,6 +31,7 @@ export const createFakeMember = (params: FakeMemberParams): OrganizationMembersh
3031
organization: { id: params.orgId } as any as OrganizationResource,
3132
id: params.id,
3233
role: params?.role || 'admin',
34+
roleName: params?.roleName || 'Admin',
3335
createdAt: params?.createdAt || new Date(),
3436
updatedAt: new Date(),
3537
publicMetadata: {},
@@ -79,6 +81,7 @@ export const createFakeDomain = (params: FakeDomainParams): OrganizationDomainRe
7981
type FakeInvitationParams = {
8082
id: string;
8183
role?: OrganizationCustomRoleKey;
84+
roleName?: string;
8285
status?: OrganizationInvitationStatus;
8386
emailAddress: string;
8487
organizationId: string;
@@ -93,6 +96,7 @@ export const createFakeOrganizationInvitation = (params: FakeInvitationParams):
9396
organizationId: params.organizationId,
9497
publicMetadata: {} as any,
9598
role: params.role || 'basic_member',
99+
roleName: params.roleName || 'Basic Member',
96100
status: params.status || 'pending',
97101
createdAt: params?.createdAt || new Date(),
98102
updatedAt: new Date(),

0 commit comments

Comments
 (0)