Reject invalid uploads and expand flow tests.

This commit is contained in:
tim
2026-09-26 15:27:51 +02:00
parent 716a609f4e
commit 8f4851e576
9 changed files with 427 additions and 11 deletions
+42
View File
@@ -139,6 +139,48 @@ test("review stops an empty story and warns about the length", () => {
assert.deepEqual(w.confirms, []);
});
const imageReviews = [
{ name: "a new upload with no text", upload: true },
{ name: "a new upload with short text", upload: true, story: "short text" },
{ name: "a retained image with no text", uploaded: "5" },
{ name: "a retained image with short text", uploaded: "5", story: "short text" },
{ name: "a pending image with no text", uploaded: "pending" },
{ name: "a pending image with short text", uploaded: "pending", story: "short text" },
{ name: "an image removed without text", uploaded: "5", remove: true, alert: true, accepted: false },
{ name: "a removed image and cancelled short text", uploaded: "5", remove: true, story: "short text", confirm: true, accepted: false },
{ name: "a removed image and accepted short text", uploaded: "5", remove: true, story: "short text", confirm: true },
{ name: "an image replaced with 100 words", uploaded: "5", remove: true, story: "word ".repeat(100) },
{ name: "an empty image reference and no text", uploaded: "", alert: true, accepted: false },
{ name: "a new upload replacing a removed image", upload: true, uploaded: "5", remove: true },
];
for (const entry of imageReviews) {
test(`review handles ${entry.name}`, (t) => {
const w = publishWindow(entry.story || "");
t.after(() => w.close());
for (const [id, value] of [["title", "T"], ["author", "A"], ["email", "a@example.org"]])
w.document.getElementById(id).value = value;
if (entry.upload) {
// jsdom cannot choose a file. review() reads only the input's value.
Object.defineProperty(w.document.getElementById("upload"), "value", { value: "C:\\fakepath\\a.png" });
}
if (entry.uploaded !== undefined) {
const uploaded = w.document.createElement("input");
uploaded.type = "hidden";
uploaded.id = "uploaded";
uploaded.value = entry.uploaded;
w.document.getElementById("form").appendChild(uploaded);
}
if (entry.remove) w.toggle_remove();
w.confirmAnswer = entry.accepted !== false;
assert.equal(w.review(), entry.accepted !== false);
assert.equal(w.alerts.length, entry.alert ? 1 : 0);
assert.equal(w.confirms.length, entry.confirm ? 1 : 0);
if (entry.alert) assert.match(w.alerts[0], /haven't submitted anything/);
if (entry.confirm) assert.match(w.confirms[0], /doesn't appear to be 100 words long/);
});
}
test("delete asks first, and then skips the review", () => {
const w = publishWindow("");
w.confirmAnswer = false;