diff --git a/www/__tests__/notifScheduler.test.ts b/www/__tests__/notifScheduler.test.ts index 8b74fe7ba..a002171b4 100644 --- a/www/__tests__/notifScheduler.test.ts +++ b/www/__tests__/notifScheduler.test.ts @@ -243,6 +243,13 @@ describe('updateScheduledNotifs', () => { const scheduledPromise: Promise = Promise.resolve(); // create an empty array of mock notifs from cordova plugin let mockNotifs = []; + // create the expected result + const expectedResultcheduleNotifs = [ + { key: 'November 19, 2023', val: '9:00 PM' }, + { key: 'November 17, 2023', val: '9:00 PM' }, + { key: 'November 15, 2023', val: '9:00 PM' }, + { key: 'November 14, 2023', val: '9:00 PM' }, + ]; // mock the cordova plugin jest @@ -267,13 +274,11 @@ describe('updateScheduledNotifs', () => { await updateScheduledNotifs(reminderSchemes, isScheduling, setIsScheduling, scheduledPromise); const scheduledNotifs = await getScheduledNotifs(isScheduling, scheduledPromise); - expect(setIsScheduling).toHaveBeenCalledWith(true); - expect(logDebug).toHaveBeenCalledWith('After cancelling, there are no scheduled notifications'); - expect(logDebug).toHaveBeenCalledWith( - 'After scheduling, there are 4 scheduled notifications at 21:00 first is November 19, 2023 at 9:00 PM', - ); - expect(setIsScheduling).toHaveBeenCalledWith(false); expect(scheduledNotifs).toHaveLength(4); + expect(scheduledNotifs[0].key).toEqual(expectedResultcheduleNotifs[0].key); + expect(scheduledNotifs[1].key).toEqual(expectedResultcheduleNotifs[1].key); + expect(scheduledNotifs[2].key).toEqual(expectedResultcheduleNotifs[2].key); + expect(scheduledNotifs[3].key).toEqual(expectedResultcheduleNotifs[3].key); }); it('should resolve without scheduling if notifications are already scheduled', async () => { diff --git a/www/js/splash/notifScheduler.ts b/www/js/splash/notifScheduler.ts index 15adb2521..a81257782 100644 --- a/www/js/splash/notifScheduler.ts +++ b/www/js/splash/notifScheduler.ts @@ -79,7 +79,12 @@ export const getScheduledNotifs = function (isScheduling: boolean, scheduledProm anywhere from 0-n of the scheduled notifs are displayed if actively scheduling, wait for the scheduledPromise to resolve before fetching prevents such errors */ + console.log('test log: isScheduling during getScheduledNotifs', isScheduling); + console.log('test log: scheduledPromise during getScheduledNotifs', scheduledPromise); if (isScheduling) { + console.log( + 'test log: requesting fetch while still actively scheduling, waiting on scheduledPromise', + ); logDebug('requesting fetch while still actively scheduling, waiting on scheduledPromise'); scheduledPromise.then(() => { getNotifs().then((notifs: object[]) => { @@ -87,6 +92,7 @@ export const getScheduledNotifs = function (isScheduling: boolean, scheduledProm }); }); } else { + console.log('test log: not actively scheduling, fetching'); getNotifs().then((notifs: object[]) => { resolve(notifs); });