test: Split test utilities to improve test times (#2622)
This commit is contained in:
@@ -22,14 +22,14 @@ import {
|
||||
createLogAction,
|
||||
} from '../../../src/utils/action';
|
||||
import { arrayify } from '../../../src/utils/basic';
|
||||
import { createConfig } from '../../config/test-utils';
|
||||
import {
|
||||
createCardAPI,
|
||||
createConfig,
|
||||
createHASS,
|
||||
createMockTemplateRenderer,
|
||||
createView,
|
||||
stubConnectedHomeAssistant,
|
||||
} from '../../test-utils';
|
||||
import { createView } from '../../view/test-utils';
|
||||
|
||||
const createAPI = (): CardController => {
|
||||
const api = createCardAPI();
|
||||
@@ -215,7 +215,7 @@ describe('ActionsManager', () => {
|
||||
await manager.handleInteractionEvent(
|
||||
new CustomEvent<Interaction>('event', { detail: { action: 'tap' } }),
|
||||
);
|
||||
expect(consoleSpy).toBeCalled();
|
||||
expect(consoleSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('should handle unexpected interactions', () => {
|
||||
@@ -246,7 +246,7 @@ describe('ActionsManager', () => {
|
||||
detail: { action: interaction as unknown as InteractionName },
|
||||
}),
|
||||
);
|
||||
expect(consoleSpy).not.toBeCalled();
|
||||
expect(consoleSpy).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -271,7 +271,7 @@ describe('ActionsManager', () => {
|
||||
|
||||
const consoleSpy = vi.spyOn(global.console, 'info').mockReturnValue(undefined);
|
||||
await manager.handleCustomActionEvent(event);
|
||||
expect(consoleSpy).toBeCalled();
|
||||
expect(consoleSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not handle generic event', async () => {
|
||||
@@ -292,7 +292,7 @@ describe('ActionsManager', () => {
|
||||
|
||||
await manager.handleCustomActionEvent(event);
|
||||
|
||||
expect(handler).not.toBeCalled();
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not handle event without detail', async () => {
|
||||
@@ -300,7 +300,7 @@ describe('ActionsManager', () => {
|
||||
|
||||
const consoleSpy = vi.spyOn(global.console, 'info').mockReturnValue(undefined);
|
||||
await manager.handleCustomActionEvent(new Event('ll-custom'));
|
||||
expect(consoleSpy).not.toBeCalled();
|
||||
expect(consoleSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -319,7 +319,7 @@ describe('ActionsManager', () => {
|
||||
detail: { actions: createLogAction('Hello, world!') },
|
||||
}),
|
||||
);
|
||||
expect(consoleSpy).toBeCalled();
|
||||
expect(consoleSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -334,7 +334,7 @@ describe('ActionsManager', () => {
|
||||
|
||||
const consoleSpy = vi.spyOn(global.console, 'info').mockReturnValue(undefined);
|
||||
await manager.executeActions({ actions: createLogAction('Hello, world!') });
|
||||
expect(consoleSpy).toBeCalled();
|
||||
expect(consoleSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should execute actions', async () => {
|
||||
@@ -343,7 +343,7 @@ describe('ActionsManager', () => {
|
||||
|
||||
const consoleSpy = vi.spyOn(global.console, 'info').mockReturnValue(undefined);
|
||||
await manager.executeActions({ actions: createLogAction('Hello, world!') });
|
||||
expect(consoleSpy).toBeCalled();
|
||||
expect(consoleSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should render templates', async () => {
|
||||
@@ -372,14 +372,12 @@ describe('ActionsManager', () => {
|
||||
|
||||
await manager.executeActions({ actions: action, config, triggerData });
|
||||
|
||||
expect(vi.mocked(api.getTemplateManager().renderRecursivelyAsType)).toBeCalledWith(
|
||||
hass,
|
||||
action,
|
||||
{
|
||||
conditionState,
|
||||
triggerData,
|
||||
},
|
||||
);
|
||||
expect(
|
||||
vi.mocked(api.getTemplateManager().renderRecursivelyAsType),
|
||||
).toHaveBeenCalledWith(hass, action, {
|
||||
conditionState,
|
||||
triggerData,
|
||||
});
|
||||
});
|
||||
|
||||
it('should filter actions through the lock manager before rendering them', async () => {
|
||||
@@ -403,9 +401,9 @@ describe('ActionsManager', () => {
|
||||
|
||||
// The lock manager sees the raw (unrendered) action; only the action it
|
||||
// returns is rendered and run.
|
||||
expect(api.getLockManager().getAllowedActions).toBeCalledWith([rawAction]);
|
||||
expect(allowedRan).toBeCalled();
|
||||
expect(rawRan).not.toBeCalled();
|
||||
expect(api.getLockManager().getAllowedActions).toHaveBeenCalledWith([rawAction]);
|
||||
expect(allowedRan).toHaveBeenCalled();
|
||||
expect(rawRan).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should render each action against the state at its turn', async () => {
|
||||
@@ -481,7 +479,7 @@ describe('ActionsManager', () => {
|
||||
expect(ran).toEqual(['one', 'two']);
|
||||
expect(
|
||||
vi.mocked(api.getTemplateManager().renderRecursivelyAsType),
|
||||
).toBeCalledTimes(1);
|
||||
).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should abort the remaining actions when one fails to render', async () => {
|
||||
@@ -519,7 +517,7 @@ describe('ActionsManager', () => {
|
||||
// The first action ran; the second's render threw, aborting the rest. The
|
||||
// error was caught by executeActions().
|
||||
expect(ran).toEqual(['first']);
|
||||
expect(warnSpy).toBeCalled();
|
||||
expect(warnSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should hand an if-action branch to the executor unrendered, with the trigger data', async () => {
|
||||
@@ -549,7 +547,7 @@ describe('ActionsManager', () => {
|
||||
// The branch is left raw (template intact) and forwarded with the trigger
|
||||
// data, so the nested executor renders it per-step when it runs -- not
|
||||
// frozen against the state at the `if` step.
|
||||
expect(api.getActionsManager().executeNestedActions).toBeCalledWith({
|
||||
expect(api.getActionsManager().executeNestedActions).toHaveBeenCalledWith({
|
||||
actions: [thenAction],
|
||||
config: undefined,
|
||||
triggerData: { platform: 'state', entity_id: 'binary_sensor.door' },
|
||||
@@ -557,7 +555,7 @@ describe('ActionsManager', () => {
|
||||
|
||||
// The log action is handed to the (mocked) nested executor, not run here,
|
||||
// so it must not actually log.
|
||||
expect(consoleSpy).not.toBeCalled();
|
||||
expect(consoleSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should render if-action branch actions per-step', async () => {
|
||||
@@ -633,7 +631,7 @@ describe('ActionsManager', () => {
|
||||
|
||||
await manager.executeActions({ actions: createLogAction('Blocked') });
|
||||
|
||||
expect(consoleSpy).not.toBeCalled();
|
||||
expect(consoleSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('should forward haptics', () => {
|
||||
@@ -651,7 +649,9 @@ describe('ActionsManager', () => {
|
||||
|
||||
await manager.executeActions({ actions: { action: 'none' } });
|
||||
|
||||
expect(handler).toBeCalledWith(expect.objectContaining({ detail: 'success' }));
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ detail: 'success' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should forward warning haptic', async () => {
|
||||
@@ -669,7 +669,9 @@ describe('ActionsManager', () => {
|
||||
actions: { action: 'none', confirmation: true },
|
||||
});
|
||||
|
||||
expect(handler).toBeCalledWith(expect.objectContaining({ detail: 'warning' }));
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ detail: 'warning' }),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -712,7 +714,7 @@ describe('ActionsManager', () => {
|
||||
await promise;
|
||||
|
||||
// Action set will not continue.
|
||||
expect(consoleSpy).not.toBeCalled();
|
||||
expect(consoleSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('should handle base action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(confirm).not.toBeCalled();
|
||||
expect(confirm).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should continue execution when confirmed', async () => {
|
||||
@@ -61,7 +61,7 @@ describe('should handle base action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(confirm).toBeCalled();
|
||||
expect(confirm).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should abort execution when not confirmed', async () => {
|
||||
@@ -76,7 +76,7 @@ describe('should handle base action', () => {
|
||||
|
||||
vi.mocked(confirm).mockReturnValue(false);
|
||||
|
||||
expect(async () => await action.execute(api)).rejects.toThrowError(/Aborted action/);
|
||||
expect(async () => await action.execute(api)).rejects.toThrow(/Aborted action/);
|
||||
});
|
||||
|
||||
it('should not confirm when exempted', async () => {
|
||||
@@ -100,7 +100,7 @@ describe('should handle base action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(confirm).not.toBeCalled();
|
||||
expect(confirm).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('should show correct confirmation text', () => {
|
||||
@@ -121,7 +121,7 @@ describe('should handle base action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(confirm).toBeCalledWith(
|
||||
expect(confirm).toHaveBeenCalledWith(
|
||||
'Are you sure you want to perform this action: more-info',
|
||||
);
|
||||
});
|
||||
@@ -143,7 +143,7 @@ describe('should handle base action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(confirm).toBeCalledWith(
|
||||
expect(confirm).toHaveBeenCalledWith(
|
||||
'Are you sure you want to perform this action: clips',
|
||||
);
|
||||
});
|
||||
@@ -167,7 +167,7 @@ describe('should handle base action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(confirm).toBeCalledWith('Test text');
|
||||
expect(confirm).toHaveBeenCalledWith('Test text');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle call_answer action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCallManager().answer).toBeCalled();
|
||||
expect(api.getCallManager().answer).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle call_end action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCallManager().end).toBeCalled();
|
||||
expect(api.getCallManager().end).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ describe('CallServiceAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(hass.callService).toBeCalledWith(
|
||||
expect(hass.callService).toHaveBeenCalledWith(
|
||||
'light',
|
||||
'turn_on',
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ it('should handle call_start action without a camera or stream', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCallManager().start).toBeCalledWith({
|
||||
expect(api.getCallManager().start).toHaveBeenCalledWith({
|
||||
cameraID: undefined,
|
||||
streamID: undefined,
|
||||
});
|
||||
@@ -35,7 +35,7 @@ it('should handle call_start action with a camera and stream', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCallManager().start).toBeCalledWith({
|
||||
expect(api.getCallManager().start).toHaveBeenCalledWith({
|
||||
cameraID: 'camera.front',
|
||||
streamID: 'camera.front_doorbell',
|
||||
});
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { CameraSelectAction } from '../../../../src/card-controller/actions/actions/camera-select';
|
||||
import { createCardAPI, createConfig, createView } from '../../../test-utils';
|
||||
import { createConfig } from '../../../config/test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { createView } from '../../../view/test-utils';
|
||||
|
||||
describe('should handle camera_select action', () => {
|
||||
it('with valid camera and view', async () => {
|
||||
@@ -19,7 +21,7 @@ describe('should handle camera_select action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledWith(
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
params: {
|
||||
view: 'live',
|
||||
@@ -49,7 +51,7 @@ describe('should handle camera_select action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).not.toBeCalled();
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('without config', async () => {
|
||||
@@ -72,7 +74,7 @@ describe('should handle camera_select action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledWith(
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
params: {
|
||||
view: 'timeline',
|
||||
@@ -110,7 +112,7 @@ describe('should handle camera_select action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledWith(
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
params: {
|
||||
view: 'clips',
|
||||
@@ -139,7 +141,7 @@ describe('should handle camera_select action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledWith(
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
params: {
|
||||
view: 'live',
|
||||
@@ -167,7 +169,7 @@ describe('should handle camera_select action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).not.toBeCalled();
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('without a current view', async () => {
|
||||
@@ -184,6 +186,6 @@ describe('should handle camera_select action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).not.toBeCalled();
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle camera_ui action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraURLManager().openURL).toBeCalled();
|
||||
expect(api.getCameraURLManager().openURL).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('CustomAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(handler).toBeCalledWith(
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
detail: { action: 'fire-dom-event', foo: 'bar', 1: 2 },
|
||||
}),
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle default action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewDefaultWithNewQuery).toBeCalled();
|
||||
expect(api.getViewManager().setViewDefaultWithNewQuery).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ it('should handle default action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toHaveBeenCalledWith({
|
||||
params: {
|
||||
displayMode: 'grid',
|
||||
},
|
||||
|
||||
@@ -2,7 +2,8 @@ import { expect, it, vi } from 'vitest';
|
||||
|
||||
import { DownloadAction } from '../../../../src/card-controller/actions/actions/download';
|
||||
import { QueryResults } from '../../../../src/view/query-results';
|
||||
import { createCardAPI, createView, TestViewMedia } from '../../../test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { createView, TestViewMedia } from '../../../view/test-utils';
|
||||
|
||||
it('should handle download action with selected media', async () => {
|
||||
const api = createCardAPI();
|
||||
@@ -23,7 +24,7 @@ it('should handle download action with selected media', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().download).toBeCalledWith(selectedMedia);
|
||||
expect(api.getViewItemManager().download).toHaveBeenCalledWith(selectedMedia);
|
||||
});
|
||||
|
||||
it('should handle download action without selected media', async () => {
|
||||
@@ -40,5 +41,5 @@ it('should handle download action without selected media', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().download).not.toBeCalled();
|
||||
expect(api.getViewItemManager().download).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle expand action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getExpandManager().toggleExpanded).toBeCalled();
|
||||
expect(api.getExpandManager().toggleExpanded).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle fullscreen action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getFullscreenManager().toggleFullscreen).toBeCalled();
|
||||
expect(api.getFullscreenManager().toggleFullscreen).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('GeneratedAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getActionsManager().executeNestedActions).toBeCalledWith({
|
||||
expect(api.getActionsManager().executeNestedActions).toHaveBeenCalledWith({
|
||||
actions: generated,
|
||||
config: undefined,
|
||||
triggerData: undefined,
|
||||
@@ -37,7 +37,7 @@ describe('GeneratedAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getActionsManager().executeNestedActions).toBeCalledWith({
|
||||
expect(api.getActionsManager().executeNestedActions).toHaveBeenCalledWith({
|
||||
actions: generated,
|
||||
config: undefined,
|
||||
triggerData: undefined,
|
||||
@@ -53,7 +53,7 @@ describe('GeneratedAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getActionsManager().executeNestedActions).not.toBeCalled();
|
||||
expect(api.getActionsManager().executeNestedActions).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should pass the api and trigger data to the generator', async () => {
|
||||
@@ -72,6 +72,6 @@ describe('GeneratedAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(generator).toBeCalledWith({ api, triggerData });
|
||||
expect(generator).toHaveBeenCalledWith({ api, triggerData });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@ describe('IfAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getActionsManager().executeNestedActions).toBeCalledWith({
|
||||
expect(api.getActionsManager().executeNestedActions).toHaveBeenCalledWith({
|
||||
actions: thenActions,
|
||||
config: undefined,
|
||||
triggerData: undefined,
|
||||
@@ -59,7 +59,7 @@ describe('IfAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getActionsManager().executeNestedActions).toBeCalledWith({
|
||||
expect(api.getActionsManager().executeNestedActions).toHaveBeenCalledWith({
|
||||
actions: elseActions,
|
||||
config: undefined,
|
||||
triggerData: undefined,
|
||||
@@ -82,6 +82,6 @@ describe('IfAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getActionsManager().executeNestedActions).not.toBeCalled();
|
||||
expect(api.getActionsManager().executeNestedActions).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,8 @@ import { describe, expect, it, vi } from 'vitest';
|
||||
import { InfoAction } from '../../../../src/card-controller/actions/actions/info';
|
||||
import { QueryResults } from '../../../../src/view/query-results';
|
||||
import { View } from '../../../../src/view/view';
|
||||
import { createCardAPI, TestViewMedia } from '../../../test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { TestViewMedia } from '../../../view/test-utils';
|
||||
|
||||
describe('InfoAction', () => {
|
||||
it('should handle info action with media', async () => {
|
||||
@@ -29,7 +30,7 @@ describe('InfoAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getNotificationManager().setNotification).toBeCalled();
|
||||
expect(api.getNotificationManager().setNotification).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not handle info action without media', async () => {
|
||||
@@ -46,6 +47,6 @@ describe('InfoAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getNotificationManager().setNotification).not.toBeCalled();
|
||||
expect(api.getNotificationManager().setNotification).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,5 +18,5 @@ it('should handle internal callback action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(callback).toBeCalledWith(api);
|
||||
expect(callback).toHaveBeenCalledWith(api);
|
||||
});
|
||||
|
||||
@@ -21,5 +21,5 @@ it('should handle log action', async () => {
|
||||
|
||||
const spy = vi.spyOn(global.console, 'warn').mockImplementation(() => true);
|
||||
await action.execute(api);
|
||||
expect(spy).toBeCalledWith('Hello, world!');
|
||||
expect(spy).toHaveBeenCalledWith('Hello, world!');
|
||||
});
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { MediaPlayerAction } from '../../../../src/card-controller/actions/actions/media-player';
|
||||
import { createCardAPI, createView, createViewWithMedia } from '../../../test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { createView, createViewWithMedia } from '../../../view/test-utils';
|
||||
|
||||
afterEach(() => {
|
||||
vi.resetAllMocks();
|
||||
@@ -23,7 +24,9 @@ describe('should handle media_player action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getMediaPlayerManager().stop).toBeCalledWith('this_is_a_media_player');
|
||||
expect(api.getMediaPlayerManager().stop).toHaveBeenCalledWith(
|
||||
'this_is_a_media_player',
|
||||
);
|
||||
});
|
||||
|
||||
it('to play live', async () => {
|
||||
@@ -47,7 +50,7 @@ describe('should handle media_player action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getMediaPlayerManager().playLive).toBeCalledWith(
|
||||
expect(api.getMediaPlayerManager().playLive).toHaveBeenCalledWith(
|
||||
'this_is_a_media_player',
|
||||
'camera',
|
||||
);
|
||||
@@ -74,7 +77,7 @@ describe('should handle media_player action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getMediaPlayerManager().playMedia).toBeCalledWith(
|
||||
expect(api.getMediaPlayerManager().playMedia).toHaveBeenCalledWith(
|
||||
'this_is_a_media_player',
|
||||
view.queryResults?.getSelectedResult(),
|
||||
);
|
||||
@@ -100,7 +103,7 @@ describe('should handle media_player action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getMediaPlayerManager().playMedia).not.toBeCalled();
|
||||
expect(api.getMediaPlayerManager().playMedia).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('to not play live without camera', async () => {
|
||||
@@ -124,6 +127,6 @@ describe('should handle media_player action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getMediaPlayerManager().playLive).not.toBeCalled();
|
||||
expect(api.getMediaPlayerManager().playLive).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle menu toggle action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCardElementManager().toggleMenu).toBeCalled();
|
||||
expect(api.getCardElementManager().toggleMenu).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle microphone_connect action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getMicrophoneManager().connect).toBeCalled();
|
||||
expect(api.getMicrophoneManager().connect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle microphone_disconnect action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getMicrophoneManager().disconnect).toBeCalled();
|
||||
expect(api.getMicrophoneManager().disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle microphone_mute action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getMicrophoneManager().mute).toBeCalled();
|
||||
expect(api.getMicrophoneManager().mute).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should handle microphone_unmute action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getMicrophoneManager().unmute).toBeCalled();
|
||||
expect(api.getMicrophoneManager().unmute).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ describe('should handle more-info action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(handler).toBeCalledWith(
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
detail: { entityId: 'light.office' },
|
||||
}),
|
||||
@@ -51,7 +51,7 @@ describe('should handle more-info action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(handler).toBeCalledWith(
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
detail: { entityId: 'light.office' },
|
||||
}),
|
||||
@@ -76,6 +76,6 @@ describe('should handle more-info action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(handler).not.toBeCalled();
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,5 +23,5 @@ it('should handle mute action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(mediaPlayerController.mute).toBeCalled();
|
||||
expect(mediaPlayerController.mute).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('should handle navigate action', () => {
|
||||
await action.execute(createCardAPI());
|
||||
|
||||
expect(history.length).toBe(historyLength + 1);
|
||||
expect(handler).toBeCalledWith(
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
detail: { replace: false },
|
||||
}),
|
||||
@@ -49,7 +49,7 @@ describe('should handle navigate action', () => {
|
||||
await action.execute(createCardAPI());
|
||||
|
||||
expect(history.length).toBe(historyLength);
|
||||
expect(handler).toBeCalledWith(
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
detail: { replace: true },
|
||||
}),
|
||||
|
||||
@@ -25,5 +25,5 @@ it('should handle pause action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(mediaPlayerController.playback?.pause).toBeCalled();
|
||||
expect(mediaPlayerController.playback?.pause).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ describe('PerformActionAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(hass.callService).toBeCalledWith(
|
||||
expect(hass.callService).toHaveBeenCalledWith(
|
||||
'light',
|
||||
'turn_on',
|
||||
{
|
||||
|
||||
@@ -15,5 +15,5 @@ it('should toggle PIP', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getPIPManager().togglePIP).toBeCalled();
|
||||
expect(api.getPIPManager().togglePIP).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -25,5 +25,5 @@ it('should handle play action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(mediaPlayerController.playback?.play).toBeCalled();
|
||||
expect(mediaPlayerController.playback?.play).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ describe('PTZControlsAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
ptzControls: { enabled: true, type: 'buttons' },
|
||||
});
|
||||
});
|
||||
@@ -41,7 +41,7 @@ describe('PTZControlsAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
ptzControls: { enabled: false },
|
||||
});
|
||||
});
|
||||
@@ -59,7 +59,7 @@ describe('PTZControlsAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
ptzControls: {},
|
||||
});
|
||||
});
|
||||
@@ -78,7 +78,7 @@ describe('PTZControlsAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
ptzControls: { type: 'gestures' },
|
||||
});
|
||||
});
|
||||
@@ -100,7 +100,7 @@ describe('PTZControlsAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
ptzControls: { type: 'buttons' },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,8 @@ import type {
|
||||
ZoomSettingsObserved,
|
||||
} from '../../../../src/components-lib/zoom/types';
|
||||
import type { PTZAction } from '../../../../src/config/schema/actions/custom/ptz';
|
||||
import { createCardAPI, createView } from '../../../test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { createView } from '../../../view/test-utils';
|
||||
|
||||
describe('should handle ptz digital action', () => {
|
||||
const defaultSettings = {
|
||||
@@ -47,7 +48,7 @@ describe('should handle ptz digital action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
zoom: {
|
||||
camera: {
|
||||
observed: undefined,
|
||||
@@ -77,7 +78,7 @@ describe('should handle ptz digital action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
zoom: {
|
||||
camera: {
|
||||
observed: undefined,
|
||||
@@ -101,7 +102,7 @@ describe('should handle ptz digital action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toBeCalledWith();
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should do nothing without a camera', async () => {
|
||||
@@ -125,7 +126,7 @@ describe('should handle ptz digital action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toBeCalled();
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('should honor ptz_action', () => {
|
||||
@@ -338,7 +339,7 @@ describe('should handle ptz digital action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledWith({
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledWith({
|
||||
zoom: {
|
||||
camera: {
|
||||
observed: undefined,
|
||||
@@ -428,12 +429,12 @@ describe('should handle ptz digital action', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledTimes(2);
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledTimes(2);
|
||||
|
||||
action.stop();
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledTimes(2);
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('stop', async () => {
|
||||
@@ -463,7 +464,7 @@ describe('should handle ptz digital action', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledTimes(1);
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledTimes(1);
|
||||
|
||||
const stopAction = new PTZDigitalAction(context, {
|
||||
action: 'fire-dom-event',
|
||||
@@ -474,7 +475,7 @@ describe('should handle ptz digital action', () => {
|
||||
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getViewManager().setViewWithMergedContext).toBeCalledTimes(1);
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,12 +3,9 @@ import { describe, expect, it, vi } from 'vitest';
|
||||
import { Capabilities } from '../../../../src/camera-manager/capabilities';
|
||||
import { PTZMultiAction } from '../../../../src/card-controller/actions/actions/ptz-multi';
|
||||
import { PTZMovementType } from '../../../../src/types';
|
||||
import {
|
||||
createCameraManager,
|
||||
createCardAPI,
|
||||
createStore,
|
||||
createView,
|
||||
} from '../../../test-utils';
|
||||
import { createCameraManager, createStore } from '../../../camera-manager/test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { createView } from '../../../view/test-utils';
|
||||
|
||||
describe('should handle ptz multi action', () => {
|
||||
describe.each([
|
||||
@@ -42,7 +39,7 @@ describe('should handle ptz multi action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'left',
|
||||
{
|
||||
@@ -50,7 +47,7 @@ describe('should handle ptz multi action', () => {
|
||||
preset: undefined,
|
||||
},
|
||||
);
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toBeCalled();
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should use digital ptz when camera does not have ptz support', async () => {
|
||||
@@ -79,7 +76,7 @@ describe('should handle ptz multi action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).not.toBeCalled();
|
||||
expect(api.getCameraManager().executePTZAction).not.toHaveBeenCalled();
|
||||
expect(api.getViewManager().setViewWithMergedContext).toHaveBeenLastCalledWith({
|
||||
zoom: {
|
||||
'camera.office': {
|
||||
@@ -117,8 +114,8 @@ describe('should handle ptz multi action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).not.toBeCalled();
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toBeCalled();
|
||||
expect(api.getCameraManager().executePTZAction).not.toHaveBeenCalled();
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should do nothing with a media-less view without an explicit target_id', async () => {
|
||||
@@ -146,7 +143,7 @@ describe('should handle ptz multi action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).not.toBeCalled();
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toBeCalled();
|
||||
expect(api.getCameraManager().executePTZAction).not.toHaveBeenCalled();
|
||||
expect(api.getViewManager().setViewWithMergedContext).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,13 +3,10 @@ import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
||||
import { Capabilities } from '../../../../src/camera-manager/capabilities';
|
||||
import { PTZAction } from '../../../../src/card-controller/actions/actions/ptz';
|
||||
import { PTZMovementType } from '../../../../src/types';
|
||||
import {
|
||||
createCameraConfig,
|
||||
createCameraManager,
|
||||
createCardAPI,
|
||||
createStore,
|
||||
createView,
|
||||
} from '../../../test-utils';
|
||||
import { createCameraManager, createStore } from '../../../camera-manager/test-utils';
|
||||
import { createCameraConfig } from '../../../config/test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { createView } from '../../../view/test-utils';
|
||||
|
||||
describe('should handle ptz action', () => {
|
||||
it('should execute simple action', async () => {
|
||||
@@ -39,7 +36,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'left',
|
||||
{
|
||||
@@ -74,7 +71,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'left',
|
||||
{
|
||||
@@ -121,7 +118,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office_hd',
|
||||
'left',
|
||||
{
|
||||
@@ -149,7 +146,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).not.toBeCalled();
|
||||
expect(api.getCameraManager().executePTZAction).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -168,7 +165,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).not.toBeCalled();
|
||||
expect(api.getCameraManager().executePTZAction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('when there is no action', () => {
|
||||
@@ -195,7 +192,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'preset',
|
||||
{
|
||||
@@ -244,7 +241,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'preset',
|
||||
{
|
||||
@@ -290,7 +287,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'preset',
|
||||
{
|
||||
@@ -328,7 +325,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).not.toBeCalled();
|
||||
expect(api.getCameraManager().executePTZAction).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -361,7 +358,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'preset',
|
||||
{
|
||||
@@ -400,7 +397,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'left',
|
||||
{
|
||||
@@ -447,7 +444,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'left',
|
||||
{
|
||||
@@ -456,7 +453,7 @@ describe('should handle ptz action', () => {
|
||||
);
|
||||
|
||||
vi.runOnlyPendingTimers();
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'left',
|
||||
{
|
||||
@@ -491,12 +488,12 @@ describe('should handle ptz action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(1);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(1);
|
||||
|
||||
action.stop();
|
||||
vi.runOnlyPendingTimers();
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(1);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -535,20 +532,20 @@ describe('should handle ptz action', () => {
|
||||
});
|
||||
await startAction.execute(api);
|
||||
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledWith(
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledWith(
|
||||
'camera.office',
|
||||
'left',
|
||||
{
|
||||
phase: undefined,
|
||||
},
|
||||
);
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(1);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(1);
|
||||
|
||||
await vi.runOnlyPendingTimersAsync();
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(2);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(2);
|
||||
|
||||
await vi.runOnlyPendingTimersAsync();
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(3);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(3);
|
||||
|
||||
const stopAction = new PTZAction(context, {
|
||||
action: 'fire-dom-event',
|
||||
@@ -560,7 +557,7 @@ describe('should handle ptz action', () => {
|
||||
|
||||
// There should be no additional calls.
|
||||
await vi.runOnlyPendingTimersAsync();
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(3);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it('should honor stop', async () => {
|
||||
@@ -590,10 +587,10 @@ describe('should handle ptz action', () => {
|
||||
});
|
||||
|
||||
await action.execute(api);
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(1);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(1);
|
||||
|
||||
await vi.runOnlyPendingTimersAsync();
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(2);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(2);
|
||||
|
||||
// Emulate the stop being called while the action is running, but before
|
||||
// the *next* timer is scheduled.
|
||||
@@ -604,7 +601,7 @@ describe('should handle ptz action', () => {
|
||||
vi.mocked(cameraManager.executePTZAction).mockReturnValueOnce(promise);
|
||||
|
||||
await vi.runOnlyPendingTimersAsync();
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(3);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(3);
|
||||
|
||||
action.stop();
|
||||
|
||||
@@ -612,7 +609,7 @@ describe('should handle ptz action', () => {
|
||||
await vi.runOnlyPendingTimersAsync();
|
||||
|
||||
// There should be no additional calls.
|
||||
expect(api.getCameraManager().executePTZAction).toBeCalledTimes(3);
|
||||
expect(api.getCameraManager().executePTZAction).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,6 +25,6 @@ describe('should handle reload action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(location.reload).toBeCalledTimes(1);
|
||||
expect(location.reload).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ describe('should handle screenshot action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(downloadURL).toBeCalledWith('screenshot-url', 'screenshot.jpg');
|
||||
expect(downloadURL).toHaveBeenCalledWith('screenshot-url', 'screenshot.jpg');
|
||||
});
|
||||
|
||||
it('should handle screenshot action without screenshot URL', async () => {
|
||||
@@ -58,6 +58,6 @@ describe('should handle screenshot action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(downloadURL).not.toBeCalled();
|
||||
expect(downloadURL).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,8 @@ import { describe, expect, it, vi } from 'vitest';
|
||||
import { SetReviewAction } from '../../../../src/card-controller/actions/actions/set-review';
|
||||
import { ViewMediaType } from '../../../../src/view/item';
|
||||
import { QueryResults } from '../../../../src/view/query-results';
|
||||
import { createCardAPI, createView, TestViewMedia } from '../../../test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { createView, TestViewMedia } from '../../../view/test-utils';
|
||||
|
||||
describe('SetReviewAction', () => {
|
||||
it('should toggle item reviewed state', async () => {
|
||||
@@ -27,13 +28,13 @@ describe('SetReviewAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().reviewMedia).toBeCalledWith(item, true);
|
||||
expect(api.getViewItemManager().reviewMedia).toHaveBeenCalledWith(item, true);
|
||||
|
||||
// toggleReviewed mutates the item in-place
|
||||
expect(item.isReviewed()).toBe(true);
|
||||
|
||||
// Verify UI update is triggered to refresh menu icon
|
||||
expect(api.getCardElementManager().update).toBeCalled();
|
||||
expect(api.getCardElementManager().update).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set reviewed to true when requested and currently false', async () => {
|
||||
@@ -58,7 +59,7 @@ describe('SetReviewAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().reviewMedia).toBeCalledWith(item, true);
|
||||
expect(api.getViewItemManager().reviewMedia).toHaveBeenCalledWith(item, true);
|
||||
expect(item.isReviewed()).toBe(true);
|
||||
});
|
||||
|
||||
@@ -84,7 +85,7 @@ describe('SetReviewAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().reviewMedia).not.toBeCalled();
|
||||
expect(api.getViewItemManager().reviewMedia).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not act on non-review media', async () => {
|
||||
@@ -108,7 +109,7 @@ describe('SetReviewAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().reviewMedia).not.toBeCalled();
|
||||
expect(api.getViewItemManager().reviewMedia).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not act without a view', async () => {
|
||||
@@ -125,7 +126,7 @@ describe('SetReviewAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().reviewMedia).not.toBeCalled();
|
||||
expect(api.getViewItemManager().reviewMedia).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not act without query results', async () => {
|
||||
@@ -143,7 +144,7 @@ describe('SetReviewAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().reviewMedia).not.toBeCalled();
|
||||
expect(api.getViewItemManager().reviewMedia).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not update UI if review action fails', async () => {
|
||||
@@ -170,7 +171,7 @@ describe('SetReviewAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().reviewMedia).toBeCalledWith(item, true);
|
||||
expect(api.getCardElementManager().update).not.toBeCalled();
|
||||
expect(api.getViewItemManager().reviewMedia).toHaveBeenCalledWith(item, true);
|
||||
expect(api.getCardElementManager().update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('ActionSet', () => {
|
||||
|
||||
const consoleSpy = vi.spyOn(global.console, 'info').mockReturnValue(undefined);
|
||||
await set.execute(api);
|
||||
expect(consoleSpy).toBeCalled();
|
||||
expect(consoleSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not execute invalid action', async () => {
|
||||
@@ -39,7 +39,7 @@ describe('ActionSet', () => {
|
||||
|
||||
const consoleSpy = vi.spyOn(global.console, 'info').mockReturnValue(undefined);
|
||||
await set.execute(api);
|
||||
expect(consoleSpy).not.toBeCalled();
|
||||
expect(consoleSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should stop execution', async () => {
|
||||
@@ -50,6 +50,6 @@ describe('ActionSet', () => {
|
||||
const consoleSpy = vi.spyOn(global.console, 'info').mockReturnValue(undefined);
|
||||
await set.stop();
|
||||
await set.execute(api);
|
||||
expect(consoleSpy).not.toBeCalled();
|
||||
expect(consoleSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,5 +22,5 @@ it('should handle sleep action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(sleep).toBeCalledWith(5.2);
|
||||
expect(sleep).toHaveBeenCalledWith(5.2);
|
||||
});
|
||||
|
||||
@@ -17,7 +17,9 @@ describe('should handle status bar action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getStatusBarItemManager().removeAllDynamicStatusBarItems).toBeCalled();
|
||||
expect(
|
||||
api.getStatusBarItemManager().removeAllDynamicStatusBarItems,
|
||||
).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('add', async () => {
|
||||
@@ -39,7 +41,9 @@ describe('should handle status bar action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getStatusBarItemManager().addDynamicStatusBarItem).toBeCalledWith(item);
|
||||
expect(api.getStatusBarItemManager().addDynamicStatusBarItem).toHaveBeenCalledWith(
|
||||
item,
|
||||
);
|
||||
});
|
||||
|
||||
it('remove', async () => {
|
||||
@@ -61,8 +65,8 @@ describe('should handle status bar action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getStatusBarItemManager().removeDynamicStatusBarItem).toBeCalledWith(
|
||||
item,
|
||||
);
|
||||
expect(
|
||||
api.getStatusBarItemManager().removeDynamicStatusBarItem,
|
||||
).toHaveBeenCalledWith(item);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,8 @@ import { SubstreamOffAction } from '../../../../src/card-controller/actions/acti
|
||||
import { applyViewModifiers } from '../../../../src/card-controller/view/modifiers';
|
||||
import { createSubstreamOffAction } from '../../../../src/utils/action';
|
||||
import type { View } from '../../../../src/view/view';
|
||||
import { createCardAPI, createView } from '../../../test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { createView } from '../../../view/test-utils';
|
||||
|
||||
// Runs the off-action for `view` and applies the modifier it produces.
|
||||
const applySubstreamOff = async (
|
||||
|
||||
@@ -7,13 +7,13 @@ import { createSubstreamOnAction } from '../../../../src/utils/action';
|
||||
import { getStreamCameraID } from '../../../../src/view/substream';
|
||||
import type { View } from '../../../../src/view/view';
|
||||
import {
|
||||
createCameraConfig,
|
||||
createCameraManager,
|
||||
createCapabilities,
|
||||
createCardAPI,
|
||||
createStore,
|
||||
createView,
|
||||
} from '../../../test-utils';
|
||||
} from '../../../camera-manager/test-utils';
|
||||
import { createCameraConfig } from '../../../config/test-utils';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { createView } from '../../../view/test-utils';
|
||||
|
||||
// A store where `camera.office` has one substream dependency, `camera.kitchen`.
|
||||
const createStoreWithSubstreams = (): CameraManagerStore =>
|
||||
@@ -181,6 +181,6 @@ describe('SubstreamOnAction', () => {
|
||||
|
||||
await new SubstreamOnAction({}, createSubstreamOnAction()).execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParameters).not.toBeCalled();
|
||||
expect(api.getViewManager().setViewByParameters).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,9 +46,13 @@ describe('ToggleAction', () => {
|
||||
const action = new ToggleAction({}, { action: 'toggle' }, { entity: entityID });
|
||||
await action.execute(api);
|
||||
|
||||
expect(hass.callService).toBeCalledWith(expectedServiceDomain, expectedService, {
|
||||
entity_id: entityID,
|
||||
});
|
||||
expect(hass.callService).toHaveBeenCalledWith(
|
||||
expectedServiceDomain,
|
||||
expectedService,
|
||||
{
|
||||
entity_id: entityID,
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -62,7 +66,7 @@ describe('ToggleAction', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(hass.callService).not.toBeCalled();
|
||||
expect(hass.callService).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should do nothing without an entity state', async () => {
|
||||
@@ -77,6 +81,6 @@ describe('ToggleAction', () => {
|
||||
);
|
||||
await action.execute(api);
|
||||
|
||||
expect(hass.callService).not.toBeCalled();
|
||||
expect(hass.callService).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,5 +23,5 @@ it('should handle unmute action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(mediaPlayerController.unmute).toBeCalled();
|
||||
expect(mediaPlayerController.unmute).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('should handle view action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledWith(
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
params: {
|
||||
view: viewName,
|
||||
@@ -53,7 +53,7 @@ describe('should handle folder view action', () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledWith(
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
params: {
|
||||
view: viewName,
|
||||
|
||||
Reference in New Issue
Block a user