test: Split test utilities to improve test times (#2622)

This commit is contained in:
Dermot Duffy
2026-07-26 16:29:53 -07:00
committed by GitHub
parent 8d44fcecf1
commit ad89aa9538
234 changed files with 2730 additions and 2516 deletions
+16 -20
View File
@@ -5,12 +5,8 @@ import { ViewItemManager } from '../../../src/card-controller/view/item-manager'
import { homeAssistantGetSignedURLIfNecessary } from '../../../src/ha/sign-path.js';
import { downloadURL } from '../../../src/utils/download';
import { ViewFolder, ViewMediaType } from '../../../src/view/item';
import {
createCardAPI,
createFolder,
createHASS,
TestViewMedia,
} from '../../test-utils';
import { createCardAPI, createFolder, createHASS } from '../../test-utils';
import { TestViewMedia } from '../../view/test-utils';
vi.mock('../../../src/utils/download');
vi.mock('../../../src/ha/sign-path.js');
@@ -95,7 +91,7 @@ describe('ViewItemManager', () => {
vi.mocked(homeAssistantGetSignedURLIfNecessary).mockRejectedValue(signError);
expect(await manager.download(item)).toBe(false);
expect(api.getNotificationManager().setNotification).toBeCalledWith(
expect(api.getNotificationManager().setNotification).toHaveBeenCalledWith(
expect.objectContaining({
heading: expect.objectContaining({
text: 'Download failed',
@@ -126,7 +122,7 @@ describe('ViewItemManager', () => {
);
expect(await manager.download(item)).toBe(true);
expect(downloadURL).toBeCalledWith(
expect(downloadURL).toHaveBeenCalledWith(
'http://foo/signed-url',
'camera-office_id.mp4',
);
@@ -149,7 +145,7 @@ describe('ViewItemManager', () => {
);
expect(await manager.download(item)).toBe(true);
expect(downloadURL).toBeCalledWith('http://foo/signed-url', 'media_id.mp4');
expect(downloadURL).toHaveBeenCalledWith('http://foo/signed-url', 'media_id.mp4');
});
it('should download media without signing', async () => {
@@ -165,7 +161,7 @@ describe('ViewItemManager', () => {
});
expect(await manager.download(item)).toBe(true);
expect(downloadURL).toBeCalledWith('foo', 'camera-office_id.mp4');
expect(downloadURL).toHaveBeenCalledWith('foo', 'camera-office_id.mp4');
});
it('should download media without camera or folder', async () => {
@@ -176,7 +172,7 @@ describe('ViewItemManager', () => {
const item = new TestViewMedia({ cameraID: null, folder: null });
expect(await manager.download(item)).toBe(false);
expect(api.getNotificationManager().setNotification).toBeCalledWith(
expect(api.getNotificationManager().setNotification).toHaveBeenCalledWith(
expect.objectContaining({
heading: expect.objectContaining({
text: 'Download failed',
@@ -203,7 +199,7 @@ describe('ViewItemManager', () => {
});
expect(await manager.download(item)).toBe(true);
expect(downloadURL).toBeCalledWith('foo', 'camera.mp4');
expect(downloadURL).toHaveBeenCalledWith('foo', 'camera.mp4');
});
it('should generate filename for media with start time', async () => {
@@ -223,7 +219,7 @@ describe('ViewItemManager', () => {
// Use format() to generate expected filename timestamp (formats in local time)
const expectedFilename = `camera_id_${format(startTime, 'yyyy-MM-dd-HH-mm-ss')}.mp4`;
expect(downloadURL).toBeCalledWith('foo', expectedFilename);
expect(downloadURL).toHaveBeenCalledWith('foo', expectedFilename);
});
it('should generate filename for snapshot', async () => {
@@ -239,7 +235,7 @@ describe('ViewItemManager', () => {
});
expect(await manager.download(item)).toBe(true);
expect(downloadURL).toBeCalledWith('foo', 'camera_id.jpg');
expect(downloadURL).toHaveBeenCalledWith('foo', 'camera_id.jpg');
});
it('should generate filename for folder without title', async () => {
@@ -255,7 +251,7 @@ describe('ViewItemManager', () => {
});
expect(await manager.download(item)).toBe(true);
expect(downloadURL).toBeCalledWith('foo', 'media');
expect(downloadURL).toHaveBeenCalledWith('foo', 'media');
});
it('should generate filename for folder with title', async () => {
@@ -271,7 +267,7 @@ describe('ViewItemManager', () => {
});
expect(await manager.download(item)).toBe(true);
expect(downloadURL).toBeCalledWith('foo', 'title');
expect(downloadURL).toHaveBeenCalledWith('foo', 'title');
});
});
});
@@ -288,7 +284,7 @@ describe('ViewItemManager', () => {
await manager.favorite(item, true);
expect(api.getCameraManager().favoriteMedia).toBeCalledWith(item, true);
expect(api.getCameraManager().favoriteMedia).toHaveBeenCalledWith(item, true);
});
it('should favorite folder media', async () => {
@@ -302,7 +298,7 @@ describe('ViewItemManager', () => {
await manager.favorite(item, true);
expect(api.getFoldersManager().favorite).toBeCalledWith(item, true);
expect(api.getFoldersManager().favorite).toHaveBeenCalledWith(item, true);
});
});
@@ -318,7 +314,7 @@ describe('ViewItemManager', () => {
await manager.reviewMedia(item, true);
expect(api.getCameraManager().reviewMedia).toBeCalledWith(item, true);
expect(api.getCameraManager().reviewMedia).toHaveBeenCalledWith(item, true);
});
it('should not review non-review media', async () => {
@@ -332,7 +328,7 @@ describe('ViewItemManager', () => {
await manager.reviewMedia(item, true);
expect(api.getCameraManager().reviewMedia).not.toBeCalled();
expect(api.getCameraManager().reviewMedia).not.toHaveBeenCalled();
});
});
});