|
| 1 | +import { test } from '@playwright/test'; |
| 2 | + |
| 3 | +import type { Application } from '../models/application'; |
| 4 | +import { appConfigs } from '../presets'; |
| 5 | +import type { FakeUser } from '../testUtils'; |
| 6 | +import { createTestUtils } from '../testUtils'; |
| 7 | + |
| 8 | +test.describe('user profile @generic', () => { |
| 9 | + test.describe.configure({ mode: 'serial' }); |
| 10 | + let app: Application; |
| 11 | + let fakeUser: FakeUser; |
| 12 | + |
| 13 | + test.beforeAll(async () => { |
| 14 | + app = await appConfigs.next.appRouter |
| 15 | + .clone() |
| 16 | + .addFile( |
| 17 | + 'src/app/provider.tsx', |
| 18 | + () => `'use client' |
| 19 | +import { ClerkProvider } from "@clerk/nextjs"; |
| 20 | +
|
| 21 | +export function Provider({ children }: { children: any }) { |
| 22 | + return ( |
| 23 | + <ClerkProvider> |
| 24 | + {children} |
| 25 | + </ClerkProvider> |
| 26 | + ) |
| 27 | +}`, |
| 28 | + ) |
| 29 | + .addFile( |
| 30 | + 'src/app/layout.tsx', |
| 31 | + () => `import './globals.css'; |
| 32 | +import { Inter } from 'next/font/google'; |
| 33 | +import { Provider } from './provider'; |
| 34 | +
|
| 35 | +const inter = Inter({ subsets: ['latin'] }); |
| 36 | +
|
| 37 | +export const metadata = { |
| 38 | + title: 'Create Next App', |
| 39 | + description: 'Generated by create next app', |
| 40 | +}; |
| 41 | +
|
| 42 | +export default function RootLayout({ children }: { children: React.ReactNode }) { |
| 43 | + return ( |
| 44 | + <Provider> |
| 45 | + <html lang='en'> |
| 46 | + <body className={inter.className}>{children}</body> |
| 47 | + </html> |
| 48 | + </Provider> |
| 49 | + ); |
| 50 | +}`, |
| 51 | + ) |
| 52 | + .addFile( |
| 53 | + 'src/app/hash/user/page.tsx', |
| 54 | + () => ` |
| 55 | +import { UserProfile, UserButton } from '@clerk/nextjs'; |
| 56 | +
|
| 57 | +export default function Page() { |
| 58 | + return ( |
| 59 | + <div> |
| 60 | + <UserButton /> |
| 61 | + <UserProfile routing="hash" /> |
| 62 | + </div> |
| 63 | + ); |
| 64 | +}`, |
| 65 | + ) |
| 66 | + .commit(); |
| 67 | + await app.setup(); |
| 68 | + await app.withEnv(appConfigs.envs.withEmailCodes); |
| 69 | + await app.build(); |
| 70 | + |
| 71 | + const m = createTestUtils({ app }); |
| 72 | + fakeUser = m.services.users.createFakeUser(); |
| 73 | + await m.services.users.createBapiUser(fakeUser); |
| 74 | + |
| 75 | + await app.serve(); |
| 76 | + }); |
| 77 | + |
| 78 | + test.afterAll(async () => { |
| 79 | + await fakeUser.deleteIfExists(); |
| 80 | + await app.teardown(); |
| 81 | + }); |
| 82 | + |
| 83 | + test('user profile with path routing', async ({ page, context }) => { |
| 84 | + const u = createTestUtils({ app, page, context }); |
| 85 | + await u.po.signIn.goTo(); |
| 86 | + await u.po.signIn.waitForMounted(); |
| 87 | + await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); |
| 88 | + await u.po.expect.toBeSignedIn(); |
| 89 | + |
| 90 | + await u.po.userProfile.goTo(); |
| 91 | + await u.po.userProfile.waitForMounted(); |
| 92 | + |
| 93 | + await u.po.userProfile.clickSetUsername(); |
| 94 | + |
| 95 | + u.page.getByText(/Update username/i); |
| 96 | + |
| 97 | + await u.po.userProfile.typeUsername('some_username'); |
| 98 | + |
| 99 | + await u.page.getByText(/Cancel/i).click(); |
| 100 | + |
| 101 | + await u.page.waitForSelector('.cl-profileSectionContent__username .cl-headerTitle', { state: 'detached' }); |
| 102 | + |
| 103 | + await u.po.userProfile.clickAddEmailAddress(); |
| 104 | + |
| 105 | + u.page.getByText(/an email containing/i); |
| 106 | + |
| 107 | + await u.po.userProfile.typeEmailAddress('some@email.com'); |
| 108 | + |
| 109 | + await u.page.getByText(/Cancel/i).click(); |
| 110 | + }); |
| 111 | + |
| 112 | + test('user profile with hash routing', async ({ page, context }) => { |
| 113 | + const u = createTestUtils({ app, page, context }); |
| 114 | + await u.po.signIn.goTo(); |
| 115 | + await u.po.signIn.waitForMounted(); |
| 116 | + await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); |
| 117 | + await u.po.expect.toBeSignedIn(); |
| 118 | + |
| 119 | + await u.page.goToRelative('/hash/user'); |
| 120 | + await u.po.userProfile.waitForMounted(); |
| 121 | + |
| 122 | + await u.po.userProfile.clickSetUsername(); |
| 123 | + |
| 124 | + u.page.getByText(/Update username/i); |
| 125 | + |
| 126 | + await u.po.userProfile.typeUsername('some_username'); |
| 127 | + |
| 128 | + await u.page.getByText(/Cancel/i).click(); |
| 129 | + |
| 130 | + await u.page.waitForSelector('.cl-profileSectionContent__username .cl-headerTitle', { state: 'detached' }); |
| 131 | + |
| 132 | + await u.po.userProfile.clickAddEmailAddress(); |
| 133 | + |
| 134 | + u.page.getByText(/an email containing/i); |
| 135 | + |
| 136 | + await u.po.userProfile.typeEmailAddress('some@email.com'); |
| 137 | + |
| 138 | + await u.page.getByText(/Cancel/i).click(); |
| 139 | + }); |
| 140 | + |
| 141 | + test('user profile from user button opens actions correctly', async ({ page, context }) => { |
| 142 | + const u = createTestUtils({ app, page, context }); |
| 143 | + await u.po.signIn.goTo(); |
| 144 | + await u.po.signIn.waitForMounted(); |
| 145 | + await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); |
| 146 | + await u.po.expect.toBeSignedIn(); |
| 147 | + |
| 148 | + await u.page.goToRelative('/'); |
| 149 | + await u.page.waitForClerkComponentMounted(); |
| 150 | + |
| 151 | + await u.page.getByRole('button', { name: 'Open user button' }).click(); |
| 152 | + |
| 153 | + await u.page.getByText(/Manage account/).click(); |
| 154 | + |
| 155 | + await u.page.waitForSelector('.cl-modalContent > .cl-userProfile-root', { state: 'attached' }); |
| 156 | + |
| 157 | + await u.po.userProfile.clickSetUsername(); |
| 158 | + await u.page.getByText(/Cancel/i).click(); |
| 159 | + |
| 160 | + await u.page.waitForSelector('.cl-profileSectionContent__username .cl-headerTitle', { state: 'detached' }); |
| 161 | + |
| 162 | + await u.po.userProfile.clickAddEmailAddress(); |
| 163 | + await u.page.getByText(/Cancel/i).click(); |
| 164 | + }); |
| 165 | +}); |
0 commit comments