Skip to content

Commit

Permalink
test(clerk-js): Add test case for displaying custom roles in select menu
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef committed Nov 3, 2023
1 parent 0ba8ee0 commit bf51225
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { MembershipRole, OrganizationInvitationResource } from '@clerk/types';
import { describe } from '@jest/globals';
import { waitFor } from '@testing-library/dom';
import { act } from '@testing-library/react';
import React from 'react';

import { ClerkAPIResponseError } from '../../../../core/resources';
Expand All @@ -18,7 +19,7 @@ describe('InviteMembersPage', () => {
});

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
const { getByText } = render(<InviteMembersPage />, { wrapper });
const { getByText } = await act(() => render(<InviteMembersPage />, { wrapper }));
expect(getByText('Invite new members to this organization')).toBeDefined();
});

Expand Down Expand Up @@ -62,6 +63,43 @@ describe('InviteMembersPage', () => {
});
});

it('fetches custom role and sends invite to email entered and teacher role when clicking Send', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withOrganizations();
f.withUser({
email_addresses: ['[email protected]'],
organization_memberships: [{ name: 'Org1', role: 'admin' }],
});
});

fixtures.clerk.organization?.getRoles.mockResolvedValueOnce({
data: [
{
pathRoot: '',
reload: jest.fn(),
id: '1',
description: '',
updatedAt: new Date(),
createdAt: new Date(),
permissions: [],
name: 'Teacher',
key: 'org:teacher',
},
],
total_count: 1,
});
fixtures.clerk.organization?.inviteMembers.mockResolvedValueOnce([{}] as OrganizationInvitationResource[]);
const { getByRole, userEvent, getByTestId, getByText } = render(<InviteMembersPage />, { wrapper });
await userEvent.type(getByTestId('tag-input'), '[email protected],');
await userEvent.click(getByRole('button', { name: 'Select an option' }));
await userEvent.click(getByText('Teacher'));
await userEvent.click(getByRole('button', { name: 'Send invitations' }));
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['[email protected]'],
role: 'org:teacher' as MembershipRole,
});
});

it('sends invites to multiple emails', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withOrganizations();
Expand Down

0 comments on commit bf51225

Please sign in to comment.