linkContribution.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import t from 'tap';
  2. import {testContentFunctions} from '#test-lib';
  3. t.test('generateContributionLinks (unit)', async t => {
  4. const artist1 = {
  5. name: 'Clark Powell',
  6. directory: 'clark-powell',
  7. urls: ['https://soundcloud.com/plazmataz'],
  8. };
  9. const artist2 = {
  10. name: 'Grounder & Scratch',
  11. directory: 'the-big-baddies',
  12. urls: [],
  13. };
  14. const artist3 = {
  15. name: 'Toby Fox',
  16. directory: 'toby-fox',
  17. urls: ['https://tobyfox.bandcamp.com/', 'https://toby.fox/'],
  18. };
  19. const annotation1 = null;
  20. const annotation2 = 'Snooping';
  21. const annotation3 = 'Arrangement';
  22. await testContentFunctions(t, 'generateContributionLinks (unit 1)', async (t, evaluate) => {
  23. const slots = {
  24. showAnnotation: true,
  25. showExternalLinks: true,
  26. };
  27. await evaluate.load({
  28. mock: evaluate.mock(mock => ({
  29. linkArtist: {
  30. relations: mock
  31. .function('linkArtist.relations', () => ({}))
  32. .args([undefined, artist1]).next()
  33. .args([undefined, artist2]).next()
  34. .args([undefined, artist3]),
  35. data: mock
  36. .function('linkArtist.data', () => ({}))
  37. .args([artist1]).next()
  38. .args([artist2]).next()
  39. .args([artist3]),
  40. // This can be tweaked to return a specific (mocked) template
  41. // for each artist if we need to test for slots in the future.
  42. generate: mock.function('linkArtist.generate', () => 'artist link')
  43. .repeat(3),
  44. },
  45. generateExternalIcon: {
  46. data: mock
  47. .function('generateExternalIcon.data', () => ({}))
  48. .args([artist1.urls[0]]).next()
  49. .args([artist3.urls[0]]).next()
  50. .args([artist3.urls[1]]),
  51. generate: mock
  52. .function('generateExternalIcon.generate', () => ({
  53. toString: () => 'icon',
  54. setSlot: () => {},
  55. }))
  56. .repeat(3),
  57. }
  58. })),
  59. });
  60. evaluate({
  61. name: 'linkContribution',
  62. multiple: [
  63. {args: [{artist: artist1, annotation: annotation1}]},
  64. {args: [{artist: artist2, annotation: annotation2}]},
  65. {args: [{artist: artist3, annotation: annotation3}]},
  66. ],
  67. slots,
  68. });
  69. });
  70. await testContentFunctions(t, 'generateContributionLinks (unit 2)', async (t, evaluate) => {
  71. const slots = {
  72. showAnnotation: false,
  73. showExternalLinks: false,
  74. };
  75. await evaluate.load({
  76. mock: evaluate.mock(mock => ({
  77. linkArtist: {
  78. relations: mock
  79. .function('linkArtist.relations', () => ({}))
  80. .args([undefined, artist1]).next()
  81. .args([undefined, artist2]).next()
  82. .args([undefined, artist3]),
  83. data: mock
  84. .function('linkArtist.data', () => ({}))
  85. .args([artist1]).next()
  86. .args([artist2]).next()
  87. .args([artist3]),
  88. generate: mock
  89. .function(() => 'artist link')
  90. .repeat(3),
  91. },
  92. // Even though icons are hidden, these are still called! The dependency
  93. // tree is the same since whether or not the external icon links are
  94. // shown is dependent on a slot, which is undefined and arbitrary at
  95. // relations/data time (it might change on a whim at generate time).
  96. generateExternalIcon: {
  97. data: mock
  98. .function('generateExternalIcon.data', () => ({}))
  99. .repeat(3),
  100. generate: mock
  101. .function('generateExternalIcon.generate', () => ({
  102. toString: () => 'icon',
  103. setSlot: () => {},
  104. }))
  105. .repeat(3),
  106. },
  107. })),
  108. });
  109. evaluate({
  110. name: 'linkContribution',
  111. multiple: [
  112. {args: [{artist: artist1, annotation: annotation1}]},
  113. {args: [{artist: artist2, annotation: annotation2}]},
  114. {args: [{artist: artist3, annotation: annotation3}]},
  115. ],
  116. slots,
  117. });
  118. });
  119. });