electron-97: completed point 1 in refactoring

This commit is contained in:
Vishwas Shashidhar
2017-08-23 22:08:33 +05:30
parent 5d6a3670a2
commit 7ab0f75e2e
13 changed files with 7261 additions and 87 deletions
+21 -21
View File
@@ -1,21 +1,21 @@
const downloadManager = require('../js/downloadManager/downloadManager');
const downloadManager = require('../js/downloadManager');
const electron = require('./__mocks__/electron');
describe('download manager', function () {
describe('Download Manager to create DOM once download is initiated', function () {
beforeEach(function () {
describe('download manager', function() {
describe('Download Manager to create DOM once download is initiated', function() {
beforeEach(function() {
global.document.body.innerHTML =
'<div id="download-main">' +
'</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 });
expect(document.getElementsByClassName('text-cutoff')[0].innerHTML).toBe('test');
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: '67890', fileName: 'test1', total: 200 });
@@ -31,23 +31,23 @@ describe('download manager', function () {
});
describe('Download Manager to initiate footer', function () {
beforeEach(function () {
describe('Download Manager to initiate footer', function() {
beforeEach(function() {
global.document.body.innerHTML =
'<div id="footer" class="hidden">' +
'<div id="download-manager-footer">' +
'<div id="download-main">' +
'</div>' +
'</div>' +
'<div id="download-manager-footer">' +
'<div id="download-main">' +
'</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');
expect(document.getElementById('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');
expect(document.getElementById('footer').classList).not.toContain('hidden');
@@ -59,19 +59,19 @@ describe('download manager', function () {
});
describe('Download Manager to initiate footer', function () {
describe('Download Manager to initiate footer', function() {
beforeEach(function () {
beforeEach(function() {
global.document.body.innerHTML =
'<div id="footer" class="hidden">' +
'<div id="download-manager-footer">' +
'<div id="download-main">' +
'</div>' +
'</div>' +
'<div id="download-manager-footer">' +
'<div id="download-main">' +
'</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');
+5 -6
View File
@@ -1,10 +1,9 @@
const { ScreenSnippet, readResult } = require('../js/screenSnippet/ScreenSnippet.js');
const { ScreenSnippet, readResult } = require('../js/screenSnippet');
const path = require('path');
const fs = require('fs');
const os = require('os');
const { isMac } = require('../js/utils/misc.js')
const { isMac } = require('../js/utils/misc.js');
const snippetBase64 = require('./fixtures/snippet/snippet-base64.js');
@@ -27,7 +26,7 @@ function mockedExecFile(util, args, doneCallback) {
}
function copyTestFile(destFile, done) {
const testfile = path.join(__dirname ,
const testfile = path.join(__dirname,
'fixtures/snippet/ScreenSnippet.jpeg');
let reader = fs.createReadStream(testfile);
@@ -43,7 +42,7 @@ function copyTestFile(destFile, done) {
function createTestFile(done) {
let tmpDir = os.tmpdir();
const testFileName = path.join(tmpDir,
'ScreenSnippet-' + Date.now() + '.jpeg');
'ScreenSnippet-' + Date.now() + '.jpeg');
copyTestFile(testFileName, function() {
done(testFileName)
@@ -132,4 +131,4 @@ describe('Tests for ScreenSnippet', function() {
}
});
}
});
});
+13 -13
View File
@@ -3,29 +3,29 @@ const childProcess = require('child_process');
let activityDetection;
describe('Tests for Activity Detection', function () {
describe('Tests for Activity Detection', function() {
var originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
beforeAll(function (done) {
childProcess.exec(`npm rebuild --target=${process.version} --build-from-source`, function (err) {
activityDetection = require('../js/activityDetection/activityDetection.js');
beforeAll(function(done) {
childProcess.exec(`npm rebuild --target=${process.version} --build-from-source`, function(err) {
activityDetection = require('../js/activityDetection');
activityDetection.setActivityWindow(900000, electron.ipcRenderer);
done();
});
});
beforeEach(function () {
beforeEach(function() {
jest.clearAllMocks()
});
afterAll(function (done) {
afterAll(function(done) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
done();
});
it('should return null', function () {
it('should return null', function() {
activityDetection.setActivityWindow(0, electron.ipcRenderer);
const noData = activityDetection.activityDetection();
@@ -33,17 +33,17 @@ describe('Tests for Activity Detection', function () {
});
it('should send activity event', function () {
it('should send activity event', function() {
const spy = jest.spyOn(activityDetection, 'send');
expect(spy).not.toBeCalled();
activityDetection.send({systemIdleTime: 120000});
expect(spy).toHaveBeenCalledWith({systemIdleTime: 120000});
activityDetection.send({ systemIdleTime: 120000 });
expect(spy).toHaveBeenCalledWith({ systemIdleTime: 120000 });
});
it('should monitor user activity', function () {
it('should monitor user activity', function() {
activityDetection.setActivityWindow(500000, electron.ipcRenderer);
const spy = jest.spyOn(activityDetection, 'monitorUserActivity');
@@ -54,7 +54,7 @@ describe('Tests for Activity Detection', function () {
});
it('should not send activity event as data is undefined', function () {
it('should not send activity event as data is undefined', function() {
const spy = jest.spyOn(activityDetection, 'send');
expect(spy).not.toBeCalled();
@@ -64,4 +64,4 @@ describe('Tests for Activity Detection', function () {
});
});
});