Files
cloudbeaver/webapp/packages/core-utils/src/download.test.ts
T
sergeyteleshevandmr-anton-t 78daa21c87 [CB] update frontend deps (#3973)
* dbeaver/pro#7748 updates yarn.locks

* fixes incorrect types

* updates helper libs

* updates vitest + fixes test cases incorrect mocks

* runs tests sequentially with document and windows objects to prevent mock collisions

* Revert "runs tests sequentially with document and windows objects to prevent mock collisions"

This reverts commit f871837df3.

* skips download test

* removes export from resetDeprecatedSettings

* updates react-data-grid to beta-59 and react to 19.2

* updates storybook

* pr fixes

* updates yarn lock

* removes skip for download test

* cleanups download ts with empty body html

* updates vitest for core-connections

* updates yarn.lock

* linter fix + mocks once

* fixes hotkeys

* reverts version of react-hotkeys-hook library

---------

Co-authored-by: mr-anton-t <42037741+mr-anton-t@users.noreply.github.com>
2025-12-18 12:49:11 +01:00

53 lines
1.7 KiB
TypeScript

/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import { download } from './download.js';
describe('download', () => {
beforeEach(() => {
// Clean up any existing links from previous tests
document.body.innerHTML = '';
});
it('should not create links after download', () => {
const blob = new Blob(['test'], { type: 'text/plain' });
const linksBefore = document.querySelectorAll('a');
expect(linksBefore.length).toBe(0);
download(blob, 'test.txt');
const linksAfter = document.querySelectorAll('a');
expect(linksAfter.length).toBe(0);
});
it('should create a link with url and click it to download file', () => {
const element = document.createElement('a');
const createElementSpy = vitest.spyOn(document, 'createElement').mockImplementation(() => element);
const clickSpy = vitest.spyOn(element, 'click');
const createObjectURLSpy = vitest.spyOn(URL, 'createObjectURL');
const blob = new Blob(['test'], { type: 'text/plain' });
download(blob, 'test.txt');
expect(createElementSpy).toHaveBeenCalledWith('a');
expect(createElementSpy).toHaveBeenCalledTimes(1);
expect(clickSpy).toHaveBeenCalledWith();
expect(clickSpy).toHaveBeenCalledTimes(1);
expect(createObjectURLSpy).toHaveBeenCalledWith(blob);
expect(createObjectURLSpy).toHaveBeenCalledTimes(1);
createElementSpy.mockRestore();
clickSpy.mockRestore();
createObjectURLSpy.mockRestore();
});
});