-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathnext-quickstart.test.ts
111 lines (74 loc) · 3.55 KB
/
next-quickstart.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
import { expect, test } from '@playwright/test';
import { appConfigs } from '../presets';
import type { FakeUser } from '../testUtils';
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodesQuickstart] })('nextjs @quickstart', ({ app }) => {
test.describe.configure({ mode: 'serial' });
let fakeUser: FakeUser;
test.beforeAll(async () => {
const u = createTestUtils({ app });
fakeUser = u.services.users.createFakeUser();
await u.services.users.createBapiUser(fakeUser);
});
test.afterAll(async () => {
await fakeUser.deleteIfExists();
await app.teardown();
});
test('Clerk client loads on first visit and Sign In button renders', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.page.goToAppHome();
await u.page.waitForClerkJsLoaded();
await u.po.expect.toBeSignedOut();
await expect(u.page.getByRole('button', { name: /Sign in/i })).toBeVisible();
});
test('can sign in with email and password', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.page.goToAppHome();
await u.page.waitForClerkJsLoaded();
await u.po.expect.toBeSignedOut();
await u.page.getByRole('button', { name: /Sign in/i }).click();
await u.po.signIn.waitForMounted();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
await u.page.waitForAppUrl('/');
await u.po.expect.toBeSignedIn();
await u.po.userButton.waitForMounted();
await expect(u.page.getByRole('button', { name: /Open user button/i })).toBeVisible();
});
test('user button is functional after sign in', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.page.goToAppHome();
await u.page.waitForClerkJsLoaded();
await u.po.expect.toBeSignedOut();
await u.page.getByRole('button', { name: /Sign in/i }).click();
await u.po.signIn.waitForMounted();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
await u.page.waitForAppUrl('/');
await u.po.expect.toBeSignedIn();
await u.po.userButton.waitForMounted();
await u.po.userButton.toggleTrigger();
await u.po.userButton.waitForPopover();
await u.po.userButton.toHaveVisibleMenuItems([/Manage account/i, /Sign out$/i]);
await u.po.userButton.triggerManageAccount();
await u.po.userProfile.waitForUserProfileModal();
await expect(u.page.getByText(/profile details/i)).toBeVisible();
});
test('can sign out through user button', async ({ page, context }) => {
const u = createTestUtils({ app, page, context });
await u.page.goToAppHome();
await u.page.waitForClerkJsLoaded();
await u.po.expect.toBeSignedOut();
await u.page.getByRole('button', { name: /Sign in/i }).click();
await u.po.signIn.waitForMounted();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
await u.page.waitForAppUrl('/');
await u.po.expect.toBeSignedIn();
await u.po.userButton.waitForMounted();
await u.po.userButton.toggleTrigger();
await u.po.userButton.waitForPopover();
await u.po.userButton.toHaveVisibleMenuItems([/Sign out$/i]);
await u.po.userButton.triggerSignOut();
await u.page.waitForAppUrl('/');
await u.po.expect.toBeSignedOut();
await expect(u.page.getByRole('button', { name: /Sign in/i })).toBeVisible();
});
});