From cc32c2ae66bd47a5b1f983585b76cb4e1a0365a3 Mon Sep 17 00:00:00 2001 From: Arthur Araujo Date: Wed, 26 Oct 2022 21:54:16 -0300 Subject: [PATCH] Fix #889: Adapting calendar tests to new format --- __tests__/__main__/main-window.js | 22 ++++--- .../__renderer__/classes/BaseCalendar.js | 57 ++++++++++++++++--- .../__renderer__/classes/CalendarFactory.js | 54 +++++++++++------- .../classes/FlexibleDayCalendar.js | 53 ++++++++++++----- .../classes/FlexibleMonthCalendar.js | 47 +++++++++++---- __tests__/__renderer__/workday-waiver-aux.js | 6 ++ renderer/classes/BaseCalendar.js | 12 +++- renderer/classes/CalendarFactory.js | 2 +- 8 files changed, 188 insertions(+), 65 deletions(-) diff --git a/__tests__/__main__/main-window.js b/__tests__/__main__/main-window.js index 8ccb77b20..cbdaf244c 100644 --- a/__tests__/__main__/main-window.js +++ b/__tests__/__main__/main-window.js @@ -51,7 +51,7 @@ describe('main-window.js', () => expect(mainWindow).toBeInstanceOf(BrowserWindow); expect(ipcMain.listenerCount('TOGGLE_TRAY_PUNCH_TIME')).toBe(1); expect(ipcMain.listenerCount('RESIZE_MAIN_WINDOW')).toBe(1); - expect(ipcMain.listenerCount('VIEW_CHANGED')).toBe(1); + expect(ipcMain.listenerCount('SWITCH_VIEW')).toBe(1); expect(ipcMain.listenerCount('RECEIVE_LEAVE_BY')).toBe(1); expect(mainWindow.listenerCount('minimize')).toBe(2); expect(mainWindow.listenerCount('close')).toBe(1); @@ -73,13 +73,17 @@ describe('main-window.js', () => const mainWindow = getMainWindow(); mainWindow.on('ready-to-show', () => { - ipcMain.emit('RESIZE_MAIN_WINDOW', {}, 500, 600); - expect(mainWindow.getSize()).toEqual([500, 600]); + ipcMain.emit('RESIZE_MAIN_WINDOW'); + expect(mainWindow.getSize()).toEqual([1010, 800]); done(); }); }); test('It should not resize window if values are smaller than minimum', (done) => { + savePreferences({ + ...defaultPreferences, + ['view']: 'day' + }); createWindow(); /** * @type {BrowserWindow} @@ -87,16 +91,16 @@ describe('main-window.js', () => const mainWindow = getMainWindow(); mainWindow.on('ready-to-show', () => { - ipcMain.emit('RESIZE_MAIN_WINDOW', {}, 100, 100); - expect(mainWindow.getSize()).toEqual([450, 450]); + ipcMain.emit('RESIZE_MAIN_WINDOW'); + expect(mainWindow.getSize()).toEqual([500, 500]); done(); }); }); }); - describe('emit VIEW_CHANGED', () => + describe('emit SWITCH_VIEW', () => { - test('It should send new event to ipcRendered', (done) => + test('It should send new event to ipcRenderer', (done) => { createWindow(); /** @@ -117,10 +121,10 @@ describe('main-window.js', () => ipcMain.on('FINISH_TEST', (event, savedPreferences) => { expect(windowSpy).toBeCalledTimes(1); - expect(savedPreferences).toEqual({ new: 'prefrences' }); + expect(savedPreferences['view']).toEqual('day'); done(); }); - ipcMain.emit('VIEW_CHANGED', {}, { new: 'prefrences' }); + ipcMain.emit('SWITCH_VIEW'); windowSpy.mockRestore(); }); }); diff --git a/__tests__/__renderer__/classes/BaseCalendar.js b/__tests__/__renderer__/classes/BaseCalendar.js index f1d61371a..97cdbb35c 100644 --- a/__tests__/__renderer__/classes/BaseCalendar.js +++ b/__tests__/__renderer__/classes/BaseCalendar.js @@ -1,9 +1,10 @@ import ElectronStore from 'electron-store'; -import { BaseCalendar } from '../../../js/classes/BaseCalendar.js'; +import { BaseCalendar } from '../../../renderer/classes/BaseCalendar.js'; import { generateKey } from '../../../js/date-db-formatter.js'; -import { getUserPreferences, resetPreferences, savePreferences } from '../../../js/user-preferences.js'; +import { getUserPreferences, resetPreferences, savePreferences, switchCalendarView } from '../../../js/user-preferences.js'; const Store = require('electron-store'); const timeBalance = require('../../../js/time-balance'); +import { calendarApi } from '../../../renderer/preload-scripts/calendar-api.js'; jest.mock('../../../js/time-math', () => { @@ -17,6 +18,19 @@ jest.mock('../../../js/time-math', () => const timeMath = require('../../../js/time-math'); window.$ = require('jquery'); +// Mocked APIs from the preload script of the calendar window +window.mainApi = calendarApi; + +window.mainApi.computeAllTimeBalanceUntilPromise = (targetDate) => +{ + return timeBalance.computeAllTimeBalanceUntilAsync(targetDate); +}; + +window.mainApi.switchView = () => +{ + switchCalendarView(); +}; + describe('BaseCalendar.js', () => { class ExtendedClass extends BaseCalendar @@ -39,6 +53,15 @@ describe('BaseCalendar.js', () => waivedWorkdays.clear(); ExtendedClass.prototype._initCalendar = () => {}; ExtendedClass.prototype._getTargetDayForAllTimeBalance = () => {}; + + window.mainApi.getFlexibleStoreContents = () => + { + return flexibleStore.store; + }; + window.mainApi.getWaiverStoreContents = () => + { + return waivedWorkdays.store; + }; }); describe('constructor', () => @@ -60,7 +83,7 @@ describe('BaseCalendar.js', () => expect(() => new ExtendedClass(preferences, languageData)._getTargetDayForAllTimeBalance()).toThrow('Please implement this.'); }); - test('Should build with default values', (done) => + test('Should build with default values', async(done) => { ExtendedClass.prototype._initCalendar = () => { done(); }; const preferences = {view: 'day'}; @@ -68,12 +91,19 @@ describe('BaseCalendar.js', () => const calendar = new ExtendedClass(preferences, languageData); expect(calendar._calendarDate).toBeInstanceOf(Date); expect(calendar._languageData).toEqual(languageData); + expect(calendar._preferences).toEqual(preferences); + + // These no longer get set in the constructor + expect(calendar._internalStore).toEqual(undefined); + expect(calendar._internalWaiverStore).toEqual(undefined); + + // But are set after awaiting for initialization + await calendar.initializeStores(); expect(calendar._internalStore).toEqual({}); expect(calendar._internalWaiverStore).toEqual({}); - expect(calendar._preferences).toEqual(preferences); }); - test('Should build with default internal store values', (done) => + test('Should build with default internal store values', async(done) => { ExtendedClass.prototype._initCalendar = () => { done(); }; const flexibleStore = new ElectronStore({name: 'flexible-store'}); @@ -90,6 +120,14 @@ describe('BaseCalendar.js', () => const calendar = new ExtendedClass(preferences, languageData); expect(calendar._calendarDate).toBeInstanceOf(Date); expect(calendar._languageData).toEqual(languageData); + expect(calendar._preferences).toEqual(preferences); + + // These no longer get set in the constructor + expect(calendar._internalStore).toEqual(undefined); + expect(calendar._internalWaiverStore).toEqual(undefined); + + // But are set after awaiting for initialization + await calendar.initializeStores(); expect(calendar._internalStore).toEqual({ flexible: 'store' }); @@ -99,7 +137,6 @@ describe('BaseCalendar.js', () => hours: '10:00' } }); - expect(calendar._preferences).toEqual(preferences); }); }); @@ -116,7 +153,7 @@ describe('BaseCalendar.js', () => expect(mocks.compute).toHaveBeenCalledTimes(0); }); - test('Should not update value because of rejection', () => + test('Should not update value because of rejection', async() => { mocks.compute = jest.spyOn(timeBalance, 'computeAllTimeBalanceUntilAsync').mockImplementation(() => Promise.reject()); const preferences = {view: 'day'}; @@ -388,20 +425,21 @@ describe('BaseCalendar.js', () => describe('_updateDayTotal()', () => { - test('Should not update when day has not ended', () => + test('Should not update when day has not ended', async() => { const newDate = new Date(); const key = generateKey(newDate.getFullYear(), newDate.getMonth(), newDate.getDate()); $('body').append(`
`); $(`#${key}`).append(''); const calendar = new ExtendedClass(getUserPreferences(), {}); + await calendar.initializeStores(); calendar._updateDayTotal(key); const dayTotalSpan = $('#' + key).parent().find('.day-total-cell span'); $(`#${key}`).remove(); expect(dayTotalSpan.text()).toBe(''); }); - test('Should update when day has ended', () => + test('Should update when day has ended', async() => { const flexibleStore = new Store({name: 'flexible-store'}); const newDate = new Date(); @@ -413,6 +451,7 @@ describe('BaseCalendar.js', () => $(`#${key}`).append(''); $(`#${key}`).append(''); const calendar = new ExtendedClass(getUserPreferences(), {}); + await calendar.initializeStores(); calendar._setStore(key, ['08:00', '16:30']); calendar._updateDayTotal(key); const dayTotalSpan = $('#' + key).parent().find('.day-total-cell span'); diff --git a/__tests__/__renderer__/classes/CalendarFactory.js b/__tests__/__renderer__/classes/CalendarFactory.js index 229576a4f..895734e4a 100644 --- a/__tests__/__renderer__/classes/CalendarFactory.js +++ b/__tests__/__renderer__/classes/CalendarFactory.js @@ -1,12 +1,19 @@ -import { CalendarFactory } from '../../../js/classes/CalendarFactory.js'; -import { FlexibleDayCalendar } from '../../../js/classes/FlexibleDayCalendar.js'; -import { FlexibleMonthCalendar } from '../../../js/classes/FlexibleMonthCalendar.js'; +import { CalendarFactory } from '../../../renderer/classes/CalendarFactory.js'; +import { FlexibleDayCalendar } from '../../../renderer/classes/FlexibleDayCalendar.js'; +import { FlexibleMonthCalendar } from '../../../renderer/classes/FlexibleMonthCalendar.js'; -jest.mock('../../../js/classes/BaseCalendar.js', () => +import { calendarApi } from '../../../renderer/preload-scripts/calendar-api.js'; + +// Mocked APIs from the preload script of the calendar window +window.mainApi = calendarApi; + +jest.mock('../../../renderer/classes/BaseCalendar.js', () => { class BaseCalendar { constructor() { } + + async reload() { } } return { BaseCalendar }; @@ -29,16 +36,21 @@ const { ipcRenderer } = require('electron'); describe('CalendarFactory', () => { - test('Should fail wrong view', () => + test('Should fail wrong view', async() => { - expect(() => CalendarFactory.getInstance({ + const promise = CalendarFactory.getInstance({ view: 'not_supported' - })).toThrow('Could not instantiate not_supported'); + }, {}); + expect(promise).toBeInstanceOf(Promise); + promise.then(() => {}).catch((reason) => + { + expect(reason).toBe('Could not instantiate not_supported'); + }); }); describe('FlexibleDayCalendar', () => { - test('Should fail wrong view', () => + test('Should fail wrong view', async() => { let calls = 0; const testCalendar = { @@ -49,14 +61,14 @@ describe('CalendarFactory', () => updatePreferences: () => { calls++; }, redraw: () => { calls++; }, }; - const calendar = CalendarFactory.getInstance({ + const calendar = await CalendarFactory.getInstance({ view: 'day', }, {}, testCalendar); expect(calendar).toEqual(testCalendar); expect(calls).toBe(3); }); - test('Should return new calendar without resizing', () => + test('Should return new calendar without resizing', async() => { let calls = 0; const testCalendar = { @@ -67,28 +79,28 @@ describe('CalendarFactory', () => updatePreferences: () => { calls++; }, redraw: () => { calls++; }, }; - const calendar = CalendarFactory.getInstance({ + const calendar = await CalendarFactory.getInstance({ view: 'day', }, {}, testCalendar); expect(calendar).toBeInstanceOf(FlexibleDayCalendar); expect(calls).toBe(0); }); - test('Should return new calendar without resizing', () => + test('Should return new calendar without resizing', async() => { let calls = 0; jest.spyOn(ipcRenderer, 'send').mockImplementation(() => { calls++; }); - const calendar = CalendarFactory.getInstance({ + const calendar = await CalendarFactory.getInstance({ view: 'day', }, {}, undefined); expect(calendar).toBeInstanceOf(FlexibleDayCalendar); expect(calls).toBe(0); }); - test('Should return new calendar with resizing', () => + test('Should return new calendar with resizing', async() => { let calls = 0; const testCalendar = { @@ -103,7 +115,7 @@ describe('CalendarFactory', () => { calls++; }); - const calendar = CalendarFactory.getInstance({ + const calendar = await CalendarFactory.getInstance({ view: 'day', }, {}, testCalendar); expect(calendar).toBeInstanceOf(FlexibleDayCalendar); @@ -113,7 +125,7 @@ describe('CalendarFactory', () => describe('FlexibleMonthCalendar', () => { - test('Should fail wrong view', () => + test('Should fail wrong view', async() => { let calls = 0; const testCalendar = { @@ -124,28 +136,28 @@ describe('CalendarFactory', () => updatePreferences: () => { calls++; }, redraw: () => { calls++; }, }; - const calendar = CalendarFactory.getInstance({ + const calendar = await CalendarFactory.getInstance({ view: 'month', }, {}, testCalendar); expect(calendar).toEqual(testCalendar); expect(calls).toBe(3); }); - test('Should return new calendar without resizing', () => + test('Should return new calendar without resizing', async() => { let calls = 0; jest.spyOn(ipcRenderer, 'send').mockImplementation(() => { calls++; }); - const calendar = CalendarFactory.getInstance({ + const calendar = await CalendarFactory.getInstance({ view: 'month', }, {}, undefined); expect(calendar).toBeInstanceOf(FlexibleMonthCalendar); expect(calls).toBe(0); }); - test('Should return new calendar with resizing', () => + test('Should return new calendar with resizing', async() => { let calls = 0; const testCalendar = { @@ -160,7 +172,7 @@ describe('CalendarFactory', () => { calls++; }); - const calendar = CalendarFactory.getInstance({ + const calendar = await CalendarFactory.getInstance({ view: 'month', }, {}, testCalendar); expect(calendar).toBeInstanceOf(FlexibleMonthCalendar); diff --git a/__tests__/__renderer__/classes/FlexibleDayCalendar.js b/__tests__/__renderer__/classes/FlexibleDayCalendar.js index 62d78f55f..9e0fdfd90 100644 --- a/__tests__/__renderer__/classes/FlexibleDayCalendar.js +++ b/__tests__/__renderer__/classes/FlexibleDayCalendar.js @@ -2,7 +2,8 @@ const Store = require('electron-store'); import { defaultPreferences } from '../../../js/user-preferences.js'; -import { CalendarFactory } from '../../../js/classes/CalendarFactory.js'; +import { CalendarFactory } from '../../../renderer/classes/CalendarFactory.js'; +import { calendarApi } from '../../../renderer/preload-scripts/calendar-api.js'; window.$ = window.jQuery = require('jquery'); @@ -18,6 +19,9 @@ window.$.fn.extend({ } }); +// APIs from the preload script of the calendar window +window.mainApi = calendarApi; + jest.mock('../../../renderer/i18n-translator.js', () => ({ translatePage: jest.fn().mockReturnThis(), getTranslationInLanguageData: jest.fn().mockReturnThis() @@ -25,13 +29,32 @@ jest.mock('../../../renderer/i18n-translator.js', () => ({ const languageData = {'language': 'en', 'data': {'dummy_string': 'dummy_string_translated'}}; +const flexibleStore = new Store({name: 'flexible-store'}); +const waivedWorkdays = new Store({name: 'waived-workdays'}); + +window.mainApi.getFlexibleStoreContents = () => { return new Promise((resolve) => { resolve(flexibleStore.store); }); }; +window.mainApi.getWaiverStoreContents = () => { return new Promise((resolve) => resolve(waivedWorkdays.store)); }; +window.mainApi.setFlexibleStoreData = (key, contents) => +{ + return new Promise((resolve) => + { + flexibleStore.set(key, contents); + resolve(true); + }); +}; +window.mainApi.deleteFlexibleStoreData = (key) => +{ + return new Promise((resolve) => + { + flexibleStore.delete(key); + resolve(true); + }); +}; + describe('FlexibleDayCalendar class Tests', () => { process.env.NODE_ENV = 'test'; - const flexibleStore = new Store({name: 'flexible-store'}); - const waivedWorkdays = new Store({name: 'waived-workdays'}); - flexibleStore.clear(); const regularEntries = { '2020-3-1': {'values': ['08:00', '12:00', '13:00', '17:00']}, @@ -51,7 +74,11 @@ describe('FlexibleDayCalendar class Tests', () => const testPreferences = defaultPreferences; testPreferences['view'] = 'day'; - const calendar = CalendarFactory.getInstance(testPreferences, languageData); + let calendar; + beforeAll(() => + { + CalendarFactory.getInstance(testPreferences, languageData).then((_c) => { calendar = _c; }); + }); test('FlexibleDayCalendar starts with today\'s date', () => { @@ -94,7 +121,7 @@ describe('FlexibleDayCalendar class Tests', () => expect(flexibleStore.size).toStrictEqual(2); }); - test('FlexibleDayCalendar internal waiver storage correct loading', () => + test('FlexibleDayCalendar internal waiver storage correct loading', async() => { // Waiver Store internally saves the human month index, but the calendar methods use JS month index expect(calendar._internalWaiverStore['2019-12-31']).toStrictEqual({ reason: 'New Year\'s eve', hours: '08:00' }); @@ -113,7 +140,7 @@ describe('FlexibleDayCalendar class Tests', () => expect(calendar._internalWaiverStore['2010-12-31']).toStrictEqual(undefined); expect(calendar._getWaiverStore(2010, 11, 31)).toStrictEqual(undefined); - calendar.loadInternalWaiveStore(); + await calendar.loadInternalWaiveStore(); expect(Object.keys(calendar._internalWaiverStore).length).toStrictEqual(4); @@ -142,7 +169,7 @@ describe('FlexibleDayCalendar class Tests', () => expect(calendar._getDayTotal(2010, 3, 1)).toStrictEqual(undefined); }); - test('getDayTotal on waived days', () => + test('getDayTotal on waived days', async() => { // Original dates expect(calendar._getDayTotal(2019, 11, 31)).toStrictEqual('08:00'); @@ -158,14 +185,14 @@ describe('FlexibleDayCalendar class Tests', () => }; waivedWorkdays.set(newWaivedEntry); - calendar.loadInternalWaiveStore(); + await calendar.loadInternalWaiveStore(); expect(calendar._getWaiverStore(2010, 2, 1)).toStrictEqual({ reason: 'Test', hours: '06:00' }); expect(calendar._getDayTotal(2010, 2, 1)).toStrictEqual('06:00'); // Clearing entry - back to undefined value waivedWorkdays.clear(); waivedWorkdays.set(waivedEntries); - calendar.loadInternalWaiveStore(); + await calendar.loadInternalWaiveStore(); expect(calendar._getDayTotal(2010, 2, 1)).toStrictEqual(undefined); }); }); @@ -297,15 +324,15 @@ describe('FlexibleDayCalendar class Tests', () => }); }); - test('FlexibleMonthCalendar to FlexibleDayCalendar', () => + test('FlexibleMonthCalendar to FlexibleDayCalendar', async() => { const testPreferences = defaultPreferences; testPreferences['view'] = 'month'; - let calendar = CalendarFactory.getInstance(testPreferences, languageData); + let calendar = await CalendarFactory.getInstance(testPreferences, languageData); expect(calendar.constructor.name).toBe('FlexibleMonthCalendar'); testPreferences['view'] = 'day'; - calendar = CalendarFactory.getInstance(testPreferences, languageData, calendar); + calendar = await CalendarFactory.getInstance(testPreferences, languageData, calendar); expect(calendar.constructor.name).toBe('FlexibleDayCalendar'); }); diff --git a/__tests__/__renderer__/classes/FlexibleMonthCalendar.js b/__tests__/__renderer__/classes/FlexibleMonthCalendar.js index 0b767f98e..2d4e26c26 100644 --- a/__tests__/__renderer__/classes/FlexibleMonthCalendar.js +++ b/__tests__/__renderer__/classes/FlexibleMonthCalendar.js @@ -3,7 +3,8 @@ const Store = require('electron-store'); import { defaultPreferences } from '../../../js/user-preferences.js'; -import { CalendarFactory } from '../../../js/classes/CalendarFactory.js'; +import { CalendarFactory } from '../../../renderer/classes/CalendarFactory.js'; +import { calendarApi } from '../../../renderer/preload-scripts/calendar-api.js'; window.$ = window.jQuery = require('jquery'); @@ -19,6 +20,9 @@ window.$.fn.extend({ } }); +// APIs from the preload script of the calendar window +window.mainApi = calendarApi; + jest.mock('../../../renderer/i18n-translator.js', () => ({ translatePage: jest.fn().mockReturnThis(), getTranslationInLanguageData: jest.fn().mockReturnThis() @@ -26,13 +30,32 @@ jest.mock('../../../renderer/i18n-translator.js', () => ({ const languageData = {'language': 'en', 'data': {'dummy_string': 'dummy_string_translated'}}; +const flexibleStore = new Store({name: 'flexible-store'}); +const waivedWorkdays = new Store({name: 'waived-workdays'}); + +window.mainApi.getFlexibleStoreContents = () => { return new Promise((resolve) => { resolve(flexibleStore.store); }); }; +window.mainApi.getWaiverStoreContents = () => { return new Promise((resolve) => resolve(waivedWorkdays.store)); }; +window.mainApi.setFlexibleStoreData = (key, contents) => +{ + return new Promise((resolve) => + { + flexibleStore.set(key, contents); + resolve(true); + }); +}; +window.mainApi.deleteFlexibleStoreData = (key) => +{ + return new Promise((resolve) => + { + flexibleStore.delete(key); + resolve(true); + }); +}; + describe('FlexibleMonthCalendar class Tests', () => { process.env.NODE_ENV = 'test'; - const flexibleStore = new Store({name: 'flexible-store'}); - const waivedWorkdays = new Store({name: 'waived-workdays'}); - flexibleStore.clear(); const regularEntries = { '2020-3-1': {'values': ['08:00', '12:00', '13:00', '17:00']}, @@ -51,7 +74,11 @@ describe('FlexibleMonthCalendar class Tests', () => const today = new Date(); const testPreferences = defaultPreferences; - const calendar = CalendarFactory.getInstance(testPreferences, languageData); + let calendar; + beforeAll(async() => + { + calendar = await CalendarFactory.getInstance(testPreferences, languageData); + }); test('FlexibleMonthCalendar starts with today\'s date', () => { @@ -94,7 +121,7 @@ describe('FlexibleMonthCalendar class Tests', () => expect(flexibleStore.size).toStrictEqual(2); }); - test('FlexibleMonthCalendar internal waiver storage correct loading', () => + test('FlexibleMonthCalendar internal waiver storage correct loading', async() => { // Waiver Store internally saves the human month index, but the calendar methods use JS month index expect(calendar._internalWaiverStore['2019-12-31']).toStrictEqual({ reason: 'New Year\'s eve', hours: '08:00' }); @@ -113,7 +140,7 @@ describe('FlexibleMonthCalendar class Tests', () => expect(calendar._internalWaiverStore['2010-12-31']).toStrictEqual(undefined); expect(calendar._getWaiverStore(2010, 11, 31)).toStrictEqual(undefined); - calendar.loadInternalWaiveStore(); + await calendar.loadInternalWaiveStore(); expect(Object.keys(calendar._internalWaiverStore).length).toStrictEqual(4); @@ -197,15 +224,15 @@ describe('FlexibleMonthCalendar class Tests', () => }); }); - test('FlexibleDayCalendar to FlexibleMonthCalendar', () => + test('FlexibleDayCalendar to FlexibleMonthCalendar', async() => { const testPreferences = defaultPreferences; testPreferences['view'] = 'day'; - let calendar = CalendarFactory.getInstance(testPreferences, languageData); + let calendar = await CalendarFactory.getInstance(testPreferences, languageData); expect(calendar.constructor.name).toBe('FlexibleDayCalendar'); testPreferences['view'] = 'month'; - calendar = CalendarFactory.getInstance(testPreferences, languageData, calendar); + calendar = await CalendarFactory.getInstance(testPreferences, languageData, calendar); expect(calendar.constructor.name).toBe('FlexibleMonthCalendar'); }); }); diff --git a/__tests__/__renderer__/workday-waiver-aux.js b/__tests__/__renderer__/workday-waiver-aux.js index 285023d0e..18c790907 100644 --- a/__tests__/__renderer__/workday-waiver-aux.js +++ b/__tests__/__renderer__/workday-waiver-aux.js @@ -3,6 +3,12 @@ import { formatDayId, displayWaiverWindow } from '../../renderer/workday-waiver-aux.js'; +// Mocking call +// TODO: find a better way to mock this or even really test it +window.mainApi = { + displayWaiverWindow: () => {} +}; + describe('Workday Waiver Aux', function() { process.env.NODE_ENV = 'test'; diff --git a/renderer/classes/BaseCalendar.js b/renderer/classes/BaseCalendar.js index d25237b0f..1c1ed0d67 100644 --- a/renderer/classes/BaseCalendar.js +++ b/renderer/classes/BaseCalendar.js @@ -33,6 +33,15 @@ class BaseCalendar throw Error('Please implement this.'); } + /** + * Loads internal stores. Required to start and used by the factory. + */ + async initializeStores() + { + await this.loadInternalStore(); + await this.loadInternalWaiveStore(); + } + /** * Returns a date object for which the all time balance will be calculated. * If current month, returns the actual day. If not, first day of following month. @@ -145,8 +154,7 @@ class BaseCalendar */ async reload() { - await this.loadInternalStore(); - await this.loadInternalWaiveStore(); + await this.initializeStores(); this.redraw(); } diff --git a/renderer/classes/CalendarFactory.js b/renderer/classes/CalendarFactory.js index 48ca59458..80771de38 100644 --- a/renderer/classes/CalendarFactory.js +++ b/renderer/classes/CalendarFactory.js @@ -10,7 +10,7 @@ class CalendarFactory const view = preferences['view']; if (view !== 'day' && view !== 'month') { - throw new Error(`Could not instantiate ${view}`); + return Promise.reject(`Could not instantiate ${view}`); } const constructorName = view === 'day' ? 'FlexibleDayCalendar': 'FlexibleMonthCalendar';