fix: Timeline should should show folder media even without camera support (#2216)
- Closes #2205
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { QueryType } from '../../src/camera-manager/types';
|
||||
import { AdvancedCameraCardView } from '../../src/config/schema/common/const';
|
||||
import { CapabilityKey } from '../../src/types';
|
||||
import { getCameraIDsForViewName } from '../../src/view/view-to-cameras';
|
||||
import { EventMediaQuery } from '../../src/view/query';
|
||||
import { QueryResults } from '../../src/view/query-results';
|
||||
import {
|
||||
getCameraIDsForViewName,
|
||||
isViewSupportedByCamera,
|
||||
isViewSupportedByQueryOnly,
|
||||
} from '../../src/view/view-support';
|
||||
import {
|
||||
createCameraConfig,
|
||||
createCameraManager,
|
||||
createCapabilities,
|
||||
createStore,
|
||||
generateViewMediaArray,
|
||||
} from '../test-utils';
|
||||
|
||||
describe('getCameraIDsForViewName', () => {
|
||||
@@ -29,13 +37,13 @@ describe('getCameraIDsForViewName', () => {
|
||||
]),
|
||||
);
|
||||
|
||||
expect(getCameraIDsForViewName(cameraManager, viewName)).toEqual(
|
||||
expect(getCameraIDsForViewName(viewName, cameraManager)).toEqual(
|
||||
new Set(['camera-1', 'camera-2']),
|
||||
);
|
||||
expect(getCameraIDsForViewName(cameraManager, viewName, 'camera-1')).toEqual(
|
||||
expect(getCameraIDsForViewName(viewName, cameraManager, 'camera-1')).toEqual(
|
||||
new Set(['camera-1', 'camera-2']),
|
||||
);
|
||||
expect(getCameraIDsForViewName(cameraManager, viewName, 'camera-2')).toEqual(
|
||||
expect(getCameraIDsForViewName(viewName, cameraManager, 'camera-2')).toEqual(
|
||||
new Set(['camera-1', 'camera-2']),
|
||||
);
|
||||
});
|
||||
@@ -62,7 +70,7 @@ describe('getCameraIDsForViewName', () => {
|
||||
]),
|
||||
);
|
||||
|
||||
expect(getCameraIDsForViewName(cameraManager, viewName)).toEqual(
|
||||
expect(getCameraIDsForViewName(viewName, cameraManager)).toEqual(
|
||||
new Set(['camera-2']),
|
||||
);
|
||||
});
|
||||
@@ -89,15 +97,81 @@ describe('getCameraIDsForViewName', () => {
|
||||
]),
|
||||
);
|
||||
|
||||
expect(getCameraIDsForViewName(cameraManager, viewName)).toEqual(
|
||||
expect(getCameraIDsForViewName(viewName, cameraManager)).toEqual(
|
||||
new Set(['camera-1', 'camera-2']),
|
||||
);
|
||||
expect(getCameraIDsForViewName(cameraManager, viewName, 'camera-1')).toEqual(
|
||||
expect(getCameraIDsForViewName(viewName, cameraManager, 'camera-1')).toEqual(
|
||||
new Set(['camera-1', 'camera-2']),
|
||||
);
|
||||
expect(getCameraIDsForViewName(cameraManager, viewName, 'camera-2')).toEqual(
|
||||
expect(getCameraIDsForViewName(viewName, cameraManager, 'camera-2')).toEqual(
|
||||
new Set(['camera-2']),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isViewSupportedByCamera', () => {
|
||||
it('should return true for supported view', () => {
|
||||
const cameraManager = createCameraManager();
|
||||
vi.mocked(cameraManager.getStore).mockReturnValue(
|
||||
createStore([
|
||||
{
|
||||
cameraID: 'camera-1',
|
||||
capabilities: createCapabilities({ live: true }),
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
expect(isViewSupportedByCamera('live', cameraManager, 'camera-1')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for unsupported view', () => {
|
||||
const cameraManager = createCameraManager();
|
||||
vi.mocked(cameraManager.getStore).mockReturnValue(
|
||||
createStore([
|
||||
{
|
||||
cameraID: 'camera-1',
|
||||
capabilities: createCapabilities({ live: false }),
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
expect(isViewSupportedByCamera('live', cameraManager, 'camera-1')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isViewSupportedByQueryOnly', () => {
|
||||
it.each([
|
||||
['live' as const],
|
||||
['image' as const],
|
||||
['diagnostics' as const],
|
||||
['clip' as const],
|
||||
['clips' as const],
|
||||
['snapshot' as const],
|
||||
['snapshots' as const],
|
||||
['recording' as const],
|
||||
['recordings' as const],
|
||||
['media' as const],
|
||||
])('%s', (viewName: AdvancedCameraCardView) => {
|
||||
expect(isViewSupportedByQueryOnly(viewName)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for timeline without query', () => {
|
||||
expect(isViewSupportedByQueryOnly('timeline')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true for timeline with query and query results', () => {
|
||||
const query = new EventMediaQuery([
|
||||
{
|
||||
type: QueryType.Event,
|
||||
cameraIDs: new Set(['camera-1']),
|
||||
},
|
||||
]);
|
||||
const queryResults = new QueryResults({
|
||||
results: generateViewMediaArray({ count: 5 }),
|
||||
selectedIndex: 0,
|
||||
});
|
||||
|
||||
expect(isViewSupportedByQueryOnly('timeline', query, queryResults)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user