2023-02-07 21:48:57 +01:00
|
|
|
import Gallery from 'src/components/gallery/gallery.vue'
|
|
|
|
|
|
2024-09-21 11:56:34 +03:00
|
|
|
describe('Gallery', () => {
|
2023-02-07 21:48:57 +01:00
|
|
|
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 = {
|
2026-03-06 17:14:29 +02:00
|
|
|
attachments: [{ type: 'audio' }],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('one image attachment', () => {
|
|
|
|
|
local = {
|
2026-03-06 17:14:29 +02:00
|
|
|
attachments: [{ type: 'image' }],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ items: [{ type: 'image' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('one audio attachment and one image attachment', () => {
|
|
|
|
|
local = {
|
2026-03-06 17:14:29 +02:00
|
|
|
attachments: [{ type: 'audio' }, { type: 'image' }],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
|
|
|
|
{ items: [{ type: 'image' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('has "size" key set to "hide"', () => {
|
|
|
|
|
let local
|
|
|
|
|
local = {
|
2026-03-06 17:14:29 +02:00
|
|
|
attachments: [{ type: 'audio' }],
|
2026-01-06 16:22:52 +02:00
|
|
|
size: 'hide',
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ minimal: true, items: [{ type: 'audio' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
local = {
|
|
|
|
|
attachments: [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'audio' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'audio' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
2023-02-07 21:48:57 +01:00
|
|
|
],
|
2026-01-06 16:22:52 +02:00
|
|
|
size: 'hide',
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// When defining `size: hide`, the `items` aren't
|
|
|
|
|
// grouped and `audio` isn't set
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ minimal: true, items: [{ type: 'image' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'image' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'image' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'audio' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'image' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'audio' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'image' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'image' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'image' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// types other than image or audio should be `minimal`
|
2026-03-06 17:14:29 +02:00
|
|
|
it('non-image', () => {
|
2023-02-07 21:48:57 +01:00
|
|
|
let local
|
|
|
|
|
local = {
|
2026-03-06 17:14:29 +02:00
|
|
|
attachments: [{ type: 'plain' }],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ minimal: true, items: [{ type: 'plain' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
|
2026-03-06 17:14:29 +02:00
|
|
|
// No grouping of non-image items
|
2023-02-07 21:48:57 +01:00
|
|
|
local = {
|
2026-03-06 17:31:34 +02:00
|
|
|
attachments: [{ type: 'plain' }, { type: 'plain' }, { type: 'plain' }],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ minimal: true, items: [{ type: 'plain' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'plain' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'plain' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
local = {
|
|
|
|
|
attachments: [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'plain' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'audio' },
|
2026-01-06 16:22:52 +02:00
|
|
|
],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
// NOTE / TODO: When defining `size: hide`, the `items` aren't
|
|
|
|
|
// grouped and `audio` isn't set
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ items: [{ type: 'image' }] },
|
|
|
|
|
{ minimal: true, items: [{ type: 'plain' }] },
|
|
|
|
|
{ items: [{ type: 'image' }] },
|
|
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('mixed attachments', () => {
|
|
|
|
|
local = {
|
|
|
|
|
attachments: [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'audio' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'audio' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
2026-01-06 16:22:52 +02:00
|
|
|
],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
|
|
|
|
{ items: [{ type: 'image' }] },
|
|
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
2026-01-06 16:22:52 +02:00
|
|
|
{
|
|
|
|
|
items: [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
2026-01-06 16:22:52 +02:00
|
|
|
],
|
|
|
|
|
},
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
local = {
|
|
|
|
|
attachments: [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'audio' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'audio' },
|
2026-01-06 16:22:52 +02:00
|
|
|
],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-01-06 16:22:52 +02:00
|
|
|
{
|
2026-03-06 17:31:34 +02:00
|
|
|
items: [{ type: 'image' }, { type: 'image' }, { type: 'image' }],
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
2026-03-06 17:14:29 +02:00
|
|
|
{ items: [{ type: 'image' }] },
|
|
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
|
|
|
|
{ items: [{ type: 'image' }] },
|
|
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
local = {
|
|
|
|
|
attachments: [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
2026-01-06 16:22:52 +02:00
|
|
|
],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Group by three-per-row, unless there's one dangling, then stick it on the end of the last row
|
2026-03-06 17:14:29 +02:00
|
|
|
// https:/.pleroma.social-fe/-_requests#note_98514
|
2023-02-07 21:48:57 +01:00
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-01-06 16:22:52 +02:00
|
|
|
{
|
2026-03-06 17:31:34 +02:00
|
|
|
items: [{ type: 'image' }, { type: 'image' }, { type: 'image' }],
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
items: [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
2026-01-06 16:22:52 +02:00
|
|
|
],
|
|
|
|
|
},
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
local = {
|
|
|
|
|
attachments: [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
2026-01-06 16:22:52 +02:00
|
|
|
],
|
2023-02-07 21:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-01-06 16:22:52 +02:00
|
|
|
{
|
2026-03-06 17:31:34 +02:00
|
|
|
items: [{ type: 'image' }, { type: 'image' }, { type: 'image' }],
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
|
|
|
|
{
|
2026-03-06 17:31:34 +02:00
|
|
|
items: [{ type: 'image' }, { type: 'image' }, { type: 'image' }],
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
2026-03-06 17:14:29 +02:00
|
|
|
{ items: [{ type: 'image' }, { type: 'image' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does not do grouping when grid is set', () => {
|
|
|
|
|
const attachments = [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'audio' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'audio' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
2023-02-07 21:48:57 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
local = { grid: true, attachments }
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-01-06 16:22:52 +02:00
|
|
|
{ grid: true, items: attachments },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('limit is set', () => {
|
|
|
|
|
const attachments = [
|
2026-03-06 17:14:29 +02:00
|
|
|
{ type: 'audio' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'image' },
|
|
|
|
|
{ type: 'audio' },
|
|
|
|
|
{ type: 'image' },
|
2023-02-07 21:48:57 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
let local
|
|
|
|
|
local = { attachments, limit: 2 }
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
|
|
|
|
{ items: [{ type: 'image' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
local = { attachments, limit: 3 }
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
|
|
|
|
{ items: [{ type: 'image' }, { type: 'image' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
local = { attachments, limit: 4 }
|
|
|
|
|
|
|
|
|
|
expect(Gallery.computed.rows.call(local)).to.eql([
|
2026-03-06 17:14:29 +02:00
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
|
|
|
|
{ items: [{ type: 'image' }, { type: 'image' }] },
|
|
|
|
|
{ audio: true, items: [{ type: 'audio' }] },
|
2023-02-07 21:48:57 +01:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
})
|