feat: polish workspace transfers and verify Craft server file workflows
This commit is contained in:
1 parent
7fd7ae6733
commit
c209f1effc
49 files changed
+1459
-670
No files matched your search
@@ -0,0 +1,192 @@
|
||||
const fs = require("node:fs"),
|
||||
path = require("node:path"),
|
||||
assert = require("node:assert/strict");
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE);
|
||||
(async () => {
|
||||
const base = process.env.FILEBROWSER_QA_URL,
|
||||
root = process.env.FILEBROWSER_QA_ROOT,
|
||||
out = process.env.FILEBROWSER_QA_OUTPUT;
|
||||
fs.mkdirSync(out, { recursive: true });
|
||||
const b = await chromium.launch({
|
||||
executablePath: process.env.BROWSER_EXECUTABLE,
|
||||
headless: true,
|
||||
args: ["--use-angle=swiftshader", "--enable-unsafe-swiftshader"],
|
||||
});
|
||||
const result = [];
|
||||
try {
|
||||
const p = await b.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
p.on("dialog", (d) => d.accept());
|
||||
const request = async (method, url, data) => {
|
||||
let r = await p.request.fetch(base + url, {
|
||||
method,
|
||||
data,
|
||||
headers: { "X-FB-Request": "1" },
|
||||
});
|
||||
assert(
|
||||
r.ok(),
|
||||
method + " " + url + ":" + r.status() + " " + (await r.text())
|
||||
);
|
||||
return r;
|
||||
};
|
||||
await request("POST", "/api/resources/projects/");
|
||||
await request("POST", "/api/resources/projects/test.txt", "Hello server");
|
||||
await request(
|
||||
"PATCH",
|
||||
"/api/resources/projects/test.txt?action=copy&destination=%2Fprojects%2Fcopy.txt"
|
||||
);
|
||||
await request(
|
||||
"PATCH",
|
||||
"/api/resources/projects/copy.txt?action=rename&destination=%2Frenamed.txt"
|
||||
);
|
||||
await request("PUT", "/api/resources/renamed.txt", "Updated file");
|
||||
assert.equal(
|
||||
await (await request("GET", "/api/raw/renamed.txt")).text(),
|
||||
"Updated file"
|
||||
);
|
||||
await request("DELETE", "/api/resources/renamed.txt");
|
||||
assert(!fs.existsSync(path.join(root, "renamed.txt")));
|
||||
result.push("create/upload/copy/move/update/download/delete");
|
||||
await request("POST", "/api/share/notes.txt", { key: "qa-main" });
|
||||
await request("POST", "/api/share/notes.txt", {
|
||||
key: "qa-protected",
|
||||
password: "test-password",
|
||||
expires: "1",
|
||||
unit: "hours",
|
||||
});
|
||||
let links = await (await request("GET", "/api/share/notes.txt")).json();
|
||||
assert.equal(links.length, 2);
|
||||
result.push("multiple shares, optional password and expiration");
|
||||
await p.goto(base + "/files/");
|
||||
let video = await p.evaluate(async () => {
|
||||
const c = document.createElement("canvas");
|
||||
c.width = 320;
|
||||
c.height = 180;
|
||||
let ctx = c.getContext("2d");
|
||||
ctx.fillStyle = "#21334d";
|
||||
ctx.fillRect(0, 0, 320, 180);
|
||||
ctx.fillStyle = "white";
|
||||
ctx.font = "22px sans-serif";
|
||||
ctx.fillText("Video preview", 70, 90);
|
||||
let rec = new MediaRecorder(c.captureStream(10), {
|
||||
mimeType: "video/webm",
|
||||
}),
|
||||
chunks = [];
|
||||
rec.ondataavailable = (e) => chunks.push(e.data);
|
||||
let done = new Promise(
|
||||
(resolve) =>
|
||||
(rec.onstop = async () =>
|
||||
resolve([...new Uint8Array(await new Blob(chunks).arrayBuffer())]))
|
||||
);
|
||||
rec.start();
|
||||
await new Promise((r) => setTimeout(r, 1200));
|
||||
rec.stop();
|
||||
return done;
|
||||
});
|
||||
fs.writeFileSync(path.join(root, "movie.webm"), Buffer.from(video));
|
||||
await p.route("**/api/tus/**", async (route) => {
|
||||
if (route.request().method() === "PATCH")
|
||||
await new Promise((r) => setTimeout(r, 1800));
|
||||
await route.continue().catch(() => {});
|
||||
});
|
||||
let payload = Buffer.alloc(3 * 1024 * 1024, 65);
|
||||
await p
|
||||
.locator("#upload-input")
|
||||
.setInputFiles({
|
||||
name: "upload-check.txt",
|
||||
mimeType: "text/plain",
|
||||
buffer: payload,
|
||||
});
|
||||
await p.locator(".upload-files").waitFor();
|
||||
await p.screenshot({ path: path.join(out, "desktop-upload.png") });
|
||||
await p.locator(".transfer-header button").first().click();
|
||||
await p.screenshot({ path: path.join(out, "desktop-upload-expanded.png") });
|
||||
await p
|
||||
.locator(".upload-files")
|
||||
.waitFor({ state: "hidden", timeout: 30000 });
|
||||
assert(
|
||||
fs.readFileSync(path.join(root, "upload-check.txt")).equals(payload)
|
||||
);
|
||||
result.push("UI chunked upload and transfer panel");
|
||||
await p
|
||||
.locator("#upload-input")
|
||||
.setInputFiles({
|
||||
name: "cancel-check.txt",
|
||||
mimeType: "text/plain",
|
||||
buffer: payload,
|
||||
});
|
||||
await p.locator(".upload-files").waitFor();
|
||||
await p.locator(".transfer-header button").last().click();
|
||||
await p.locator(".upload-files").waitFor({ state: "hidden" });
|
||||
await p.waitForTimeout(2300);
|
||||
assert(!fs.existsSync(path.join(root, "cancel-check.txt")));
|
||||
result.push("upload cancellation");
|
||||
await p.unroute("**/api/tus/**");
|
||||
for (let mobile of [false, true]) {
|
||||
await p.setViewportSize(
|
||||
mobile ? { width: 390, height: 844 } : { width: 1440, height: 1000 }
|
||||
);
|
||||
for (let route of [
|
||||
"/files/",
|
||||
"/files/movie.webm",
|
||||
"/settings/profile",
|
||||
"/settings/shares",
|
||||
"/settings/global",
|
||||
"/s/qa-main",
|
||||
"/s/qa-protected",
|
||||
]) {
|
||||
await p.goto(base + route);
|
||||
await p.waitForTimeout(650);
|
||||
assert.equal(
|
||||
await p.evaluate(
|
||||
() => document.documentElement.scrollWidth > innerWidth + 1
|
||||
),
|
||||
false,
|
||||
"overflow " + route
|
||||
);
|
||||
await p.screenshot({
|
||||
path: path.join(
|
||||
out,
|
||||
(mobile ? "mobile" : "desktop") +
|
||||
route.replaceAll("/", "-") +
|
||||
".png"
|
||||
),
|
||||
fullPage: true,
|
||||
});
|
||||
}
|
||||
await p.goto(base + "/settings/global");
|
||||
await p.locator(".admin-users-tile").click();
|
||||
await p.locator(".users-management").waitFor();
|
||||
await p.screenshot({
|
||||
path: path.join(out, (mobile ? "mobile" : "desktop") + "-users.png"),
|
||||
fullPage: true,
|
||||
});
|
||||
await p.keyboard.press("Escape");
|
||||
await p.goto(base + "/editor/wordcraft?path=%2Fdocument.docx");
|
||||
await p.waitForTimeout(5000);
|
||||
let f = p.frames().find((x) => x !== p.mainFrame());
|
||||
await f
|
||||
.locator("canvas")
|
||||
.click({ position: { x: Math.min(mobile ? 190 : 550, 550), y: 350 } });
|
||||
await p.keyboard.press("Control+o");
|
||||
await p.locator(".server-picker").waitFor();
|
||||
await p.locator(".server-picker li").first().waitFor();
|
||||
await p.screenshot({
|
||||
path: path.join(
|
||||
out,
|
||||
(mobile ? "mobile" : "desktop") + "-server-picker.png"
|
||||
),
|
||||
});
|
||||
await p.locator(".picker-header button").click();
|
||||
}
|
||||
console.log(JSON.stringify(result));
|
||||
fs.writeFileSync(
|
||||
path.join(out, "functional.json"),
|
||||
JSON.stringify(result, null, 2)
|
||||
);
|
||||
} finally {
|
||||
await b.close();
|
||||
}
|
||||
})().catch((e) => {
|
||||
console.error(e);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in new issue
Block a user