test: Improve timezone resilience / cleanliness of tests (#2279)

- Related: https://github.com/dermotduffy/advanced-camera-card/pull/2278
- Reported by @0x464e
This commit is contained in:
Dermot Duffy
2025-12-11 05:33:48 -08:00
committed by GitHub
parent 236f3b7b57
commit f64690335b
6 changed files with 63 additions and 26 deletions
@@ -1,3 +1,4 @@
import { format } from 'date-fns';
import { describe, expect, it } from 'vitest';
import { mock } from 'vitest-mock-extended';
import { CameraManager } from '../../../../src/camera-manager/manager';
@@ -18,7 +19,9 @@ describe('ThumbnailFeatureController', () => {
controller.calculate(null, itemWithTime, false);
expect(controller.getTitle()).toBe('17:03');
// Use format() to generate expected time in local timezone
const expectedTime = format(itemWithTime.getStartTime()!, 'HH:mm');
expect(controller.getTitle()).toBe(expectedTime);
});
it('should not set title when details are shown ', () => {
@@ -50,7 +53,9 @@ describe('ThumbnailFeatureController', () => {
controller.calculate(null, itemWithTime, false);
expect(controller.getSubtitles()).toContain('May 18th');
// Use format() to generate expected date string (formats in local time)
const expectedDate = format(itemWithTime.getStartTime()!, 'MMM do');
expect(controller.getSubtitles()).toContain(expectedDate);
});
it('should set subtitle with source from item title ', () => {