Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/renderer/utils/notifications/handlers/checkSuite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createPartialMockNotification,
} from '../../../__mocks__/notifications-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import { IconColor } from '../../../types';
import { checkSuiteHandler, getCheckSuiteAttributes } from './checkSuite';

describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
Expand Down Expand Up @@ -182,6 +183,38 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
).toBe('CheckIcon');
});

it('iconColor', () => {
expect(
checkSuiteHandler.iconColor(
createMockSubject({ type: 'CheckSuite', state: 'success' }),
),
).toBe(IconColor.GREEN);

expect(
checkSuiteHandler.iconColor(
createMockSubject({ type: 'CheckSuite', state: 'failure' }),
),
).toBe(IconColor.RED);

expect(
checkSuiteHandler.iconColor(
createMockSubject({ type: 'CheckSuite', state: 'cancelled' }),
),
).toBe(IconColor.GRAY);

expect(
checkSuiteHandler.iconColor(
createMockSubject({ type: 'CheckSuite', state: 'skipped' }),
),
).toBe(IconColor.GRAY);

expect(
checkSuiteHandler.iconColor(
createMockSubject({ type: 'CheckSuite', state: null }),
),
).toBe(IconColor.GRAY);
});

describe('getCheckSuiteState', () => {
it('cancelled check suite state', async () => {
const mockNotification = createPartialMockNotification({
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/utils/notifications/handlers/checkSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import {
} from '@primer/octicons-react';

import type { SettingsState } from '../../../types';
import { IconColor } from '../../../types';
import type {
CheckSuiteAttributes,
CheckSuiteStatus,
GitifySubject,
Notification,
Subject,
} from '../../../typesGitHub';
import { DefaultHandler } from './default';
import { DefaultHandler, defaultHandler } from './default';

class CheckSuiteHandler extends DefaultHandler {
readonly type = 'CheckSuite';
Expand Down Expand Up @@ -52,6 +53,17 @@ class CheckSuiteHandler extends DefaultHandler {
return RocketIcon;
}
}

iconColor(subject: Subject): IconColor {
switch (subject.state) {
case 'success':
return IconColor.GREEN;
case 'failure':
return IconColor.RED;
default:
return defaultHandler.iconColor(subject);
}
}
}

export const checkSuiteHandler = new CheckSuiteHandler();
Expand Down
31 changes: 10 additions & 21 deletions src/renderer/utils/notifications/handlers/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,17 @@ describe('renderer/utils/notifications/handlers/default.ts', () => {
});

describe('iconColor', () => {
const cases: Array<[StateType | null, IconColor]> = [
['open' as StateType, IconColor.GREEN],
['reopened' as StateType, IconColor.GREEN],
['ANSWERED' as StateType, IconColor.GREEN],
['success' as StateType, IconColor.GREEN],
['closed' as StateType, IconColor.RED],
['failure' as StateType, IconColor.RED],
['completed' as StateType, IconColor.PURPLE],
['RESOLVED' as StateType, IconColor.PURPLE],
['merged' as StateType, IconColor.PURPLE],
['not_planned' as StateType, IconColor.GRAY],
['draft' as StateType, IconColor.GRAY],
['skipped' as StateType, IconColor.GRAY],
['cancelled' as StateType, IconColor.GRAY],
['unknown' as StateType, IconColor.GRAY],
[null, IconColor.GRAY],
[undefined, IconColor.GRAY],
];
it('returns GRAY for any state (fallback behavior)', () => {
const states: Array<StateType | null | undefined> = [
'unknown' as StateType,
null,
undefined,
];

it.each(cases)('returns correct color for state %s', (state, expected) => {
const subject = createMockSubject({ state });
expect(defaultHandler.iconColor(subject)).toBe(expected);
states.forEach((state) => {
const subject = createMockSubject({ state });
expect(defaultHandler.iconColor(subject)).toBe(IconColor.GRAY);
});
});
});

Expand Down
19 changes: 2 additions & 17 deletions src/renderer/utils/notifications/handlers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,8 @@ export class DefaultHandler implements NotificationTypeHandler {
return QuestionIcon;
}

iconColor(subject: Subject): IconColor {
switch (subject.state) {
case 'open':
case 'reopened':
case 'ANSWERED':
case 'success':
return IconColor.GREEN;
case 'closed':
case 'failure':
return IconColor.RED;
case 'completed':
case 'RESOLVED':
case 'merged':
return IconColor.PURPLE;
default:
return IconColor.GRAY;
}
iconColor(_subject: Subject): IconColor {
return IconColor.GRAY;
}

formattedNotificationType(notification: Notification): string {
Expand Down
34 changes: 33 additions & 1 deletion src/renderer/utils/notifications/handlers/discussion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
createPartialMockNotification,
} from '../../../__mocks__/notifications-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import type { Link } from '../../../types';
import { IconColor, type Link } from '../../../types';
import type { Owner, Repository } from '../../../typesGitHub';
import {
type AuthorFieldsFragment,
Expand Down Expand Up @@ -325,6 +325,38 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
).displayName,
).toBe('DiscussionClosedIcon');
});

it('iconColor', () => {
expect(
discussionHandler.iconColor(
createMockSubject({ type: 'Discussion', state: 'ANSWERED' }),
),
).toBe(IconColor.GREEN);

expect(
discussionHandler.iconColor(
createMockSubject({ type: 'Discussion', state: 'RESOLVED' }),
),
).toBe(IconColor.PURPLE);

expect(
discussionHandler.iconColor(
createMockSubject({ type: 'Discussion', state: 'DUPLICATE' }),
),
).toBe(IconColor.GRAY);

expect(
discussionHandler.iconColor(
createMockSubject({ type: 'Discussion', state: 'OUTDATED' }),
),
).toBe(IconColor.GRAY);

expect(
discussionHandler.iconColor(
createMockSubject({ type: 'Discussion', state: 'OPEN' }),
),
).toBe(IconColor.GRAY);
});
});

function mockDiscussionNode(
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/utils/notifications/handlers/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { differenceInMilliseconds } from 'date-fns';

import type { SettingsState } from '../../../types';
import { IconColor } from '../../../types';
import type {
DiscussionStateType,
GitifySubject,
Expand All @@ -24,7 +25,7 @@ import type {
FetchDiscussionByNumberQuery,
} from '../../api/graphql/generated/graphql';
import { isStateFilteredOut } from '../filters/filter';
import { DefaultHandler } from './default';
import { DefaultHandler, defaultHandler } from './default';

type DiscussionComment = NonNullable<
NonNullable<
Expand Down Expand Up @@ -110,6 +111,17 @@ class DiscussionHandler extends DefaultHandler {
return CommentDiscussionIcon;
}
}

iconColor(subject: Subject): IconColor {
switch (subject.state) {
case 'ANSWERED':
return IconColor.GREEN;
case 'RESOLVED':
return IconColor.PURPLE;
default:
return defaultHandler.iconColor(subject);
}
}
}

export const discussionHandler = new DiscussionHandler();
Expand Down
40 changes: 39 additions & 1 deletion src/renderer/utils/notifications/handlers/issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../../../__mocks__/notifications-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import { createPartialMockUser } from '../../../__mocks__/user-mocks';
import type { Link } from '../../../types';
import { IconColor, type Link } from '../../../types';
import type { Notification } from '../../../typesGitHub';
import { issueHandler } from './issue';

Expand Down Expand Up @@ -341,4 +341,42 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
).displayName,
).toBe('IssueReopenedIcon');
});

it('iconColor', () => {
expect(
issueHandler.iconColor(
createMockSubject({ type: 'Issue', state: 'open' }),
),
).toBe(IconColor.GREEN);

expect(
issueHandler.iconColor(
createMockSubject({ type: 'Issue', state: 'reopened' }),
),
).toBe(IconColor.GREEN);

expect(
issueHandler.iconColor(
createMockSubject({ type: 'Issue', state: 'closed' }),
),
).toBe(IconColor.RED);

expect(
issueHandler.iconColor(
createMockSubject({ type: 'Issue', state: 'completed' }),
),
).toBe(IconColor.PURPLE);

expect(
issueHandler.iconColor(
createMockSubject({ type: 'Issue', state: 'draft' }),
),
).toBe(IconColor.GRAY);

expect(
issueHandler.iconColor(
createMockSubject({ type: 'Issue', state: 'not_planned' }),
),
).toBe(IconColor.GRAY);
});
});
17 changes: 16 additions & 1 deletion src/renderer/utils/notifications/handlers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@primer/octicons-react';

import type { SettingsState } from '../../../types';
import { IconColor } from '../../../types';
import type {
GitifySubject,
Notification,
Expand All @@ -18,7 +19,7 @@ import type {
} from '../../../typesGitHub';
import { getIssue, getIssueOrPullRequestComment } from '../../api/client';
import { isStateFilteredOut } from '../filters/filter';
import { DefaultHandler } from './default';
import { DefaultHandler, defaultHandler } from './default';
import { getSubjectUser } from './utils';

class IssueHandler extends DefaultHandler {
Expand Down Expand Up @@ -76,6 +77,20 @@ class IssueHandler extends DefaultHandler {
return IssueOpenedIcon;
}
}

iconColor(subject: Subject): IconColor {
switch (subject.state) {
case 'open':
case 'reopened':
return IconColor.GREEN;
case 'closed':
return IconColor.RED;
case 'completed':
return IconColor.PURPLE;
default:
return defaultHandler.iconColor(subject);
}
}
}

export const issueHandler = new IssueHandler();
34 changes: 33 additions & 1 deletion src/renderer/utils/notifications/handlers/pullRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../../../__mocks__/notifications-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import { createPartialMockUser } from '../../../__mocks__/user-mocks';
import type { Link } from '../../../types';
import { IconColor, type Link } from '../../../types';
import type { Notification, PullRequest } from '../../../typesGitHub';
import {
getLatestReviewForReviewers,
Expand Down Expand Up @@ -472,6 +472,38 @@ describe('renderer/utils/notifications/handlers/pullRequest.ts', () => {
).toBe('GitMergeIcon');
});

it('iconColor', () => {
expect(
pullRequestHandler.iconColor(
createMockSubject({ type: 'PullRequest', state: 'open' }),
),
).toBe(IconColor.GREEN);

expect(
pullRequestHandler.iconColor(
createMockSubject({ type: 'PullRequest', state: 'reopened' }),
),
).toBe(IconColor.GREEN);

expect(
pullRequestHandler.iconColor(
createMockSubject({ type: 'PullRequest', state: 'closed' }),
),
).toBe(IconColor.RED);

expect(
pullRequestHandler.iconColor(
createMockSubject({ type: 'PullRequest', state: 'merged' }),
),
).toBe(IconColor.PURPLE);

expect(
pullRequestHandler.iconColor(
createMockSubject({ type: 'PullRequest', state: 'draft' }),
),
).toBe(IconColor.GRAY);
});

describe('Pull Request Reviews - Latest Reviews By Reviewer', () => {
it('returns latest review state per reviewer', async () => {
nock('https://api.github.com')
Expand Down
Loading