@@ -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',
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user