Skip to content

Commit 6f42acb

Browse files
test: add viewer role to tests (#10398)
* fix: add viewer role to tests * global setup for viewer * add global setup * fix global setup * cleanup * Update app/tests/viewer-access.spec.ts Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> --------- Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
1 parent 4b615b7 commit 6f42acb

File tree

4 files changed

+116
-2
lines changed

4 files changed

+116
-2
lines changed

app/global-setup.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ async function globalSetup(config: FullConfig) {
2323
await page.waitForURL("**/projects");
2424
await page.goto(`${baseURL}/settings/general`);
2525
await page.waitForURL("**/settings/general");
26-
await page.getByRole("button", { name: "Add User" }).click();
2726

2827
// Add member user
28+
await page.getByRole("button", { name: "Add User" }).click();
2929
await page.getByLabel("Email").fill("[email protected]");
3030
await page.getByLabel("Username").fill("member");
3131
await page.getByLabel("Password", { exact: true }).fill("member");
@@ -38,11 +38,25 @@ async function globalSetup(config: FullConfig) {
3838
.getByRole("button", { name: "Add User" })
3939
.click();
4040

41+
// Add viewer user
42+
await page.getByRole("button", { name: "Add User" }).click();
43+
await page.getByLabel("Email").fill("[email protected]");
44+
await page.getByLabel("Username").fill("viewer");
45+
await page.getByLabel("Password", { exact: true }).fill("viewer");
46+
await page.getByLabel("Confirm Password").fill("viewer");
47+
48+
await page.getByRole("dialog").getByLabel("member", { exact: true }).click();
49+
await page.getByRole("option", { name: "viewer" }).click();
50+
await page
51+
.getByRole("dialog")
52+
.getByRole("button", { name: "Add User" })
53+
.click();
54+
4155
// Log out of admin account
4256
await page.getByRole("button", { name: "Log Out" }).click();
4357

4458
// Log in as member
45-
page.goto(`${baseURL}/login`);
59+
await page.goto(`${baseURL}/login`);
4660
await page.getByLabel("Email").fill("[email protected]");
4761
await page.getByLabel("Password").fill("member");
4862
await page.getByRole("button", { name: "Log In", exact: true }).click();
@@ -53,6 +67,19 @@ async function globalSetup(config: FullConfig) {
5367
await page.getByLabel("New Password").fill("member123");
5468
await page.getByLabel("Confirm Password").fill("member123");
5569
await page.getByRole("button", { name: "Reset Password" }).click();
70+
71+
// Log in as viewer
72+
await page.goto(`${baseURL}/login`);
73+
await page.getByLabel("Email").fill("[email protected]");
74+
await page.getByLabel("Password").fill("viewer");
75+
await page.getByRole("button", { name: "Log In", exact: true }).click();
76+
77+
// Reset viewer password
78+
await page.waitForURL("**/reset-password");
79+
await page.getByLabel("Old Password").fill("viewer");
80+
await page.getByLabel("New Password").fill("viewer123");
81+
await page.getByLabel("Confirm Password").fill("viewer123");
82+
await page.getByRole("button", { name: "Reset Password" }).click();
5683
}
5784

5885
export default globalSetup;

app/tests/member-access.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,15 @@ test("can create user key", async ({ page }) => {
3434
timeout: 60000,
3535
});
3636
});
37+
38+
test("should be able to create a new project", async ({ page }) => {
39+
await page.goto("/projects");
40+
await page.waitForURL("**/projects");
41+
42+
// Wait for the page to be loaded
43+
await expect(
44+
page.getByRole("searchbox", { name: "Search projects by name" })
45+
).toBeVisible();
46+
47+
await expect(page.getByRole("button", { name: "New Project" })).toBeVisible();
48+
});

app/tests/user-management.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,28 @@ test("can create a user", async ({ page }) => {
3434
// Check if the user is created
3535
await expect(page.getByRole("cell", { name: email })).toBeVisible();
3636
});
37+
38+
test("can create a user with viewer role", async ({ page }) => {
39+
await page.goto("/settings/general");
40+
await page.waitForURL("**/settings/general");
41+
await page.getByRole("button", { name: "Add User" }).click();
42+
43+
const email = `viewer-${randomUUID()}@localhost.com`;
44+
// Add the user
45+
await page.getByLabel("Email").fill(email);
46+
await page.getByLabel("Username").fill(email);
47+
await page.getByLabel("Password", { exact: true }).fill("viewer123");
48+
await page.getByLabel("Confirm Password").fill("viewer123");
49+
await page.getByRole("dialog").getByLabel("member", { exact: true }).click();
50+
await page
51+
.getByRole("dialog")
52+
.getByRole("option", { name: "viewer" })
53+
.click();
54+
await page
55+
.getByRole("dialog")
56+
.getByRole("button", { name: "Add User" })
57+
.click();
58+
59+
// Check if the user is created
60+
await expect(page.getByRole("cell", { name: email })).toBeVisible();
61+
});

app/tests/viewer-access.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { expect, test } from "@playwright/test";
2+
import { randomUUID } from "crypto";
3+
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto(`/login`);
6+
await page.getByLabel("Email").fill("[email protected]");
7+
await page.getByLabel("Password").fill("viewer123");
8+
await page.getByRole("button", { name: "Log In", exact: true }).click();
9+
await page.waitForURL("**/projects");
10+
});
11+
12+
test("can create user key", async ({ page }) => {
13+
// Navigate to profile page
14+
await page.goto("/profile");
15+
16+
// Generate a unique key name for this test run
17+
const keyName = `key-${randomUUID()}`;
18+
19+
// Click the "New Key" button to open the create dialog
20+
await page.getByRole("button", { name: "New Key" }).click();
21+
22+
// Fill in the key name and submit
23+
await page.getByRole("dialog").getByLabel("Name").fill(keyName);
24+
await page.getByRole("button", { name: "Create Key" }).click();
25+
26+
// Close the dialog that appears after creating the key
27+
await page
28+
.getByRole("dialog")
29+
.getByRole("button", { name: "dismiss" })
30+
.click();
31+
32+
// Verify the named key appears in the table - which means key creation succeeded
33+
await expect(page.getByRole("cell", { name: keyName })).toBeVisible({
34+
timeout: 60000,
35+
});
36+
});
37+
38+
test("should not be able to create a new project", async ({ page }) => {
39+
await page.goto("/projects");
40+
await page.waitForURL("**/projects");
41+
42+
// Wait for the page to be loaded
43+
await expect(
44+
page.getByRole("searchbox", { name: "Search projects by name" })
45+
).toBeVisible();
46+
47+
await expect(
48+
page.getByRole("button", { name: "New Project" })
49+
).not.toBeVisible();
50+
});

0 commit comments

Comments
 (0)