Skip to content

Commit

Permalink
βŒπŸ™ Fix codecov-test failure - β€ΌοΈπŸ“… Rewrite - notifScheduler.ts (#1123)
Browse files Browse the repository at this point in the history
* Test log

* Add more test logs

* More test logs

* More test logs

* Add test log for mocknotifs and scheduledNotifs

* Correct the expected result to reflect the test

* Use arrayContaining

* Change the way to expect scheduledNotifs - Val contains a non-valid character (unicode U+202F)
  • Loading branch information
sebastianbarry authored Jan 23, 2024
1 parent 8f85e05 commit 3cbb5f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 11 additions & 6 deletions www/__tests__/notifScheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ describe('updateScheduledNotifs', () => {
const scheduledPromise: Promise<any> = 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
Expand All @@ -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 () => {
Expand Down
6 changes: 6 additions & 0 deletions www/js/splash/notifScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,20 @@ 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[]) => {
resolve(notifs);
});
});
} else {
console.log('test log: not actively scheduling, fetching');
getNotifs().then((notifs: object[]) => {
resolve(notifs);
});
Expand Down

0 comments on commit 3cbb5f0

Please sign in to comment.