Skip to content

Commit ca25646

Browse files
committed
refactor: handler enhancements
Signed-off-by: Adam Setch <[email protected]>
1 parent cbb9e9e commit ca25646

File tree

6 files changed

+29
-35
lines changed

6 files changed

+29
-35
lines changed

src/renderer/components/notifications/NotificationRow.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export const NotificationRow: FC<INotificationRow> = ({
7070
};
7171

7272
const handler = createNotificationHandler(notification);
73-
7473
const NotificationIcon = handler.iconType(notification.subject);
7574
const iconColor = handler.iconColor(notification.subject);
7675
const notificationType = handler.formattedNotificationType(notification);

src/renderer/utils/helpers.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
} from './api/__mocks__/response-mocks';
1717
import * as apiRequests from './api/request';
1818
import {
19-
formatForDisplay,
2019
generateGitHubWebUrl,
2120
generateNotificationReferrerId,
2221
getChevronDetails,
@@ -517,22 +516,6 @@ describe('renderer/utils/helpers.ts', () => {
517516
});
518517
});
519518

520-
describe('formatting', () => {
521-
it('formatForDisplay', () => {
522-
expect(formatForDisplay(null)).toBe('');
523-
expect(formatForDisplay([])).toBe('');
524-
expect(formatForDisplay(['open', 'PullRequest'])).toBe(
525-
'Open Pull Request',
526-
);
527-
expect(formatForDisplay(['OUTDATED', 'Discussion'])).toBe(
528-
'Outdated Discussion',
529-
);
530-
expect(formatForDisplay(['not_planned', 'Issue'])).toBe(
531-
'Not Planned Issue',
532-
);
533-
});
534-
});
535-
536519
describe('getChevronDetails', () => {
537520
it('should return correct chevron details', () => {
538521
expect(getChevronDetails(true, true, 'account')).toEqual({

src/renderer/utils/helpers.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,6 @@ export async function generateGitHubWebUrl(
171171
return url.toString() as Link;
172172
}
173173

174-
export function formatForDisplay(text: string[]): string {
175-
if (!text) {
176-
return '';
177-
}
178-
179-
return text
180-
.join(' ')
181-
.replace(/([a-z])([A-Z])/g, '$1 $2') // Add space between lowercase character followed by an uppercase character
182-
.replace(/_/g, ' ') // Replace underscores with spaces
183-
.replace(/\w+/g, (word) => {
184-
// Convert to proper case (capitalize first letter of each word)
185-
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
186-
});
187-
}
188-
189174
export function getChevronDetails(
190175
hasNotifications: boolean,
191176
isVisible: boolean,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import type {
1111
Subject,
1212
SubjectType,
1313
} from '../../../typesGitHub';
14-
import { formatForDisplay } from '../../helpers';
1514
import type { NotificationTypeHandler } from './types';
15+
import { formatForDisplay } from './utils';
1616

1717
export class DefaultHandler implements NotificationTypeHandler {
1818
type?: SubjectType;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { partialMockUser } from '../../../__mocks__/partial-mocks';
2-
import { getSubjectUser } from './utils';
2+
import { formatForDisplay, getSubjectUser } from './utils';
33

44
describe('renderer/utils/notifications/handlers/utils.ts', () => {
55
describe('getSubjectUser', () => {
@@ -33,4 +33,16 @@ describe('renderer/utils/notifications/handlers/utils.ts', () => {
3333
});
3434
});
3535
});
36+
37+
it('formatForDisplay', () => {
38+
expect(formatForDisplay(null)).toBe('');
39+
expect(formatForDisplay([])).toBe('');
40+
expect(formatForDisplay(['open', 'PullRequest'])).toBe('Open Pull Request');
41+
expect(formatForDisplay(['OUTDATED', 'Discussion'])).toBe(
42+
'Outdated Discussion',
43+
);
44+
expect(formatForDisplay(['not_planned', 'Issue'])).toBe(
45+
'Not Planned Issue',
46+
);
47+
});
3648
});

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,18 @@ export function getSubjectUser(users: User[]): SubjectUser {
2323

2424
return subjectUser;
2525
}
26+
27+
export function formatForDisplay(text: string[]): string {
28+
if (!text) {
29+
return '';
30+
}
31+
32+
return text
33+
.join(' ')
34+
.replace(/([a-z])([A-Z])/g, '$1 $2') // Add space between lowercase character followed by an uppercase character
35+
.replace(/_/g, ' ') // Replace underscores with spaces
36+
.replace(/\w+/g, (word) => {
37+
// Convert to proper case (capitalize first letter of each word)
38+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
39+
});
40+
}

0 commit comments

Comments
 (0)