Skip to content

Commit c4da59a

Browse files
committed
Merge branch 'main' into refactor/fetch-issue-graphql
Signed-off-by: Adam Setch <[email protected]>
2 parents 021c22c + 5e05265 commit c4da59a

File tree

10 files changed

+214
-59
lines changed

10 files changed

+214
-59
lines changed

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
createPartialMockNotification,
44
} from '../../../__mocks__/notifications-mocks';
55
import { mockSettings } from '../../../__mocks__/state-mocks';
6-
import type { Link } from '../../../types';
6+
import { IconColor, type Link } from '../../../types';
77
import type { Notification } from '../../../typesGitHub';
88
import { checkSuiteHandler, getCheckSuiteAttributes } from './checkSuite';
99

@@ -196,6 +196,38 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
196196
).toBe('CheckIcon');
197197
});
198198

199+
it('iconColor', () => {
200+
expect(
201+
checkSuiteHandler.iconColor(
202+
createMockSubject({ type: 'CheckSuite', state: 'success' }),
203+
),
204+
).toBe(IconColor.GREEN);
205+
206+
expect(
207+
checkSuiteHandler.iconColor(
208+
createMockSubject({ type: 'CheckSuite', state: 'failure' }),
209+
),
210+
).toBe(IconColor.RED);
211+
212+
expect(
213+
checkSuiteHandler.iconColor(
214+
createMockSubject({ type: 'CheckSuite', state: 'cancelled' }),
215+
),
216+
).toBe(IconColor.GRAY);
217+
218+
expect(
219+
checkSuiteHandler.iconColor(
220+
createMockSubject({ type: 'CheckSuite', state: 'skipped' }),
221+
),
222+
).toBe(IconColor.GRAY);
223+
224+
expect(
225+
checkSuiteHandler.iconColor(
226+
createMockSubject({ type: 'CheckSuite', state: null }),
227+
),
228+
).toBe(IconColor.GRAY);
229+
});
230+
199231
it('defaultUrl', () => {
200232
const mockHtmlUrl =
201233
'https://github.com/gitify-app/notifications-test' as Link;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import {
1212
import type {
1313
GitifyCheckSuiteStatus,
1414
GitifySubject,
15+
IconColor,
1516
Link,
1617
SettingsState,
1718
} from '../../../types';
1819
import type { Notification, Subject } from '../../../typesGitHub';
1920
import { actionsURL } from '../../helpers';
20-
import { DefaultHandler } from './default';
21+
import { DefaultHandler, defaultHandler } from './default';
2122

2223
export interface CheckSuiteAttributes {
2324
workflowName: string;
@@ -62,6 +63,17 @@ class CheckSuiteHandler extends DefaultHandler {
6263
}
6364
}
6465

66+
iconColor(subject: Subject): IconColor {
67+
switch (subject.state as GitifyCheckSuiteStatus) {
68+
case 'SUCCESS':
69+
return IconColor.GREEN;
70+
case 'FAILURE':
71+
return IconColor.RED;
72+
default:
73+
return defaultHandler.iconColor(subject);
74+
}
75+
}
76+
6577
defaultUrl(notification: Notification): Link {
6678
return getCheckSuiteUrl(notification);
6779
}

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,17 @@ describe('renderer/utils/notifications/handlers/default.ts', () => {
3636
});
3737

3838
describe('iconColor', () => {
39-
const cases: Array<[GitifyNotificationState | null, IconColor]> = [
40-
['OPEN' as GitifyNotificationState, IconColor.GREEN],
41-
['REOPENED' as GitifyNotificationState, IconColor.GREEN],
42-
['ANSWERED' as GitifyNotificationState, IconColor.GREEN],
43-
['SUCCESS' as GitifyNotificationState, IconColor.GREEN],
44-
['CLOSED' as GitifyNotificationState, IconColor.RED],
45-
['FAILURE' as GitifyNotificationState, IconColor.RED],
46-
['COMPLETED' as GitifyNotificationState, IconColor.PURPLE],
47-
['RESOLVED' as GitifyNotificationState, IconColor.PURPLE],
48-
['MERGED' as GitifyNotificationState, IconColor.PURPLE],
49-
['NOT_PLANNED' as GitifyNotificationState, IconColor.GRAY],
50-
['DRAFT' as GitifyNotificationState, IconColor.GRAY],
51-
['SKIPPED' as GitifyNotificationState, IconColor.GRAY],
52-
['CANCELLED' as GitifyNotificationState, IconColor.GRAY],
53-
['unknown' as GitifyNotificationState, IconColor.GRAY],
54-
[null, IconColor.GRAY],
55-
[undefined, IconColor.GRAY],
56-
];
57-
58-
it.each(cases)('returns correct color for state %s', (state, expected) => {
59-
const subject = createMockSubject({ state });
60-
expect(defaultHandler.iconColor(subject)).toBe(expected);
39+
it('returns GRAY for any state (fallback behavior)', () => {
40+
const states: Array<StateType | null | undefined> = [
41+
'unknown' as StateType,
42+
null,
43+
undefined,
44+
];
45+
46+
states.forEach((state) => {
47+
const subject = createMockSubject({ state });
48+
expect(defaultHandler.iconColor(subject)).toBe(IconColor.GRAY);
49+
});
6150
});
6251
});
6352

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,8 @@ export class DefaultHandler implements NotificationTypeHandler {
2323
return QuestionIcon;
2424
}
2525

26-
iconColor(subject: Subject): IconColor {
27-
switch (subject.state) {
28-
case 'OPEN':
29-
case 'REOPENED':
30-
case 'ANSWERED':
31-
case 'SUCCESS':
32-
return IconColor.GREEN;
33-
case 'CLOSED':
34-
case 'FAILURE':
35-
return IconColor.RED;
36-
case 'COMPLETED':
37-
case 'RESOLVED':
38-
case 'MERGED':
39-
return IconColor.PURPLE;
40-
default:
41-
return IconColor.GRAY;
42-
}
26+
iconColor(_subject: Subject): IconColor {
27+
return IconColor.GRAY;
4328
}
4429

4530
formattedNotificationType(notification: Notification): string {

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
createPartialMockNotification,
77
} from '../../../__mocks__/notifications-mocks';
88
import { mockSettings } from '../../../__mocks__/state-mocks';
9-
import type { GitifySubject, Link } from '../../../types';
9+
import { type GitifySubject, IconColor, type Link } from '../../../types';
1010
import type { Notification, Owner, Repository } from '../../../typesGitHub';
1111
import type {
1212
AuthorFieldsFragment,
@@ -313,6 +313,38 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
313313
).toBe('DiscussionClosedIcon');
314314
});
315315

316+
it('iconColor', () => {
317+
expect(
318+
discussionHandler.iconColor(
319+
createMockSubject({ type: 'Discussion', state: 'ANSWERED' }),
320+
),
321+
).toBe(IconColor.GREEN);
322+
323+
expect(
324+
discussionHandler.iconColor(
325+
createMockSubject({ type: 'Discussion', state: 'RESOLVED' }),
326+
),
327+
).toBe(IconColor.PURPLE);
328+
329+
expect(
330+
discussionHandler.iconColor(
331+
createMockSubject({ type: 'Discussion', state: 'DUPLICATE' }),
332+
),
333+
).toBe(IconColor.GRAY);
334+
335+
expect(
336+
discussionHandler.iconColor(
337+
createMockSubject({ type: 'Discussion', state: 'OUTDATED' }),
338+
),
339+
).toBe(IconColor.GRAY);
340+
341+
expect(
342+
discussionHandler.iconColor(
343+
createMockSubject({ type: 'Discussion', state: 'OPEN' }),
344+
),
345+
).toBe(IconColor.GRAY);
346+
});
347+
316348
it('defaultUrl', () => {
317349
const mockHtmlUrl =
318350
'https://github.com/gitify-app/notifications-test' as Link;

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ import {
1010

1111
import { differenceInMilliseconds } from 'date-fns';
1212

13-
import type {
14-
GitifyDiscussionState,
15-
GitifySubject,
16-
Link,
17-
SettingsState,
13+
import {
14+
type GitifyDiscussionState,
15+
type GitifySubject,
16+
IconColor,
17+
type Link,
18+
type SettingsState,
1819
} from '../../../types';
1920
import type { Notification, Subject } from '../../../typesGitHub';
2021
import { fetchDiscussionByNumber } from '../../api/client';
2122
import type {
2223
CommentFieldsFragment,
2324
FetchDiscussionByNumberQuery,
2425
} from '../../api/graphql/generated/graphql';
25-
import { DefaultHandler } from './default';
26+
import { DefaultHandler, defaultHandler } from './default';
2627
import { getNotificationAuthor } from './utils';
2728

2829
type DiscussionComment = NonNullable<
@@ -81,7 +82,7 @@ class DiscussionHandler extends DefaultHandler {
8182
}
8283

8384
iconType(subject: Subject): FC<OcticonProps> | null {
84-
switch (subject.state) {
85+
switch (subject.state as GitifyDiscussionState) {
8586
case 'DUPLICATE':
8687
return DiscussionDuplicateIcon;
8788
case 'OUTDATED':
@@ -93,6 +94,17 @@ class DiscussionHandler extends DefaultHandler {
9394
}
9495
}
9596

97+
iconColor(subject: Subject): IconColor {
98+
switch (subject.state as GitifyDiscussionState) {
99+
case 'ANSWERED':
100+
return IconColor.GREEN;
101+
case 'RESOLVED':
102+
return IconColor.PURPLE;
103+
default:
104+
return defaultHandler.iconColor(subject);
105+
}
106+
}
107+
96108
defaultUrl(notification: Notification): Link {
97109
const url = new URL(notification.repository.html_url);
98110
url.pathname += '/discussions';

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../../../__mocks__/notifications-mocks';
88
import { mockSettings } from '../../../__mocks__/state-mocks';
99
import { createPartialMockUser } from '../../../__mocks__/user-mocks';
10-
import type { GitifySubject, Link } from '../../../types';
10+
import { type GitifySubject, IconColor, type Link } from '../../../types';
1111
import type { Notification } from '../../../typesGitHub';
1212
import type { FetchIssueByNumberQuery } from '../../api/graphql/generated/graphql';
1313
import { issueHandler } from './issue';
@@ -423,6 +423,44 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
423423
).toBe('IssueReopenedIcon');
424424
});
425425

426+
it('iconColor', () => {
427+
expect(
428+
issueHandler.iconColor(
429+
createMockSubject({ type: 'Issue', state: 'OPEN' }),
430+
),
431+
).toBe(IconColor.GREEN);
432+
433+
expect(
434+
issueHandler.iconColor(
435+
createMockSubject({ type: 'Issue', state: 'REOPENED' }),
436+
),
437+
).toBe(IconColor.GREEN);
438+
439+
expect(
440+
issueHandler.iconColor(
441+
createMockSubject({ type: 'Issue', state: 'CLOSED' }),
442+
),
443+
).toBe(IconColor.RED);
444+
445+
expect(
446+
issueHandler.iconColor(
447+
createMockSubject({ type: 'Issue', state: 'COMPLETED' }),
448+
),
449+
).toBe(IconColor.PURPLE);
450+
451+
expect(
452+
issueHandler.iconColor(
453+
createMockSubject({ type: 'Issue', state: 'DRAFT' }),
454+
),
455+
).toBe(IconColor.GRAY);
456+
457+
expect(
458+
issueHandler.iconColor(
459+
createMockSubject({ type: 'Issue', state: 'NOT_PLANNED' }),
460+
),
461+
).toBe(IconColor.GRAY);
462+
});
463+
426464
it('defaultUrl', () => {
427465
const mockHtmlUrl =
428466
'https://github.com/gitify-app/notifications-test' as Link;

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import type {
1414
Link,
1515
SettingsState,
1616
} from '../../../types';
17+
import { IconColor } from '../../../types';
1718
import type { Notification, Subject } from '../../../typesGitHub';
1819
import { fetchIssueByNumber } from '../../api/client';
19-
import { DefaultHandler } from './default';
20+
import { DefaultHandler, defaultHandler } from './default';
2021
import { getNotificationAuthor } from './utils';
2122

2223
class IssueHandler extends DefaultHandler {
@@ -64,6 +65,20 @@ class IssueHandler extends DefaultHandler {
6465
}
6566
}
6667

68+
iconColor(subject: Subject): IconColor {
69+
switch (subject.state) {
70+
case 'open':
71+
case 'reopened':
72+
return IconColor.GREEN;
73+
case 'closed':
74+
return IconColor.RED;
75+
case 'completed':
76+
return IconColor.PURPLE;
77+
default:
78+
return defaultHandler.iconColor(subject);
79+
}
80+
}
81+
6782
defaultUrl(notification: Notification): Link {
6883
const url = new URL(notification.repository.html_url);
6984
url.pathname += '/issues';

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../../../__mocks__/notifications-mocks';
88
import { mockSettings } from '../../../__mocks__/state-mocks';
99
import { createPartialMockUser } from '../../../__mocks__/user-mocks';
10-
import type { GitifySubject, Link } from '../../../types';
10+
import { type GitifySubject, IconColor, type Link } from '../../../types';
1111
import type { Notification } from '../../../typesGitHub';
1212
import type {
1313
FetchPullRequestByNumberQuery,
@@ -554,6 +554,32 @@ describe('renderer/utils/notifications/handlers/pullRequest.ts', () => {
554554
).toBe('GitMergeIcon');
555555
});
556556

557+
it('iconColor', () => {
558+
expect(
559+
pullRequestHandler.iconColor(
560+
createMockSubject({ type: 'PullRequest', state: 'OPEN' }),
561+
),
562+
).toBe(IconColor.GREEN);
563+
564+
expect(
565+
pullRequestHandler.iconColor(
566+
createMockSubject({ type: 'PullRequest', state: 'CLOSED' }),
567+
),
568+
).toBe(IconColor.RED);
569+
570+
expect(
571+
pullRequestHandler.iconColor(
572+
createMockSubject({ type: 'PullRequest', state: 'MERGED' }),
573+
),
574+
).toBe(IconColor.PURPLE);
575+
576+
expect(
577+
pullRequestHandler.iconColor(
578+
createMockSubject({ type: 'PullRequest', state: 'DRAFT' }),
579+
),
580+
).toBe(IconColor.GRAY);
581+
});
582+
557583
it('defaultUrl', () => {
558584
const mockHtmlUrl =
559585
'https://github.com/gitify-app/notifications-test' as Link;

0 commit comments

Comments
 (0)