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
2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint",
"typecheck": "tsc --noEmit",
"fetch:rates": "tsx scripts/fetch-rates.ts",
"prebuild": "node --test scripts/workdays-faq-parity.test.mjs && node scripts/check-site-url.mjs && tsx scripts/fetch-rates.ts && node scripts/check-pressure-reference.mjs && node scripts/check-currency-rate-freshness.mjs",
"prebuild": "node --test scripts/workdays-faq-parity.test.mjs && node --test scripts/sharebar-state-navigation.test.mjs && node scripts/check-site-url.mjs && tsx scripts/fetch-rates.ts && node scripts/check-pressure-reference.mjs && node scripts/check-currency-rate-freshness.mjs",
"sitemap": "tsx scripts/generate-sitemap.ts",
"validate": "tsx scripts/validate.ts",
"audit:seo": "tsx scripts/audit-seo.ts",
Expand Down
20 changes: 20 additions & 0 deletions site/scripts/sharebar-state-navigation.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";

const share = readFileSync(new URL("../src/components/tools/ShareBar.tsx", import.meta.url), "utf8");

test("share state resynchronizes after URL or tool slug changes", () => {
assert.match(share, /setHasResultLink\(new URLSearchParams\(window\.location\.search\)\.has\("s"\)\)/);
assert.match(share, /\}, \[url, slug\]\);/);
for (const event of ["toolify:share-state-change", "popstate", "pageshow"]) {
assert.ok(share.includes(`window.addEventListener("${event}", sync)`), event + " listener");
assert.ok(share.includes(`window.removeEventListener("${event}", sync)`), event + " cleanup");
}
});

test("safe embed and tracked share attribution stay intact", () => {
assert.match(share, /buildToolEmbedSnippet\(title, embedUrl, url\)/);
assert.match(share, /socialShareUrl\(url, source\)/);
assert.match(share, /if \(isShareCancelled\(error\)\) return;/);
});
2 changes: 1 addition & 1 deletion site/src/components/tools/ShareBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function ShareBar({ url, embedUrl, title, slug }: Props) {
window.removeEventListener("popstate", sync);
window.removeEventListener("pageshow", sync);
};
}, []);
}, [url, slug]); // Recheck shared-result state on locale/tool navigation.

const enc = encodeURIComponent;
// Keep optional embed attribution visible to readers without ranking-credit links.
Expand Down
Loading