Skip to content

Commit 9aad1c8

Browse files
committed
Add tests
1 parent 1fa88ea commit 9aad1c8

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

packages/ui/src/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,57 @@ describe('OrganizationSwitcher', () => {
308308
expect(queryByText('Create organization')).not.toBeInTheDocument();
309309
});
310310

311+
it('does not allow creating organization if max allowed memberships is reached', async () => {
312+
const { wrapper, props } = await createFixtures(f => {
313+
f.withOrganizations();
314+
f.withMaxAllowedMemberships({ max: 1 });
315+
f.withUser({
316+
email_addresses: ['[email protected]'],
317+
create_organization_enabled: true,
318+
organization_memberships: [{ name: 'Org1', id: '1', role: 'admin' }],
319+
});
320+
});
321+
322+
props.setProps({ hidePersonal: true });
323+
const { queryByText, getByRole, userEvent } = render(<OrganizationSwitcher />, { wrapper });
324+
await userEvent.click(getByRole('button', { name: 'Open organization switcher' }));
325+
expect(queryByText('Create organization')).not.toBeInTheDocument();
326+
});
327+
328+
it('does allow creating organization if max allowed memberships is not reached', async () => {
329+
const { wrapper, props } = await createFixtures(f => {
330+
f.withOrganizations();
331+
f.withMaxAllowedMemberships({ max: 2 });
332+
f.withUser({
333+
email_addresses: ['[email protected]'],
334+
create_organization_enabled: true,
335+
organization_memberships: [{ name: 'Org1', id: '1', role: 'admin' }],
336+
});
337+
});
338+
339+
props.setProps({ hidePersonal: true });
340+
const { queryByText, getByRole, userEvent } = render(<OrganizationSwitcher />, { wrapper });
341+
await userEvent.click(getByRole('button', { name: 'Open organization switcher' }));
342+
expect(queryByText('Create organization')).not.toBeInTheDocument();
343+
});
344+
345+
it('does allow creating organization if max allowed memberships is unlimited', async () => {
346+
const { wrapper, props } = await createFixtures(f => {
347+
f.withOrganizations();
348+
f.withMaxAllowedMemberships({ max: 0 });
349+
f.withUser({
350+
email_addresses: ['[email protected]'],
351+
create_organization_enabled: true,
352+
organization_memberships: [{ name: 'Org1', id: '1', role: 'admin' }],
353+
});
354+
});
355+
356+
props.setProps({ hidePersonal: true });
357+
const { queryByText, getByRole, userEvent } = render(<OrganizationSwitcher />, { wrapper });
358+
await userEvent.click(getByRole('button', { name: 'Open organization switcher' }));
359+
expect(queryByText('Create organization')).not.toBeInTheDocument();
360+
});
361+
311362
it.each([
312363
['Admin', 'admin'],
313364
['Member', 'basic_member'],

0 commit comments

Comments
 (0)