mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-11-21 16:38:41 -06:00
8f518e3936
* SDA-1995: add download handler functionality for Mana Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1995: add unit tests Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1995: fix unit tests on Windows Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> * SDA-1955: address PR comments Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com>
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
jest.mock('electron-log');
|
|
|
|
jest.mock('../src/app/window-handler', () => {
|
|
return {
|
|
windowHandler: {
|
|
setIsAutoReload: jest.fn(() => true),
|
|
},
|
|
};
|
|
});
|
|
|
|
jest.mock('../src/app/window-utils', () => {
|
|
return {
|
|
windowExists: jest.fn(() => true),
|
|
};
|
|
});
|
|
|
|
describe('download handler', () => {
|
|
let downloadHandlerInstance;
|
|
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
// I did it for reset module imported between tests
|
|
const { downloadHandler } = require('../src/app/download-handler');
|
|
downloadHandlerInstance = downloadHandler;
|
|
});
|
|
|
|
afterAll((done) => {
|
|
done();
|
|
});
|
|
|
|
it('should call `sendDownloadCompleted` when download succeeds', () => {
|
|
const spy: jest.SpyInstance = jest.spyOn(downloadHandlerInstance, 'sendDownloadCompleted')
|
|
.mockImplementation(() => jest.fn());
|
|
|
|
const data: any = {
|
|
_id: '121312-123912321-1231231',
|
|
savedPath: '/abc/def/123.txt',
|
|
total: '1234556',
|
|
fileName: 'Test.txt',
|
|
};
|
|
|
|
downloadHandlerInstance.onDownloadSuccess(data);
|
|
expect(spy).toBeCalled();
|
|
});
|
|
|
|
it('should call `sendDownloadFailed` when download fails', () => {
|
|
const spy: jest.SpyInstance = jest.spyOn(downloadHandlerInstance, 'sendDownloadFailed')
|
|
.mockImplementation(() => jest.fn());
|
|
|
|
downloadHandlerInstance.onDownloadFailed();
|
|
expect(spy).toBeCalled();
|
|
});
|
|
|
|
});
|