-
Notifications
You must be signed in to change notification settings - Fork 295
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,types): Add hideSlug prop to Organization components (#…
…3882) Co-authored-by: panteliselef <[email protected]>
- Loading branch information
1 parent
020c889
commit 9b2aeac
Showing
10 changed files
with
119 additions
and
14 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 | ||
--- | ||
|
||
Add option to hide the slug field in the `<CreateOrganization />`, `<OrganizationSwitcher />`, and `<OrganizationList />` components |
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
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
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 |
---|---|---|
|
@@ -79,6 +79,38 @@ describe('CreateOrganization', () => { | |
expect(getByRole('heading', { name: 'Create organization', level: 1 })).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders component without slug field', async () => { | ||
const { wrapper, fixtures, props } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
f.withUser({ | ||
email_addresses: ['[email protected]'], | ||
}); | ||
}); | ||
|
||
fixtures.clerk.createOrganization.mockReturnValue( | ||
Promise.resolve( | ||
getCreatedOrg({ | ||
maxAllowedMemberships: 1, | ||
slug: 'new-org-1722578361', | ||
}), | ||
), | ||
); | ||
|
||
props.setProps({ hideSlug: true }); | ||
const { userEvent, getByRole, queryByText, queryByLabelText, getByLabelText } = render(<CreateOrganization />, { | ||
wrapper, | ||
}); | ||
|
||
expect(queryByLabelText(/Slug/i)).not.toBeInTheDocument(); | ||
|
||
await userEvent.type(getByLabelText(/Name/i), 'new org'); | ||
await userEvent.click(getByRole('button', { name: /create organization/i })); | ||
|
||
await waitFor(() => { | ||
expect(queryByText(/Invite new members/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('skips invitation screen', async () => { | ||
const { wrapper, fixtures, props } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
|
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
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 |
---|---|---|
|
@@ -256,6 +256,26 @@ describe('OrganizationList', () => { | |
}); | ||
}); | ||
|
||
it('displays CreateOrganization without slug field', async () => { | ||
const { wrapper, props } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
f.withUser({ | ||
email_addresses: ['[email protected]'], | ||
create_organization_enabled: true, | ||
}); | ||
}); | ||
|
||
props.setProps({ hideSlug: true }); | ||
const { findByRole, getByRole, userEvent, queryByLabelText } = render(<OrganizationList />, { wrapper }); | ||
|
||
await waitFor(async () => | ||
expect(await findByRole('menuitem', { name: 'Create organization' })).toBeInTheDocument(), | ||
); | ||
await userEvent.click(getByRole('menuitem', { name: 'Create organization' })); | ||
expect(queryByLabelText(/Name/i)).toBeInTheDocument(); | ||
expect(queryByLabelText(/Slug/i)).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('does not display CreateOrganization within OrganizationList when disabled', async () => { | ||
const { wrapper } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
|
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
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 |
---|---|---|
|
@@ -223,6 +223,23 @@ describe('OrganizationSwitcher', () => { | |
expect(fixtures.clerk.openCreateOrganization).toHaveBeenCalled(); | ||
}); | ||
|
||
it('opens create organization without slug field', async () => { | ||
const { wrapper, fixtures, props } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
f.withUser({ | ||
email_addresses: ['[email protected]'], | ||
create_organization_enabled: true, | ||
}); | ||
}); | ||
|
||
props.setProps({ hideSlug: true }); | ||
const { getByRole, queryByLabelText, userEvent } = render(<OrganizationSwitcher />, { wrapper }); | ||
await userEvent.click(getByRole('button', { name: 'Open organization switcher' })); | ||
await userEvent.click(getByRole('menuitem', { name: 'Create organization' })); | ||
expect(fixtures.clerk.openCreateOrganization).toHaveBeenCalled(); | ||
expect(queryByLabelText(/Slug/i)).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('does not display create organization button if permissions not present', async () => { | ||
const { wrapper, props } = await createFixtures(f => { | ||
f.withOrganizations(); | ||
|
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
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