-
Notifications
You must be signed in to change notification settings - Fork 338
/
Copy pathwaitlist-mode.test.ts
176 lines (146 loc) · 5.17 KB
/
waitlist-mode.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { expect, test } from '@playwright/test';
import type { Application } from '../models/application';
import { appConfigs } from '../presets';
import type { FakeUser } from '../testUtils';
import { createTestUtils } from '../testUtils';
test.describe('Waitlist mode', () => {
test.describe.configure({ mode: 'parallel' });
let app: Application;
let fakeUser: FakeUser;
test.beforeAll(async () => {
app = await appConfigs.next.appRouter
.clone()
.addFile(
'src/app/provider.tsx',
() => `'use client'
import { ClerkProvider } from "@clerk/nextjs";
export function Provider({ children }: { children: any }) {
return (
<ClerkProvider waitlistUrl='/waitlist'>
{children}
</ClerkProvider>
)
}`,
)
.addFile(
'src/app/layout.tsx',
() => `import './globals.css';
import { Inter } from 'next/font/google';
import { Provider } from './provider';
const inter = Inter({ subsets: ['latin'] });
export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<Provider>
<html lang='en'>
<body className={inter.className}>{children}</body>
</html>
</Provider>
);
}`,
)
.addFile(
'src/app/hash/user/page.tsx',
() => `
import { UserProfile, UserButton } from '@clerk/nextjs';
export default function Page() {
return (
<div>
<UserButton />
<UserProfile routing="hash" />
</div>
);
}`,
)
.addFile(
'src/app/waitlist/page.tsx',
() => `
import { Waitlist } from '@clerk/nextjs';
export default function Page() {
return (
<div>
<Waitlist />
</div>
);
}`,
)
.commit();
await app.setup();
await app.withEnv(appConfigs.envs.withWaitlistdMode);
await app.dev();
const m = createTestUtils({ app });
fakeUser = m.services.users.createFakeUser({
withUsername: true,
fictionalEmail: true,
withPhoneNumber: true,
});
await m.services.users.createBapiUser({
...fakeUser,
username: undefined,
phoneNumber: undefined,
});
});
test.afterAll(async () => {
await fakeUser.deleteIfExists();
await app.teardown();
});
test('Existing user signs in succesfull', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.signIn.goTo();
await u.po.signIn.waitForMounted();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
await u.po.expect.toBeSignedIn();
await u.po.userProfile.goTo();
await u.po.userProfile.waitForMounted();
});
test('Sign up page return restricted and click Back to sign in', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.signUp.goTo();
await u.po.signUp.waitForMounted();
await expect(u.page.getByText(/Access restricted/i).first()).toBeVisible();
const backToSignIn = u.page.getByRole('link', { name: /Sign in/i });
await backToSignIn.click();
await u.po.signIn.waitForMounted();
await u.page.waitForAppUrl('/sign-in');
});
test('Sign up page with invitation render correctly and sign up', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
const invitedUser = u.services.users.createFakeUser();
const invitation = await u.services.invitations.createBapiInvitation(invitedUser.email);
await u.po.testingToken.setup();
await u.page.goto(invitation.url);
await u.po.signUp.waitForMounted();
await expect(u.page.getByText(/Create your account/i).first()).toBeVisible();
await u.po.signUp.signUp({
password: invitedUser.password,
});
await u.po.expect.toBeSignedIn();
await invitedUser.deleteIfExists();
});
test('Navigate to waitlist page and join the waitlist', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.waitlist.goTo();
await u.po.waitlist.waitForMounted();
await expect(u.page.getByText(/Join the waitlist/i).first()).toBeVisible();
await u.po.waitlist.joinWaitlist({ email: fakeUser.email });
await expect(u.page.getByText(/Thanks for joining the waitlist!/i).first()).toBeVisible();
});
test('Navigate between sign-in and waitlist', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.po.signIn.goTo();
await u.po.signIn.waitForMounted();
const waitlistLink = u.page.getByRole('link', { name: /Join waitlist/i });
await expect(waitlistLink).toBeVisible();
await waitlistLink.click();
await u.po.waitlist.waitForMounted();
await u.page.waitForAppUrl('/waitlist');
const signInList = u.page.getByRole('link', { name: /Sign in/i });
await expect(signInList).toBeVisible();
await signInList.click();
await u.po.signIn.waitForMounted();
await u.page.waitForAppUrl('/sign-in');
});
});