Skip to content

Commit cdffe2e

Browse files
committed
test(e2e): cover Profile, UserProfile and OrganizationProfile on their own pages
1 parent aa77957 commit cdffe2e

4 files changed

Lines changed: 123 additions & 6 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use client';
2+
3+
import { MosaicProvider, Profile } from '@clerk/mosaic';
4+
5+
export default function Page() {
6+
return (
7+
<MosaicProvider>
8+
<Profile
9+
customPages={[{ label: 'Custom page', path: 'custom-page', content: <p>custom-page-content</p> }]}
10+
organizationProfileProps={{
11+
customPages: [{ label: 'Team page', path: 'team-page', content: <p>team-page-content</p> }],
12+
}}
13+
/>
14+
</MosaicProvider>
15+
);
16+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use client';
22

3-
import { MosaicProvider, Profile } from '@clerk/mosaic';
3+
import { MosaicProvider, UserProfile } from '@clerk/mosaic';
44

55
export default function Page() {
66
return (
77
<MosaicProvider>
8-
<Profile customPages={[{ label: 'Custom page', path: 'custom-page', content: <p>custom-page-content</p> }]} />
8+
<UserProfile customPages={[{ label: 'Custom page', path: 'custom-page', content: <p>custom-page-content</p> }]} />
99
</MosaicProvider>
1010
);
1111
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import type { Organization } from '@clerk/backend';
2+
import type { BrowserContext, Page } from '@playwright/test';
3+
import { expect, test } from '@playwright/test';
4+
5+
import type { FakeUser } from '../../testUtils';
6+
import { createTestUtils, testAgainstRunningApps } from '../../testUtils';
7+
8+
testAgainstRunningApps({ withPattern: ['next.appRouterMosaic.*'] })('Mosaic Profile @mosaic', ({ app }) => {
9+
test.describe.configure({ mode: 'serial' });
10+
11+
let fakeUser: FakeUser;
12+
let organization: Organization;
13+
const cleanups: Array<() => Promise<unknown>> = [];
14+
15+
test.beforeAll(async () => {
16+
const u = await createTestUtils({ app });
17+
fakeUser = u.services.users.createFakeUser(test);
18+
cleanups.push(() => fakeUser.deleteIfExists());
19+
const user = await u.services.users.createBapiUser(fakeUser);
20+
organization = await u.services.clerk.organizations.createOrganization({
21+
name: `Mosaic ${Date.now()}`,
22+
createdBy: user.id,
23+
});
24+
cleanups.push(() => u.services.clerk.organizations.deleteOrganization(organization.id));
25+
});
26+
27+
test.afterAll(async () => {
28+
const results = await Promise.allSettled(cleanups.map(cleanup => cleanup()));
29+
await app.teardown();
30+
const failures = results.flatMap(result => (result.status === 'rejected' ? [result.reason] : []));
31+
if (failures.length > 0) {
32+
throw new AggregateError(failures, 'Mosaic Profile cleanup failed');
33+
}
34+
});
35+
36+
const path = '/profile';
37+
const tab = (page: Page, name: string) => page.getByRole('navigation').getByRole('tab', { name, exact: true });
38+
39+
async function signIn({ page, context }: { page: Page; context: BrowserContext }) {
40+
const u = await createTestUtils({ app, page, context });
41+
await page.setViewportSize({ width: 1280, height: 800 });
42+
await u.po.signIn.goTo();
43+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
44+
await u.page.goToRelative(path);
45+
await u.po.expect.toBeSignedIn();
46+
await expect(tab(page, 'Account')).toBeVisible();
47+
return u;
48+
}
49+
50+
test('renders nothing when signed out', async ({ page, context }) => {
51+
const u = await createTestUtils({ app, page, context });
52+
await u.page.goToRelative(path);
53+
await u.page.waitForClerkJsLoaded();
54+
55+
await expect(tab(page, 'Account')).toHaveCount(0);
56+
});
57+
58+
test('opens on the account page with the signed-in user', async ({ page, context }) => {
59+
await signIn({ page, context });
60+
61+
await expect(tab(page, 'Account')).toHaveAttribute('aria-selected', 'true');
62+
await expect(page.getByText(fakeUser.email)).toBeVisible();
63+
});
64+
65+
test("lists the active organization's pages after the account's", async ({ page, context }) => {
66+
await signIn({ page, context });
67+
68+
await page.evaluate(orgId => window.Clerk?.setActive({ organization: orgId }), organization.id);
69+
await page.waitForFunction(orgId => window.Clerk?.organization?.id === orgId, organization.id);
70+
71+
await expect(tab(page, 'General')).toBeVisible();
72+
await expect(page.getByRole('navigation').getByRole('tab')).toHaveText([
73+
'Account',
74+
'Security',
75+
'Custom page',
76+
'General',
77+
'Members',
78+
'Team page',
79+
]);
80+
81+
await tab(page, 'General').click();
82+
await expect(tab(page, 'General')).toHaveAttribute('aria-selected', 'true');
83+
await expect(page.getByText(organization.name).first()).toBeVisible();
84+
});
85+
86+
test("renders a custom page in the organization's group", async ({ page, context }) => {
87+
await signIn({ page, context });
88+
89+
await page.evaluate(orgId => window.Clerk?.setActive({ organization: orgId }), organization.id);
90+
await page.waitForFunction(orgId => window.Clerk?.organization?.id === orgId, organization.id);
91+
92+
await tab(page, 'Team page').click();
93+
await expect(page.getByText('team-page-content')).toBeVisible();
94+
});
95+
96+
test('renders a custom page', async ({ page, context }) => {
97+
await signIn({ page, context });
98+
99+
await tab(page, 'Custom page').click();
100+
await expect(page.getByText('custom-page-content')).toBeVisible();
101+
});
102+
});

‎integration/tests/mosaic/user-profile.test.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ testAgainstRunningApps({ withPattern: ['next.appRouterMosaic.*'] })('Mosaic User
6262
await expect(page.getByText(fakeUser.email)).toBeVisible();
6363
});
6464

65-
test("lists the active organization's pages after the account's", async ({ page, context }) => {
65+
test("leaves out the organization's pages with an active organization", async ({ page, context }) => {
6666
await signIn({ page, context });
6767

6868
await page.evaluate(orgId => window.Clerk?.setActive({ organization: orgId }), organization.id);
6969
await page.waitForFunction(orgId => window.Clerk?.organization?.id === orgId, organization.id);
7070

71-
await tab(page, 'General').click();
72-
await expect(tab(page, 'General')).toHaveAttribute('aria-selected', 'true');
73-
await expect(page.getByText(organization.name).first()).toBeVisible();
71+
await expect(tab(page, 'Security')).toBeVisible();
72+
await expect(tab(page, 'General')).toHaveCount(0);
7473
});
7574

7675
test('renders a custom page', async ({ page, context }) => {

0 commit comments

Comments
 (0)