|
1 | 1 | import { ClerkAPIResponseError } from '@clerk/shared/error'; |
2 | 2 | import type { OrganizationInvitationResource } from '@clerk/shared/types'; |
3 | 3 | import { waitFor } from '@testing-library/react'; |
4 | | -import React from 'react'; |
5 | 4 | import { beforeEach, describe, expect, it, vi } from 'vitest'; |
6 | 5 |
|
7 | 6 | import { bindCreateFixtures } from '@/test/create-fixtures'; |
@@ -246,6 +245,59 @@ describe('InviteMembersPage', () => { |
246 | 245 | await waitFor(() => expect(getByRole('button', { name: /select role/i })).toBeInTheDocument()); |
247 | 246 | }); |
248 | 247 |
|
| 248 | + it('enables selecting other options if default role is not available', async () => { |
| 249 | + const { wrapper, fixtures } = await createFixtures(f => { |
| 250 | + f.withOrganizations(); |
| 251 | + f.withOrganizationDomains(undefined, 'mydefaultrole'); |
| 252 | + f.withUser({ |
| 253 | + email_addresses: ['[email protected]'], |
| 254 | + organization_memberships: [{ name: 'Org1', role: 'admin' }], |
| 255 | + }); |
| 256 | + }); |
| 257 | + |
| 258 | + fixtures.clerk.organization?.getInvitations.mockRejectedValue(null); |
| 259 | + fixtures.clerk.organization?.getRoles.mockResolvedValue({ |
| 260 | + total_count: 1, |
| 261 | + data: [ |
| 262 | + { |
| 263 | + pathRoot: '', |
| 264 | + reload: vi.fn(), |
| 265 | + id: 'member', |
| 266 | + key: 'member', |
| 267 | + name: 'member', |
| 268 | + description: '', |
| 269 | + permissions: [], |
| 270 | + createdAt: new Date(), |
| 271 | + updatedAt: new Date(), |
| 272 | + }, |
| 273 | + { |
| 274 | + pathRoot: '', |
| 275 | + reload: vi.fn(), |
| 276 | + id: 'admin', |
| 277 | + key: 'admin', |
| 278 | + name: 'admin', |
| 279 | + description: '', |
| 280 | + permissions: [], |
| 281 | + createdAt: new Date(), |
| 282 | + updatedAt: new Date(), |
| 283 | + }, |
| 284 | + ], |
| 285 | + }); |
| 286 | + |
| 287 | + fixtures.clerk.organization?.inviteMembers.mockResolvedValueOnce([{}] as OrganizationInvitationResource[]); |
| 288 | + const { getByRole, userEvent, getByTestId } = render( |
| 289 | + <Action.Root> |
| 290 | + <InviteMembersScreen /> |
| 291 | + </Action.Root>, |
| 292 | + { wrapper }, |
| 293 | + ); |
| 294 | + await userEvent.type(getByTestId('tag-input'), '[email protected],'); |
| 295 | + await waitFor(() => expect(getByRole('button', { name: /select role/i })).toBeInTheDocument()); |
| 296 | + await userEvent.click(getByRole('button', { name: /select role/i })); |
| 297 | + await userEvent.click(getByRole('button', { name: /admin/i })); |
| 298 | + await waitFor(() => expect(getByRole('button', { name: 'Send invitations' })).not.toBeDisabled()); |
| 299 | + }); |
| 300 | + |
249 | 301 | it('enables send button with default role once email address has been entered', async () => { |
250 | 302 | const defaultRole = 'mydefaultrole'; |
251 | 303 |
|
|
0 commit comments