Skip to content

Commit 7c75955

Browse files
committed
Fix unit tests
1 parent 463110e commit 7c75955

File tree

3 files changed

+83
-15
lines changed

3 files changed

+83
-15
lines changed

packages/clerk-js/src/ui/components/CreateOrganization/__tests__/CreateOrganization.test.tsx

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ describe('CreateOrganization', () => {
114114
});
115115
});
116116

117-
describe('with organization slug disabled on environment', () => {
118-
it('renders component without slug field', async () => {
117+
describe('with organization slug configured on environment', () => {
118+
it('when disabled, renders component without slug field', async () => {
119119
const { wrapper, fixtures } = await createFixtures(f => {
120120
f.withOrganizations();
121121
f.withOrganizationSlug(false);
@@ -146,6 +146,71 @@ describe('CreateOrganization', () => {
146146
expect(queryByText(/Invite new members/i)).toBeInTheDocument();
147147
});
148148
});
149+
150+
it('when enabled, renders component slug field', async () => {
151+
const { wrapper, fixtures } = await createFixtures(f => {
152+
f.withOrganizations();
153+
f.withOrganizationSlug(true);
154+
f.withUser({
155+
email_addresses: ['[email protected]'],
156+
});
157+
});
158+
159+
fixtures.clerk.createOrganization.mockReturnValue(
160+
Promise.resolve(
161+
getCreatedOrg({
162+
maxAllowedMemberships: 1,
163+
slug: 'new-org-1722578361',
164+
}),
165+
),
166+
);
167+
168+
const { userEvent, getByRole, queryByText, queryByLabelText, getByLabelText } = render(<CreateOrganization />, {
169+
wrapper,
170+
});
171+
172+
expect(queryByLabelText(/Slug/i)).toBeInTheDocument();
173+
174+
await userEvent.type(getByLabelText(/Name/i), 'new org');
175+
await userEvent.click(getByRole('button', { name: /create organization/i }));
176+
177+
await waitFor(() => {
178+
expect(queryByText(/Invite new members/i)).toBeInTheDocument();
179+
});
180+
});
181+
182+
it('when enabled and `hideSlug` prop is passed, renders component slug field', async () => {
183+
const { wrapper, fixtures, props } = await createFixtures(f => {
184+
f.withOrganizations();
185+
f.withOrganizationSlug(true);
186+
f.withUser({
187+
email_addresses: ['[email protected]'],
188+
});
189+
});
190+
191+
fixtures.clerk.createOrganization.mockReturnValue(
192+
Promise.resolve(
193+
getCreatedOrg({
194+
maxAllowedMemberships: 1,
195+
slug: 'new-org-1722578361',
196+
}),
197+
),
198+
);
199+
200+
props.setProps({ hideSlug: true });
201+
const { userEvent, getByRole, queryByText, queryByLabelText, getByLabelText } = render(<CreateOrganization />, {
202+
wrapper,
203+
});
204+
205+
expect(queryByLabelText(/Slug/i)).not.toBeInTheDocument();
206+
207+
await userEvent.type(getByLabelText(/Name/i), 'new org');
208+
await userEvent.click(getByRole('button', { name: /create organization/i }));
209+
210+
await waitFor(() => {
211+
expect(queryByText(/Invite new members/i)).toBeInTheDocument();
212+
});
213+
});
149214
});
150215

151216
it('skips invitation screen', async () => {

packages/clerk-js/src/ui/components/OrganizationList/__tests__/OrganizationList.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ describe('OrganizationList', () => {
210210
it('display CreateOrganization within OrganizationList', async () => {
211211
const { wrapper } = await createFixtures(f => {
212212
f.withOrganizations();
213+
f.withOrganizationSlug(true);
213214
f.withUser({
214215
email_addresses: ['[email protected]'],
215216
create_organization_enabled: true,

packages/clerk-js/src/ui/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,27 @@ describe('TaskChooseOrganization', () => {
217217
});
218218
});
219219

220-
const { queryByLabelText } = render(<TaskChooseOrganization />, { wrapper });
220+
const { findByRole, queryByLabelText } = render(<TaskChooseOrganization />, { wrapper });
221221

222+
expect(await findByRole('textbox', { name: /name/i })).toBeInTheDocument();
222223
expect(queryByLabelText(/Slug/i)).not.toBeInTheDocument();
223224
});
224-
});
225225

226-
it("display slug field if it's enabled on environment", async () => {
227-
const { wrapper } = await createFixtures(f => {
228-
f.withOrganizations();
229-
f.withOrganizationSlug(true);
230-
f.withForceOrganizationSelection();
231-
f.withUser({
232-
create_organization_enabled: true,
233-
tasks: [{ key: 'choose-organization' }],
226+
it("display slug field if it's enabled on environment", async () => {
227+
const { wrapper } = await createFixtures(f => {
228+
f.withOrganizations();
229+
f.withOrganizationSlug(true);
230+
f.withForceOrganizationSelection();
231+
f.withUser({
232+
create_organization_enabled: true,
233+
tasks: [{ key: 'choose-organization' }],
234+
});
234235
});
235-
});
236236

237-
const { queryByLabelText } = render(<TaskChooseOrganization />, { wrapper });
237+
const { findByRole, queryByLabelText } = render(<TaskChooseOrganization />, { wrapper });
238238

239-
expect(queryByLabelText(/Slug/i)).toBeInTheDocument();
239+
expect(await findByRole('textbox', { name: /name/i })).toBeInTheDocument();
240+
expect(queryByLabelText(/Slug/i)).toBeInTheDocument();
241+
});
240242
});
241243
});

0 commit comments

Comments
 (0)