@@ -1,9 +1,17 @@
|
||||
import { expect, it } from 'vitest';
|
||||
import { expect, it, vi } from 'vitest';
|
||||
import { DownloadAction } from '../../../../src/card-controller/actions/actions/download';
|
||||
import { createCardAPI } from '../../../test-utils';
|
||||
import { QueryResults } from '../../../../src/view/query-results';
|
||||
import { createCardAPI, createView, TestViewMedia } from '../../../test-utils';
|
||||
|
||||
it('should handle download action', async () => {
|
||||
it('should handle download action with selected media', async () => {
|
||||
const api = createCardAPI();
|
||||
const selectedMedia = new TestViewMedia();
|
||||
vi.mocked(api.getViewManager().getView).mockReturnValue(
|
||||
createView({
|
||||
queryResults: new QueryResults({ results: [selectedMedia], selectedIndex: 0 }),
|
||||
}),
|
||||
);
|
||||
|
||||
const action = new DownloadAction(
|
||||
{},
|
||||
{
|
||||
@@ -14,5 +22,22 @@ it('should handle download action', async () => {
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getDownloadManager().downloadViewerMedia).toBeCalled();
|
||||
expect(api.getViewItemManager().download).toBeCalledWith(selectedMedia);
|
||||
});
|
||||
|
||||
it('should handle download action without selected media', async () => {
|
||||
const api = createCardAPI();
|
||||
vi.mocked(api.getViewManager().getView).mockReturnValue(createView());
|
||||
|
||||
const action = new DownloadAction(
|
||||
{},
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'download',
|
||||
},
|
||||
);
|
||||
|
||||
await action.execute(api);
|
||||
|
||||
expect(api.getViewItemManager().download).not.toBeCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user