image.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. ...extraDependencies,
  16. },
  17. ...opts,
  18. });
  19. quickSnapshot('source via path', {
  20. slots: {
  21. path: ['media.albumCover', 'beyond-canon', 'png'],
  22. },
  23. });
  24. quickSnapshot('source via src', {
  25. slots: {
  26. src: 'https://example.com/bananas.gif',
  27. },
  28. });
  29. quickSnapshot('source missing', {
  30. slots: {
  31. missingSourceContent: 'Example of missing source message.',
  32. },
  33. });
  34. quickSnapshot('id without link', {
  35. slots: {
  36. src: 'foobar',
  37. id: 'banana',
  38. },
  39. });
  40. quickSnapshot('id with link', {
  41. slots: {
  42. src: 'foobar',
  43. link: true,
  44. id: 'banana',
  45. },
  46. });
  47. quickSnapshot('id with square', {
  48. slots: {
  49. src: 'foobar',
  50. square: true,
  51. id: 'banana',
  52. },
  53. });
  54. quickSnapshot('width & height', {
  55. slots: {
  56. src: 'foobar',
  57. width: 600,
  58. height: 400,
  59. },
  60. });
  61. quickSnapshot('square', {
  62. slots: {
  63. src: 'foobar',
  64. square: true,
  65. },
  66. });
  67. quickSnapshot('lazy with square', {
  68. slots: {
  69. src: 'foobar',
  70. lazy: true,
  71. square: true,
  72. },
  73. });
  74. quickSnapshot('link with file size', {
  75. extraDependencies: {
  76. getSizeOfImagePath: () => 10 ** 6,
  77. },
  78. slots: {
  79. path: ['media.albumCover', 'pingas', 'png'],
  80. link: true,
  81. },
  82. });
  83. quickSnapshot('content warnings via tags', {
  84. args: [
  85. [
  86. {name: 'Dirk Strider', directory: 'dirk'},
  87. {name: 'too cool for school', isContentWarning: true},
  88. ],
  89. ],
  90. slots: {
  91. path: ['media.albumCover', 'beyond-canon', 'png'],
  92. },
  93. });
  94. evaluate.snapshot('thumbnail details', {
  95. name: 'image',
  96. extraDependencies: {
  97. checkIfImagePathHasCachedThumbnails: () => true,
  98. getSizeOfImagePath: () => 0,
  99. getDimensionsOfImagePath: () => [900, 1200],
  100. getThumbnailsAvailableForDimensions: () =>
  101. [['voluminous', 1200], ['middling', 900], ['petite', 20]],
  102. getThumbnailEqualOrSmaller: () => 'voluminous',
  103. },
  104. slots: {
  105. thumb: 'gargantuan',
  106. path: ['media.albumCover', 'beyond-canon', 'png'],
  107. },
  108. });
  109. quickSnapshot('thumb requested but source is gif', {
  110. slots: {
  111. thumb: 'medium',
  112. path: ['media.flashArt', '5426', 'gif'],
  113. },
  114. });
  115. });