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

test #1

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3b2b146
Fix #1042: Removing extra space at bottom of workday waiver window (#…
araujoarthur0 Nov 21, 2023
3648c76
Updated changelog.md
Nov 21, 2023
8c4e573
Fix #1040: Date overlapping icon on preference window after electron …
araujoarthur0 Nov 21, 2023
164a4ee
Updated changelog.md
Nov 21, 2023
b935ef3
Use toast notification syntax to support actions on Win32 (#1039)
tupaschoal Nov 22, 2023
d8b2649
Updated changelog.md
Nov 22, 2023
24bca6e
Update changelog.md consistency
tupaschoal Dec 2, 2023
9c14796
Fix #1028: make images and icons not draggable (#1025)
Karroteu Dec 23, 2023
b79a74a
Updated changelog.md
Dec 23, 2023
1103e35
Updated changelog.md
Dec 27, 2023
cbd90c6
Added offline font.
chase-west Nov 3, 2023
8a3ba45
Using only the variable weight font
araujoarthur0 Dec 24, 2023
93b7fed
Adjusting sizes and weights to match previous style
araujoarthur0 Dec 24, 2023
565d225
Change "Open source & free" to "Free and Open-Source!" (#1049)
WebSnke Jan 1, 2024
770c430
Mocking missing ipc handlers
araujoarthur0 Dec 29, 2023
c1c018a
Avoiding "failed to connect to the bus" errors on CI
araujoarthur0 Dec 29, 2023
b8cc4c7
Updating chrome driver version
araujoarthur0 Dec 29, 2023
f208833
[DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir…
araujoarthur0 Dec 29, 2023
e17f499
Fully mock needed net request functions
araujoarthur0 Dec 29, 2023
2256f8f
Mocking missing ipc handlers for calendar
araujoarthur0 Dec 29, 2023
f066266
Mocking missing ipc handlers for workday-waiver
araujoarthur0 Dec 29, 2023
82929dc
Mocking missing ipc handlers for flexible month calendar
araujoarthur0 Dec 29, 2023
94151dd
Mocking missing ipc handlers for flexible day calendar
araujoarthur0 Dec 29, 2023
262f038
Mocking and checking two expected console.log scenarios
araujoarthur0 Jan 2, 2024
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
16 changes: 14 additions & 2 deletions .github/workflows/Checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
export DISPLAY=:99
# TODO: need to download driver according to electron's version
wget --directory-prefix=/tmp https://chromedriver.storage.googleapis.com/87.0.4280.88/chromedriver_linux64.zip
wget --directory-prefix=/tmp https://chromedriver.storage.googleapis.com/100.0.4896.20/chromedriver_linux64.zip
unzip -d /tmp/chromedriver /tmp/chromedriver_linux64.zip
sudo chmod +x /tmp/chromedriver/chromedriver
/tmp/chromedriver/chromedriver &
Expand All @@ -39,8 +39,20 @@ jobs:
- name: ' Tests'
shell: bash
env:
DISPLAY: ':99'
OS: ${{ matrix.os }}
run: |
if [[ $OS == 'ubuntu-20.04' ]]; then
# Avoid "failed to connect to the bus" errors on CI https://github.com/microsoft/WSL/issues/7915
export XDG_RUNTIME_DIR=/run/user/$(id -u)
sudo mkdir -p $XDG_RUNTIME_DIR
sudo chmod 700 $XDG_RUNTIME_DIR
sudo chown $(id -un):$(id -gn) $XDG_RUNTIME_DIR
export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus

# For ChromeDriver to work
export DISPLAY=':99'
fi

npm run test:jest
- name: ' Create COV_REPORT'
run: |
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__main__/import-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@ describe('Import export', function()

afterAll(() =>
{
fs.rmdirSync(folder, {recursive: true});
fs.rmSync(folder, {recursive: true});
});
});
22 changes: 16 additions & 6 deletions __tests__/__main__/main-window.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const notification = require('../../js/notification.js');
const userPreferences = require('../../js/user-preferences.js');
const { savePreferences, defaultPreferences, resetPreferences } = userPreferences;
const { BrowserWindow, ipcMain } = require('electron');
const { app, BrowserWindow, ipcMain } = require('electron');

jest.mock('../../js/update-manager', () => ({
checkForUpdates: jest.fn(),
Expand All @@ -12,6 +12,21 @@ const mainWindowModule = require('../../js/main-window.js');
const { getMainWindow, createWindow, resetMainWindow, getLeaveByInterval, getWindowTray, triggerStartupDialogs } = mainWindowModule;
const updateManager = require('../../js/update-manager.js');

// Mocking USER_DATA_PATH for tests below
ipcMain.handle('USER_DATA_PATH', () =>
{
return new Promise((resolve) =>
{
resolve(app.getPath('userData'));
});
});

ipcMain.removeHandler('GET_LANGUAGE_DATA');
ipcMain.handle('GET_LANGUAGE_DATA', () => ({
'language': 'en',
'data': {}
}));

describe('main-window.js', () =>
{
let showSpy;
Expand Down Expand Up @@ -113,11 +128,6 @@ describe('main-window.js', () =>
{
ipcMain.emit('FINISH_TEST', event, savedPreferences);
});
ipcMain.removeHandler('GET_LANGUAGE_DATA');
ipcMain.handle('GET_LANGUAGE_DATA', () => ({
'language': 'en',
'data': {}
}));
ipcMain.on('FINISH_TEST', (event, savedPreferences) =>
{
expect(windowSpy).toBeCalledTimes(1);
Expand Down
10 changes: 9 additions & 1 deletion __tests__/__main__/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,21 @@ describe('menus.js', () =>
expect(mocks.showMessageBox).toHaveBeenCalledTimes(1);
expect(mocks.writeText).toHaveBeenCalledTimes(0);
});
test('Should show about message box', () =>
test('Should show about message box', (done) =>
{
mocks.consoleLog = jest.spyOn(console, 'log').mockImplementation();
mocks.writeText = jest.spyOn(clipboard, 'writeText').mockImplementation(() => {});
mocks.showMessageBox = jest.spyOn(dialog, 'showMessageBox').mockRejectedValue({response: 1});
getHelpMenuTemplate({})[4].click();
expect(mocks.showMessageBox).toHaveBeenCalledTimes(1);
expect(mocks.writeText).toHaveBeenCalledTimes(0);

// When the rejection happens, we call console.log with the response
setTimeout(() =>
{
expect(mocks.consoleLog).toHaveBeenCalledWith({response: 1});
done();
}, 500);
});
});

Expand Down
26 changes: 22 additions & 4 deletions __tests__/__main__/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@ describe('Notifications', function()
{
process.env.NODE_ENV = 'test';
const notification = createNotification('test');
expect(notification.body).toBe('test');
expect(notification.title).toBe('Time to Leave');
// On Win32 the notification uses a different specification, with toastXml
if (process.platform === 'win32')
{
expect(notification.toastXml).toMatch('<text>test</text>');
expect(notification.toastXml).toMatch('<text>Time to Leave</text>');
}
else
{
expect(notification.body).toBe('test');
expect(notification.title).toBe('Time to Leave');
}
notification.on('show', (event) =>
{
expect(event).toBeTruthy();
Expand Down Expand Up @@ -56,8 +65,17 @@ describe('Notifications', function()
{
process.env.NODE_ENV = 'production';
const notification = createNotification('production');
expect(notification.body).toBe('production');
expect(notification.title).toBe('Time to Leave');
// On Win32 the notification uses a different specification, with toastXml
if (process.platform === 'win32')
{
expect(notification.toastXml).toMatch('<text>production</text>');
expect(notification.toastXml).toMatch('<text>Time to Leave</text>');
}
else
{
expect(notification.body).toBe('production');
expect(notification.title).toBe('Time to Leave');
}
notification.on('show', (event) =>
{
expect(event).toBeTruthy();
Expand Down
11 changes: 9 additions & 2 deletions __tests__/__main__/update-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ describe('js/update-manager.js', () =>
{
test('should not execute when is offline', () =>
{
mocks.net = jest.spyOn(net, 'request').mockImplementation(() => {});
mocks.net = jest.spyOn(net, 'request').mockImplementation(() =>
{
return {
on: () => {},
end: () => {}
};
});
checkForUpdates();
expect(mocks.net).toBeCalledTimes(0);
});
Expand All @@ -67,7 +73,8 @@ describe('js/update-manager.js', () =>
{
expect(mocks.net).toBeCalledTimes(1);
done();
}
},
end: () => {}
};
});
checkForUpdates();
Expand Down
28 changes: 25 additions & 3 deletions __tests__/__renderer__/classes/BaseCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,25 @@ describe('BaseCalendar.js', () =>

window.mainApi.getFlexibleStoreContents = () =>
{
return flexibleStore.store;
return new Promise((resolve) =>
{
resolve(flexibleStore.store);
});
};
window.mainApi.getWaiverStoreContents = () =>
{
return waivedWorkdays.store;
return new Promise((resolve) =>
{
resolve(waivedWorkdays.store);
});
};
window.mainApi.setFlexibleStoreData = (key, contents) =>
{
flexibleStore.set(key, contents);
return new Promise((resolve) =>
{
resolve(true);
});
};
});

Expand Down Expand Up @@ -153,14 +167,22 @@ describe('BaseCalendar.js', () =>
expect(mocks.compute).toHaveBeenCalledTimes(0);
});

test('Should not update value because of rejection', async() =>
test('Should not update value because of rejection', async(done) =>
{
mocks.consoleLog = jest.spyOn(console, 'log').mockImplementation();
mocks.compute = jest.spyOn(timeBalance, 'computeAllTimeBalanceUntilAsync').mockImplementation(() => Promise.reject());
const preferences = {view: 'day'};
const languageData = {hello: 'hola'};
const calendar = new ExtendedClass(preferences, languageData);
calendar._updateAllTimeBalance();
expect(mocks.compute).toHaveBeenCalledTimes(1);

// When the rejection happens, we call console.log, but it'll be undefined here
setTimeout(() =>
{
expect(mocks.consoleLog).toHaveBeenCalledWith(undefined);
done();
}, 500);
});

test('Should not update value because no overall-balance element', () =>
Expand Down
8 changes: 8 additions & 0 deletions __tests__/__renderer__/classes/FlexibleDayCalendar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-undef */

const Store = require('electron-store');
import { computeAllTimeBalanceUntilAsync } from '../../../js/time-balance.js';
import { defaultPreferences } from '../../../js/user-preferences.js';
import { CalendarFactory } from '../../../renderer/classes/CalendarFactory.js';
import { calendarApi } from '../../../renderer/preload-scripts/calendar-api.js';
Expand Down Expand Up @@ -50,6 +51,13 @@ window.mainApi.deleteFlexibleStoreData = (key) =>
resolve(true);
});
};
window.mainApi.computeAllTimeBalanceUntilPromise = (targetDate) =>
{
return new Promise((resolve) =>
{
resolve(computeAllTimeBalanceUntilAsync(targetDate));
});
};

describe('FlexibleDayCalendar class Tests', () =>
{
Expand Down
8 changes: 8 additions & 0 deletions __tests__/__renderer__/classes/FlexibleMonthCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const Store = require('electron-store');
import { computeAllTimeBalanceUntilAsync } from '../../../js/time-balance.js';
import { defaultPreferences } from '../../../js/user-preferences.js';
import { CalendarFactory } from '../../../renderer/classes/CalendarFactory.js';
import { calendarApi } from '../../../renderer/preload-scripts/calendar-api.js';
Expand Down Expand Up @@ -51,6 +52,13 @@ window.mainApi.deleteFlexibleStoreData = (key) =>
resolve(true);
});
};
window.mainApi.computeAllTimeBalanceUntilPromise = (targetDate) =>
{
return new Promise((resolve) =>
{
resolve(computeAllTimeBalanceUntilAsync(targetDate));
});
};

describe('FlexibleMonthCalendar class Tests', () =>
{
Expand Down
24 changes: 19 additions & 5 deletions __tests__/__renderer__/workday-waiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const {
initializeHolidayInfo,
refreshDataForTest
} = require('../../src/workday-waiver');
import { showDialogSync } from '../../js/window-aux.js';
const { workdayWaiverApi } = require('../../renderer/preload-scripts/workday-waiver-api.js');
const {
getAllHolidays,
Expand All @@ -38,6 +37,7 @@ const {
} = require('../../main/workday-waiver-aux.js');
const {
defaultPreferences,
getUserPreferencesPromise,
savePreferences,
} = require('../../js/user-preferences.js');

Expand Down Expand Up @@ -103,6 +103,24 @@ window.mainApi.getRegions = (country, state) =>
});
};

window.mainApi.showDialogSync = () =>
{
return new Promise((resolve) =>
{
resolve({ response: 0 });
});
};

window.mainApi.getUserPreferences = () =>
{
const preferencesFilePathPromise = new Promise((resolve) =>
{
const userDataPath = app.getPath('userData');
resolve(path.join(userDataPath, 'preferences.json'));
});
return getUserPreferencesPromise(preferencesFilePathPromise);
};

const languageData = {'language': 'en', 'data': {'dummy_string': 'dummy_string_translated'}};

async function prepareMockup()
Expand Down Expand Up @@ -273,10 +291,6 @@ describe('Test Workday Waiver Window', function()
await prepareMockup();
addTestWaiver('2020-07-16', 'some reason');
const deleteBtn = document.querySelectorAll('#waiver-list-table .delete-btn')[0];
showDialogSync.mockImplementation((options, cb) =>
{
cb({ response: 0 });
});
deleteEntryOnClick({target: deleteBtn});
const length = document.querySelectorAll('#waiver-list-table .delete-btn').length;
expect(length).toBe(0);
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
- Enhancement [#1009]: Adding an animation to the workday waiver holidays table when the contents switch
- Enhancement [#646]: Title bar color now follows Windows mode (dark or light)
- Fix [#1008]: Sourced conflicting holidays being imported by default
- Fix [#1028]: Make images and icons not draggable
- Fix [#1034]: Preserving TTL font when offline
- Fix [#1039]: Use toast notification syntax to support actions on Win32
- Fix [#1040]: Date overlapping icon on preference window after electron 27
- Fix [#1042]: Removing extra space at bottom of workday waiver window

<!--- End changes - Do not remove -->

Expand All @@ -13,7 +18,9 @@ Who built 3.0.1:
<!--- Begin users - Do not remove -->

- BamButz
- Karroteu
- araujoarthur0
- chase-west
- gsriram24
- ochan12
- pallasite99
Expand Down
Binary file not shown.
Loading
Loading