Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions scripts/story-dialog.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,28 @@ test("popup blocked: fallback link gets the prefilled URL and copy button yields
assert.match(t.el("story-status").textContent, /^Copied\./);
});

test("popup blocked with truncated story: fallback revealed and trimmed-story notice shown", async () => {
const t = boot({ popupBlocked: true });
const long = "x".repeat(STORY_MAX - 3) + " tail-that-gets-cut";
t.el("opener-hero").dispatch("click");
t.fill({ ...VALID, "story-text": long });
t.submit();
assert.equal(t.el("story-fallback").hidden, false, "fallback revealed");
assert.match(t.el("story-status").textContent, /^Your story was trimmed to 1500 characters/, "trimmed-story notice shown when popup blocked");
const href = new URL(t.el("story-fallback-link").href);
const story = href.searchParams.get("story");
assert.equal(story, "x".repeat(STORY_MAX - 3), "fallback link carries the trimmed story");
});

test("popup blocked with non-truncated story: fallback revealed but no notice shown", () => {
const t = boot({ popupBlocked: true });
t.el("opener-hero").dispatch("click");
t.fill(VALID);
t.submit();
assert.equal(t.el("story-fallback").hidden, false, "fallback revealed");
assert.equal(t.el("story-status").textContent, "", "no truncation notice when story not truncated");
});

test("copy button tells the user to use the prefilled link when the clipboard write is rejected", async () => {
const t = boot({ popupBlocked: true, clipboardOverride: { clipboard: { writeText() { return Promise.reject(new Error("denied")); } } } });
t.el("opener-hero").dispatch("click");
Expand Down
6 changes: 4 additions & 2 deletions stories/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-e2g5HkZP+fghbsY1m7moq4GopOo7zRRaAHNyQ2Q7oSI=' 'sha256-ycRNP2kNHazBu8LXdhFNDrNJfr5JYNooQIqUE+oWqyE=' 'unsafe-hashes' 'sha256-Kkh0ufQbkIVTWPYjIGk2bAJsmDwjmUuIAt2LyPfNr3g='; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://github.com https://avatars.githubusercontent.com; font-src 'self'; base-uri 'none'; form-action 'self'">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-e2g5HkZP+fghbsY1m7moq4GopOo7zRRaAHNyQ2Q7oSI=' 'sha256-zCrCZyj808KIt7bDf+IVXtfCUKHuEuIRSeqpB1Esw/w=' 'unsafe-hashes' 'sha256-Kkh0ufQbkIVTWPYjIGk2bAJsmDwjmUuIAt2LyPfNr3g='; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://github.com https://avatars.githubusercontent.com; font-src 'self'; base-uri 'none'; form-action 'self'">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Contributor Stories — Hive Commons</title>
<meta name="description" content="Real Hive Commons contributor progression stories and public Contributor Relay metrics for event organisers, mentors, and contributors.">
Expand Down Expand Up @@ -504,15 +504,17 @@ <h2 id="story-dialog-title">Open a contributor story draft</h2>
var issueUrl = buildIssue(data);
issueText = markdown(data);
var opened = window.open("", "_blank");
var trimmedNotice = "Your story was trimmed to 1500 characters for the GitHub form. ";
if (!opened) {
fallbackLink.href = issueUrl;
fallback.hidden = false;
if (data.story_truncated) status.textContent = trimmedNotice;
return;
}
opened.opener = null;
opened.location = issueUrl;
var note = "Thanks — your story opened as a draft issue in a new tab. GitHub only prefills text fields, so pick your Role again" + (data.quote_ok ? " and re-tick Can we quote you by name?" : "") + ", then hit Submit new issue there to finish. Not signed in to GitHub? Email us or use the Discord link below.";
if (data.story_truncated) note = "Your story was trimmed to 1500 characters for the GitHub form. " + note;
if (data.story_truncated) note = trimmedNotice + note;
status.textContent = note;
});

Expand Down
Loading