Files
immich-folio/app/admin/__tests__/analyticsDays.test.ts
Ralksta ad8b09700b release: v0.19.0
Release v0.19.0. See the `## [0.19.0] — 2026-09-29` section of
[CHANGELOG.md](https://github.com/ralksta/immich-folio/blob/dev/CHANGELOG.md)
for the full list.

Highlights: client proofing links (#683), custom content pages (#738),
asset picker search (#740), concurrent-edit detection (#742), env-locked
settings (#739), an accessibility baseline (#741), three security fixes
with advisories (#737, #755, #759), and a pre-release quality pass
(#780–#797).

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: ralksta <ralksta@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Ralf <rohlenbo79@gmail.com>
Co-authored-by: Paul Thies <110185070+ImScheinox@users.noreply.github.com>
Co-authored-by: lancetm714 <108419425+lancetm714@users.noreply.github.com>
Co-authored-by: Lance Martin <lancetaylor95@gmail.com>
2026-09-29 22:50:30 +02:00

36 lines
1.4 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { lastDays } from '../components/analyticsDays';
/**
* "Last 14 Days" used to show the last 14 days that had any views, so quiet
* days vanished and the chart could span a month (QA A-16).
*/
describe('lastDays', () => {
const days = {
'2026-08-28': { pageviews: 4 },
'2026-09-20': { pageviews: 6 },
'2026-09-29': { pageviews: 16 },
};
it('returns every calendar day up to today, with 0 for days without views', () => {
const out = lastDays(days, 14, new Date('2026-09-29T12:00:00Z'));
expect(out).toHaveLength(14);
expect(out[0]).toEqual({ date: '2026-09-16', pageviews: 0 });
expect(out[4]).toEqual({ date: '2026-09-20', pageviews: 6 });
expect(out[13]).toEqual({ date: '2026-09-29', pageviews: 16 });
// Older recorded days are outside the window, not pulled into it.
expect(out.find((d) => d.date === '2026-08-28')).toBeUndefined();
});
it('counts days in UTC, the way the tracker keys them', () => {
// 23:30 UTC on the 29th is already the 30th in Berlin.
const out = lastDays(days, 2, new Date('2026-09-29T23:30:00Z'));
expect(out.map((d) => d.date)).toEqual(['2026-09-28', '2026-09-29']);
});
it('crosses a month boundary without skipping or repeating a day', () => {
const out = lastDays({}, 3, new Date('2026-10-01T00:00:00Z'));
expect(out.map((d) => d.date)).toEqual(['2026-09-29', '2026-09-30', '2026-10-01']);
});
});