2021-09-19 11:57:36 +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', () => {
|
2022-11-15 13:41:05 +03:00
|
|
|
const fetch = jest.fn();
|
2021-09-19 11:57:36 +03:00
|
|
|
let imageDownloader: ImageDownloader;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
(global as any).URL = { createObjectURL: () => '' };
|
|
|
|
|
2022-11-15 13:41:05 +03:00
|
|
|
imageDownloader = new ImageDownloader(fetch, windowMock);
|
2021-09-19 11:57:36 +03:00
|
|
|
});
|
|
|
|
|
2021-09-20 23:00:34 +03:00
|
|
|
it('calls URL with response type blob', async () => {
|
2022-11-15 13:41:05 +03:00
|
|
|
fetch.mockResolvedValue({ blob: () => new Blob() });
|
2021-09-19 11:57:36 +03:00
|
|
|
|
|
|
|
await imageDownloader.saveImage('/foo/bar.png', 'my-image.png');
|
|
|
|
|
2022-11-15 13:41:05 +03:00
|
|
|
expect(fetch).toHaveBeenCalledWith('/foo/bar.png');
|
2021-09-19 11:57:36 +03:00
|
|
|
});
|
|
|
|
});
|