Rename several view variables for clarity.
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
import { add } from 'date-fns';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { AutoUpdateManager } from '../../src/card-controller/auto-update-manager';
|
||||
import { createCardAPI, createConfig } from '../test-utils';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('AutoUpdateManager', () => {
|
||||
const start = new Date('2023-09-23T19:12:00');
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('should set default view when allowed', () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
update_seconds: 10,
|
||||
},
|
||||
}),
|
||||
);
|
||||
// Card is triggered.
|
||||
vi.mocked(api.getTriggersManager().isTriggered).mockReturnValue(true);
|
||||
vi.mocked(api.getInteractionManager().hasInteraction).mockReturnValue(false);
|
||||
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(start);
|
||||
|
||||
const manager = new AutoUpdateManager(api);
|
||||
manager.startDefaultViewTimer();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
|
||||
vi.setSystemTime(add(start, { seconds: 10 }));
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
|
||||
vi.mocked(api.getTriggersManager().isTriggered).mockReturnValue(false);
|
||||
|
||||
vi.setSystemTime(add(start, { seconds: 20 }));
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).toBeCalled();
|
||||
});
|
||||
|
||||
it('should not set default view when not configured', () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
update_seconds: 0,
|
||||
},
|
||||
}),
|
||||
);
|
||||
vi.mocked(api.getTriggersManager().isTriggered).mockReturnValue(false);
|
||||
vi.mocked(api.getInteractionManager().hasInteraction).mockReturnValue(false);
|
||||
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(start);
|
||||
|
||||
const manager = new AutoUpdateManager(api);
|
||||
manager.startDefaultViewTimer();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
|
||||
vi.setSystemTime(add(start, { seconds: 10 }));
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
@@ -301,5 +301,38 @@ describe('ConfigManager', () => {
|
||||
InitializationAspect.MICROPHONE_CONNECT,
|
||||
);
|
||||
});
|
||||
|
||||
it('view.default_reset', () => {
|
||||
const api = createCardAPI();
|
||||
const manager = new ConfigManager(api);
|
||||
const config_1 = {
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
view: {
|
||||
default_reset: {
|
||||
every_seconds: 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
vi.mocked(getOverriddenConfig).mockReturnValue(createConfig(config_1));
|
||||
|
||||
manager.setConfig(config_1);
|
||||
expect(api.getInitializationManager().uninitialize).not.toBeCalled();
|
||||
|
||||
const config_2 = {
|
||||
...config_1,
|
||||
view: {
|
||||
default_reset: {
|
||||
every_seconds: 2,
|
||||
},
|
||||
},
|
||||
};
|
||||
vi.mocked(getOverriddenConfig).mockReturnValue(createConfig(config_2));
|
||||
manager.computeOverrideConfig();
|
||||
|
||||
expect(api.getInitializationManager().uninitialize).toBeCalledWith(
|
||||
InitializationAspect.DEFAULT_RESET,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { CameraManager } from '../../src/camera-manager/manager';
|
||||
import { ActionsManager } from '../../src/card-controller/actions/actions-manager';
|
||||
import { AutoUpdateManager } from '../../src/card-controller/auto-update-manager';
|
||||
import { AutomationsManager } from '../../src/card-controller/automations-manager';
|
||||
import { CameraURLManager } from '../../src/card-controller/camera-url-manager';
|
||||
import {
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
import { ConditionsManager } from '../../src/card-controller/conditions-manager';
|
||||
import { ConfigManager } from '../../src/card-controller/config/config-manager';
|
||||
import { CardController } from '../../src/card-controller/controller';
|
||||
import { DefaultManager } from '../../src/card-controller/default-manager';
|
||||
import { DownloadManager } from '../../src/card-controller/download-manager';
|
||||
import { ExpandManager } from '../../src/card-controller/expand-manager';
|
||||
import { FullscreenManager } from '../../src/card-controller/fullscreen-manager';
|
||||
@@ -32,12 +32,12 @@ import { ResolvedMediaCache } from '../../src/utils/ha/resolved-media';
|
||||
|
||||
vi.mock('../../src/camera-manager/manager');
|
||||
vi.mock('../../src/card-controller/actions/actions-manager');
|
||||
vi.mock('../../src/card-controller/auto-update-manager');
|
||||
vi.mock('../../src/card-controller/automations-manager');
|
||||
vi.mock('../../src/card-controller/camera-url-manager');
|
||||
vi.mock('../../src/card-controller/card-element-manager');
|
||||
vi.mock('../../src/card-controller/conditions-manager');
|
||||
vi.mock('../../src/card-controller/config/config-manager');
|
||||
vi.mock('../../src/card-controller/default-manager');
|
||||
vi.mock('../../src/card-controller/download-manager');
|
||||
vi.mock('../../src/card-controller/expand-manager');
|
||||
vi.mock('../../src/card-controller/fullscreen-manager');
|
||||
@@ -107,9 +107,9 @@ describe('CardController', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('getAutoUpdateManager', () => {
|
||||
expect(createController().getAutoUpdateManager()).toBe(
|
||||
vi.mocked(AutoUpdateManager).mock.instances[0],
|
||||
it('getDefaultManager', () => {
|
||||
expect(createController().getDefaultManager()).toBe(
|
||||
vi.mocked(DefaultManager).mock.instances[0],
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { DefaultManager } from '../../src/card-controller/default-manager';
|
||||
import {
|
||||
callHASubscribeMessageHandler,
|
||||
createCardAPI,
|
||||
createConfig,
|
||||
createHASS,
|
||||
} from '../test-utils';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('DefaultManager', () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe('time based', () => {
|
||||
it('should set default view when allowed', async () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
default_reset: {
|
||||
every_seconds: 10,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
vi.mocked(api.getInteractionManager().hasInteraction).mockReturnValue(true);
|
||||
|
||||
vi.useFakeTimers();
|
||||
|
||||
const manager = new DefaultManager(api);
|
||||
await manager.initialize();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
|
||||
vi.mocked(api.getInteractionManager().hasInteraction).mockReturnValue(false);
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).toBeCalledTimes(1);
|
||||
|
||||
manager.uninitialize();
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not set default view when not configured', () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
default_reset: {
|
||||
every_seconds: 0,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
vi.mocked(api.getInteractionManager().hasInteraction).mockReturnValue(false);
|
||||
|
||||
vi.useFakeTimers();
|
||||
|
||||
const manager = new DefaultManager(api);
|
||||
manager.initialize();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should restart timer when reconfigured', async () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
default_reset: {
|
||||
every_seconds: 10,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
vi.mocked(api.getInteractionManager().hasInteraction).mockReturnValue(false);
|
||||
|
||||
const hass = createHASS();
|
||||
const unsubcribeCallback = vi.fn();
|
||||
vi.mocked(hass.connection.subscribeMessage).mockResolvedValue(unsubcribeCallback);
|
||||
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(hass);
|
||||
|
||||
vi.useFakeTimers();
|
||||
|
||||
const manager = new DefaultManager(api);
|
||||
|
||||
await manager.initialize();
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewDefault).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('state based', () => {
|
||||
it('should set default view when state changed', async () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
default_reset: {
|
||||
every_seconds: 10,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
vi.mocked(api.getInteractionManager().hasInteraction).mockReturnValue(false);
|
||||
|
||||
const hass = createHASS();
|
||||
const unsubcribeCallback = vi.fn();
|
||||
vi.mocked(hass.connection.subscribeMessage).mockResolvedValue(unsubcribeCallback);
|
||||
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(hass);
|
||||
|
||||
const manager = new DefaultManager(api);
|
||||
await manager.initialize();
|
||||
|
||||
callHASubscribeMessageHandler(hass, {
|
||||
variables: {
|
||||
trigger: {
|
||||
from_state: {
|
||||
entity_id: 'binary_sensor.foo',
|
||||
state: 'off',
|
||||
},
|
||||
to_state: {
|
||||
entity_id: 'binary_sensor.foo',
|
||||
state: 'on',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await manager.initialize();
|
||||
expect(unsubcribeCallback).toBeCalledTimes(1);
|
||||
|
||||
expect(api.getViewManager().setViewDefault).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not monitor state without config', async () => {
|
||||
const api = createCardAPI();
|
||||
const hass = createHASS();
|
||||
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(hass);
|
||||
|
||||
const manager = new DefaultManager(api);
|
||||
await manager.initialize();
|
||||
|
||||
const mock = vi.mocked(hass.connection.subscribeMessage).mock;
|
||||
expect(mock.calls.length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -146,7 +146,7 @@ describe('HASSManager', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('should set default view when', () => {
|
||||
describe('should not set default view when', () => {
|
||||
it('selected camera is unknown', () => {
|
||||
const api = createAPIWithoutMediaPlayers();
|
||||
vi.mocked(api.getCameraManager).mockReturnValue(createCameraManager());
|
||||
@@ -178,15 +178,18 @@ describe('HASSManager', () => {
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('view.update_entities changes', () => {
|
||||
it('when there is card interaction', () => {
|
||||
const api = createAPIWithoutMediaPlayers();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
update_entities: ['sensor.force_default_view'],
|
||||
default_reset: {
|
||||
entities: ['sensor.force_default_view'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
vi.mocked(api.getInteractionManager().hasInteraction).mockReturnValue(true);
|
||||
|
||||
const manager = new HASSManager(api);
|
||||
const hass = createHASS({
|
||||
@@ -195,7 +198,7 @@ describe('HASSManager', () => {
|
||||
|
||||
manager.setHASS(hass);
|
||||
|
||||
expect(api.getViewManager().setViewDefault).toBeCalled();
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -236,25 +239,4 @@ describe('HASSManager', () => {
|
||||
expect(api.getCardElementManager().update).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('set view default is not called when there is card interaction', () => {
|
||||
const api = createAPIWithoutMediaPlayers();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
update_entities: ['sensor.force_default_view'],
|
||||
},
|
||||
}),
|
||||
);
|
||||
vi.mocked(api.getInteractionManager().hasInteraction).mockReturnValue(true);
|
||||
|
||||
const manager = new HASSManager(api);
|
||||
const hass = createHASS({
|
||||
'sensor.force_default_view': createStateEntity(),
|
||||
});
|
||||
|
||||
manager.setHASS(hass);
|
||||
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -208,9 +208,13 @@ describe('InitializationManager', () => {
|
||||
expect(await manager.initializeBackgroundIfNecessary()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('successfully with minimal initializers', async () => {
|
||||
it('successfully when already initialized', async () => {
|
||||
const api = createCardAPI();
|
||||
const manager = new InitializationManager(api);
|
||||
|
||||
const initializer = mock<Initializer>();
|
||||
initializer.isInitializedMultiple.mockReturnValue(true);
|
||||
|
||||
const manager = new InitializationManager(api, initializer);
|
||||
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(createHASS());
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
@@ -226,6 +230,8 @@ describe('InitializationManager', () => {
|
||||
|
||||
expect(await manager.initializeBackgroundIfNecessary()).toBeTruthy();
|
||||
expect(api.getMediaPlayerManager().initialize).not.toBeCalled();
|
||||
expect(api.getDefaultManager().initialize).not.toBeCalled();
|
||||
expect(api.getCardElementManager().update).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('successfully with all inititalizers', async () => {
|
||||
@@ -246,10 +252,11 @@ describe('InitializationManager', () => {
|
||||
|
||||
expect(await manager.initializeBackgroundIfNecessary()).toBeTruthy();
|
||||
expect(api.getMediaPlayerManager().initialize).toBeCalled();
|
||||
expect(api.getDefaultManager().initialize).toBeCalled();
|
||||
expect(api.getCardElementManager().update).toBeCalled();
|
||||
});
|
||||
|
||||
it('with media player in progress', async () => {
|
||||
it('with initializers in progress', async () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(createHASS());
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
|
||||
@@ -23,12 +23,15 @@ describe('InteractionManager', () => {
|
||||
expect(api.getConditionsManager().setState).toBeCalledWith({ interaction: false });
|
||||
});
|
||||
|
||||
it('should take action when interaction is reported', () => {
|
||||
it('should take action after interaction ends', () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
interaction_seconds: 10,
|
||||
default_reset: {
|
||||
after_interaction: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
@@ -90,12 +93,14 @@ describe('InteractionManager', () => {
|
||||
expect(api.getViewManager().setViewDefault).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should not take action without reset_after_interaction', () => {
|
||||
it('should not take action without default_reset.after_interaction', () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
reset_after_interaction: false,
|
||||
default_reset: {
|
||||
after_interaction: false,
|
||||
},
|
||||
interaction_seconds: 10,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -129,7 +129,6 @@ describe('ViewManager.setViewDefault', () => {
|
||||
|
||||
expect(manager.getView()?.view).toBe('live');
|
||||
expect(manager.getView()?.camera).toBe('camera');
|
||||
expect(api.getAutoUpdateManager().startDefaultViewTimer).toBeCalled();
|
||||
});
|
||||
|
||||
it('should not set default view without config', () => {
|
||||
@@ -140,7 +139,6 @@ describe('ViewManager.setViewDefault', () => {
|
||||
manager.setViewDefault();
|
||||
|
||||
expect(manager.getView()).toBeNull();
|
||||
expect(api.getAutoUpdateManager().startDefaultViewTimer).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should cycle camera when configured', () => {
|
||||
@@ -161,7 +159,7 @@ describe('ViewManager.setViewDefault', () => {
|
||||
vi.mocked(api.getConfigManager().getConfig).mockReturnValue(
|
||||
createConfig({
|
||||
view: {
|
||||
update_cycle_camera: true,
|
||||
default_cycle_camera: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
frigateCardConfigSchema,
|
||||
} from '../../src/config/types';
|
||||
import { getParseErrorPaths } from '../../src/utils/zod';
|
||||
import { update } from 'lodash-es';
|
||||
|
||||
describe('general functions', () => {
|
||||
it('should set value', () => {
|
||||
@@ -134,6 +135,7 @@ describe('upgrade functions', () => {
|
||||
});
|
||||
});
|
||||
it('with non-number', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
expect(createRangedTransform((_val) => 'foo')(1)).toBe('foo');
|
||||
});
|
||||
});
|
||||
@@ -220,6 +222,7 @@ describe('upgrade functions', () => {
|
||||
c: 10,
|
||||
};
|
||||
expect(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
moveConfigValue(config, 'c', 'd', { transform: (_val) => null }),
|
||||
).toBeTruthy();
|
||||
expect(config).toEqual({});
|
||||
@@ -231,6 +234,7 @@ describe('upgrade functions', () => {
|
||||
};
|
||||
expect(
|
||||
moveConfigValue(config, 'c', 'd', {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
transform: (_val) => null,
|
||||
keepOriginal: true,
|
||||
}),
|
||||
@@ -244,6 +248,7 @@ describe('upgrade functions', () => {
|
||||
c: 10,
|
||||
};
|
||||
expect(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
moveConfigValue(config, 'c', 'd', { transform: (_val) => undefined }),
|
||||
).toBeFalsy();
|
||||
expect(config).toEqual({ c: 10 });
|
||||
@@ -294,11 +299,13 @@ describe('upgrade functions', () => {
|
||||
describe('should upgrade array', () => {
|
||||
it('in case of non-array', () => {
|
||||
const config = { c: 10 };
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
expect(upgradeArrayOfObjects('c', (_val) => false)(config)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('in case of non-object items', () => {
|
||||
const config = { c: [10, 11] };
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
expect(upgradeArrayOfObjects('c', (_val) => false)(config)).toBeFalsy();
|
||||
});
|
||||
|
||||
@@ -328,6 +335,7 @@ describe('upgrade functions', () => {
|
||||
describe('should recursively upgrade', () => {
|
||||
it('ignoring simple objects', () => {
|
||||
const config = { c: 10, d: 10 };
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
expect(upgradeObjectRecursively((_val) => false)(config)).toBeFalsy();
|
||||
expect(config).toEqual({ c: 10, d: 10 });
|
||||
});
|
||||
@@ -3099,5 +3107,91 @@ describe('should handle version specific upgrades', () => {
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
});
|
||||
|
||||
it('view.update_cycle_camera -> view.default_cycle_camera', () => {
|
||||
const config = {
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [{}],
|
||||
view: {
|
||||
update_cycle_camera: true,
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.view).toEqual({
|
||||
default_cycle_camera: true,
|
||||
});
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
describe('view.update_force -> view.default_reset.interaction_mode', () => {
|
||||
it('should convert to all when true', () => {
|
||||
const config = {
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [{}],
|
||||
view: {
|
||||
update_force: true,
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.view).toEqual({
|
||||
default_reset: {
|
||||
interaction_mode: 'all',
|
||||
},
|
||||
});
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('should remove when false', () => {
|
||||
const config = {
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [{}],
|
||||
view: {
|
||||
update_force: false,
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.view).toEqual({});
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
});
|
||||
|
||||
it('view.update_seconds', () => {
|
||||
const config = {
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [{}],
|
||||
view: {
|
||||
update_seconds: 42,
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.view).toEqual({
|
||||
default_reset: {
|
||||
every_seconds: 42,
|
||||
},
|
||||
});
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('view.update_entities', () => {
|
||||
const config = {
|
||||
type: 'custom:frigate-card',
|
||||
cameras: [{}],
|
||||
view: {
|
||||
update_entities: ['binary_sensor.foo', 'camera.bar'],
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.view).toEqual({
|
||||
default_reset: {
|
||||
entities: ['binary_sensor.foo', 'camera.bar'],
|
||||
},
|
||||
});
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -331,10 +331,13 @@ describe('config defaults', () => {
|
||||
filter_selected_camera: true,
|
||||
},
|
||||
interaction_seconds: 300,
|
||||
reset_after_interaction: true,
|
||||
update_cycle_camera: false,
|
||||
update_force: false,
|
||||
update_seconds: 0,
|
||||
default_cycle_camera: false,
|
||||
default_reset: {
|
||||
after_interaction: false,
|
||||
every_seconds: 0,
|
||||
entities: [],
|
||||
interaction_mode: 'inactive',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import {
|
||||
CameraManagerMediaCapabilities,
|
||||
} from '../src/camera-manager/types';
|
||||
import { ActionsManager } from '../src/card-controller/actions/actions-manager';
|
||||
import { AutoUpdateManager } from '../src/card-controller/auto-update-manager';
|
||||
import { DefaultManager } from '../src/card-controller/default-manager';
|
||||
import { AutomationsManager } from '../src/card-controller/automations-manager';
|
||||
import { CameraURLManager } from '../src/card-controller/camera-url-manager';
|
||||
import { CardElementManager } from '../src/card-controller/card-element-manager';
|
||||
@@ -434,7 +434,7 @@ export const createCardAPI = (): CardController => {
|
||||
|
||||
api.getActionsManager.mockReturnValue(mock<ActionsManager>());
|
||||
api.getAutomationsManager.mockReturnValue(mock<AutomationsManager>());
|
||||
api.getAutoUpdateManager.mockReturnValue(mock<AutoUpdateManager>());
|
||||
api.getDefaultManager.mockReturnValue(mock<DefaultManager>());
|
||||
api.getCameraManager.mockReturnValue(mock<CameraManager>());
|
||||
api.getCameraURLManager.mockReturnValue(mock<CameraURLManager>());
|
||||
api.getCardElementManager.mockReturnValue(mock<CardElementManager>());
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isActionAllowedBasedOnInteractionState } from '../../src/utils/interaction-mode';
|
||||
|
||||
describe('isActionAllowedBasedOnInteractionState', () => {
|
||||
it('should handle interactionMode: all', () => {
|
||||
expect(isActionAllowedBasedOnInteractionState('all', true)).toBeTruthy();
|
||||
expect(isActionAllowedBasedOnInteractionState('all', false)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should handle interactionMode: active', () => {
|
||||
expect(isActionAllowedBasedOnInteractionState('active', true)).toBeTruthy();
|
||||
expect(isActionAllowedBasedOnInteractionState('active', false)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should handle interactionMode: inactive', () => {
|
||||
expect(isActionAllowedBasedOnInteractionState('inactive', true)).toBeFalsy();
|
||||
expect(isActionAllowedBasedOnInteractionState('inactive', false)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user