|
| 1 | +import { test } from '@playwright/test'; |
| 2 | + |
| 3 | +import { appConfigs } from '../presets'; |
| 4 | +import type { FakeUser } from '../testUtils'; |
| 5 | +import { createTestUtils, testAgainstRunningApps } from '../testUtils'; |
| 6 | + |
| 7 | +testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('redirect props @nextjs', ({ app }) => { |
| 8 | + test.describe.configure({ mode: 'serial' }); |
| 9 | + |
| 10 | + let fakeUser: FakeUser; |
| 11 | + |
| 12 | + test.beforeAll(async () => { |
| 13 | + const u = createTestUtils({ app }); |
| 14 | + fakeUser = u.services.users.createFakeUser({ |
| 15 | + fictionalEmail: true, |
| 16 | + withPhoneNumber: true, |
| 17 | + withUsername: true, |
| 18 | + }); |
| 19 | + await u.services.users.createBapiUser(fakeUser); |
| 20 | + }); |
| 21 | + |
| 22 | + test.afterAll(async () => { |
| 23 | + await fakeUser.deleteIfExists(); |
| 24 | + await app.teardown(); |
| 25 | + }); |
| 26 | + |
| 27 | + test.afterEach(async ({ page, context }) => { |
| 28 | + const u = createTestUtils({ app, page, context }); |
| 29 | + await u.page.signOut(); |
| 30 | + await u.page.context().clearCookies(); |
| 31 | + }); |
| 32 | + |
| 33 | + test.describe('SignInButton', () => { |
| 34 | + test('sign in button respects forceRedirectUrl', async ({ page, context }) => { |
| 35 | + const u = createTestUtils({ app, page, context }); |
| 36 | + |
| 37 | + await u.page.goToRelative('/buttons'); |
| 38 | + await u.page.waitForClerkJsLoaded(); |
| 39 | + await u.po.expect.toBeSignedOut(); |
| 40 | + |
| 41 | + await u.page.getByText('Sign in button (force)').click(); |
| 42 | + |
| 43 | + await u.po.signIn.waitForMounted(); |
| 44 | + await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); |
| 45 | + |
| 46 | + await u.page.waitForAppUrl('/protected'); |
| 47 | + |
| 48 | + await u.po.expect.toBeSignedIn(); |
| 49 | + }); |
| 50 | + |
| 51 | + test('sign in button respects fallbackRedirectUrl', async ({ page, context }) => { |
| 52 | + const u = createTestUtils({ app, page, context }); |
| 53 | + |
| 54 | + await u.page.goToRelative('/buttons'); |
| 55 | + await u.page.waitForClerkJsLoaded(); |
| 56 | + await u.po.expect.toBeSignedOut(); |
| 57 | + |
| 58 | + await u.page.getByText('Sign in button (fallback)').click(); |
| 59 | + |
| 60 | + await u.po.signIn.waitForMounted(); |
| 61 | + await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); |
| 62 | + |
| 63 | + await u.page.waitForAppUrl('/protected'); |
| 64 | + |
| 65 | + await u.po.expect.toBeSignedIn(); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + test.describe('SignUpButton', () => { |
| 70 | + test('sign up button respects forceRedirectUrl', async ({ page, context }) => { |
| 71 | + const u = createTestUtils({ app, page, context }); |
| 72 | + const fakeUser = u.services.users.createFakeUser({ |
| 73 | + fictionalEmail: true, |
| 74 | + withPhoneNumber: true, |
| 75 | + withUsername: true, |
| 76 | + }); |
| 77 | + |
| 78 | + await u.page.goToRelative('/buttons'); |
| 79 | + await u.page.waitForClerkJsLoaded(); |
| 80 | + |
| 81 | + await u.page.getByText('Sign up button (force)').click(); |
| 82 | + |
| 83 | + // Fill in sign up form |
| 84 | + await u.po.signUp.signUpWithEmailAndPassword({ |
| 85 | + email: fakeUser.email, |
| 86 | + password: fakeUser.password, |
| 87 | + }); |
| 88 | + |
| 89 | + // Verify email |
| 90 | + await u.po.signUp.enterTestOtpCode(); |
| 91 | + |
| 92 | + await u.page.waitForAppUrl('/protected'); |
| 93 | + |
| 94 | + // Check if user is signed in |
| 95 | + await u.po.expect.toBeSignedIn(); |
| 96 | + |
| 97 | + await fakeUser.deleteIfExists(); |
| 98 | + }); |
| 99 | + |
| 100 | + test('sign up button respects fallbackRedirectUrl', async ({ page, context }) => { |
| 101 | + const u = createTestUtils({ app, page, context }); |
| 102 | + const fakeUser = u.services.users.createFakeUser({ |
| 103 | + fictionalEmail: true, |
| 104 | + withPhoneNumber: true, |
| 105 | + withUsername: true, |
| 106 | + }); |
| 107 | + |
| 108 | + await u.page.goToRelative('/buttons'); |
| 109 | + await u.page.waitForClerkJsLoaded(); |
| 110 | + |
| 111 | + await u.page.getByText('Sign up button (fallback)').click(); |
| 112 | + |
| 113 | + // Fill in sign up form |
| 114 | + await u.po.signUp.signUpWithEmailAndPassword({ |
| 115 | + email: fakeUser.email, |
| 116 | + password: fakeUser.password, |
| 117 | + }); |
| 118 | + |
| 119 | + // Verify email |
| 120 | + await u.po.signUp.enterTestOtpCode(); |
| 121 | + |
| 122 | + await u.page.waitForAppUrl('/protected'); |
| 123 | + |
| 124 | + // Check if user is signed in |
| 125 | + await u.po.expect.toBeSignedIn(); |
| 126 | + |
| 127 | + await fakeUser.deleteIfExists(); |
| 128 | + }); |
| 129 | + }); |
| 130 | +}); |
0 commit comments