SymphonyElectron/spec/downloadManager.spec.ts
Kiran Niranjan 8adabfebda Typescript (Fix issues and add support for BC) (#617)
* Typescript - Fix Auto launch, first time launch, pick safety checks

* Typescript - Fix basic auth issue

* Typescript - Add demo content for desktop capturer

* Typescript - Add BC support for Desktop capturer

* Typescript - Update code documentation

* Typescript - Add whitelisting logic and certificate verifying proxy

* Typescript - Fix console log and safety checks

* Typescript - Add screens to display loading failure and bugs fixes

* Typescript - Update unit test case for loading screen and app menu

* Typescript - Rename isCustomTitleBarAndWindowOS to isCustomTitleBar

* Typescript - Downloader Manager - Fix flashing issue and add demo
2019-04-02 10:58:41 +05:30

124 lines
4.5 KiB
TypeScript

import { shallow, ShallowWrapper } from 'enzyme';
import * as React from 'react';
import DownloadManager from '../src/renderer/components/download-manager';
describe('download manager', () => {
it('should render correctly', () => {
const wrapper = shallow(React.createElement(DownloadManager));
expect(wrapper).toMatchSnapshot();
});
it('should call `close` correctly', () => {
const spy: jest.SpyInstance = jest.spyOn(DownloadManager.prototype, 'setState');
const wrapper: ShallowWrapper = shallow(React.createElement(DownloadManager));
wrapper.find('#close-download-bar').simulate('click');
expect(spy).toBeCalledWith({ items: [], showMainComponent: true });
});
it('should call `injectItem` correctly', () => {
const { ipcRenderer } = require('./__mocks__/electron');
const spy: jest.SpyInstance = jest.spyOn(DownloadManager.prototype, 'setState');
const objectDownloadCompleted: object = {
_id: 1,
fileName: 'test.png',
savedPath: 'path://test',
total: 1,
flashing: true,
};
shallow(React.createElement(DownloadManager));
ipcRenderer.send('downloadCompleted', objectDownloadCompleted);
expect(spy).toBeCalledWith({
items: [{
_id: 1,
fileName: 'test.png',
savedPath: 'path://test',
total: 1,
flashing: true,
}], showMainComponent: true,
});
});
describe('download element ready', () => {
let wrapper: ShallowWrapper;
beforeEach(() => {
wrapper = shallow(React.createElement(DownloadManager));
wrapper.setState({
items: [
{
_id: 1,
fileName: 'test.png',
savedPath: 'path://test',
total: 1,
flashing: true,
}],
});
});
it('should exist `download-element` class when there are items', () => {
expect(wrapper.find('.download-element')).toHaveLength(1);
});
it('should call `onOpenFile` correctly', () => {
const { ipcRenderer } = require('./__mocks__/electron');
const sendEventLabel: string = 'send';
const spy: jest.SpyInstance = jest.spyOn(ipcRenderer, sendEventLabel);
wrapper.find('#download-open').simulate('click');
expect(spy).toBeCalledWith('symphony-api', {
cmd: 'download-manager-action',
path: 'path://test',
type: 'open',
});
});
it('should call `showInFinder` correctly', () => {
const { ipcRenderer } = require('./__mocks__/electron');
const sendEventLabel: string = 'send';
const spy: jest.SpyInstance = jest.spyOn(ipcRenderer, sendEventLabel);
wrapper.find('#download-show-in-folder').simulate('click');
expect(spy).toBeCalledWith('symphony-api', {
cmd: 'download-manager-action',
path: 'path://test',
type: 'show',
});
});
});
describe('download completed event', () => {
const { ipcRenderer } = require('./__mocks__/electron');
const downloadCompletedLabelEvent: string = 'downloadCompleted';
const onLabelEvent: string = 'on';
const removeListenerLabelEvent: string = 'removeListener';
it('should call the `downloadCompleted event when component is mounted', () => {
const spy: jest.SpyInstance = jest.spyOn(ipcRenderer, onLabelEvent);
shallow(React.createElement(DownloadManager));
expect(spy).toBeCalledWith(downloadCompletedLabelEvent, expect.any(Function));
});
it('should remove listen `downloadCompleted` when component is unmounted', () => {
const spyMount: jest.SpyInstance = jest.spyOn(ipcRenderer, onLabelEvent);
const spyUnmount: jest.SpyInstance = jest.spyOn(ipcRenderer, removeListenerLabelEvent);
const wrapper: ShallowWrapper = shallow(React.createElement(DownloadManager));
expect(spyMount).toBeCalledWith(downloadCompletedLabelEvent, expect.any(Function));
wrapper.unmount();
expect(spyUnmount).toBeCalledWith(downloadCompletedLabelEvent, expect.any(Function));
});
});
});