-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clerk-js): Allow skipping invitation screen after CreateOrganiza…
…tion
- Loading branch information
1 parent
6715616
commit 6fa4768
Showing
4 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Introduce the `skipInvitationScreen` prop on `<CreateOrganization />` component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
packages/clerk-js/src/ui/components/CreateOrganization/__tests__/CreateOrganization.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import type { OrganizationResource } from '@clerk/types'; | ||
import { describe, jest } from '@jest/globals'; | ||
import { waitFor } from '@testing-library/dom'; | ||
import React from 'react'; | ||
|
||
import { render } from '../../../../testUtils'; | ||
import { bindCreateFixtures } from '../../../utils/test/createFixtures'; | ||
import { CreateOrganization } from '../CreateOrganization'; | ||
|
||
const { createFixtures } = bindCreateFixtures('CreateOrganization'); | ||
|
||
type FakeOrganizationParams = { | ||
id: string; | ||
createdAt?: Date; | ||
imageUrl?: string; | ||
logoUrl?: string; | ||
slug: string; | ||
name: string; | ||
membersCount: number; | ||
pendingInvitationsCount: number; | ||
adminDeleteEnabled: boolean; | ||
maxAllowedMemberships: number; | ||
}; | ||
|
||
const createFakeOrganization = (params: FakeOrganizationParams): OrganizationResource => { | ||
return { | ||
logoUrl: null, | ||
pathRoot: '', | ||
id: params.id, | ||
name: params.name, | ||
slug: params.slug, | ||
imageUrl: params.imageUrl || '', | ||
membersCount: params.membersCount, | ||
pendingInvitationsCount: params.pendingInvitationsCount, | ||
publicMetadata: {}, | ||
adminDeleteEnabled: params.adminDeleteEnabled, | ||
maxAllowedMemberships: params?.maxAllowedMemberships, | ||
createdAt: params?.createdAt || new Date(), | ||
updatedAt: new Date(), | ||
update: jest.fn() as any, | ||
getMemberships: jest.fn() as any, | ||
getPendingInvitations: jest.fn() as any, | ||
addMember: jest.fn() as any, | ||
inviteMember: jest.fn() as any, | ||
inviteMembers: jest.fn() as any, | ||
updateMember: jest.fn() as any, | ||
removeMember: jest.fn() as any, | ||
destroy: jest.fn() as any, | ||
setLogo: jest.fn() as any, | ||
reload: jest.fn() as any, | ||
}; | ||
}; | ||
|
||
const getCreatedOrg = (params: Partial<FakeOrganizationParams>) => | ||
createFakeOrganization({ | ||
id: '1', | ||
adminDeleteEnabled: false, | ||
maxAllowedMemberships: 1, | ||
membersCount: 1, | ||
name: 'new org', | ||
pendingInvitationsCount: 0, | ||
slug: 'new-org', | ||
...params, | ||
}); | ||
|
||
describe('CreateOrganization', () => { | ||
it('renders component', async () => { | ||
const { wrapper } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
f.withUser({ | ||
email_addresses: ['test@clerk.dev'], | ||
}); | ||
}); | ||
const { getByText } = render(<CreateOrganization />, { wrapper }); | ||
expect(getByText('Create Organization')).toBeInTheDocument(); | ||
}); | ||
|
||
it('skips invitation screen', async () => { | ||
const { wrapper, fixtures, props } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
f.withUser({ | ||
email_addresses: ['test@clerk.dev'], | ||
}); | ||
}); | ||
|
||
fixtures.clerk.createOrganization.mockReturnValue( | ||
Promise.resolve( | ||
getCreatedOrg({ | ||
maxAllowedMemberships: 3, | ||
}), | ||
), | ||
); | ||
|
||
props.setProps({ skipInvitationScreen: true }); | ||
const { getByRole, userEvent, getByLabelText, queryByText } = render(<CreateOrganization />, { | ||
wrapper, | ||
}); | ||
await userEvent.type(getByLabelText(/Organization name/i), 'new org'); | ||
await userEvent.click(getByRole('button', { name: /create organization/i })); | ||
|
||
await waitFor(() => { | ||
expect(queryByText(/Invite members/i)).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('always visit invitation screen', async () => { | ||
const { wrapper, fixtures, props } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
f.withUser({ | ||
email_addresses: ['test@clerk.dev'], | ||
}); | ||
}); | ||
|
||
fixtures.clerk.createOrganization.mockReturnValue( | ||
Promise.resolve( | ||
getCreatedOrg({ | ||
maxAllowedMemberships: 1, | ||
}), | ||
), | ||
); | ||
|
||
props.setProps({ skipInvitationScreen: false }); | ||
const { getByRole, userEvent, getByLabelText, queryByText } = render(<CreateOrganization />, { | ||
wrapper, | ||
}); | ||
await userEvent.type(getByLabelText(/Organization name/i), 'new org'); | ||
await userEvent.click(getByRole('button', { name: /create organization/i })); | ||
|
||
await waitFor(() => { | ||
expect(queryByText(/Invite members/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('auto skip invitation screen', async () => { | ||
const { wrapper, fixtures } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
f.withUser({ | ||
email_addresses: ['test@clerk.dev'], | ||
}); | ||
}); | ||
|
||
fixtures.clerk.createOrganization.mockReturnValue( | ||
Promise.resolve( | ||
getCreatedOrg({ | ||
maxAllowedMemberships: 1, | ||
}), | ||
), | ||
); | ||
|
||
const { getByRole, userEvent, getByLabelText, queryByText } = render(<CreateOrganization />, { | ||
wrapper, | ||
}); | ||
await userEvent.type(getByLabelText(/Organization name/i), 'new org'); | ||
await userEvent.click(getByRole('button', { name: /create organization/i })); | ||
|
||
await waitFor(() => { | ||
expect(queryByText(/Invite members/i)).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters