-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathauth-redirect.spec.ts
More file actions
58 lines (47 loc) · 1.67 KB
/
auth-redirect.spec.ts
File metadata and controls
58 lines (47 loc) · 1.67 KB
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
import { test, expect } from './base-test'
import { authFixtures } from './fixtures'
test.describe('Auto-redirect after authentication', () => {
test.describe('Unauthenticated user', () => {
test.use({
storageState: authFixtures.public,
})
test('redirects to login with redirectTo param when accessing protected route', async ({
page,
}) => {
await page.goto('/dashboard/profile/edit')
await page.waitForURL('**/login**')
const url = new URL(page.url())
expect(url.pathname).toBe('/login')
expect(url.searchParams.get('redirectTo')).toBe('/dashboard/profile/edit')
})
test('login page preserves redirectTo in form action URL', async ({
page,
}) => {
await page.goto('/login?redirectTo=/dashboard/transactions')
await expect(page.getByText('Masuk ke akun Anda')).toBeVisible()
const currentUrl = new URL(page.url())
expect(currentUrl.searchParams.get('redirectTo')).toBe(
'/dashboard/transactions'
)
})
})
test.describe('Authenticated user', () => {
test.use({
storageState: authFixtures.member,
})
test('login page redirects to redirectTo param if already authenticated', async ({
page,
}) => {
await page.goto('/login?redirectTo=/dashboard/profile/edit')
await page.waitForURL('**/dashboard/profile/edit')
expect(page.url()).toContain('/dashboard/profile/edit')
})
test('login page redirects to dashboard by default if already authenticated', async ({
page,
}) => {
await page.goto('/login')
await page.waitForURL('**/dashboard')
expect(page.url()).toContain('/dashboard')
})
})
})