-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpermissions.test.ts
More file actions
50 lines (40 loc) · 1.93 KB
/
Copy pathpermissions.test.ts
File metadata and controls
50 lines (40 loc) · 1.93 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
import test, { expect } from '@playwright/test'
import { createGroup, deleteGroup, gotoGroup, joinGroup } from './group'
import { newWindow, randomString, register } from './generic'
import { assignPermission, createPermission } from './permission'
import 'dotenv/config'
// Two users: A owns a group and controls permissions, B is a member whose
// "Create a post" ability is toggled by the role A assigns.
test('Permissions', async ({ page }) => {
// Heavy two-user flow (two registrations, two role creations, two assignments);
// give it a larger timeout so it survives parallel load.
test.slow()
const group = { name: 'Test Group Permissions ' + randomString(), public: true }
// A creates the group
await register(page)
await createGroup(page, group)
await expect(page.locator('#group-header-title')).toHaveText(group.name)
// B joins the group
const bPage = await newWindow()
const b = await register(bPage)
await joinGroup(bPage, group)
const createPostButton = bPage.locator('#create-a-post-sidebar-button')
// A creates an empty role and a full role
const noPermission = 'No Permissions'
const fullPermission = 'Full Permissions'
const allPerms = [...Array(17).keys()]
await page.getByRole('button', { name: 'Edit Group' }).dispatchEvent('click')
await createPermission(page, group, [], noPermission)
await createPermission(page, group, allPerms, fullPermission)
// Assign the empty role -> B cannot create a post
await assignPermission(page, group, noPermission, b.username)
await gotoGroup(bPage, group)
await createPostButton.waitFor()
await expect(createPostButton).toHaveAttribute('aria-disabled', 'true')
// Assign the full role -> B can create a post
await assignPermission(page, group, fullPermission, b.username)
await gotoGroup(bPage, group)
await createPostButton.waitFor()
await expect(createPostButton).toHaveAttribute('aria-disabled', 'false')
await deleteGroup(page, group)
})