markdownRoutes.test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import assert from "node:assert/strict";
  2. import test from "node:test";
  3. import { createMarkdownRenderer } from "../src/actions/_shared/markdown.js";
  4. test("route blocks render classes without injected CSS or inline styles", () => {
  5. const renderer = createMarkdownRenderer({
  6. resources: {
  7. routes: {
  8. "mountain-loop": {
  9. detail: {
  10. name: "mountain-loop",
  11. gpxHref: "/routes/mountain-loop.gpx",
  12. srcSet: [
  13. ["/routes/mountain-loop-640.webp", "640w"],
  14. ["/routes/mountain-loop-1024.webp", "1024w"],
  15. ],
  16. aspectRatio: 1.6,
  17. attribution: "© OpenStreetMap contributors",
  18. },
  19. },
  20. },
  21. },
  22. });
  23. const html = renderer("::route mountain-loop");
  24. assert.equal(html.includes("<style"), false);
  25. assert.equal(html.includes(" style="), false);
  26. assert.equal(html.includes('class="route-block"'), true);
  27. assert.equal(html.includes('class="route-block__image"'), true);
  28. assert.equal(html.includes('class="route-block__caption"'), true);
  29. assert.equal(html.includes('class="route-block__download"'), true);
  30. assert.equal(html.includes('class="route-block__attribution"'), true);
  31. assert.equal(html.includes('src="/routes/mountain-loop-640.webp"'), true);
  32. assert.equal(html.includes('href="/routes/mountain-loop.gpx"'), true);
  33. assert.equal(html.includes("© OpenStreetMap contributors"), true);
  34. });
  35. test("missing route blocks retain classes without inline styles", () => {
  36. const renderer = createMarkdownRenderer({ resources: {} });
  37. const html = renderer("::route missing-route");
  38. assert.equal(
  39. html,
  40. '<aside class="route-block route-block--missing">Route not found: missing-route</aside>',
  41. );
  42. });