-
Notifications
You must be signed in to change notification settings - Fork 169
/
guest-links.spec.ts
135 lines (109 loc) · 4.21 KB
/
guest-links.spec.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { test, expect } from "@playwright/test";
import { login } from "./helpers/login.js";
import { readDbTokenCookie } from "./helpers/db.js";
const labelColumn = 0;
test("creates a guest link and uploads a file as a guest", async ({ page }) => {
await login(page);
await page.getByRole("menuitem", { name: "Guest Links" }).click();
await page.getByRole("button", { name: "Create new" }).click();
await expect(page).toHaveURL("/guest-links/new");
await page.locator("#label").fill("For e2e testing");
await page.locator("#max-file-size").fill("50");
await page.locator("#file-upload-limit").fill("1");
await page.getByRole("button", { name: "Create" }).click();
await expect(page).toHaveURL("/guest-links");
const guestLinkRow = await page
.getByRole("row")
.filter({ hasText: "For e2e testing" });
await expect(guestLinkRow).toBeVisible();
// Save the route to the guest link URL so that we can return to it later.
const guestLinkRouteValue = await guestLinkRow
.getByRole("cell")
.nth(labelColumn)
.getByRole("link")
.getAttribute("href");
expect(guestLinkRouteValue).not.toBeNull();
const guestLinkRoute = String(guestLinkRouteValue);
await page.getByRole("menuitem", { name: "System" }).hover();
await page.getByRole("menuitem", { name: "Log Out" }).click();
await expect(page).toHaveURL("/");
await page.goto(guestLinkRoute);
await page.locator(".file-input").setInputFiles([
{
name: "guest-link-upload.txt",
mimeType: "text/plain",
buffer: Buffer.from("uploaded by a guest user"),
},
]);
await expect(page.locator("#upload-result .message-body")).toHaveText(
"Upload complete!"
);
await expect(page.locator("#upload-result upload-links")).toHaveAttribute(
"filename",
"guest-link-upload.txt"
);
await expect(
page.locator("#upload-result upload-links #verbose-link-box #link")
).toBeVisible();
await expect(
page.locator("#upload-result upload-links #short-link-box #link")
).toBeVisible();
await page.getByRole("button", { name: "Upload Another" }).click();
await expect(page.locator("h1")).toContainText("Guest Link Inactive");
await expect(page.locator(".file-input")).toHaveCount(0);
});
test("files uploaded through guest link remain accessible after guest link is deleted", async ({
page,
browser,
}) => {
await login(page);
await page.getByRole("menuitem", { name: "Guest Links" }).click();
await page.getByRole("button", { name: "Create new" }).click();
await expect(page).toHaveURL("/guest-links/new");
await page.locator("#label").fill("I'll be deleted soon");
await page.locator("#file-upload-limit").fill("1");
await page.getByRole("button", { name: "Create" }).click();
await expect(page).toHaveURL("/guest-links");
const guestLinkRow = await page
.getByRole("row")
.filter({ hasText: "I'll be deleted soon" });
await expect(guestLinkRow).toBeVisible();
// Save the route to the guest link URL so that we can return to it later.
const guestLinkRouteValue = await guestLinkRow
.getByRole("cell")
.nth(labelColumn)
.getByRole("link")
.getAttribute("href");
expect(guestLinkRouteValue).not.toBeNull();
const guestLinkRoute = String(guestLinkRouteValue);
{
const guestContext = await browser.newContext();
// Share database across users.
await guestContext.addCookies([
readDbTokenCookie(await page.context().cookies()),
]);
const guestPage = await guestContext.newPage();
await guestPage.goto(guestLinkRoute);
await guestPage.locator(".file-input").setInputFiles([
{
name: "guest-upload2.txt",
mimeType: "text/plain",
buffer: Buffer.from("uploaded by a guest user"),
},
]);
await expect(guestPage.locator("#upload-result .message-body")).toHaveText(
"Upload complete!"
);
}
await guestLinkRow.getByRole("button", { name: "Delete" }).click();
await page.getByRole("menuitem", { name: "Files" }).click();
const filenameColumn = 0;
await page
.getByRole("row")
.filter({ hasText: "guest-upload2.txt" })
.getByRole("cell")
.nth(filenameColumn)
.getByRole("link")
.click();
await expect(page.locator("body")).toHaveText("uploaded by a guest user");
});