@@ -112,7 +125,7 @@ const MemberRow = (props: {
{isAdmin ? (
diff --git a/packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationMembers.test.tsx b/packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationMembers.test.tsx
index 1030acc862..b4ee975f7a 100644
--- a/packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationMembers.test.tsx
+++ b/packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationMembers.test.tsx
@@ -111,6 +111,15 @@ describe('OrganizationMembers', () => {
lastName: 'Last2',
createdAt: new Date('2022-01-01'),
}),
+ createFakeMember({
+ id: '3',
+ orgId: '1',
+ role: 'admin',
+ identifier: 'test_user3',
+ firstName: 'First3',
+ lastName: 'Last3',
+ createdAt: new Date('2022-01-01'),
+ }),
];
const { wrapper, fixtures } = await createFixtures(f => {
f.withOrganizations();
@@ -120,17 +129,74 @@ describe('OrganizationMembers', () => {
});
});
- fixtures.clerk.organization?.getMemberships.mockReturnValue(Promise.resolve(membersList));
- const { queryByText } = render(, { wrapper });
- expect(fixtures.clerk.organization?.getMemberships).toHaveBeenCalled();
- expect(fixtures.clerk.organization?.getPendingInvitations).not.toHaveBeenCalled();
- expect(fixtures.clerk.organization?.getMembershipRequests).not.toHaveBeenCalled();
- expect(queryByText('test_user1')).toBeDefined();
- expect(queryByText('First1 Last1')).toBeDefined();
- expect(queryByText('Admin')).toBeDefined();
- expect(queryByText('test_user2')).toBeDefined();
- expect(queryByText('First2 Last2')).toBeDefined();
- expect(queryByText('Member')).toBeDefined();
+ fixtures.clerk.organization?.getMemberships.mockReturnValueOnce(
+ Promise.resolve({
+ data: [],
+ total_count: 2,
+ }),
+ );
+
+ fixtures.clerk.organization?.getMemberships.mockReturnValueOnce(Promise.resolve(membersList));
+
+ const { queryByText, queryAllByRole } = render(, { wrapper });
+
+ await waitFor(() => {
+ expect(fixtures.clerk.organization?.getMemberships).toHaveBeenCalled();
+ expect(fixtures.clerk.organization?.getPendingInvitations).not.toHaveBeenCalled();
+ expect(fixtures.clerk.organization?.getMembershipRequests).not.toHaveBeenCalled();
+ expect(queryByText('test_user1')).toBeInTheDocument();
+ expect(queryByText('First1 Last1')).toBeInTheDocument();
+ const buttons = queryAllByRole('button', { name: 'Admin' });
+ buttons.forEach(button => expect(button).not.toBeDisabled());
+ expect(queryByText('test_user2')).toBeInTheDocument();
+ expect(queryByText('First2 Last2')).toBeInTheDocument();
+ expect(queryByText('Member')).toBeInTheDocument();
+ });
+ });
+
+ it('Last admin cannot change to member', async () => {
+ const membersList: OrganizationMembershipResource[] = [
+ createFakeMember({
+ id: '1',
+ orgId: '1',
+ role: 'admin',
+ identifier: 'test_user1',
+ firstName: 'First1',
+ lastName: 'Last1',
+ createdAt: new Date('2022-01-01'),
+ }),
+ createFakeMember({
+ id: '2',
+ orgId: '1',
+ role: 'basic_member',
+ identifier: 'test_user2',
+ firstName: 'First2',
+ lastName: 'Last2',
+ createdAt: new Date('2022-01-01'),
+ }),
+ ];
+ const { wrapper, fixtures } = await createFixtures(f => {
+ f.withOrganizations();
+ f.withUser({
+ email_addresses: ['test@clerk.dev'],
+ organization_memberships: [{ name: 'Org1', id: '1', role: 'admin' }],
+ });
+ });
+
+ fixtures.clerk.organization?.getMemberships.mockReturnValueOnce(
+ Promise.resolve({
+ data: [],
+ total_count: 0,
+ }),
+ );
+
+ fixtures.clerk.organization?.getMemberships.mockReturnValueOnce(Promise.resolve(membersList));
+
+ const { queryByRole } = render(, { wrapper });
+
+ await waitFor(() => {
+ expect(queryByRole('button', { name: 'Admin' })).toBeDisabled();
+ });
});
it('displays counter in requests tab', async () => {
|