123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- import Gallery from 'src/components/gallery/gallery.vue'
- describe.only('Gallery', () => {
- let local
- it('attachments is falsey', () => {
- local = { attachments: false }
- expect(Gallery.computed.rows.call(local)).to.eql([])
- local = { attachments: null }
- expect(Gallery.computed.rows.call(local)).to.eql([])
- local = { attachments: undefined }
- expect(Gallery.computed.rows.call(local)).to.eql([])
- })
- it('no attachments', () => {
- local = { attachments: [] }
- expect(Gallery.computed.rows.call(local)).to.eql([])
- })
- it('one audio attachment', () => {
- local = {
- attachments: [
- { mimetype: 'audio/mpeg' }
- ]
- }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] }
- ])
- })
- it('one image attachment', () => {
- local = {
- attachments: [
- { mimetype: 'image/png' }
- ]
- }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { items: [{ mimetype: 'image/png' }] }
- ])
- })
- it('one audio attachment and one image attachment', () => {
- local = {
- attachments: [
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/png' }
- ]
- }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
- { items: [{ mimetype: 'image/png' }] }
- ])
- })
- it('has "size" key set to "hide"', () => {
- let local
- local = {
- attachments: [
- { mimetype: 'audio/mpeg' }
- ],
- size: 'hide'
- }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { minimal: true, items: [{ mimetype: 'audio/mpeg' }] }
- ])
- local = {
- attachments: [
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' },
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/png' },
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' }
- ],
- size: 'hide'
- }
- // When defining `size: hide`, the `items` aren't
- // grouped and `audio` isn't set
- expect(Gallery.computed.rows.call(local)).to.eql([
- { minimal: true, items: [{ mimetype: 'image/jpg' }] },
- { minimal: true, items: [{ mimetype: 'image/png' }] },
- { minimal: true, items: [{ mimetype: 'image/jpg' }] },
- { minimal: true, items: [{ mimetype: 'audio/mpeg' }] },
- { minimal: true, items: [{ mimetype: 'image/png' }] },
- { minimal: true, items: [{ mimetype: 'audio/mpeg' }] },
- { minimal: true, items: [{ mimetype: 'image/jpg' }] },
- { minimal: true, items: [{ mimetype: 'image/png' }] },
- { minimal: true, items: [{ mimetype: 'image/jpg' }] }
- ])
- })
- // types other than image or audio should be `minimal`
- it('non-image/audio', () => {
- let local
- local = {
- attachments: [
- { mimetype: 'plain/text' }
- ]
- }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { minimal: true, items: [{ mimetype: 'plain/text' }] }
- ])
- // No grouping of non-image/audio items
- local = {
- attachments: [
- { mimetype: 'plain/text' },
- { mimetype: 'plain/text' },
- { mimetype: 'plain/text' }
- ]
- }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { minimal: true, items: [{ mimetype: 'plain/text' }] },
- { minimal: true, items: [{ mimetype: 'plain/text' }] },
- { minimal: true, items: [{ mimetype: 'plain/text' }] }
- ])
- local = {
- attachments: [
- { mimetype: 'image/png' },
- { mimetype: 'plain/text' },
- { mimetype: 'image/jpg' },
- { mimetype: 'audio/mpeg' }
- ]
- }
- // NOTE / TODO: When defining `size: hide`, the `items` aren't
- // grouped and `audio` isn't set
- expect(Gallery.computed.rows.call(local)).to.eql([
- { items: [{ mimetype: 'image/png' }] },
- { minimal: true, items: [{ mimetype: 'plain/text' }] },
- { items: [{ mimetype: 'image/jpg' }] },
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] }
- ])
- })
- it('mixed attachments', () => {
- local = {
- attachments: [
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/png' },
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/jpg' }
- ]
- }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
- { items: [{ mimetype: 'image/png' }] },
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
- { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }, { mimetype: 'image/jpg' }] }
- ])
- local = {
- attachments: [
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/jpg' },
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/png' },
- { mimetype: 'audio/mpeg' }
- ]
- }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }] },
- { items: [{ mimetype: 'image/jpg' }] },
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
- { items: [{ mimetype: 'image/png' }] },
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] }
- ])
- local = {
- attachments: [
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' }
- ]
- }
- // Group by three-per-row, unless there's one dangling, then stick it on the end of the last row
- // https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1785#note_98514
- expect(Gallery.computed.rows.call(local)).to.eql([
- { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }] },
- { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }] }
- ])
- local = {
- attachments: [
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' }
- ]
- }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/jpg' }] },
- { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }, { mimetype: 'image/png' }] },
- { items: [{ mimetype: 'image/jpg' }, { mimetype: 'image/png' }] }
- ])
- })
- it('does not do grouping when grid is set', () => {
- const attachments = [
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/png' },
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' },
- { mimetype: 'image/jpg' }
- ]
- local = { grid: true, attachments }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { grid: true, items: attachments }
- ])
- })
- it('limit is set', () => {
- const attachments = [
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/png' },
- { mimetype: 'image/jpg' },
- { mimetype: 'audio/mpeg' },
- { mimetype: 'image/jpg' }
- ]
- let local
- local = { attachments, limit: 2 }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
- { items: [{ mimetype: 'image/png' }] }
- ])
- local = { attachments, limit: 3 }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
- { items: [{ mimetype: 'image/png' }, { mimetype: 'image/jpg' }] }
- ])
- local = { attachments, limit: 4 }
- expect(Gallery.computed.rows.call(local)).to.eql([
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] },
- { items: [{ mimetype: 'image/png' }, { mimetype: 'image/jpg' }] },
- { audio: true, items: [{ mimetype: 'audio/mpeg' }] }
- ])
- })
- })
|