shlink-web-client/test/common/services/ImageDownloader.test.ts

25 lines
834 B
TypeScript
Raw Normal View History

import { fromPartial } from '@total-typescript/shoehorn';
2023-02-18 12:40:37 +03:00
import type { HttpClient } from '../../../src/common/services/HttpClient';
2023-02-18 13:11:01 +03:00
import { ImageDownloader } from '../../../src/common/services/ImageDownloader';
2022-07-16 11:52:45 +03:00
import { windowMock } from '../../__mocks__/Window.mock';
2021-09-19 11:57:36 +03:00
describe('ImageDownloader', () => {
2023-05-27 12:57:26 +03:00
const fetchBlob = vi.fn();
const httpClient = fromPartial<HttpClient>({ fetchBlob });
2021-09-19 11:57:36 +03:00
let imageDownloader: ImageDownloader;
beforeEach(() => {
(global as any).URL = { createObjectURL: () => '' };
imageDownloader = new ImageDownloader(httpClient, windowMock);
2021-09-19 11:57:36 +03:00
});
it('calls URL with response type blob', async () => {
fetchBlob.mockResolvedValue(new Blob());
2021-09-19 11:57:36 +03:00
await imageDownloader.saveImage('/foo/bar.png', 'my-image.png');
expect(fetchBlob).toHaveBeenCalledWith('/foo/bar.png');
2021-09-19 11:57:36 +03:00
});
});