-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathauth.e2e.ts
More file actions
83 lines (71 loc) · 3.07 KB
/
Copy pathauth.e2e.ts
File metadata and controls
83 lines (71 loc) · 3.07 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
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
import { expect, test, type Page } from '@playwright/test'
import { ANONYMOUS_STATE, expectLoggedIn, login, logout } from './helpers'
async function expectMobileAccountMenuContained(page: Page): Promise<void> {
const metrics = await page.getByRole('menu', { name: 'Account menu' }).evaluate((element) => {
const documentElement = document.documentElement
const viewportWidth = documentElement.clientWidth
const menuRect = element.getBoundingClientRect()
const signOut = element.querySelector('[data-testid="account-menu-sign-out"]')
const signOutRect = signOut?.getBoundingClientRect()
return {
pageOverflow: documentElement.scrollWidth - viewportWidth,
menuContained: menuRect.left >= -1 && menuRect.right <= viewportWidth + 1,
signOutVisible: Boolean(signOutRect && signOutRect.width > 0 && signOutRect.height > 0),
signOutContained: signOutRect
? signOutRect.left >= menuRect.left - 1 && signOutRect.right <= menuRect.right + 1
: false,
}
})
expect(metrics.pageOverflow).toBeLessThanOrEqual(1)
expect(metrics.menuContained).toBe(true)
expect(metrics.signOutVisible).toBe(true)
expect(metrics.signOutContained).toBe(true)
}
/**
* AUTH-003 — signing out revokes the server session, so another tab carrying
* the same old cookie cannot keep browsing authenticated admin routes.
*/
test.describe('auth session lifecycle', () => {
test.use({ storageState: ANONYMOUS_STATE })
test('revokes the signed-out session across tabs (AUTH-003)', async ({
page,
browser,
}) => {
await login(page)
await expectLoggedIn(page)
const staleContext = await browser.newContext({
storageState: await page.context().storageState(),
})
try {
const stalePage = await staleContext.newPage()
const staleConsoleErrors: string[] = []
stalePage.on('console', (message) => {
if (message.type() === 'error') staleConsoleErrors.push(message.text())
})
await stalePage.goto('/admin/site')
await expectLoggedIn(stalePage)
await logout(page)
await stalePage.goto('/admin/site')
await expect(stalePage.getByRole('heading', { name: 'Admin Login' })).toBeVisible()
await expect(stalePage.getByTestId('account-menu-trigger')).toHaveCount(0)
expect(staleConsoleErrors).not.toContainEqual(
expect.stringContaining('[module-inserter] failed to load user preference'),
)
} finally {
await staleContext.close()
}
})
test('keeps account-menu sign out reachable at mobile width (AUTH-003)', async ({
page,
}) => {
await page.setViewportSize({ width: 390, height: 844 })
await login(page)
await expectLoggedIn(page)
await page.getByTestId('account-menu-trigger').click()
await expect(page.getByRole('menu', { name: 'Account menu' })).toBeVisible()
await expectMobileAccountMenuContained(page)
await page.getByTestId('account-menu-sign-out').click()
await expect(page.getByRole('heading', { name: 'Admin Login' })).toBeVisible()
await expect(page.getByTestId('account-menu-trigger')).toHaveCount(0)
})
})