Skip to content

Commit 41d3c56

Browse files
committed
refactor: handler enhancements
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent ca25646 commit 41d3c56

3 files changed

Lines changed: 78 additions & 3 deletions

File tree

src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/utils/notifications/handlers/default.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,78 @@ describe('renderer/utils/notifications/handlers/default.ts', () => {
5454
expect(defaultHandler.iconColor(subject)).toBe(expected);
5555
});
5656
});
57+
58+
describe('formattedNotificationType', () => {
59+
it('formats state and type with proper casing and spacing', () => {
60+
const notification = partialMockNotification({
61+
title: 'Sample',
62+
type: 'PullRequest',
63+
state: 'open',
64+
});
65+
66+
expect(defaultHandler.formattedNotificationType(notification)).toBe(
67+
'Open Pull Request',
68+
);
69+
});
70+
71+
it('handles missing state (null) gracefully', () => {
72+
const notification = partialMockNotification({
73+
title: 'Sample',
74+
type: 'Issue',
75+
state: null,
76+
});
77+
78+
expect(defaultHandler.formattedNotificationType(notification)).toBe(
79+
'Issue',
80+
);
81+
});
82+
});
83+
84+
describe('formattedNotificationNumber', () => {
85+
it('returns formatted number when present', () => {
86+
const notification = partialMockNotification({
87+
title: 'Sample',
88+
type: 'Issue',
89+
state: 'open',
90+
});
91+
notification.subject.number = 42;
92+
expect(defaultHandler.formattedNotificationNumber(notification)).toBe(
93+
'#42',
94+
);
95+
});
96+
97+
it('returns empty string when number absent', () => {
98+
const notification = partialMockNotification({
99+
title: 'Sample',
100+
type: 'Issue',
101+
state: 'open',
102+
});
103+
expect(defaultHandler.formattedNotificationNumber(notification)).toBe('');
104+
});
105+
});
106+
107+
describe('formattedNotificationTitle', () => {
108+
it('appends number in brackets when present', () => {
109+
const notification = partialMockNotification({
110+
title: 'Fix bug',
111+
type: 'Issue',
112+
state: 'open',
113+
});
114+
notification.subject.number = 101;
115+
expect(defaultHandler.formattedNotificationTitle(notification)).toBe(
116+
'Fix bug [#101]',
117+
);
118+
});
119+
120+
it('returns title unchanged when number missing', () => {
121+
const notification = partialMockNotification({
122+
title: 'Improve docs',
123+
type: 'Issue',
124+
state: 'open',
125+
});
126+
expect(defaultHandler.formattedNotificationTitle(notification)).toBe(
127+
'Improve docs',
128+
);
129+
});
130+
});
57131
});

src/renderer/utils/notifications/handlers/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ export function formatForDisplay(text: string[]): string {
3636
.replace(/\w+/g, (word) => {
3737
// Convert to proper case (capitalize first letter of each word)
3838
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
39-
});
39+
})
40+
.trim();
4041
}

0 commit comments

Comments
 (0)