@@ -1,86 +0,0 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { FoldersViewAction } from '../../../../src/card-controller/actions/actions/folders-view';
|
||||
import { FolderQuery } from '../../../../src/card-controller/folders/types';
|
||||
import { FolderViewQuery } from '../../../../src/view/query';
|
||||
import { createCardAPI, createFolder } from '../../../test-utils';
|
||||
|
||||
describe('should handle folder action', async () => {
|
||||
it('should handle folder action successfully', async () => {
|
||||
const api = createCardAPI();
|
||||
const action = new FoldersViewAction(
|
||||
{},
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'folder',
|
||||
},
|
||||
);
|
||||
|
||||
const folder = createFolder();
|
||||
vi.mocked(api.getFoldersManager().getFolder).mockReturnValue(folder);
|
||||
|
||||
const query: FolderQuery = {
|
||||
folder,
|
||||
path: [{ ha: { id: 'path' } }],
|
||||
};
|
||||
vi.mocked(api.getFoldersManager().generateDefaultFolderQuery).mockReturnValue(query);
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(
|
||||
api.getViewManager().setViewByParametersWithExistingQuery,
|
||||
).toHaveBeenCalledWith({
|
||||
params: {
|
||||
view: 'folder',
|
||||
query: expect.any(FolderViewQuery),
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
vi
|
||||
.mocked(api.getViewManager().setViewByParametersWithExistingQuery)
|
||||
.mock.calls[0][0]?.params?.query?.getQuery(),
|
||||
).toBe(query);
|
||||
});
|
||||
|
||||
it('should do nothing with non-existent folder', async () => {
|
||||
const api = createCardAPI();
|
||||
const action = new FoldersViewAction(
|
||||
{},
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'folder',
|
||||
folder: 'NON-EXISTENT-FOLDER',
|
||||
},
|
||||
);
|
||||
|
||||
vi.mocked(api.getFoldersManager().getFolder).mockReturnValue(null);
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(
|
||||
api.getViewManager().setViewByParametersWithExistingQuery,
|
||||
).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should do nothing with non-existent default query', async () => {
|
||||
const api = createCardAPI();
|
||||
const action = new FoldersViewAction(
|
||||
{},
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'folder',
|
||||
},
|
||||
);
|
||||
|
||||
const folder = createFolder();
|
||||
vi.mocked(api.getFoldersManager().getFolder).mockReturnValue(folder);
|
||||
|
||||
vi.mocked(api.getFoldersManager().generateDefaultFolderQuery).mockReturnValue(null);
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(
|
||||
api.getViewManager().setViewByParametersWithExistingQuery,
|
||||
).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -22,7 +22,7 @@ describe('should handle status bar action', () => {
|
||||
it('add', async () => {
|
||||
const api = createCardAPI();
|
||||
const item = {
|
||||
type: 'custom:advanced-camera-card-status-bar-string',
|
||||
type: 'custom:advanced-camera-card-status-bar-string' as const,
|
||||
string: 'Item',
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('should handle status bar action', () => {
|
||||
it('remove', async () => {
|
||||
const api = createCardAPI();
|
||||
const item = {
|
||||
type: 'custom:advanced-camera-card-status-bar-string',
|
||||
type: 'custom:advanced-camera-card-status-bar-string' as const,
|
||||
string: 'Item',
|
||||
};
|
||||
|
||||
|
||||
@@ -36,3 +36,31 @@ describe('should handle view action', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle folder view action', () => {
|
||||
it.each([['folder' as const], ['folders' as const]])('%s', async (viewName) => {
|
||||
const api = createCardAPI();
|
||||
|
||||
const action = new ViewAction(
|
||||
{},
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: viewName,
|
||||
folder: 'folder',
|
||||
},
|
||||
);
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewManager().setViewByParametersWithNewQuery).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
params: {
|
||||
view: viewName,
|
||||
},
|
||||
queryExecutorOptions: {
|
||||
folder: 'folder',
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,7 +7,6 @@ import { DefaultAction } from '../../../src/card-controller/actions/actions/defa
|
||||
import { DisplayModeSelectAction } from '../../../src/card-controller/actions/actions/display-mode-select';
|
||||
import { DownloadAction } from '../../../src/card-controller/actions/actions/download';
|
||||
import { ExpandAction } from '../../../src/card-controller/actions/actions/expand';
|
||||
import { FoldersViewAction } from '../../../src/card-controller/actions/actions/folders-view';
|
||||
import { FullscreenAction } from '../../../src/card-controller/actions/actions/fullscreen';
|
||||
import { InternalCallbackAction } from '../../../src/card-controller/actions/actions/internal-callback';
|
||||
import { LogAction } from '../../../src/card-controller/actions/actions/log';
|
||||
@@ -97,6 +96,8 @@ describe('ActionFactory', () => {
|
||||
],
|
||||
[{ advanced_camera_card_action: 'download' as const }, DownloadAction],
|
||||
[{ advanced_camera_card_action: 'expand' as const }, ExpandAction],
|
||||
[{ advanced_camera_card_action: 'folder' as const }, ViewAction],
|
||||
[{ advanced_camera_card_action: 'folders' as const }, ViewAction],
|
||||
[{ advanced_camera_card_action: 'fullscreen' as const }, FullscreenAction],
|
||||
[{ advanced_camera_card_action: 'image' as const }, ViewAction],
|
||||
[
|
||||
@@ -185,8 +186,6 @@ describe('ActionFactory', () => {
|
||||
},
|
||||
InternalCallbackAction,
|
||||
],
|
||||
[{ advanced_camera_card_action: 'folder' as const }, FoldersViewAction],
|
||||
[{ advanced_camera_card_action: 'folders' as const }, FoldersViewAction],
|
||||
])(
|
||||
'advanced_camera_card_action: $advanced_camera_card_action',
|
||||
(action: Partial<ActionConfig>, classObject: object) => {
|
||||
|
||||
Reference in New Issue
Block a user