mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-28 09:51:06 -06:00
electron-97: completed point 1 in refactoring
This commit is contained in:
parent
5d6a3670a2
commit
7ab0f75e2e
@ -16,7 +16,7 @@ let throttleActivity;
|
|||||||
function activityDetection() {
|
function activityDetection() {
|
||||||
// Get system idle status and idle time from PaulCBetts package
|
// Get system idle status and idle time from PaulCBetts package
|
||||||
if (systemIdleTime.getIdleTime() < maxIdleTime) {
|
if (systemIdleTime.getIdleTime() < maxIdleTime) {
|
||||||
return {isUserIdle: false, systemIdleTime: systemIdleTime.getIdleTime()};
|
return { isUserIdle: false, systemIdleTime: systemIdleTime.getIdleTime() };
|
||||||
}
|
}
|
||||||
|
|
||||||
// If idle for more than 4 mins, monitor system idle status every second
|
// If idle for more than 4 mins, monitor system idle status every second
|
||||||
@ -65,7 +65,7 @@ function monitorUserActivity() {
|
|||||||
function sendActivity() {
|
function sendActivity() {
|
||||||
let systemActivity = activityDetection();
|
let systemActivity = activityDetection();
|
||||||
if (systemActivity && !systemActivity.isUserIdle && systemActivity.systemIdleTime) {
|
if (systemActivity && !systemActivity.isUserIdle && systemActivity.systemIdleTime) {
|
||||||
send({systemIdleTime: systemActivity.systemIdleTime});
|
send({ systemIdleTime: systemActivity.systemIdleTime });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,4 +97,4 @@ module.exports = {
|
|||||||
activityDetection: activityDetection,
|
activityDetection: activityDetection,
|
||||||
monitorUserActivity: monitorUserActivity, // Exporting this for unit test
|
monitorUserActivity: monitorUserActivity, // Exporting this for unit test
|
||||||
initiateActivityDetection: initiateActivityDetection
|
initiateActivityDetection: initiateActivityDetection
|
||||||
};
|
};
|
@ -46,9 +46,9 @@ function getSources(options, callback) {
|
|||||||
id = getNextId();
|
id = getNextId();
|
||||||
ipcRenderer.send('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, updatedOptions.thumbnailSize, id);
|
ipcRenderer.send('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, updatedOptions.thumbnailSize, id);
|
||||||
|
|
||||||
return ipcRenderer.once('ELECTRON_RENDERER_DESKTOP_CAPTURER_RESULT_' + id, function (event, sources) {
|
return ipcRenderer.once('ELECTRON_RENDERER_DESKTOP_CAPTURER_RESULT_' + id, function(event, sources) {
|
||||||
var source;
|
var source;
|
||||||
callback(null, (function () {
|
callback(null, (function() {
|
||||||
var i, len, results
|
var i, len, results
|
||||||
results = [];
|
results = [];
|
||||||
for (i = 0, len = sources.length; i < len; i++) {
|
for (i = 0, len = sources.length; i < len; i++) {
|
||||||
@ -65,4 +65,4 @@ function getSources(options, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getSources;
|
module.exports = getSources;
|
@ -24,7 +24,7 @@ function openFile(id) {
|
|||||||
let fileIndex = local.downloadItems.findIndex((item) => {
|
let fileIndex = local.downloadItems.findIndex((item) => {
|
||||||
return item._id === id
|
return item._id === id
|
||||||
});
|
});
|
||||||
if (fileIndex !== -1){
|
if (fileIndex !== -1) {
|
||||||
let openResponse = remote.shell.openExternal(`file:///${local.downloadItems[fileIndex].savedPath}`);
|
let openResponse = remote.shell.openExternal(`file:///${local.downloadItems[fileIndex].savedPath}`);
|
||||||
if (!openResponse) {
|
if (!openResponse) {
|
||||||
remote.dialog.showErrorBox("File not found", 'The file you are trying to open cannot be found in the specified path.');
|
remote.dialog.showErrorBox("File not found", 'The file you are trying to open cannot be found in the specified path.');
|
||||||
@ -159,7 +159,7 @@ function initiate() {
|
|||||||
|
|
||||||
let ulFind = document.getElementById('download-main');
|
let ulFind = document.getElementById('download-main');
|
||||||
|
|
||||||
if (!ulFind){
|
if (!ulFind) {
|
||||||
let uList = document.createElement('ul');
|
let uList = document.createElement('ul');
|
||||||
uList.id = 'download-main';
|
uList.id = 'download-main';
|
||||||
mainDownloadDiv.appendChild(uList);
|
mainDownloadDiv.appendChild(uList);
|
||||||
@ -167,7 +167,7 @@ function initiate() {
|
|||||||
|
|
||||||
let closeSpanFind = document.getElementById('close-download-bar');
|
let closeSpanFind = document.getElementById('close-download-bar');
|
||||||
|
|
||||||
if (!closeSpanFind){
|
if (!closeSpanFind) {
|
||||||
let closeSpan = document.createElement('span');
|
let closeSpan = document.createElement('span');
|
||||||
closeSpan.id = 'close-download-bar';
|
closeSpan.id = 'close-download-bar';
|
||||||
closeSpan.classList.add('close-download-bar');
|
closeSpan.classList.add('close-download-bar');
|
45
js/main.js
45
js/main.js
@ -1,20 +1,23 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// Third Party Dependencies
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
const nodeURL = require('url');
|
const nodeURL = require('url');
|
||||||
const squirrelStartup = require('electron-squirrel-startup');
|
const squirrelStartup = require('electron-squirrel-startup');
|
||||||
const AutoLaunch = require('auto-launch');
|
const AutoLaunch = require('auto-launch');
|
||||||
const urlParser = require('url');
|
const urlParser = require('url');
|
||||||
const { getConfigField } = require('./config.js');
|
|
||||||
const { isMac, isDevEnv } = require('./utils/misc.js');
|
|
||||||
const protocolHandler = require('./protocolHandler');
|
|
||||||
const getCmdLineArg = require('./utils/getCmdLineArg.js');
|
|
||||||
const childProcess = require('child_process');
|
const childProcess = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const AppDirectory = require('appdirectory');
|
const AppDirectory = require('appdirectory');
|
||||||
const dirs = new AppDirectory('Symphony');
|
const dirs = new AppDirectory('Symphony');
|
||||||
|
|
||||||
|
// Local Dependencies
|
||||||
|
const { getConfigField } = require('./config.js');
|
||||||
|
const { isMac, isDevEnv } = require('./utils/misc.js');
|
||||||
|
const protocolHandler = require('./protocolHandler');
|
||||||
|
const getCmdLineArg = require('./utils/getCmdLineArg.js');
|
||||||
|
|
||||||
require('electron-dl')();
|
require('electron-dl')();
|
||||||
|
|
||||||
// used to check if a url was opened when the app was already open
|
// used to check if a url was opened when the app was already open
|
||||||
@ -75,11 +78,11 @@ if (isMac) {
|
|||||||
*/
|
*/
|
||||||
app.on('ready', setupThenOpenMainWindow);
|
app.on('ready', setupThenOpenMainWindow);
|
||||||
|
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', function() {
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('activate', function () {
|
app.on('activate', function() {
|
||||||
if (windowMgr.isMainWindow(null)) {
|
if (windowMgr.isMainWindow(null)) {
|
||||||
setupThenOpenMainWindow();
|
setupThenOpenMainWindow();
|
||||||
} else {
|
} else {
|
||||||
@ -95,7 +98,7 @@ app.setAsDefaultProtocolClient('symphony');
|
|||||||
// This event is emitted only on macOS
|
// This event is emitted only on macOS
|
||||||
// at this moment, support for windows
|
// at this moment, support for windows
|
||||||
// is in pipeline (https://github.com/electron/electron/pull/8052)
|
// is in pipeline (https://github.com/electron/electron/pull/8052)
|
||||||
app.on('open-url', function (event, url) {
|
app.on('open-url', function(event, url) {
|
||||||
handleProtocolAction(url);
|
handleProtocolAction(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -137,19 +140,19 @@ function setupThenOpenMainWindow() {
|
|||||||
electron.screen.on('display-removed', windowMgr.verifyDisplays);
|
electron.screen.on('display-removed', windowMgr.verifyDisplays);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setStartup(lStartup){
|
function setStartup(lStartup) {
|
||||||
return symphonyAutoLauncher.isEnabled()
|
return symphonyAutoLauncher.isEnabled()
|
||||||
.then(function(isEnabled){
|
.then(function(isEnabled) {
|
||||||
if (!isEnabled && lStartup) {
|
if (!isEnabled && lStartup) {
|
||||||
return symphonyAutoLauncher.enable();
|
return symphonyAutoLauncher.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEnabled && !lStartup) {
|
if (isEnabled && !lStartup) {
|
||||||
return symphonyAutoLauncher.disable();
|
return symphonyAutoLauncher.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to overwrite user config on mac installer
|
// Method to overwrite user config on mac installer
|
||||||
@ -159,7 +162,7 @@ function updateUserConfigMac() {
|
|||||||
let globalConfigPath = process.argv[2];
|
let globalConfigPath = process.argv[2];
|
||||||
let userName = process.env.USER;
|
let userName = process.env.USER;
|
||||||
|
|
||||||
childProcess.exec(`rsync -r "${globalConfigPath}" "${userConfigPath}" && chown -R "${userName}" "${userConfigPath}"`, {timeout: 60000}, (err) => {
|
childProcess.exec(`rsync -r "${globalConfigPath}" "${userConfigPath}" && chown -R "${userName}" "${userConfigPath}"`, { timeout: 60000 }, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
@ -174,7 +177,7 @@ function updateUserConfigWin() {
|
|||||||
let userConfigPath = app.getPath('userData');
|
let userConfigPath = app.getPath('userData');
|
||||||
let globalConfigPath = path.join(__dirname, '..', '..', '..', 'config/Symphony.config');
|
let globalConfigPath = path.join(__dirname, '..', '..', '..', 'config/Symphony.config');
|
||||||
|
|
||||||
childProcess.exec(`echo D|xcopy /y /e /s /c "${globalConfigPath}" "${userConfigPath}"`, {timeout: 60000}, (err) => {
|
childProcess.exec(`echo D|xcopy /y /e /s /c "${globalConfigPath}" "${userConfigPath}"`, { timeout: 60000 }, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
@ -194,7 +197,7 @@ function getUrlAndCreateMainWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getConfigField('url')
|
getConfigField('url')
|
||||||
.then(createWin).catch(function (err) {
|
.then(createWin).catch(function(err) {
|
||||||
let title = 'Error loading configuration';
|
let title = 'Error loading configuration';
|
||||||
electron.dialog.showErrorBox(title, title + ': ' + err);
|
electron.dialog.showErrorBox(title, title + ': ' + err);
|
||||||
});
|
});
|
||||||
@ -252,4 +255,4 @@ function handleProtocolAction(uri) {
|
|||||||
// app is already open, so, just trigger the protocol action method
|
// app is already open, so, just trigger the protocol action method
|
||||||
protocolHandler.processProtocolAction(uri);
|
protocolHandler.processProtocolAction(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ const electron = require('electron');
|
|||||||
const windowMgr = require('./windowMgr.js');
|
const windowMgr = require('./windowMgr.js');
|
||||||
const log = require('./log.js');
|
const log = require('./log.js');
|
||||||
const logLevels = require('./enums/logLevels');
|
const logLevels = require('./enums/logLevels');
|
||||||
const activityDetection = require('./activityDetection/activityDetection');
|
const activityDetection = require('./activityDetection');
|
||||||
const badgeCount = require('./badgeCount.js');
|
const badgeCount = require('./badgeCount.js');
|
||||||
const protocolHandler = require('./protocolHandler');
|
const protocolHandler = require('./protocolHandler');
|
||||||
const configureNotification = require('./notify/settings/configure-notification-position');
|
const configureNotification = require('./notify/settings/configure-notification-position');
|
||||||
@ -107,7 +107,7 @@ electron.ipcMain.on(apiName, (event, arg) => {
|
|||||||
|
|
||||||
// expose these methods primarily for testing...
|
// expose these methods primarily for testing...
|
||||||
module.exports = {
|
module.exports = {
|
||||||
shouldCheckValidWindow: function (shouldCheck) {
|
shouldCheckValidWindow: function(shouldCheck) {
|
||||||
checkValidWindow = shouldCheck;
|
checkValidWindow = shouldCheck;
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -19,7 +19,7 @@ const apiCmds = apiEnums.cmds;
|
|||||||
const apiName = apiEnums.apiName;
|
const apiName = apiEnums.apiName;
|
||||||
const getMediaSources = require('../desktopCapturer/getSources');
|
const getMediaSources = require('../desktopCapturer/getSources');
|
||||||
|
|
||||||
require('../downloadManager/downloadManager');
|
require('../downloadManager');
|
||||||
|
|
||||||
// bug in electron preventing us from using spellchecker in pop outs
|
// bug in electron preventing us from using spellchecker in pop outs
|
||||||
// https://github.com/electron/electron/issues/4025
|
// https://github.com/electron/electron/issues/4025
|
||||||
@ -28,7 +28,7 @@ require('../downloadManager/downloadManager');
|
|||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
try {
|
try {
|
||||||
/* eslint-disable global-require */
|
/* eslint-disable global-require */
|
||||||
const SpellCheckerHelper = require('../spellChecker/spellChecker').SpellCheckHelper;
|
const SpellCheckerHelper = require('../spellChecker').SpellCheckHelper;
|
||||||
/* eslint-enable global-require */
|
/* eslint-enable global-require */
|
||||||
// Method to initialize spell checker
|
// Method to initialize spell checker
|
||||||
const spellChecker = new SpellCheckerHelper();
|
const spellChecker = new SpellCheckerHelper();
|
||||||
@ -102,7 +102,7 @@ function createAPI() {
|
|||||||
containerIdentifier: appName,
|
containerIdentifier: appName,
|
||||||
containerVer: appVer,
|
containerVer: appVer,
|
||||||
apiVer: '1.0.0'
|
apiVer: '1.0.0'
|
||||||
}
|
};
|
||||||
resolve(verInfo);
|
resolve(verInfo);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -126,9 +126,9 @@ function createAPI() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* provides api to allow user to capture portion of screen, see api
|
* provides api to allow user to capture portion of screen, see api
|
||||||
* details in screenSnipper/ScreenSnippet.js
|
* details in screenSnipper/index.js
|
||||||
*/
|
*/
|
||||||
ScreenSnippet: remote.require('./screenSnippet/ScreenSnippet.js').ScreenSnippet,
|
ScreenSnippet: remote.require('./screenSnippet/index.js').ScreenSnippet,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Brings window forward and gives focus.
|
* Brings window forward and gives focus.
|
||||||
@ -191,7 +191,7 @@ function createAPI() {
|
|||||||
* this registration func is invoked then the protocolHandler callback
|
* this registration func is invoked then the protocolHandler callback
|
||||||
* will be immediately called.
|
* will be immediately called.
|
||||||
*/
|
*/
|
||||||
registerProtocolHandler: function (protocolHandler) {
|
registerProtocolHandler: function(protocolHandler) {
|
||||||
if (typeof protocolHandler === 'function') {
|
if (typeof protocolHandler === 'function') {
|
||||||
|
|
||||||
local.processProtocolAction = protocolHandler;
|
local.processProtocolAction = protocolHandler;
|
||||||
@ -347,4 +347,4 @@ function createAPI() {
|
|||||||
window.addEventListener('online', updateOnlineStatus, false);
|
window.addEventListener('online', updateOnlineStatus, false);
|
||||||
|
|
||||||
updateOnlineStatus();
|
updateOnlineStatus();
|
||||||
}
|
}
|
@ -47,21 +47,21 @@ class ScreenSnippet {
|
|||||||
// utilize Mac OSX built-in screencapture tool which has been
|
// utilize Mac OSX built-in screencapture tool which has been
|
||||||
// available since OSX ver 10.2.
|
// available since OSX ver 10.2.
|
||||||
captureUtil = '/usr/sbin/screencapture';
|
captureUtil = '/usr/sbin/screencapture';
|
||||||
captureUtilArgs = [ '-i', '-s', '-t', 'jpg', outputFileName ];
|
captureUtilArgs = ['-i', '-s', '-t', 'jpg', outputFileName];
|
||||||
} else {
|
} else {
|
||||||
// use custom built windows screen capture tool
|
// use custom built windows screen capture tool
|
||||||
if (isDevEnv) {
|
if (isDevEnv) {
|
||||||
// for dev env pick up tool from node nodules
|
// for dev env pick up tool from node nodules
|
||||||
captureUtil =
|
captureUtil =
|
||||||
path.join(__dirname,
|
path.join(__dirname,
|
||||||
'../../node_modules/screen-snippet/bin/Release/ScreenSnippet.exe');
|
'../../node_modules/screen-snippet/bin/Release/ScreenSnippet.exe');
|
||||||
} else {
|
} else {
|
||||||
// for production gets installed next to exec.
|
// for production gets installed next to exec.
|
||||||
let execPath = path.dirname(app.getPath('exe'));
|
let execPath = path.dirname(app.getPath('exe'));
|
||||||
captureUtil = path.join(execPath, 'ScreenSnippet.exe');
|
captureUtil = path.join(execPath, 'ScreenSnippet.exe');
|
||||||
}
|
}
|
||||||
|
|
||||||
captureUtilArgs = [ outputFileName ];
|
captureUtilArgs = [outputFileName];
|
||||||
}
|
}
|
||||||
|
|
||||||
log.send(logLevels.INFO, 'ScreenSnippet: starting screen capture util: ' + captureUtil + ' with args=' + captureUtilArgs);
|
log.send(logLevels.INFO, 'ScreenSnippet: starting screen capture util: ' + captureUtil + ' with args=' + captureUtilArgs);
|
||||||
@ -120,8 +120,7 @@ function readResult(outputFileName, resolve, reject, childProcessErr) {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(createError(error));
|
reject(createError(error));
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
// remove tmp file (async)
|
// remove tmp file (async)
|
||||||
fs.unlink(outputFileName, function(removeErr) {
|
fs.unlink(outputFileName, function(removeErr) {
|
||||||
// note: node complains if calling async
|
// note: node complains if calling async
|
||||||
@ -153,4 +152,4 @@ module.exports = {
|
|||||||
ScreenSnippet: ScreenSnippet,
|
ScreenSnippet: ScreenSnippet,
|
||||||
// note: readResult only exposed for testing purposes
|
// note: readResult only exposed for testing purposes
|
||||||
readResult: readResult
|
readResult: readResult
|
||||||
}
|
};
|
7171
package-lock.json
generated
Normal file
7171
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -26,7 +26,9 @@
|
|||||||
"transformIgnorePatterns": []
|
"transformIgnorePatterns": []
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"asarUnpack": ["node_modules/@paulcbetts/cld/build/Release/cld.node"],
|
"asarUnpack": [
|
||||||
|
"node_modules/@paulcbetts/cld/build/Release/cld.node"
|
||||||
|
],
|
||||||
"files": [
|
"files": [
|
||||||
"!coverage/*",
|
"!coverage/*",
|
||||||
"!installer/*",
|
"!installer/*",
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
const downloadManager = require('../js/downloadManager/downloadManager');
|
const downloadManager = require('../js/downloadManager');
|
||||||
const electron = require('./__mocks__/electron');
|
const electron = require('./__mocks__/electron');
|
||||||
|
|
||||||
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 });
|
||||||
|
|
||||||
@ -31,23 +31,23 @@ 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 =
|
global.document.body.innerHTML =
|
||||||
'<div id="footer" class="hidden">' +
|
'<div id="footer" class="hidden">' +
|
||||||
'<div id="download-manager-footer">' +
|
'<div id="download-manager-footer">' +
|
||||||
'<div id="download-main">' +
|
'<div id="download-main">' +
|
||||||
'</div>' +
|
'</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('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');
|
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 =
|
global.document.body.innerHTML =
|
||||||
'<div id="footer" class="hidden">' +
|
'<div id="footer" class="hidden">' +
|
||||||
'<div id="download-manager-footer">' +
|
'<div id="download-manager-footer">' +
|
||||||
'<div id="download-main">' +
|
'<div id="download-main">' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</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');
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
|
const { ScreenSnippet, readResult } = require('../js/screenSnippet');
|
||||||
const { ScreenSnippet, readResult } = require('../js/screenSnippet/ScreenSnippet.js');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
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');
|
const snippetBase64 = require('./fixtures/snippet/snippet-base64.js');
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ function mockedExecFile(util, args, doneCallback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function copyTestFile(destFile, done) {
|
function copyTestFile(destFile, done) {
|
||||||
const testfile = path.join(__dirname ,
|
const testfile = path.join(__dirname,
|
||||||
'fixtures/snippet/ScreenSnippet.jpeg');
|
'fixtures/snippet/ScreenSnippet.jpeg');
|
||||||
|
|
||||||
let reader = fs.createReadStream(testfile);
|
let reader = fs.createReadStream(testfile);
|
||||||
@ -43,7 +42,7 @@ function copyTestFile(destFile, done) {
|
|||||||
function createTestFile(done) {
|
function createTestFile(done) {
|
||||||
let tmpDir = os.tmpdir();
|
let tmpDir = os.tmpdir();
|
||||||
const testFileName = path.join(tmpDir,
|
const testFileName = path.join(tmpDir,
|
||||||
'ScreenSnippet-' + Date.now() + '.jpeg');
|
'ScreenSnippet-' + Date.now() + '.jpeg');
|
||||||
|
|
||||||
copyTestFile(testFileName, function() {
|
copyTestFile(testFileName, function() {
|
||||||
done(testFileName)
|
done(testFileName)
|
||||||
@ -132,4 +131,4 @@ describe('Tests for ScreenSnippet', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -3,29 +3,29 @@ const childProcess = require('child_process');
|
|||||||
|
|
||||||
let activityDetection;
|
let activityDetection;
|
||||||
|
|
||||||
describe('Tests for Activity Detection', function () {
|
describe('Tests for Activity Detection', function() {
|
||||||
|
|
||||||
var originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
var originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
|
||||||
|
|
||||||
beforeAll(function (done) {
|
beforeAll(function(done) {
|
||||||
childProcess.exec(`npm rebuild --target=${process.version} --build-from-source`, function (err) {
|
childProcess.exec(`npm rebuild --target=${process.version} --build-from-source`, function(err) {
|
||||||
activityDetection = require('../js/activityDetection/activityDetection.js');
|
activityDetection = require('../js/activityDetection');
|
||||||
activityDetection.setActivityWindow(900000, electron.ipcRenderer);
|
activityDetection.setActivityWindow(900000, electron.ipcRenderer);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function() {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(function (done) {
|
afterAll(function(done) {
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null', function () {
|
it('should return null', function() {
|
||||||
|
|
||||||
activityDetection.setActivityWindow(0, electron.ipcRenderer);
|
activityDetection.setActivityWindow(0, electron.ipcRenderer);
|
||||||
const noData = activityDetection.activityDetection();
|
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');
|
const spy = jest.spyOn(activityDetection, 'send');
|
||||||
|
|
||||||
expect(spy).not.toBeCalled();
|
expect(spy).not.toBeCalled();
|
||||||
|
|
||||||
activityDetection.send({systemIdleTime: 120000});
|
activityDetection.send({ systemIdleTime: 120000 });
|
||||||
expect(spy).toHaveBeenCalledWith({systemIdleTime: 120000});
|
expect(spy).toHaveBeenCalledWith({ systemIdleTime: 120000 });
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should monitor user activity', function () {
|
it('should monitor user activity', function() {
|
||||||
activityDetection.setActivityWindow(500000, electron.ipcRenderer);
|
activityDetection.setActivityWindow(500000, electron.ipcRenderer);
|
||||||
const spy = jest.spyOn(activityDetection, 'monitorUserActivity');
|
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');
|
const spy = jest.spyOn(activityDetection, 'send');
|
||||||
|
|
||||||
expect(spy).not.toBeCalled();
|
expect(spy).not.toBeCalled();
|
||||||
@ -64,4 +64,4 @@ describe('Tests for Activity Detection', function () {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user