salix-front/test/vitest/__tests__/composables/downloadFile.spec.js

26 lines
773 B
JavaScript
Raw Normal View History

2023-10-31 07:56:51 +00:00
import { vi, describe, expect, it } from 'vitest';
import { axios } from 'app/test/vitest/helper';
import { downloadFile } from 'src/composables/downloadFile';
import { useSession } from 'src/composables/useSession';
const session = useSession();
const token = session.getToken();
describe('downloadFile', () => {
it('should open a new window to download the file', async () => {
const url = 'http://localhost:9000';
vi.spyOn(axios, 'get').mockResolvedValueOnce({ data: url });
const mockWindowOpen = vi.spyOn(window, 'open');
await downloadFile(1);
expect(mockWindowOpen).toHaveBeenCalledWith(
`${url}/api/dms/1/downloadFile?access_token=${token}`
);
mockWindowOpen.mockRestore();
});
});