From 4db62d77d5d15a6745d116ae318c0a3ca326b4d1 Mon Sep 17 00:00:00 2001 From: Sebastian Barry <61334340+sebastianbarry@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:05:50 -0600 Subject: [PATCH 1/8] Test log --- www/__tests__/notifScheduler.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/www/__tests__/notifScheduler.test.ts b/www/__tests__/notifScheduler.test.ts index 8b74fe7ba..ddf52f155 100644 --- a/www/__tests__/notifScheduler.test.ts +++ b/www/__tests__/notifScheduler.test.ts @@ -267,6 +267,8 @@ describe('updateScheduledNotifs', () => { await updateScheduledNotifs(reminderSchemes, isScheduling, setIsScheduling, scheduledPromise); const scheduledNotifs = await getScheduledNotifs(isScheduling, scheduledPromise); + console.log('test log'); + expect(setIsScheduling).toHaveBeenCalledWith(true); expect(logDebug).toHaveBeenCalledWith('After cancelling, there are no scheduled notifications'); expect(logDebug).toHaveBeenCalledWith( From 877ce2a1e4a7988e32f76b9bb2f0e7836a1202b4 Mon Sep 17 00:00:00 2001 From: Sebastian Barry <61334340+sebastianbarry@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:18:10 -0600 Subject: [PATCH 2/8] Add more test logs --- www/__tests__/notifScheduler.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/www/__tests__/notifScheduler.test.ts b/www/__tests__/notifScheduler.test.ts index ddf52f155..ed8499bbd 100644 --- a/www/__tests__/notifScheduler.test.ts +++ b/www/__tests__/notifScheduler.test.ts @@ -264,10 +264,15 @@ describe('updateScheduledNotifs', () => { callback(arg); }); // call the function + console.log('test log: before calling updateScheduledNotifs', mockNotifs); + await updateScheduledNotifs(reminderSchemes, isScheduling, setIsScheduling, scheduledPromise); + + console.log('test log: after calling updateScheduledNotifs', mockNotifs); + const scheduledNotifs = await getScheduledNotifs(isScheduling, scheduledPromise); - console.log('test log'); + console.log('test log: after calling getScheduleNotifs', mockNotifs); expect(setIsScheduling).toHaveBeenCalledWith(true); expect(logDebug).toHaveBeenCalledWith('After cancelling, there are no scheduled notifications'); From 4b30e63d5210d180c5f4c8b853ca4ec57e3dd267 Mon Sep 17 00:00:00 2001 From: Sebastian Barry <61334340+sebastianbarry@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:26:54 -0600 Subject: [PATCH 3/8] More test logs --- www/__tests__/notifScheduler.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/__tests__/notifScheduler.test.ts b/www/__tests__/notifScheduler.test.ts index ed8499bbd..f58d4bd95 100644 --- a/www/__tests__/notifScheduler.test.ts +++ b/www/__tests__/notifScheduler.test.ts @@ -265,14 +265,17 @@ describe('updateScheduledNotifs', () => { }); // call the function console.log('test log: before calling updateScheduledNotifs', mockNotifs); + console.log('test log: before calling updateScheduledNotifs', isScheduling); await updateScheduledNotifs(reminderSchemes, isScheduling, setIsScheduling, scheduledPromise); console.log('test log: after calling updateScheduledNotifs', mockNotifs); + console.log('test log: after calling updateScheduledNotifs', isScheduling); const scheduledNotifs = await getScheduledNotifs(isScheduling, scheduledPromise); console.log('test log: after calling getScheduleNotifs', mockNotifs); + console.log('test log: after calling getScheduleNotifs', isScheduling); expect(setIsScheduling).toHaveBeenCalledWith(true); expect(logDebug).toHaveBeenCalledWith('After cancelling, there are no scheduled notifications'); From b54eac007b9b8051ae1049c71978ffa7301dd4e6 Mon Sep 17 00:00:00 2001 From: Sebastian Barry <61334340+sebastianbarry@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:42:10 -0600 Subject: [PATCH 4/8] More test logs --- www/js/splash/notifScheduler.ts | 6 ++++++ 1 file changed, 6 insertions(+) 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); }); From d7f25d9db4ed6eaef1c4874a0e2408baafa92099 Mon Sep 17 00:00:00 2001 From: Sebastian Barry <61334340+sebastianbarry@users.noreply.github.com> Date: Mon, 22 Jan 2024 16:22:32 -0600 Subject: [PATCH 5/8] Add test log for mocknotifs and scheduledNotifs --- www/__tests__/notifScheduler.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/__tests__/notifScheduler.test.ts b/www/__tests__/notifScheduler.test.ts index f58d4bd95..8608a4023 100644 --- a/www/__tests__/notifScheduler.test.ts +++ b/www/__tests__/notifScheduler.test.ts @@ -274,8 +274,9 @@ describe('updateScheduledNotifs', () => { const scheduledNotifs = await getScheduledNotifs(isScheduling, scheduledPromise); - console.log('test log: after calling getScheduleNotifs', mockNotifs); + console.log('test log: mockNotifs after calling getScheduleNotifs', mockNotifs); console.log('test log: after calling getScheduleNotifs', isScheduling); + console.log('test log: scheduleNotifs', scheduledNotifs); expect(setIsScheduling).toHaveBeenCalledWith(true); expect(logDebug).toHaveBeenCalledWith('After cancelling, there are no scheduled notifications'); From ec3477ec1b906527a8566db08bdb9d03a8f4b169 Mon Sep 17 00:00:00 2001 From: Sebastian Barry <61334340+sebastianbarry@users.noreply.github.com> Date: Mon, 22 Jan 2024 16:45:33 -0600 Subject: [PATCH 6/8] Correct the expected result to reflect the test --- www/__tests__/notifScheduler.test.ts | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/www/__tests__/notifScheduler.test.ts b/www/__tests__/notifScheduler.test.ts index 8608a4023..30708a649 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 @@ -264,27 +271,10 @@ describe('updateScheduledNotifs', () => { callback(arg); }); // call the function - console.log('test log: before calling updateScheduledNotifs', mockNotifs); - console.log('test log: before calling updateScheduledNotifs', isScheduling); - await updateScheduledNotifs(reminderSchemes, isScheduling, setIsScheduling, scheduledPromise); - - console.log('test log: after calling updateScheduledNotifs', mockNotifs); - console.log('test log: after calling updateScheduledNotifs', isScheduling); - const scheduledNotifs = await getScheduledNotifs(isScheduling, scheduledPromise); - console.log('test log: mockNotifs after calling getScheduleNotifs', mockNotifs); - console.log('test log: after calling getScheduleNotifs', isScheduling); - console.log('test log: scheduleNotifs', scheduledNotifs); - - 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).toEqual(expectedResultcheduleNotifs); }); it('should resolve without scheduling if notifications are already scheduled', async () => { From 691e69d55080802009d7962b7bd8604ba3162a16 Mon Sep 17 00:00:00 2001 From: Sebastian Barry <61334340+sebastianbarry@users.noreply.github.com> Date: Mon, 22 Jan 2024 17:17:25 -0600 Subject: [PATCH 7/8] Use arrayContaining --- www/__tests__/notifScheduler.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/__tests__/notifScheduler.test.ts b/www/__tests__/notifScheduler.test.ts index 30708a649..c3f5f60b2 100644 --- a/www/__tests__/notifScheduler.test.ts +++ b/www/__tests__/notifScheduler.test.ts @@ -274,7 +274,7 @@ describe('updateScheduledNotifs', () => { await updateScheduledNotifs(reminderSchemes, isScheduling, setIsScheduling, scheduledPromise); const scheduledNotifs = await getScheduledNotifs(isScheduling, scheduledPromise); - expect(scheduledNotifs).toEqual(expectedResultcheduleNotifs); + expect(scheduledNotifs).toEqual(expect.arrayContaining(expectedResultcheduleNotifs)); }); it('should resolve without scheduling if notifications are already scheduled', async () => { From aa68cb01ef2d36f3db085e6beeefc753c44121a8 Mon Sep 17 00:00:00 2001 From: Sebastian Barry <61334340+sebastianbarry@users.noreply.github.com> Date: Mon, 22 Jan 2024 17:36:47 -0600 Subject: [PATCH 8/8] Change the way to expect scheduledNotifs - Val contains a non-valid character (unicode U+202F) --- www/__tests__/notifScheduler.test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/www/__tests__/notifScheduler.test.ts b/www/__tests__/notifScheduler.test.ts index c3f5f60b2..a002171b4 100644 --- a/www/__tests__/notifScheduler.test.ts +++ b/www/__tests__/notifScheduler.test.ts @@ -245,10 +245,10 @@ describe('updateScheduledNotifs', () => { 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' }, + { 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 @@ -274,7 +274,11 @@ describe('updateScheduledNotifs', () => { await updateScheduledNotifs(reminderSchemes, isScheduling, setIsScheduling, scheduledPromise); const scheduledNotifs = await getScheduledNotifs(isScheduling, scheduledPromise); - expect(scheduledNotifs).toEqual(expect.arrayContaining(expectedResultcheduleNotifs)); + 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 () => {