Skip to content

Commit e653a58

Browse files
chore(clerk-js): Add tests cases for org switcher preview visibility (#7094)
1 parent ebc0f74 commit e653a58

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

.changeset/gold-planes-wear.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,52 @@ describe('OrganizationSwitcher', () => {
6262
});
6363

6464
describe('OrganizationSwitcherTrigger', () => {
65+
it('shows OrganizationPreview when user has an active organization', async () => {
66+
const { wrapper, fixtures } = await createFixtures(f => {
67+
f.withOrganizations();
68+
f.withUser({
69+
email_addresses: ['[email protected]'],
70+
organization_memberships: [{ name: 'Test Organization', id: '1', role: 'admin' }],
71+
});
72+
});
73+
74+
// Set the active organization in the context
75+
fixtures.clerk.organization = {
76+
id: '1',
77+
name: 'Test Organization',
78+
slug: 'test-organization',
79+
membersCount: 1,
80+
pendingInvitationsCount: 0,
81+
adminDeleteEnabled: true,
82+
maxAllowedMemberships: 100,
83+
} as any;
84+
85+
const { getByText } = render(<OrganizationSwitcher />, { wrapper });
86+
expect(getByText('Test Organization')).toBeInTheDocument();
87+
});
88+
89+
it('shows PersonalWorkspacePreview when user has no active organization and hidePersonal is false', async () => {
90+
const { wrapper, props } = await createFixtures(f => {
91+
f.withOrganizations();
92+
f.withUser({ email_addresses: ['[email protected]'] });
93+
});
94+
95+
props.setProps({ hidePersonal: false });
96+
const { getByText } = render(<OrganizationSwitcher />, { wrapper });
97+
expect(getByText('Personal account')).toBeInTheDocument();
98+
});
99+
100+
it('shows "No organization selected" when user has no active organization and hidePersonal is true', async () => {
101+
const { wrapper, props } = await createFixtures(f => {
102+
f.withOrganizations();
103+
f.withUser({ email_addresses: ['[email protected]'] });
104+
});
105+
106+
props.setProps({ hidePersonal: true });
107+
const { getByText } = render(<OrganizationSwitcher />, { wrapper });
108+
expect(getByText('No organization selected')).toBeInTheDocument();
109+
});
110+
65111
it('shows the counter for pending suggestions and invitations', async () => {
66112
const { wrapper, fixtures } = await createFixtures(f => {
67113
f.withOrganizations();

0 commit comments

Comments
 (0)