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
1 change: 0 additions & 1 deletion src/renderer/__helpers__/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '@testing-library/jest-dom';

import { TextDecoder, TextEncoder } from 'node:util';

/**
Expand Down
15 changes: 15 additions & 0 deletions src/renderer/__mocks__/notifications-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AccountNotifications } from '../types';
import type { StateType, Subject, SubjectType } from '../typesGitHub';
import {
mockEnterpriseNotifications,
mockGitHubNotifications,
Expand Down Expand Up @@ -28,3 +29,17 @@ export const mockSingleAccountNotifications: AccountNotifications[] = [
error: null,
},
];

export function createSubjectMock(mocks: {
title?: string;
type?: SubjectType;
state?: StateType;
}): Subject {
return {
title: mocks.title ?? 'Mock Subject',
type: mocks.type ?? ('Unknown' as SubjectType),
state: mocks.state ?? ('Unknown' as StateType),
url: null,
latest_comment_url: null,
};
}
10 changes: 5 additions & 5 deletions src/renderer/components/notifications/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import type { Notification } from '../../typesGitHub';
import { cn } from '../../utils/cn';
import { isMarkAsDoneFeatureSupported } from '../../utils/features';
import { formatForDisplay } from '../../utils/helpers';
import {
getNotificationTypeIcon,
getNotificationTypeIconColor,
} from '../../utils/icons';
import { getNotificationTypeIconColor } from '../../utils/icons';
import { openNotification } from '../../utils/links';
import { createNotificationHandler } from '../../utils/notifications/handlers';
import { HoverButton } from '../primitives/HoverButton';
import { HoverGroup } from '../primitives/HoverGroup';
import { NotificationFooter } from './NotificationFooter';
Expand Down Expand Up @@ -73,7 +71,9 @@ export const NotificationRow: FC<INotificationRow> = ({
unsubscribeNotification(notification);
};

const NotificationIcon = getNotificationTypeIcon(notification.subject);
const handler = createNotificationHandler(notification);

const NotificationIcon = handler.getIcon(notification.subject);
const iconColor = getNotificationTypeIconColor(notification.subject);

const notificationType = formatForDisplay([
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/utils/__snapshots__/icons.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions src/renderer/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import type { Notification } from '../typesGitHub';
import { getHtmlUrl, getLatestDiscussion } from './api/client';
import type { PlatformType } from './auth/types';
import { Constants } from './constants';
import {
getCheckSuiteAttributes,
getClosestDiscussionCommentOrReply,
getWorkflowRunAttributes,
} from './subject';
import { getCheckSuiteAttributes } from './notifications/handlers/checkSuite';
import { getClosestDiscussionCommentOrReply } from './notifications/handlers/discussion';
import { getWorkflowRunAttributes } from './notifications/handlers/workflowRun';

export function getPlatformFromHostname(hostname: string): PlatformType {
return hostname.endsWith(Constants.DEFAULT_AUTH_OPTIONS.hostname)
Expand Down
195 changes: 0 additions & 195 deletions src/renderer/utils/icons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,207 +17,12 @@ import type {
import {
getAuthMethodIcon,
getDefaultUserIcon,
getNotificationTypeIcon,
getNotificationTypeIconColor,
getPlatformIcon,
getPullRequestReviewIcon,
} from './icons';

describe('renderer/utils/icons.ts', () => {
describe('getNotificationTypeIcon - should get the notification type icon', () => {
expect(
getNotificationTypeIcon(
createSubjectMock({ type: 'CheckSuite', state: null }),
).displayName,
).toBe('RocketIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'CheckSuite',
state: 'cancelled',
}),
).displayName,
).toBe('StopIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'CheckSuite',
state: 'failure',
}),
).displayName,
).toBe('XIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'CheckSuite',
state: 'skipped',
}),
).displayName,
).toBe('SkipIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'CheckSuite',
state: 'success',
}),
).displayName,
).toBe('CheckIcon');

expect(
getNotificationTypeIcon(createSubjectMock({ type: 'Commit' }))
.displayName,
).toBe('GitCommitIcon');

expect(
getNotificationTypeIcon(createSubjectMock({ type: 'Discussion' }))
.displayName,
).toBe('CommentDiscussionIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({ type: 'Discussion', state: 'DUPLICATE' }),
).displayName,
).toBe('DiscussionDuplicateIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({ type: 'Discussion', state: 'OUTDATED' }),
).displayName,
).toBe('DiscussionOutdatedIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({ type: 'Discussion', state: 'RESOLVED' }),
).displayName,
).toBe('DiscussionClosedIcon');

expect(
getNotificationTypeIcon(createSubjectMock({ type: 'Issue' })).displayName,
).toBe('IssueOpenedIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({ type: 'Issue', state: 'draft' }),
).displayName,
).toBe('IssueDraftIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'Issue',
state: 'closed',
}),
).displayName,
).toBe('IssueClosedIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'Issue',
state: 'completed',
}),
).displayName,
).toBe('IssueClosedIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'Issue',
state: 'not_planned',
}),
).displayName,
).toBe('SkipIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'Issue',
state: 'reopened',
}),
).displayName,
).toBe('IssueReopenedIcon');

expect(
getNotificationTypeIcon(createSubjectMock({ type: 'PullRequest' }))
.displayName,
).toBe('GitPullRequestIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'PullRequest',
state: 'draft',
}),
).displayName,
).toBe('GitPullRequestDraftIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'PullRequest',
state: 'closed',
}),
).displayName,
).toBe('GitPullRequestClosedIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'PullRequest',
state: 'merged',
}),
).displayName,
).toBe('GitMergeIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'Release',
}),
).displayName,
).toBe('TagIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'RepositoryDependabotAlertsThread',
}),
).displayName,
).toBe('AlertIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'RepositoryInvitation',
}),
).displayName,
).toBe('MailIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'RepositoryVulnerabilityAlert',
}),
).displayName,
).toBe('AlertIcon');

expect(
getNotificationTypeIcon(
createSubjectMock({
type: 'WorkflowRun',
}),
).displayName,
).toBe('RocketIcon');

expect(getNotificationTypeIcon(createSubjectMock({})).displayName).toBe(
'QuestionIcon',
);
});

describe('getNotificationTypeIconColor', () => {
it('should format the notification color for check suite', () => {
expect(
Expand Down
89 changes: 0 additions & 89 deletions src/renderer/utils/icons.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
import type { FC } from 'react';

import {
AlertIcon,
AppsIcon,
CheckIcon,
CommentDiscussionIcon,
CommentIcon,
DiscussionClosedIcon,
DiscussionDuplicateIcon,
DiscussionOutdatedIcon,
FeedPersonIcon,
FileDiffIcon,
GitCommitIcon,
GitMergeIcon,
GitPullRequestClosedIcon,
GitPullRequestDraftIcon,
GitPullRequestIcon,
IssueClosedIcon,
IssueDraftIcon,
IssueOpenedIcon,
IssueReopenedIcon,
KeyIcon,
MailIcon,
MarkGithubIcon,
type OcticonProps,
OrganizationIcon,
PersonIcon,
QuestionIcon,
RocketIcon,
ServerIcon,
SkipIcon,
StopIcon,
TagIcon,
XIcon,
} from '@primer/octicons-react';

import { IconColor, type PullRequestApprovalIcon } from '../types';
Expand All @@ -43,74 +22,6 @@ import type {
} from '../typesGitHub';
import type { AuthMethod, PlatformType } from './auth/types';

export function getNotificationTypeIcon(subject: Subject): FC<OcticonProps> {
switch (subject.type) {
case 'CheckSuite':
switch (subject.state) {
case 'cancelled':
return StopIcon;
case 'failure':
return XIcon;
case 'skipped':
return SkipIcon;
case 'success':
return CheckIcon;
default:
return RocketIcon;
}
case 'Commit':
return GitCommitIcon;
case 'Discussion':
switch (subject.state) {
case 'DUPLICATE':
return DiscussionDuplicateIcon;
case 'OUTDATED':
return DiscussionOutdatedIcon;
case 'RESOLVED':
return DiscussionClosedIcon;
default:
return CommentDiscussionIcon;
}
case 'Issue':
switch (subject.state) {
case 'draft':
return IssueDraftIcon;
case 'closed':
case 'completed':
return IssueClosedIcon;
case 'not_planned':
return SkipIcon;
case 'reopened':
return IssueReopenedIcon;
default:
return IssueOpenedIcon;
}
case 'PullRequest':
switch (subject.state) {
case 'draft':
return GitPullRequestDraftIcon;
case 'closed':
return GitPullRequestClosedIcon;
case 'merged':
return GitMergeIcon;
default:
return GitPullRequestIcon;
}
case 'Release':
return TagIcon;
case 'RepositoryDependabotAlertsThread':
return AlertIcon;
case 'RepositoryInvitation':
return MailIcon;
case 'RepositoryVulnerabilityAlert':
return AlertIcon;
case 'WorkflowRun':
return RocketIcon;
default:
return QuestionIcon;
}
}

export function getNotificationTypeIconColor(subject: Subject): IconColor {
switch (subject.state) {
case 'open':
Expand Down
Loading
Loading