#265 add grouping by day as well as month

This commit is contained in:
Alan Grainger
2026-07-17 14:27:51 +12:00
parent 4e7af0ab57
commit c2fcb81807
11 changed files with 180 additions and 22 deletions
+12 -1
View File
@@ -52,7 +52,8 @@ const bucketResponse = {
ratio: [1.5, 0.5, 1],
thumbhash: ['hashA', null, 'hashC'],
isTrashed: [false, true, false],
fileCreatedAt: ['2026-06-03T00:00:00.000Z', '2026-06-02T00:00:00.000Z', '2026-06-01T00:00:00.000Z']
fileCreatedAt: ['2026-06-03T00:00:00.000Z', '2026-06-02T00:00:00.000Z', '2026-06-01T00:00:00.000Z'],
localOffsetHours: [5.5, -8, 0]
}
function routeFetch (sharedLink: unknown) {
@@ -100,6 +101,16 @@ describe('album timeline enumeration (Immich 3.0)', () => {
expect(assets[0].width!).toBeGreaterThan(assets[0].height!)
})
it('synthesises localDateTime from fileCreatedAt + localOffsetHours', async () => {
vi.stubGlobal('fetch', routeFetch(sharedLinkResponse()))
const result = await getShareByKey(uniqueKey(), undefined, KeyType.key)
const assets = result.link!.assets
// aaa: 2026-06-03T00:00Z + 5.5h -> 05:30 local
expect(assets[0].localDateTime).toBe('2026-06-03T05:30:00.000Z')
// ccc: 2026-06-01T00:00Z + 0h -> unchanged
expect(assets[1].localDateTime).toBe('2026-06-01T00:00:00.000Z')
})
it('stamps the share key/keyType onto every asset', async () => {
vi.stubGlobal('fetch', routeFetch(sharedLinkResponse()))
const key = uniqueKey()
+91
View File
@@ -0,0 +1,91 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { state } from '../src/client/state'
import { computeLayout } from '../src/client/layout'
import type { GalleryItem, GroupByDateMode } from '../src/shared/types'
/*
* Exercises the date-grouping generalisation in client/layout.ts: month vs day
* bucketing, the localDateTime-over-fileCreatedAt precedence (the timezone
* boundary case), and the "all undated" header suppression. We assert on the
* bucket structure (header count / order) rather than the localised label
* strings, which vary with the test runner's locale.
*/
function item (partial: Partial<GalleryItem>): GalleryItem {
return {
id: partial.id || Math.random().toString(),
type: 'IMAGE',
previewUrl: '',
thumbnailUrl: '',
downloadFilename: '',
width: 1000,
height: 800,
...partial
}
}
function labelsFor (items: GalleryItem[], mode: GroupByDateMode | false): Array<string> {
state.items = items
state.groupByDate = mode
// Desktop width so the justified-rows path runs; grouping is width-agnostic.
return computeLayout(1200).headers.map(h => h.label)
}
describe('gallery date grouping', () => {
beforeEach(() => {
state.items = []
state.groupByDate = false
})
it('produces no headers when grouping is off', () => {
const items = [
item({ localDateTime: '2024-12-25T10:00:00.000Z' }),
item({ localDateTime: '2024-11-01T10:00:00.000Z' })
]
expect(labelsFor(items, false)).toEqual([])
})
it('buckets by month, collapsing same-month days into one header', () => {
const items = [
item({ localDateTime: '2024-12-25T10:00:00.000Z' }),
item({ localDateTime: '2024-12-02T10:00:00.000Z' }),
item({ localDateTime: '2024-11-30T10:00:00.000Z' })
]
// Dec + Nov = 2 month headers
expect(labelsFor(items, 'month')).toHaveLength(2)
})
it('buckets by day, giving each distinct day its own header', () => {
const items = [
item({ localDateTime: '2024-12-25T10:00:00.000Z' }),
item({ localDateTime: '2024-12-02T10:00:00.000Z' }),
item({ localDateTime: '2024-11-30T10:00:00.000Z' })
]
expect(labelsFor(items, 'day')).toHaveLength(3)
})
it('prefers localDateTime over fileCreatedAt for the bucket (timezone boundary)', () => {
// Shot at 23:00 local on the 25th; stored UTC ticks over to the 26th.
// Day grouping must follow the local date, so both land under the 25th.
const items = [
item({ localDateTime: '2024-12-25T23:00:00.000Z', fileCreatedAt: '2024-12-26T04:00:00.000Z' }),
item({ localDateTime: '2024-12-25T21:00:00.000Z', fileCreatedAt: '2024-12-26T02:00:00.000Z' })
]
expect(labelsFor(items, 'day')).toHaveLength(1)
})
it('falls back to fileCreatedAt when localDateTime is absent', () => {
const items = [
item({ fileCreatedAt: '2024-12-25T10:00:00.000Z' }),
item({ fileCreatedAt: '2024-11-30T10:00:00.000Z' })
]
expect(labelsFor(items, 'month')).toHaveLength(2)
})
it('suppresses the lone header when every item is undated', () => {
const items = [item({}), item({})]
// One "undated" bucket, but its header is dropped -> label is null
const labels = labelsFor(items, 'day')
expect(labels).toEqual([])
})
})