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
@@ -11,12 +11,8 @@ import { homeAssistantWSRequest } from '../../../../src/ha/ws-request';
import { QuerySource } from '../../../../src/query-source';
import type { Endpoint } from '../../../../src/types';
import { ViewFolder, ViewMedia } from '../../../../src/view/item';
import {
createBrowseMedia,
createFolder,
createHASS,
TestViewMedia,
} from '../../../test-utils';
import { createBrowseMedia, createFolder, createHASS } from '../../../test-utils';
import { TestViewMedia } from '../../../view/test-utils';
vi.mock('../../../../src/ha/download');
vi.mock('../../../../src/ha/ws-request');
@@ -143,11 +139,11 @@ describe('HAFoldersEngine', () => {
expect(results?.[0]).toBeInstanceOf(ViewMedia);
expect(results?.[1]).toBeInstanceOf(ViewFolder);
expect(homeAssistantWSRequest).toBeCalledTimes(1);
expect(homeAssistantWSRequest).toHaveBeenCalledTimes(1);
// Expanding the folder again should use the cache.
await engine.expandFolder(createHASS(), query);
expect(homeAssistantWSRequest).toBeCalledTimes(1);
expect(homeAssistantWSRequest).toHaveBeenCalledTimes(1);
});
it('should expand folder without cache when requested', async () => {
@@ -190,11 +186,11 @@ describe('HAFoldersEngine', () => {
expect(results?.[0]).toBeInstanceOf(ViewMedia);
expect(results?.[1]).toBeInstanceOf(ViewFolder);
expect(homeAssistantWSRequest).toBeCalledTimes(1);
expect(homeAssistantWSRequest).toHaveBeenCalledTimes(1);
// Expanding the folder again should use the cache.
await engine.expandFolder(createHASS(), query);
expect(homeAssistantWSRequest).toBeCalledTimes(2);
expect(homeAssistantWSRequest).toHaveBeenCalledTimes(2);
});
it('should use id from browsemedia in folder in query', async () => {
@@ -225,7 +221,7 @@ describe('HAFoldersEngine', () => {
const engine = new HAFoldersEngine(templateManager);
await engine.expandFolder(hass, query);
expect(homeAssistantWSRequest).toBeCalledWith(hass, browseMediaSchema, {
expect(homeAssistantWSRequest).toHaveBeenCalledWith(hass, browseMediaSchema, {
type: 'media_source/browse_media',
media_content_id: 'media-source://id',
});