Merge pull request #148 from VikasShashidhar/electron-94

electron-94: fixed issues related to download manager tests
This commit is contained in:
Vikas Shashidhar 2017-07-03 15:41:12 +05:30 committed by GitHub
commit 2708754e8c
2 changed files with 24 additions and 34 deletions

View File

@ -195,7 +195,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
webContents.send('downloadProgress'); webContents.send('downloadProgress');
// Send file path when download is complete // Send file path when download is complete
item.once('done', (event, state) => { item.once('done', (e, state) => {
if (state === 'completed') { if (state === 'completed') {
let data = { let data = {
_id: getGuid(), _id: getGuid(),

View File

@ -1,73 +1,59 @@
const downloadManager = require('../js/downloadManager/downloadManager'); const downloadManager = require('../js/downloadManager/downloadManager');
const electron = require('./__mocks__/electron'); const electron = require('./__mocks__/electron');
const $ = require('jquery');
describe('download manager', function() {
describe('download manager', function () {
describe('Download Manager to create DOM once download is initiated', function () { describe('Download Manager to create DOM once download is initiated', function () {
beforeEach(function () { beforeEach(function () {
global.document.body.innerHTML = global.document.body.innerHTML =
'<div id="download-main">' + '<div id="download-main">' +
'</div>'; '</div>';
}); });
it('should inject download bar element into DOM once download is initiated', function() { it('should inject download bar element into DOM once download is initiated', function () {
electron.ipcRenderer.send('downloadCompleted', { _id: '12345', fileName: 'test', total: 100 });
electron.ipcRenderer.send('downloadCompleted', {_id: '12345', fileName: 'test', total: 100});
expect(document.getElementsByClassName('text-cutoff')[0].innerHTML).toBe('test'); expect(document.getElementsByClassName('text-cutoff')[0].innerHTML).toBe('test');
expect(document.getElementById('per').innerHTML).toBe('100 Downloaded'); expect(document.getElementById('per').innerHTML).toBe('100 Downloaded');
}); });
it('should inject multiple download items during multiple downloads', function() { it('should inject multiple download items during multiple downloads', function () {
electron.ipcRenderer.send('downloadCompleted', { _id: '12345', fileName: 'test', total: 100 });
electron.ipcRenderer.send('downloadCompleted', {_id: '12345', fileName: 'test', total: 100}); electron.ipcRenderer.send('downloadCompleted', { _id: '67890', fileName: 'test1', total: 200 });
electron.ipcRenderer.send('downloadCompleted', {_id: '67890', fileName: 'test1', total: 200});
let fileNames = document.getElementsByClassName('text-cutoff'); let fileNames = document.getElementsByClassName('text-cutoff');
expect(fileNames[0].innerHTML).toBe('test1'); expect(fileNames[0].innerHTML).toBe('test1');
expect(fileNames[1].innerHTML).toBe('test'); expect(fileNames[1].innerHTML).toBe('test');
expect(document.getElementById('per').innerHTML).toBe('100 Downloaded'); expect(document.getElementById('per').innerHTML).toBe('100 Downloaded');
let downloadElements = document.getElementsByClassName('download-element'); let downloadElements = document.getElementsByClassName('download-element');
expect(downloadElements[0].id).toBe('67890'); expect(downloadElements[0].id).toBe('67890');
expect(downloadElements[1].id).toBe('12345'); expect(downloadElements[1].id).toBe('12345');
}); });
}); });
describe('Download Manager to initiate footer', function () { describe('Download Manager to initiate footer', function () {
beforeEach(function () { beforeEach(function () {
global.document.body.innerHTML = global.document.body.innerHTML =
'<div id="download-manager-footer" class="hidden">' + '<div id="footer" class="hidden">' +
'<div id="download-main">' + '<div id="download-manager-footer">' +
'<div id="download-main">' +
'</div>' +
'</div>' + '</div>' +
'</div>'; '</div>';
}); });
it('should inject dom element once download is completed', function() { it('should inject dom element once download is completed', function () {
electron.ipcRenderer.send('downloadProgress'); electron.ipcRenderer.send('downloadProgress');
expect(document.getElementById('footer').classList).not.toContain('hidden');
expect(document.getElementById('download-manager-footer').classList).not.toContain('hidden');
}); });
it('should remove the download bar and clear up the download items', function() { it('should remove the download bar and clear up the download items', function () {
electron.ipcRenderer.send('downloadProgress'); electron.ipcRenderer.send('downloadProgress');
expect(document.getElementById('footer').classList).not.toContain('hidden');
console.log(document.getElementById('download-manager-footer').classList); document.getElementById('close-download-bar').click();
expect(document.getElementById('download-manager-footer').classList).not.toContain('hidden'); expect(document.getElementById('footer').classList).toContain('hidden');
$('#close-download-bar').click();
expect(document.getElementById('download-manager-footer').classList).toContain('hidden');
}); });
@ -77,16 +63,20 @@ describe('download manager', function() {
beforeEach(function () { beforeEach(function () {
global.document.body.innerHTML = global.document.body.innerHTML =
'<div id="download-manager-footer" class="hidden">' + '<div id="footer" class="hidden">' +
'<div id="download-manager-footer">' +
'<div id="download-main">' +
'</div>' +
'</div>' +
'</div>'; '</div>';
}); });
it('should inject ul element if not found', function() { it('should inject ul element if not found', function () {
electron.ipcRenderer.send('downloadProgress'); electron.ipcRenderer.send('downloadProgress');
expect(document.getElementById('download-main')).not.toBeNull(); expect(document.getElementById('download-main')).not.toBeNull();
expect(document.getElementById('download-manager-footer').classList).not.toContain('hidden'); expect(document.getElementById('footer').classList).not.toContain('hidden');
}); });