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

Improve notifications - coverage tests #911

Merged
merged 81 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
ae72a3c
Use electron notification for macOS
ochan12 Nov 16, 2022
c2268f6
Add notification channel to send messages thorugh IPC
ochan12 Nov 16, 2022
1ff631d
Remove interval from esm-main
ochan12 Nov 16, 2022
edd9dcc
Move notify interval ot main window creation
ochan12 Nov 16, 2022
ad6669f
Validate date first, send #leave-by parameter
ochan12 Nov 16, 2022
76c3101
Add comments, remove node-notifier, use native election notifications
ochan12 Nov 17, 2022
178611f
Typo on win32
ochan12 Nov 17, 2022
f9098ac
Set interval to one minute
ochan12 Nov 17, 2022
0d9750f
Activate window when clicking notification
ochan12 Nov 17, 2022
e6acf4b
Update tests
ochan12 Nov 17, 2022
d10de43
Update title and tests
ochan12 Nov 17, 2022
0871b62
Try to install libnotify
ochan12 Nov 17, 2022
5891f29
Try running notify-osd
ochan12 Nov 17, 2022
4d7c7b6
Remove notify install
ochan12 Nov 17, 2022
d776dfc
Emit notifications only on linux and CI
ochan12 Nov 17, 2022
78be6e7
Add fn for testing, test whole notifications
ochan12 Nov 17, 2022
3c5b45b
Bug on leave by
ochan12 Nov 17, 2022
d91bbca
Create notification channel test
ochan12 Nov 18, 2022
34eb160
Add tests for main window
ochan12 Nov 19, 2022
8158d74
Add more tests for main window
ochan12 Nov 19, 2022
21ad079
fix tests for linux
ochan12 Nov 19, 2022
1cedaf2
Fix tests on minimize
ochan12 Nov 19, 2022
0f468d1
Merge branch 'main' into improve-notifications
ochan12 Nov 19, 2022
98eb954
Fix lint errors
ochan12 Nov 19, 2022
4556a49
Windows tests
ochan12 Nov 19, 2022
620125f
Typos
ochan12 Nov 19, 2022
9a07840
Some menu tests
ochan12 Nov 19, 2022
54f6077
Menus and notificaiton tests
ochan12 Nov 19, 2022
eaec922
Remove extra if, tests on most of menus
ochan12 Nov 19, 2022
bd76dcb
Test interval
ochan12 Nov 19, 2022
4c400b0
Test notificationclick emit
ochan12 Nov 19, 2022
9360283
Bug on time-mathd and full validate of dates
ochan12 Nov 20, 2022
952eac0
Update-manager
ochan12 Nov 20, 2022
7422b56
Refactor Calendar factory and tests
ochan12 Nov 20, 2022
acdf529
Tests on base calendar
ochan12 Nov 20, 2022
e467a6b
Workday waiver tests
ochan12 Nov 20, 2022
2a65076
Time balance tests
ochan12 Nov 20, 2022
8e74ae0
Use electron notification for macOS
ochan12 Nov 16, 2022
2306e57
Add notification channel to send messages thorugh IPC
ochan12 Nov 16, 2022
d887897
Remove interval from esm-main
ochan12 Nov 16, 2022
f817cfb
Move notify interval ot main window creation
ochan12 Nov 16, 2022
ae938c1
Validate date first, send #leave-by parameter
ochan12 Nov 16, 2022
c0f7348
Add comments, remove node-notifier, use native election notifications
ochan12 Nov 17, 2022
07e5cae
Typo on win32
ochan12 Nov 17, 2022
82cedfb
Set interval to one minute
ochan12 Nov 17, 2022
c1198bf
Activate window when clicking notification
ochan12 Nov 17, 2022
4574427
Update tests
ochan12 Nov 17, 2022
dcbf297
Update title and tests
ochan12 Nov 17, 2022
4433f84
Try to install libnotify
ochan12 Nov 17, 2022
bc1cdc4
Try running notify-osd
ochan12 Nov 17, 2022
c72d542
Remove notify install
ochan12 Nov 17, 2022
6169a83
Emit notifications only on linux and CI
ochan12 Nov 17, 2022
1792d6b
Add fn for testing, test whole notifications
ochan12 Nov 17, 2022
f832667
Bug on leave by
ochan12 Nov 17, 2022
9ecc9f1
Create notification channel test
ochan12 Nov 18, 2022
14c8933
Add tests for main window
ochan12 Nov 19, 2022
4434754
Add more tests for main window
ochan12 Nov 19, 2022
96ad2ab
fix tests for linux
ochan12 Nov 19, 2022
1e90bd0
Fix tests on minimize
ochan12 Nov 19, 2022
1cc907c
Fix lint errors
ochan12 Nov 19, 2022
2368ef5
Windows tests
ochan12 Nov 19, 2022
3f058af
Typos
ochan12 Nov 19, 2022
610482c
Some menu tests
ochan12 Nov 19, 2022
19ce2eb
Menus and notificaiton tests
ochan12 Nov 19, 2022
f9dfe0e
Remove extra if, tests on most of menus
ochan12 Nov 19, 2022
08a3859
Test interval
ochan12 Nov 19, 2022
56f89eb
Test notificationclick emit
ochan12 Nov 19, 2022
29751ed
Bug on time-mathd and full validate of dates
ochan12 Nov 20, 2022
efa8f1c
Update-manager
ochan12 Nov 20, 2022
3b57ef5
Refactor Calendar factory and tests
ochan12 Nov 20, 2022
005d50d
Tests on base calendar
ochan12 Nov 20, 2022
2624343
Workday waiver tests
ochan12 Nov 20, 2022
8b8ae6b
Time balance tests
ochan12 Nov 20, 2022
da0b6a9
Merge branch 'improve-notifications-coverage-tests' of https://github…
ochan12 Jan 16, 2023
7306800
Merge branch 'main' into improve-notifications-coverage-tests
ochan12 Jan 16, 2023
1b96b82
Merge branch 'main' into improve-notifications-coverage-tests
ochan12 Sep 22, 2023
99ee407
Merge branch 'main' into improve-notifications-coverage-tests
ochan12 Oct 11, 2023
1011667
Fix tests
ochan12 Oct 11, 2023
8c63f4c
change spy
ochan12 Oct 11, 2023
99930df
Remove number of times as it is different on each OS
ochan12 Oct 11, 2023
3013c17
space accidentally removed
ochan12 Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/__main__/main-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ describe('main-window.js', () =>

test('Should minimize if minimize-to-tray is false', (done) =>
{
const userPreferencesSpy = jest.spyOn(userPreferences, 'getUserPreferences');
savePreferences({
...defaultPreferences,
['minimize-to-tray']: false
Expand All @@ -266,10 +265,11 @@ describe('main-window.js', () =>
* @type {BrowserWindow}
*/
const mainWindow = getMainWindow();
const minimizeSpy = jest.spyOn(mainWindow, 'minimize');
mainWindow.on('ready-to-show', () =>
{
mainWindow.emit('minimize', {});
expect(userPreferencesSpy).toHaveBeenCalledTimes(1);
expect(minimizeSpy).toBeCalled();
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__main__/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Notifications', function()
{
describe('notify', () =>
{
beforeAll(() =>
beforeEach(() =>
{
// displays a notification in test fails if mocks are not restored
jest.restoreAllMocks();
Expand Down
38 changes: 37 additions & 1 deletion __tests__/__main__/time-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
const Store = require('electron-store');
import {
computeAllTimeBalanceUntil,
getFirstInputInDb
getFirstInputInDb,
computeAllTimeBalanceUntilAsync
} from '../../js/time-balance.js';
import { resetPreferences } from '../../js/user-preferences.js';

Expand Down Expand Up @@ -93,6 +94,26 @@ describe('Time Balance', () =>
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 7))).resolves.toBe('-24:00');
});

test('computeAllTimeBalanceUntil: only regular days, timesAreProgressing false', async() =>
{
const entryEx = {
'2020-6-1': {'values': ['08:00', '12:00', '17:00', '13:00']} // wed (8h total)
};
flexibleStore.set(entryEx);
// time balance until thu (excluding thu)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 2))).resolves.toBe('-08:00');
// time balance until fri (excluding fri)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 3))).resolves.toBe('-16:00');
// time balance until sat (excluding sat)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 4))).resolves.toBe('-24:00');
// time balance until sun (excluding sun)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 5))).resolves.toBe('-24:00');
// time balance until mon (excluding mon)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 6))).resolves.toBe('-24:00');
// time balance until tue (excluding tue)
await expect(computeAllTimeBalanceUntil(new Date(2020, 6, 7))).resolves.toBe('-32:00');
});

test('computeAllTimeBalanceUntil: only regular days (6 entries)', async() =>
{
const entryEx = {
Expand Down Expand Up @@ -318,4 +339,19 @@ describe('Time Balance', () =>
waivedWorkdays.set(waivedEntries);
await expect(computeAllTimeBalanceUntil(new Date(2020, 5, 1))).resolves.toBe('00:00');
});

test('computeAllTimeBalanceUntilAsync: target date in the past of entries', async() =>
{
const entryEx = {
'2020-6-1': {'values': ['08:00', '12:00', '13:00', '17:00']}, // wed (8h total)
'2020-6-3': {'values': ['08:00', '12:00', '13:00', '17:00']} // fri (8h total)
};
flexibleStore.set(entryEx);
const waivedEntries = {
'2020-07-02': { reason: 'Waiver', hours: '02:00' }, // tue
};
waivedWorkdays.set(waivedEntries);
await expect(computeAllTimeBalanceUntilAsync(new Date(2020, 5, 1))).resolves.toBe('00:00');
});

});
50 changes: 40 additions & 10 deletions __tests__/__main__/time-math.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,45 @@ describe('Time Math Functions', () =>

test('validateDate(date)', () =>
{
expect(validateDate('0001-00-00')).toBeFalsy();
expect(validateDate('1-00-00')).toBeFalsy();
expect(validateDate('1996-13-00')).toBeFalsy();
expect(validateDate('1996-1-00')).toBeFalsy();
expect(validateDate('1996-01-1')).toBeFalsy();
expect(validateDate('1996-01-40')).toBeFalsy();
expect(validateDate('1996-01-31')).toBeFalsy();
expect(validateDate('I\'m a date!')).toBeFalsy();
expect(validateDate('1996-01-29')).toBeTruthy();
expect(validateDate('1996-01-30')).toBeFalsy();
const tests = [
{date: '0001-00-00',valid: false},
{date: '1-00-00',valid: false},
{date: '1996-13-00',valid: false},
{date: '1996-1-00',valid: false},
{date: '1996-01-1',valid: false},
{date: '1996-01-40',valid: false},
{date: '1996-01-31',valid: false},
{date: 'I\'m a date!',valid: false},
{date: '1996-01-29',valid: true},
{date: '1996-01-30',valid: false},
{date: '1996-00-01', valid: true},
{date: '1996-01-01', valid: true},
{date: '1996-02-01', valid: true},
{date: '1996-03-01', valid: true},
{date: '1996-04-01', valid: true},
{date: '1996-05-01', valid: true},
{date: '1996-06-01', valid: true},
{date: '1996-07-01', valid: true},
{date: '1996-08-01', valid: true},
{date: '1996-09-01', valid: true},
{date: '1996-10-01', valid: true},
{date: '1996-11-01', valid: true},
{date: '1996-00-40', valid: false},
{date: '1996-01-40', valid: false},
{date: '1996-02-40', valid: false},
{date: '1996-03-40', valid: false},
{date: '1996-04-40', valid: false},
{date: '1996-05-40', valid: false},
{date: '1996-06-40', valid: false},
{date: '1996-07-40', valid: false},
{date: '1996-08-40', valid: false},
{date: '1996-09-40', valid: false},
{date: '1996-10-40', valid: false},
{date: '1996-11-40', valid: false},
];
for (const test of tests)
{
expect(validateDate(test.date)).toBe(test.valid);
}
});
});
85 changes: 85 additions & 0 deletions __tests__/__main__/update-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const ElectronStore = require('electron-store');
const { getDateStr } = require('../../js/date-aux');
const {shouldCheckForUpdates, checkForUpdates} = require('../../js/update-manager');

jest.mock('electron', () =>
{
const original = jest.requireActual('electron');
return {
__esModule: true,
...original,
net: {
...original.net,
request: jest.fn()
}
};
});

jest.mock('is-online', () => () => jest.fn().mockResolvedValueOnce(false).mockResolvedValue(true));

const { net } = require('electron');

describe('js/update-manager.js', () =>
{
const mocks = {};
describe('shouldCheckForUpdates', () =>
{
test('Should return true when was never checked', () =>
{
const store = new ElectronStore();
store.set('update-remind-me-after', false);
expect(shouldCheckForUpdates()).toBe(true);
});

test('Should return true when was checked before today', () =>
{
const now = new Date();
now.setDate(now.getDate() - 1);
const store = new ElectronStore();
store.set('update-remind-me-after', getDateStr(now));
expect(shouldCheckForUpdates()).toBe(true);
});

test('Should return false when was checked today', () =>
{
const now = new Date();
const store = new ElectronStore();
store.set('update-remind-me-after', getDateStr(now));
expect(shouldCheckForUpdates()).toBe(false);
});
});

describe('checkForUpdates', () =>
{
test('should not execute when is offline', () =>
{
mocks.net = jest.spyOn(net, 'request').mockImplementation(() => {});
checkForUpdates();
expect(mocks.net).toBeCalledTimes(0);
});

test('should not execute when is online', (done) =>
{
mocks.net = jest.spyOn(net, 'request').mockImplementation(() =>
{
return {
on: () =>
{
expect(mocks.net).toBeCalledTimes(1);
done();
}
};
});
checkForUpdates();
});

});

afterEach(() =>
{
for (const mock of Object.values(mocks))
{
mock.mockClear();
}
});
});
94 changes: 94 additions & 0 deletions __tests__/__main__/windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const { BrowserWindow } = require('electron');
const { getDateStr } = require('../../js/date-aux.js');
const windows = require('../../js/windows.js');
const {getWaiverWindow, tray, contextMenu, prefWindow, resetWindowsElements, openWaiverManagerWindow, getDialogCoordinates} = require('../../js/windows.js');

describe('windows.js', () =>
{
let showSpy;
let loadSpy;
beforeEach(() =>
{
// Avoid window being shown
loadSpy = jest.spyOn(BrowserWindow.prototype, 'loadURL').mockImplementation(() => {});
showSpy = jest.spyOn(BrowserWindow.prototype, 'show').mockImplementation(() => {});
jest.spyOn(windows, 'getDialogCoordinates').mockImplementation(() => ({x:0, y:0}));
});

test('Elements should be null on starting', () =>
{
expect(getWaiverWindow()).toBe(null);
expect(tray).toBe(null);
expect(contextMenu).toBe(null);
expect(prefWindow).toBe(null);
});

test('Should create waiver window', (done) =>
{
const mainWindow = new BrowserWindow({
show: false
});
openWaiverManagerWindow(mainWindow);
expect(getWaiverWindow()).not.toBe(null);
expect(getWaiverWindow()).toBeInstanceOf(BrowserWindow);
expect(getWaiverWindow().getSize()).toEqual([600, 500]);
done();
});

test('Should show waiver window it has been created', (done) =>
{
const mainWindow = new BrowserWindow({
show: false
});
openWaiverManagerWindow(mainWindow);
openWaiverManagerWindow(mainWindow);
expect(getWaiverWindow()).not.toBe(null);
// It should only load once the URL because it already exists
expect(showSpy).toHaveBeenCalledTimes(2);
expect(loadSpy).toHaveBeenCalledTimes(1);
done();
});

test('Should set global waiverDay when event is sent', (done) =>
{
const mainWindow = new BrowserWindow({
show: false
});
openWaiverManagerWindow(mainWindow, true);
expect(getWaiverWindow()).not.toBe(null);
expect(global.waiverDay).toBe(getDateStr(new Date()));
done();
});

test('Should reset waiverWindow on close', () =>
{
const mainWindow = new BrowserWindow({
show: false
});
openWaiverManagerWindow(mainWindow, true);
getWaiverWindow().emit('close');
expect(getWaiverWindow()).toBe(null);
});

test('Should get dialog coordinates', () =>
{
const coordinates = getDialogCoordinates(500, 250, {
getBounds: () => ({
x: 200,
y: 300,
width: 400,
height: 600
})
});
expect(coordinates).toEqual({
x: 150,
y: 475
});
});

afterEach(() =>
{
jest.restoreAllMocks();
resetWindowsElements();
});
});
53 changes: 53 additions & 0 deletions __tests__/__renderer__/workday-waiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,15 @@ describe('Test Workday Waiver Window', function()
expect(mockCallback).toBeCalledTimes(holidaysLength);
});

test('Do not load holidays table on empty holidays', () =>
{
loadHolidaysTable();
const holidaysLength = 0;
const rowLength = $('#holiday-list-table tbody tr').length;
expect($('#holiday-list-table').css('display')).toBe('table');
expect(holidaysLength).toBe(rowLength);
});

test('Load holidays table', async() =>
{
$('#year').append($('<option selected></option>').val(year).html(year));
Expand Down Expand Up @@ -473,6 +482,50 @@ describe('Test Workday Waiver Window', function()
expect(thirdCell).toBe('undefined');
expect(fourthCell).toEqual(fourthCellContent);
});

test('Holiday added not working day, no conflicts', () =>
{
const day = 'test day';
const reason = 'test reason';
const workingDay = 'No';
const conflicts = undefined;
addHolidayToList(day, reason, workingDay);
const table = $('#holiday-list-table tbody');
const rowsLength = table.find('tr').length;
expect(rowsLength).toBe(1);
const firstCell = table.find('td')[0].innerHTML;
const secondCell = table.find('td')[1].innerHTML;
const thirdCell = table.find('td')[2].innerHTML;
const fourthCell = table.find('td')[4].innerHTML;
const fourthCellContent = `<label class="switch"><input type="checkbox" checked="${conflicts || workingDay === 'No' ? '' : 'checked'}" name="import-${day}" id="import-${day}"><span class="slider round"></span></label>`;
expect(firstCell).toBe(day);
expect(secondCell).toBe(reason);
expect(thirdCell).toBe(workingDay);
expect(fourthCell).toEqual(fourthCellContent);
});

test('Holiday added not working day, with conflicts', () =>
{
const day = 'test day';
const reason = 'test reason';
const workingDay = 'No';
const conflicts = '<span>this is a conflict</span>';
addHolidayToList(day, reason, workingDay, conflicts);
const table = $('#holiday-list-table tbody');
const rowsLength = table.find('tr').length;
expect(rowsLength).toBe(1);
const firstCell = table.find('td')[0].innerHTML;
const secondCell = table.find('td')[1].innerHTML;
const thirdCell = table.find('td')[2].innerHTML;
const conflictsCell = table.find('td')[3].innerHTML;
const fourthCell = table.find('td')[4].innerHTML;
const fourthCellContent = `<label class="switch"><input type="checkbox" checked="${conflicts || workingDay === 'No' ? '' : 'checked'}" name="import-${day}" id="import-${day}"><span class="slider round"></span></label>`;
expect(firstCell).toBe(day);
expect(secondCell).toBe(reason);
expect(thirdCell).toBe(workingDay);
expect(conflictsCell).toBe(conflicts);
expect(fourthCell).toEqual(fourthCellContent);
});
});

describe('Clearing the table', () =>
Expand Down
Loading