-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added notification threshold setting, badge count and missing test ca…
…ses, ongoing refactoring
- Loading branch information
ransome1
committed
Oct 21, 2023
1 parent
b30c8fd
commit 8848b0b
Showing
41 changed files
with
389 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
|
||
2023-10-20 Line 1 rec:1d due:2023-10-21 | ||
2023-10-20 Line 1 rec:w due:2023-10-27 | ||
2023-10-20 Line 1 rec:2m due:2023-12-20 | ||
2023-10-20 Line 1 rec:+1d due:2023-10-22 | ||
2023-10-20 Line 1 rec:7w due:2023-12-08 | ||
2023-10-21 Line 1 rec:1d due:2023-10-22 | ||
2023-10-21 Line 1 rec:w due:2023-10-28 | ||
2023-10-21 Line 1 rec:2m due:2023-12-21 | ||
2023-10-21 Line 1 rec:+1d due:2023-10-23 | ||
2023-10-21 Line 1 rec:7w due:2023-12-09 | ||
2023-07-21 Line 1 due:2023-07-24 rec:+1b | ||
2021-01-01 taxes are due in one year t:2022-03-30 due:2022-04-30 rec:+1y | ||
2023-10-20 Water plants @home +quick due:2023-10-27 t:2023-10-17 rec:1w | ||
2023-10-20 Line 1 rec:+1d t:2023-09-20 due:2023-10-21 | ||
(A) 2023-10-20 Line 1 rec:1d pri:A due:2023-10-21 | ||
2023-10-21 Water plants @home +quick due:2023-10-28 t:2023-10-18 rec:1w | ||
2023-10-21 Line 1 rec:+1d t:2023-09-20 due:2023-10-22 | ||
(A) 2023-10-21 Line 1 rec:1d pri:A due:2023-10-22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
Line 1 | ||
Edited line | ||
New line | ||
2023-10-20 New line with creation date | ||
New line with relative threshold date t:June 3rd, 2005 | ||
Multi line 1Multi line 2Multi line 3 | ||
Updated line | ||
Append 1 | ||
Append 2 | ||
New line with relative threshold date t:June 3rd, 2005 | ||
Line4 | ||
Line5 | ||
Line6 | ||
Multi line 1Multi line 2Multi line 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { handleNotification, sendNotification } from '../../main/modules/HandleNotification'; | ||
import { configStorage } from '../../main/config'; | ||
import { badge } from '../../main/modules/TodoObject/CreateTodoObjects'; | ||
import { Notification } from 'electron'; | ||
import dayjs from 'dayjs'; | ||
|
||
const dateToday = dayjs(); | ||
const dateTodayString = dateToday.format('YYYY-MM-DD'); | ||
const dateTomorrowString = dateToday.add(1, 'day').format('YYYY-MM-DD'); | ||
const dateInSevenDaysString = dateToday.add(7, 'day').format('YYYY-MM-DD'); | ||
const dateInTwentyDaysString = dateToday.add(20, 'day').format('YYYY-MM-DD'); | ||
|
||
jest.mock('../../main/modules/TodoObject/CreateTodoObjects', () => ({ | ||
badge: { | ||
count: 0, | ||
}, | ||
})); | ||
|
||
jest.mock('electron', () => ({ | ||
Notification: jest.fn().mockImplementation(() => ({ | ||
show: jest.fn(), | ||
})), | ||
})); | ||
|
||
jest.mock('../../main/config', () => ({ | ||
configStorage: { | ||
get: jest.fn((key) => { | ||
if (key === 'notificationsAllowed') { | ||
return true; | ||
} else if (key === 'notificationThreshold') { | ||
return 10; | ||
} | ||
}), | ||
set: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('Notifications', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('should push notification for a todo due today', () => { | ||
handleNotification(1, dateTodayString, 'Sample todo due:today', badge); | ||
expect(Notification).toHaveBeenCalledWith({ title: 'Due today', body: 'Sample todo due:today', silent: false }); | ||
expect(badge.count).toBe(1); | ||
}); | ||
|
||
test('should push notification for a todo due tomorrow', () => { | ||
handleNotification(2, dateTomorrowString, 'Sample todo due:tomorrow', badge); | ||
expect(Notification).toHaveBeenCalledWith({ title: 'Due tomorrow', body: 'Sample todo due:tomorrow', silent: false }); | ||
expect(badge.count).toBe(2); | ||
}); | ||
|
||
test('should push notification for a todo due in 7 days', () => { | ||
handleNotification(3, dateInSevenDaysString, 'Sample todo due:in 7 days', badge); | ||
expect(Notification).toHaveBeenCalledWith({ title: 'Due in 7 days', body: 'Sample todo due:in 7 days', silent: false }); | ||
expect(badge.count).toBe(3); | ||
}); | ||
|
||
test('should NOT push notification for a todo due in 20 days', () => { | ||
handleNotification(4, dateInTwentyDaysString, 'Sample todo due:in 20 days', badge); | ||
expect(Notification).not.toHaveBeenCalled(); | ||
expect(badge.count).toBe(3); | ||
}); | ||
|
||
test('should NOT handle notification when not allowed', () => { | ||
const configStorageGetMock = jest.fn((key) => { | ||
if (key === 'notificationsAllowed') { | ||
return false; | ||
} | ||
}); | ||
configStorage.get = configStorageGetMock; | ||
handleNotification(5, '2023-10-20', 'Sample todo', badge); | ||
expect(configStorageGetMock).toHaveBeenCalledWith('notificationsAllowed'); | ||
expect(Notification).not.toHaveBeenCalled(); | ||
expect(badge.count).toBe(3); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.