generateAlbumAdditionalFilesList.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import t from 'tap';
  2. import {testContentFunctions} from '#test-lib';
  3. import thingConstructors from '#things';
  4. const {Album} = thingConstructors;
  5. testContentFunctions(t, 'generateAlbumAdditionalFilesList (snapshot)', async (t, evaluate) => {
  6. const sizeMap = {
  7. 'sburbwp_1280x1024.jpg': 2500,
  8. 'sburbwp_1440x900.jpg': null,
  9. 'sburbwp_1920x1080.jpg': null,
  10. 'Internet Explorer.gif': 1,
  11. 'Homestuck_Vol4_alt1.jpg': 1234567,
  12. 'Homestuck_Vol4_alt2.jpg': 1234567,
  13. 'Homestuck_Vol4_alt3.jpg': 1234567,
  14. };
  15. const extraDependencies = {
  16. getSizeOfAdditionalFile: file =>
  17. Object.entries(sizeMap)
  18. .find(key => file.includes(key))
  19. ?.at(1) ?? null,
  20. };
  21. await evaluate.load({
  22. mock: {
  23. image: evaluate.stubContentFunction('image'),
  24. },
  25. });
  26. const album = new Album();
  27. album.directory = 'exciting-album';
  28. evaluate.snapshot('no additional files', {
  29. extraDependencies,
  30. name: 'generateAlbumAdditionalFilesList',
  31. args: [album, []],
  32. });
  33. try {
  34. evaluate.snapshot('basic behavior', {
  35. extraDependencies,
  36. name: 'generateAlbumAdditionalFilesList',
  37. args: [
  38. album,
  39. [
  40. {
  41. title: 'SBURB Wallpaper',
  42. files: [
  43. 'sburbwp_1280x1024.jpg',
  44. 'sburbwp_1440x900.jpg',
  45. 'sburbwp_1920x1080.jpg',
  46. ],
  47. },
  48. {
  49. title: 'Fake Section',
  50. description: 'No sizes for these files',
  51. files: [
  52. 'oops.mp3',
  53. 'Internet Explorer.gif',
  54. 'daisy.mp3',
  55. ],
  56. },
  57. {
  58. title: `Empty Section`,
  59. description: `These files haven't been made available.`,
  60. },
  61. {
  62. title: 'Alternate Covers',
  63. description: 'This is just an example description.',
  64. files: [
  65. 'Homestuck_Vol4_alt1.jpg',
  66. 'Homestuck_Vol4_alt2.jpg',
  67. 'Homestuck_Vol4_alt3.jpg',
  68. ],
  69. },
  70. ],
  71. ],
  72. });
  73. } catch (error) {
  74. console.log(error);
  75. }
  76. });