image.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import t from 'tap';
  2. import {testContentFunctions} from '#test-lib';
  3. testContentFunctions(t, 'image (snapshot)', async (t, evaluate) => {
  4. await evaluate.load();
  5. const quickSnapshot = (message, {extraDependencies, ...opts}) =>
  6. evaluate.snapshot(message, {
  7. name: 'image',
  8. extraDependencies: {
  9. checkIfImagePathHasCachedThumbnails: path => !path.endsWith('.gif'),
  10. getSizeOfImagePath: () => 0,
  11. getDimensionsOfImagePath: () => [600, 600],
  12. getThumbnailEqualOrSmaller: () => 'medium',
  13. getThumbnailsAvailableForDimensions: () =>
  14. [['large', 800], ['medium', 400], ['small', 250]],
  15. missingImagePaths: ['album-art/missing/cover.png'],
  16. ...extraDependencies,
  17. },
  18. ...opts,
  19. });
  20. quickSnapshot('source via path', {
  21. slots: {
  22. path: ['media.albumCover', 'beyond-canon', 'png'],
  23. },
  24. });
  25. quickSnapshot('source via src', {
  26. slots: {
  27. src: 'https://example.com/bananas.gif',
  28. },
  29. });
  30. quickSnapshot('source missing', {
  31. slots: {
  32. missingSourceContent: 'Example of missing source message.',
  33. },
  34. });
  35. quickSnapshot('dimensions', {
  36. slots: {
  37. src: 'foobar',
  38. dimensions: [600, 400],
  39. },
  40. });
  41. quickSnapshot('square', {
  42. slots: {
  43. src: 'foobar',
  44. square: true,
  45. },
  46. });
  47. quickSnapshot('dimensions with square', {
  48. slots: {
  49. src: 'foobar',
  50. dimensions: [600, 400],
  51. square: true,
  52. },
  53. });
  54. quickSnapshot('lazy with square', {
  55. slots: {
  56. src: 'foobar',
  57. lazy: true,
  58. square: true,
  59. },
  60. });
  61. quickSnapshot('link with file size', {
  62. extraDependencies: {
  63. getSizeOfImagePath: () => 10 ** 6,
  64. },
  65. slots: {
  66. path: ['media.albumCover', 'pingas', 'png'],
  67. link: true,
  68. },
  69. });
  70. quickSnapshot('content warnings via tags', {
  71. args: [
  72. [
  73. {name: 'Dirk Strider', directory: 'dirk'},
  74. {name: 'too cool for school', isContentWarning: true},
  75. ],
  76. ],
  77. slots: {
  78. path: ['media.albumCover', 'beyond-canon', 'png'],
  79. },
  80. });
  81. evaluate.snapshot('thumbnail details', {
  82. name: 'image',
  83. extraDependencies: {
  84. checkIfImagePathHasCachedThumbnails: () => true,
  85. getSizeOfImagePath: () => 0,
  86. getDimensionsOfImagePath: () => [900, 1200],
  87. getThumbnailsAvailableForDimensions: () =>
  88. [['voluminous', 1200], ['middling', 900], ['petite', 20]],
  89. getThumbnailEqualOrSmaller: () => 'voluminous',
  90. missingImagePaths: [],
  91. },
  92. slots: {
  93. thumb: 'gargantuan',
  94. path: ['media.albumCover', 'beyond-canon', 'png'],
  95. },
  96. });
  97. quickSnapshot('thumb requested but source is gif', {
  98. slots: {
  99. thumb: 'medium',
  100. path: ['media.flashArt', '5426', 'gif'],
  101. },
  102. });
  103. quickSnapshot('missing image path', {
  104. slots: {
  105. thumb: 'medium',
  106. path: ['media.albumCover', 'missing', 'png'],
  107. link: true,
  108. },
  109. });
  110. quickSnapshot('missing image path w/ missingSourceContent', {
  111. slots: {
  112. thumb: 'medium',
  113. path: ['media.albumCover', 'missing', 'png'],
  114. missingSourceContent: `Cover's missing, whoops`,
  115. },
  116. });
  117. });