gallery.spec.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import Gallery from 'src/components/gallery/gallery.vue'
  2. describe('Gallery', () => {
  3. let local
  4. it('attachments is falsey', () => {
  5. local = { attachments: false }
  6. expect(Gallery.computed.rows.call(local)).to.eql([])
  7. local = { attachments: null }
  8. expect(Gallery.computed.rows.call(local)).to.eql([])
  9. local = { attachments: undefined }
  10. expect(Gallery.computed.rows.call(local)).to.eql([])
  11. })
  12. it('no attachments', () => {
  13. local = { attachments: [] }
  14. expect(Gallery.computed.rows.call(local)).to.eql([])
  15. })
  16. it('one audio attachment', () => {
  17. local = {
  18. attachments: [
  19. { mimetype: 'audio/mpeg' }
  20. ]
  21. }
  22. expect(Gallery.computed.rows.call(local)).to.eql([
  23. { audio: true, items: [{ mimetype: 'audio/mpeg' }] }
  24. ])
  25. })
  26. it('one image attachment', () => {
  27. local = {
  28. attachments: [
  29. { mimetype: 'image/png' }
  30. ]
  31. }
  32. expect(Gallery.computed.rows.call(local)).to.eql([
  33. { items: [{ mimetype: 'image/png' }] }
  34. ])
  35. })
  36. it('one audio attachment and one image attachment', () => {
  37. local = {
  38. attachments: [
  39. { mimetype: 'audio/mpeg' },
  40. { mimetype: 'image/png' }
  41. ]
  42. }
  43. expect(Gallery.computed.rows.call(local)).to.eql([
  44. { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
  45. { items: [{ mimetype: 'image/png' }] }
  46. ])
  47. })
  48. it('has "size" key set to "hide"', () => {
  49. let local
  50. local = {
  51. attachments: [
  52. { mimetype: 'audio/mpeg' }
  53. ],
  54. size: 'hide'
  55. }
  56. expect(Gallery.computed.rows.call(local)).to.eql([
  57. { minimal: true, items: [{ mimetype: 'audio/mpeg' }] }
  58. ])
  59. local = {
  60. attachments: [
  61. { mimetype: 'image/jpg' },
  62. { mimetype: 'image/png' },
  63. { mimetype: 'image/jpg' },
  64. { mimetype: 'audio/mpeg' },
  65. { mimetype: 'image/png' },
  66. { mimetype: 'audio/mpeg' },
  67. { mimetype: 'image/jpg' },
  68. { mimetype: 'image/png' },
  69. { mimetype: 'image/jpg' }
  70. ],
  71. size: 'hide'
  72. }
  73. // When defining `size: hide`, the `items` aren't
  74. // grouped and `audio` isn't set
  75. expect(Gallery.computed.rows.call(local)).to.eql([
  76. { minimal: true, items: [{ mimetype: 'image/jpg' }] },
  77. { minimal: true, items: [{ mimetype: 'image/png' }] },
  78. { minimal: true, items: [{ mimetype: 'image/jpg' }] },
  79. { minimal: true, items: [{ mimetype: 'audio/mpeg' }] },
  80. { minimal: true, items: [{ mimetype: 'image/png' }] },
  81. { minimal: true, items: [{ mimetype: 'audio/mpeg' }] },
  82. { minimal: true, items: [{ mimetype: 'image/jpg' }] },
  83. { minimal: true, items: [{ mimetype: 'image/png' }] },
  84. { minimal: true, items: [{ mimetype: 'image/jpg' }] }
  85. ])
  86. })
  87. // types other than image or audio should be `minimal`
  88. it('non-image/audio', () => {
  89. let local
  90. local = {
  91. attachments: [
  92. { mimetype: 'plain/text' }
  93. ]
  94. }
  95. expect(Gallery.computed.rows.call(local)).to.eql([
  96. { minimal: true, items: [{ mimetype: 'plain/text' }] }
  97. ])
  98. // No grouping of non-image/audio items
  99. local = {
  100. attachments: [
  101. { mimetype: 'plain/text' },
  102. { mimetype: 'plain/text' },
  103. { mimetype: 'plain/text' }
  104. ]
  105. }
  106. expect(Gallery.computed.rows.call(local)).to.eql([
  107. { minimal: true, items: [{ mimetype: 'plain/text' }] },
  108. { minimal: true, items: [{ mimetype: 'plain/text' }] },
  109. { minimal: true, items: [{ mimetype: 'plain/text' }] }
  110. ])
  111. local = {
  112. attachments: [
  113. { mimetype: 'image/png' },
  114. { mimetype: 'plain/text' },
  115. { mimetype: 'image/jpg' },
  116. { mimetype: 'audio/mpeg' }
  117. ]
  118. }
  119. // NOTE / TODO: When defining `size: hide`, the `items` aren't
  120. // grouped and `audio` isn't set
  121. expect(Gallery.computed.rows.call(local)).to.eql([
  122. { items: [{ mimetype: 'image/png' }] },
  123. { minimal: true, items: [{ mimetype: 'plain/text' }] },
  124. { items: [{ mimetype: 'image/jpg' }] },
  125. { audio: true, items: [{ mimetype: 'audio/mpeg' }] }
  126. ])
  127. })
  128. it('mixed attachments', () => {
  129. local = {
  130. attachments: [
  131. { mimetype: 'audio/mpeg' },
  132. { mimetype: 'image/png' },
  133. { mimetype: 'audio/mpeg' },
  134. { mimetype: 'image/jpg' },
  135. { mimetype: 'image/png' },
  136. { mimetype: 'image/jpg' },
  137. { mimetype: 'image/jpg' }
  138. ]
  139. }
  140. expect(Gallery.computed.rows.call(local)).to.eql([
  141. { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
  142. { items: [{ mimetype: 'image/png' }] },
  143. { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
  144. { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }, { mimetype: 'image/jpg' }] }
  145. ])
  146. local = {
  147. attachments: [
  148. { mimetype: 'image/jpg' },
  149. { mimetype: 'image/png' },
  150. { mimetype: 'image/jpg' },
  151. { mimetype: 'image/jpg' },
  152. { mimetype: 'audio/mpeg' },
  153. { mimetype: 'image/png' },
  154. { mimetype: 'audio/mpeg' }
  155. ]
  156. }
  157. expect(Gallery.computed.rows.call(local)).to.eql([
  158. { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }] },
  159. { items: [{ mimetype: 'image/jpg' }] },
  160. { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
  161. { items: [{ mimetype: 'image/png' }] },
  162. { audio: true, items: [{ mimetype: 'audio/mpeg' }] }
  163. ])
  164. local = {
  165. attachments: [
  166. { mimetype: 'image/jpg' },
  167. { mimetype: 'image/png' },
  168. { mimetype: 'image/jpg' },
  169. { mimetype: 'image/jpg' },
  170. { mimetype: 'image/png' },
  171. { mimetype: 'image/png' },
  172. { mimetype: 'image/jpg' }
  173. ]
  174. }
  175. // Group by three-per-row, unless there's one dangling, then stick it on the end of the last row
  176. // https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1785#note_98514
  177. expect(Gallery.computed.rows.call(local)).to.eql([
  178. { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }] },
  179. { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }] }
  180. ])
  181. local = {
  182. attachments: [
  183. { mimetype: 'image/jpg' },
  184. { mimetype: 'image/png' },
  185. { mimetype: 'image/jpg' },
  186. { mimetype: 'image/jpg' },
  187. { mimetype: 'image/png' },
  188. { mimetype: 'image/png' },
  189. { mimetype: 'image/jpg' },
  190. { mimetype: 'image/png' }
  191. ]
  192. }
  193. expect(Gallery.computed.rows.call(local)).to.eql([
  194. { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }] },
  195. { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/png' }] },
  196. { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }] }
  197. ])
  198. })
  199. it('does not do grouping when grid is set', () => {
  200. const attachments = [
  201. { mimetype: 'audio/mpeg' },
  202. { mimetype: 'image/png' },
  203. { mimetype: 'audio/mpeg' },
  204. { mimetype: 'image/jpg' },
  205. { mimetype: 'image/png' },
  206. { mimetype: 'image/jpg' },
  207. { mimetype: 'image/jpg' }
  208. ]
  209. local = { grid: true, attachments }
  210. expect(Gallery.computed.rows.call(local)).to.eql([
  211. { grid: true, items: attachments }
  212. ])
  213. })
  214. it('limit is set', () => {
  215. const attachments = [
  216. { mimetype: 'audio/mpeg' },
  217. { mimetype: 'image/png' },
  218. { mimetype: 'image/jpg' },
  219. { mimetype: 'audio/mpeg' },
  220. { mimetype: 'image/jpg' }
  221. ]
  222. let local
  223. local = { attachments, limit: 2 }
  224. expect(Gallery.computed.rows.call(local)).to.eql([
  225. { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
  226. { items: [{ mimetype: 'image/png' }] }
  227. ])
  228. local = { attachments, limit: 3 }
  229. expect(Gallery.computed.rows.call(local)).to.eql([
  230. { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
  231. { items: [{ mimetype: 'image/png' }, { mimetype: 'image/jpg' }] }
  232. ])
  233. local = { attachments, limit: 4 }
  234. expect(Gallery.computed.rows.call(local)).to.eql([
  235. { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
  236. { items: [{ mimetype: 'image/png' }, { mimetype: 'image/jpg' }] },
  237. { audio: true, items: [{ mimetype: 'audio/mpeg' }] }
  238. ])
  239. })
  240. })