fix: Preserve parsers/matches on folder navigation (#2249)
- Closes #2231
This commit is contained in:
@@ -130,6 +130,38 @@ describe('FoldersExecutor', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateChildFolderQuery', () => {
|
||||
it('should generate child folder query', () => {
|
||||
const folder: FolderConfig = createFolder();
|
||||
const query: FolderQuery = {
|
||||
folder,
|
||||
path: [{ ha: { id: 'media-source://' } }],
|
||||
};
|
||||
const viewFolder = new ViewFolder(folder);
|
||||
|
||||
const haFolderEngine = mock<HAFoldersEngine>();
|
||||
haFolderEngine.generateChildFolderQuery.mockReturnValue(query);
|
||||
const executor = new FoldersExecutor({ ha: haFolderEngine });
|
||||
|
||||
expect(executor.generateChildFolderQuery(query, viewFolder)).toEqual(query);
|
||||
expect(haFolderEngine.generateChildFolderQuery).toBeCalledWith(query, viewFolder);
|
||||
});
|
||||
|
||||
it('should return null for non-existent folder engine', () => {
|
||||
const folder: FolderConfig = {
|
||||
type: 'UNKNOWN',
|
||||
} as unknown as FolderConfig;
|
||||
const query: FolderQuery = {
|
||||
folder,
|
||||
path: [{ ha: { id: 'media-source://' } }],
|
||||
};
|
||||
const viewFolder = new ViewFolder(folder);
|
||||
const executor = new FoldersExecutor();
|
||||
|
||||
expect(executor.generateChildFolderQuery(query, viewFolder)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('expandFolder', () => {
|
||||
it('should reject folders of the wrong type', async () => {
|
||||
const query = {
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('HAFoldersEngine', () => {
|
||||
|
||||
describe('should generate default folder query', () => {
|
||||
it('should generate default folder query', () => {
|
||||
const folder: FolderConfig = { type: 'ha' };
|
||||
const folder: FolderConfig = { type: 'ha', id: 'test' };
|
||||
const engine = new HAFoldersEngine();
|
||||
|
||||
const query = engine.generateDefaultFolderQuery(folder);
|
||||
@@ -143,7 +143,7 @@ describe('HAFoldersEngine', () => {
|
||||
|
||||
it('should expand folder with cache by default', async () => {
|
||||
const query: FolderQuery = {
|
||||
folder: { type: 'ha' },
|
||||
folder: { type: 'ha', id: 'test' },
|
||||
path: [{ ha: { id: 'media-source://id' } }],
|
||||
};
|
||||
|
||||
@@ -180,7 +180,7 @@ describe('HAFoldersEngine', () => {
|
||||
|
||||
it('should expand folder without cache when requested', async () => {
|
||||
const query: FolderQuery = {
|
||||
folder: { type: 'ha' },
|
||||
folder: { type: 'ha', id: 'test' },
|
||||
path: [{ ha: { id: 'media-source://id' } }],
|
||||
};
|
||||
|
||||
@@ -231,7 +231,7 @@ describe('HAFoldersEngine', () => {
|
||||
});
|
||||
|
||||
const query: FolderQuery = {
|
||||
folder: { type: 'ha' },
|
||||
folder: { type: 'ha', id: 'test' },
|
||||
path: [
|
||||
{
|
||||
folder: new BrowseMediaViewFolder(createFolder(), browseMedia),
|
||||
@@ -259,7 +259,7 @@ describe('HAFoldersEngine', () => {
|
||||
|
||||
it('should not expand without a folder with an id', async () => {
|
||||
const query: FolderQuery = {
|
||||
folder: { type: 'ha' },
|
||||
folder: { type: 'ha', id: 'test' },
|
||||
// There's no component in the query with an id to start from.
|
||||
path: [{ ha: {} }],
|
||||
};
|
||||
@@ -293,7 +293,7 @@ describe('HAFoldersEngine', () => {
|
||||
],
|
||||
])('%s', async (_name: string, matcher: Matcher, expectedMatches: number) => {
|
||||
const query: FolderQuery = {
|
||||
folder: { type: 'ha' },
|
||||
folder: { type: 'ha', id: 'test' },
|
||||
path: [{ ha: { id: 'media-source://' } }, { ha: { matchers: [matcher] } }, {}],
|
||||
};
|
||||
|
||||
@@ -330,4 +330,80 @@ describe('HAFoldersEngine', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateChildFolderQuery', () => {
|
||||
it('should return null if folder type is not ha', () => {
|
||||
const engine = new HAFoldersEngine();
|
||||
const query: FolderQuery = {
|
||||
folder: { type: 'other' } as unknown as FolderConfig,
|
||||
path: [{ ha: { id: 'root' } }],
|
||||
};
|
||||
const folder = new ViewFolder(createFolder());
|
||||
|
||||
expect(engine.generateChildFolderQuery(query, folder)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return null if folder has no id', () => {
|
||||
const engine = new HAFoldersEngine();
|
||||
const query: FolderQuery = {
|
||||
folder: { type: 'ha', id: 'test' },
|
||||
path: [{ ha: { id: 'root' } }],
|
||||
};
|
||||
const folder = new ViewFolder(createFolder(), { id: '' });
|
||||
|
||||
expect(engine.generateChildFolderQuery(query, folder)).toBeNull();
|
||||
});
|
||||
|
||||
it('should extend query with configured component', () => {
|
||||
const engine = new HAFoldersEngine();
|
||||
const folderConfig: FolderConfig = {
|
||||
type: 'ha',
|
||||
id: 'test',
|
||||
ha: {
|
||||
path: [{ id: 'child', matchers: [{ type: 'title', title: 'foo' }] }],
|
||||
},
|
||||
};
|
||||
const query: FolderQuery = {
|
||||
folder: folderConfig,
|
||||
path: [{ ha: { id: 'media-source://' } }],
|
||||
};
|
||||
const folder = new ViewFolder(createFolder(), { id: 'child' });
|
||||
|
||||
const result = engine.generateChildFolderQuery(query, folder);
|
||||
|
||||
expect(result).toEqual({
|
||||
folder: folderConfig,
|
||||
path: [
|
||||
{ ha: { id: 'media-source://' } },
|
||||
{
|
||||
folder,
|
||||
ha: { id: 'child', matchers: [{ type: 'title', title: 'foo' }] },
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('should extend query with default component when no configuration exists', () => {
|
||||
const engine = new HAFoldersEngine();
|
||||
const folderConfig: FolderConfig = { type: 'ha', id: 'test' };
|
||||
const query: FolderQuery = {
|
||||
folder: folderConfig,
|
||||
path: [{ ha: { id: 'media-source://' } }],
|
||||
};
|
||||
const folder = new ViewFolder(createFolder(), { id: 'child' });
|
||||
|
||||
const result = engine.generateChildFolderQuery(query, folder);
|
||||
|
||||
expect(result).toEqual({
|
||||
folder: folderConfig,
|
||||
path: [
|
||||
{ ha: { id: 'media-source://' } },
|
||||
{
|
||||
folder,
|
||||
ha: { id: 'child' },
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ import { FolderQuery } from '../../../src/card-controller/folders/types';
|
||||
import { FolderConfig, FolderConfigWithoutID } from '../../../src/config/schema/folders';
|
||||
import { ResolvedMediaCache } from '../../../src/ha/resolved-media';
|
||||
import { Endpoint } from '../../../src/types';
|
||||
import { ViewFolder } from '../../../src/view/item';
|
||||
import { ViewItemCapabilities } from '../../../src/view/types';
|
||||
import {
|
||||
createCardAPI,
|
||||
@@ -180,6 +181,25 @@ describe('FoldersManager', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateChildFolderQuery', () => {
|
||||
it('should generate child folder query', () => {
|
||||
const folder: FolderConfig = createFolder();
|
||||
const query: FolderQuery = {
|
||||
folder,
|
||||
path: [{ ha: { id: 'media-source://' } }],
|
||||
};
|
||||
const viewFolder = new ViewFolder(folder);
|
||||
|
||||
const executor = mock<FoldersExecutor>();
|
||||
vi.mocked(executor.generateChildFolderQuery).mockReturnValue(query);
|
||||
|
||||
const manager = new FoldersManager(createCardAPI(), executor);
|
||||
|
||||
expect(manager.generateChildFolderQuery(query, viewFolder)).toEqual(query);
|
||||
expect(executor.generateChildFolderQuery).toBeCalledWith(query, viewFolder);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should expand folder', () => {
|
||||
it('should expand folder with hass', async () => {
|
||||
const hass = createHASS();
|
||||
|
||||
Reference in New Issue
Block a user