transformContent.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import t from 'tap';
  2. import {testContentFunctions} from '#test-lib';
  3. testContentFunctions(t, 'transformContent (snapshot)', async (t, evaluate) => {
  4. await evaluate.load({
  5. mock: {
  6. image: evaluate.stubContentFunction('image'),
  7. },
  8. });
  9. const extraDependencies = {
  10. wikiData: {
  11. albumData: [
  12. {directory: 'cool-album', name: 'Cool Album', color: '#123456'},
  13. ],
  14. },
  15. to: (key, ...args) => `to-${key}/${args.join('/')}`,
  16. };
  17. const quickSnapshot = (message, content, slots) =>
  18. evaluate.snapshot(message, {
  19. name: 'transformContent',
  20. args: [content],
  21. extraDependencies,
  22. slots,
  23. });
  24. quickSnapshot(
  25. 'two text paragraphs',
  26. `Hello, world!\n` +
  27. `Wow, this is very cool.`);
  28. quickSnapshot(
  29. 'links to a thing',
  30. `This is [[album:cool-album|my favorite album]].\n` +
  31. `That's right, [[album:cool-album]]!`);
  32. quickSnapshot(
  33. 'inline images',
  34. `<img src="snooping.png"> as USUAL...\n` +
  35. `What do you know? <img src="cowabunga.png" width="24" height="32">\n` +
  36. `[[album:cool-album|I'm on the left.]]<img src="im-on-the-right.jpg">\n` +
  37. `<img src="im-on-the-left.jpg">[[album:cool-album|I'm on the right.]]\n` +
  38. `Media time! <img src="media/misc/interesting.png"> Oh yeah!\n` +
  39. `<img src="must.png"><img src="stick.png"><img src="together.png">\n` +
  40. `And... all done! <img src="end-of-source.png">`);
  41. quickSnapshot(
  42. 'non-inline image #1',
  43. `<img src="spark.png">`);
  44. quickSnapshot(
  45. 'non-inline image #2',
  46. `Rad.\n` +
  47. `<img src="spark.png">`);
  48. quickSnapshot(
  49. 'non-inline image #3',
  50. `<img src="spark.png">\n` +
  51. `Baller.`);
  52. quickSnapshot(
  53. 'dates',
  54. `[[date:2023-04-13]] Yep!\n` +
  55. `Very nice: [[date:25 October 2413]]`);
  56. quickSnapshot(
  57. 'super basic string',
  58. `Neat listing: [[string:listingPage.listAlbums.byDate.title]]`);
  59. quickSnapshot(
  60. 'lyrics - basic line breaks',
  61. `Hey, ho\n` +
  62. `And away we go\n` +
  63. `Truly, music\n` +
  64. `\n` +
  65. `(Oh yeah)\n` +
  66. `(That's right)`,
  67. {mode: 'lyrics'});
  68. quickSnapshot(
  69. 'lyrics - repeated and edge line breaks',
  70. `\n\nWell, you know\nHow it goes\n\n\nYessiree\n\n\n`,
  71. {mode: 'lyrics'});
  72. quickSnapshot(
  73. 'lyrics - line breaks around tags',
  74. `The date be [[date:13 April 2004]]\n` +
  75. `I say, the date be [[date:13 April 2004]]\n` +
  76. `[[date:13 April 2004]]\n` +
  77. `[[date:13 April 2004]][[date:13 April 2004]][[date:13 April 2004]]\n` +
  78. `(Aye!)\n` +
  79. `\n` +
  80. `[[date:13 April 2004]]\n` +
  81. `[[date:13 April 2004]][[date:13 April 2004]]\n` +
  82. `[[date:13 April 2004]]\n` +
  83. `\n` +
  84. `[[date:13 April 2004]]\n` +
  85. `[[date:13 April 2004]], and don't ye forget it`,
  86. {mode: 'lyrics'});
  87. // TODO: Snapshots for mode: inline
  88. // TODO: Snapshots for mode: single-link
  89. });