Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapting workday waiver window to use a non-remote environment #887

Merged
merged 8 commits into from
Oct 8, 2023
8 changes: 6 additions & 2 deletions __tests__/__renderer__/classes/BaseCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ describe('BaseCalendar.js', () =>

describe('punchDate()', () =>
{
const workAllDayPreferences = ({...getUserPreferences(), 'working-days-saturday': true,
'working-days-sunday': true});
const today = new Date();
const nextYear = new Date();
nextYear.setFullYear(today.getFullYear() + 1);
Expand Down Expand Up @@ -322,7 +324,8 @@ describe('BaseCalendar.js', () =>
date: new Date(),
getCalendar: () =>
{
const calendar = new ExtendedClass(getUserPreferences(), languageData);
// Setting all days as work days so test works every day
const calendar = new ExtendedClass(workAllDayPreferences, languageData);
return calendar;
},
expect: () =>
Expand Down Expand Up @@ -352,7 +355,8 @@ describe('BaseCalendar.js', () =>
date: new Date(),
getCalendar: () =>
{
const calendar = new ExtendedClass(getUserPreferences(), languageData);
// Setting all days as work days so test works every day
const calendar = new ExtendedClass(workAllDayPreferences, languageData);
return calendar;
},
expect: () =>
Expand Down
147 changes: 73 additions & 74 deletions __tests__/__renderer__/window-aux.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('window-aux.js Testing', function()

const mockHtmlPath = path.join('file://', __dirname, '../../__mocks__/mock.html');

const devToolsShortcut = new KeyboardEvent('keyup', {keyCode: 73, ctrlKey: true, shiftKey: true});
const badDevToolsShortcut = new KeyboardEvent('keyup', {keyCode: 74, ctrlKey: true, shiftKey: true});
// const devToolsShortcut = new KeyboardEvent('keyup', {keyCode: 73, ctrlKey: true, shiftKey: true});
// const badDevToolsShortcut = new KeyboardEvent('keyup', {keyCode: 74, ctrlKey: true, shiftKey: true});
const browserWindowOptions = {
webPreferences: {
enableRemoteModule: true,
Expand All @@ -22,72 +22,75 @@ describe('window-aux.js Testing', function()
};
const timeoutValue = 1500;

describe('bindDevToolsShortcut(window)', function()
// Testcase no longer being used since the move to electron without remote
// but we should make use of it for a mocha testcase to still be sure the proferences window
// and workday waiver have the shortcut working

// describe('bindDevToolsShortcut(window)', function()
// {

// test('No bind: should not open anything', async() =>
// {
// const testWindow = new BrowserWindow(browserWindowOptions);
// testWindow.loadURL(mockHtmlPath);
// expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();

// testWindow.webContents.on('dom-ready', () =>
// {
// window.dispatchEvent(devToolsShortcut);
// });
// testWindow.on('did-fail-load', (event, code, desc, url, isMainFrame) =>
// {
// console.log('did-fail-load: ', event, code, desc, url, isMainFrame);
// });

// await new Promise(r => setTimeout(r, timeoutValue));
// expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();
// });

// test('Bind: should open devTools', async() =>
// {
// const testWindow = new BrowserWindow(browserWindowOptions);
// testWindow.loadURL(mockHtmlPath);
// expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();

// testWindow.webContents.on('dom-ready', () =>
// {
// bindDevToolsShortcut(window);
// window.dispatchEvent(devToolsShortcut);
// });
// testWindow.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) =>
// {
// console.log('did-fail-load: ', event, code, desc, url, isMainFrame);
// });

// await new Promise(r => setTimeout(r, timeoutValue));
// expect(testWindow.webContents.isDevToolsOpened()).toBeTruthy();
// });

// test('Bind: bad shortcut, should not open devTools', async() =>
// {
// const testWindow = new BrowserWindow(browserWindowOptions);
// testWindow.loadURL(mockHtmlPath);
// expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();

// testWindow.webContents.on('dom-ready', () =>
// {
// bindDevToolsShortcut(window);
// window.dispatchEvent(badDevToolsShortcut);
// });
// testWindow.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) =>
// {
// console.log('did-fail-load: ', event, code, desc, url, isMainFrame);
// });

// await new Promise(r => setTimeout(r, timeoutValue));
// expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();
// });
// });

describe('showDialogSync(options, successCallback)', function()
{

test('No bind: should not open anything', async() =>
{
const testWindow = new BrowserWindow(browserWindowOptions);
testWindow.loadURL(mockHtmlPath);
expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();

testWindow.webContents.on('dom-ready', () =>
{
window.dispatchEvent(devToolsShortcut);
});
testWindow.on('did-fail-load', (event, code, desc, url, isMainFrame) =>
{
console.log('did-fail-load: ', event, code, desc, url, isMainFrame);
});

await new Promise(r => setTimeout(r, timeoutValue));
expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();
});

test('Bind: should open devTools', async() =>
{
const testWindow = new BrowserWindow(browserWindowOptions);
testWindow.loadURL(mockHtmlPath);
expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();

testWindow.webContents.on('dom-ready', () =>
{
windowAux.bindDevToolsShortcut(window);
window.dispatchEvent(devToolsShortcut);
});
testWindow.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) =>
{
console.log('did-fail-load: ', event, code, desc, url, isMainFrame);
});

await new Promise(r => setTimeout(r, timeoutValue));
expect(testWindow.webContents.isDevToolsOpened()).toBeTruthy();
});

test('Bind: bad shortcut, should not open devTools', async() =>
{
const testWindow = new BrowserWindow(browserWindowOptions);
testWindow.loadURL(mockHtmlPath);
expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();

testWindow.webContents.on('dom-ready', () =>
{
windowAux.bindDevToolsShortcut(window);
window.dispatchEvent(badDevToolsShortcut);
});
testWindow.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) =>
{
console.log('did-fail-load: ', event, code, desc, url, isMainFrame);
});

await new Promise(r => setTimeout(r, timeoutValue));
expect(testWindow.webContents.isDevToolsOpened()).not.toBeTruthy();
});
});

describe('showDialog(options, successCallback)', function()
{

test('Does not crash', async() =>
{
const testWindow = new BrowserWindow(browserWindowOptions);
Expand All @@ -96,12 +99,12 @@ describe('window-aux.js Testing', function()
let spy;
testWindow.webContents.on('dom-ready', () =>
{
spy = jest.spyOn(windowAux, 'showDialog');
spy = jest.spyOn(windowAux, 'showDialogSync');

const options = {
title: 'Time to Leave',
};
windowAux.showDialog(options, () =>
windowAux.showDialogSync(options, () =>
{
return;
});
Expand All @@ -121,7 +124,6 @@ describe('window-aux.js Testing', function()

describe('showAlert(message)', function()
{

test('Does not crash', async() =>
{
const testWindow = new BrowserWindow(browserWindowOptions);
Expand All @@ -130,10 +132,7 @@ describe('window-aux.js Testing', function()
let spy;
testWindow.webContents.on('dom-ready', () =>
{
const { dialog } = require('electron').remote;

spy = jest.spyOn(dialog, 'showMessageBoxSync').mockImplementation(() => {});

spy = jest.spyOn(windowAux, 'showAlert');
windowAux.showAlert('Test showAlert');
});
testWindow.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) =>
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__renderer__/workday-waiver-aux.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-undef */
'use strict';

import { formatDayId, displayWaiverWindow } from '../../js/workday-waiver-aux.js';
import { formatDayId, displayWaiverWindow } from '../../renderer/workday-waiver-aux.js';

describe('Workday Waiver Aux', function()
{
Expand Down
Loading