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
16 changes: 0 additions & 16 deletions src/renderer/__mocks__/notifications-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { Constants } from '../constants';
import type {
AccountNotifications,
GitifyNotification,
GitifyNotificationState,
GitifyRepository,
GitifySubject,
Hostname,
Link,
SubjectType,
} from '../types';
import {
mockEnterpriseNotifications,
Expand Down Expand Up @@ -42,20 +40,6 @@ export const mockSingleAccountNotifications: AccountNotifications[] = [
},
];

export function createMockSubject(mocks: {
title?: string;
type?: SubjectType;
state?: GitifyNotificationState;
}): GitifySubject {
return {
title: mocks.title ?? 'Mock Subject',
type: mocks.type ?? ('Unknown' as SubjectType),
state: mocks.state ?? ('Unknown' as GitifyNotificationState),
url: null,
latestCommentUrl: null,
};
}

export function createPartialMockNotification(
subject: Partial<GitifySubject>,
repository?: Partial<GitifyRepository>,
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/notifications/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export const NotificationRow: FC<NotificationRowProps> = ({
};

const handler = createNotificationHandler(notification);
const NotificationIcon = handler.iconType(notification.subject);
const iconColor = handler.iconColor(notification.subject);
const NotificationIcon = handler.iconType(notification);
const iconColor = handler.iconColor(notification);
const notificationType = handler.formattedNotificationType(notification);
const notificationNumber = handler.formattedNotificationNumber(notification);
const notificationTitle = handler.formattedNotificationTitle(notification);
Expand Down
31 changes: 17 additions & 14 deletions src/renderer/utils/notifications/handlers/checkSuite.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
createMockSubject,
createPartialMockNotification,
} from '../../../__mocks__/notifications-mocks';
import { createPartialMockNotification } from '../../../__mocks__/notifications-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import type { GitifyNotification } from '../../../types';
import {
Expand Down Expand Up @@ -178,11 +175,14 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
it.each(
Object.entries(cases) as Array<[GitifyCheckSuiteStatus, IconColor]>,
)('iconType for check suite with status %s', (checkSuiteStatus, checkSuiteIconType) => {
expect(
checkSuiteHandler.iconType(
createMockSubject({ type: 'CheckSuite', state: checkSuiteStatus }),
).displayName,
).toBe(checkSuiteIconType);
const mockNotification = createPartialMockNotification({
type: 'CheckSuite',
state: checkSuiteStatus,
});

expect(checkSuiteHandler.iconType(mockNotification).displayName).toBe(
checkSuiteIconType,
);
});
});

Expand All @@ -206,11 +206,14 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
it.each(
Object.entries(cases) as Array<[GitifyCheckSuiteStatus, IconColor]>,
)('iconColor for check suite with status %s', (checkSuiteStatus, checkSuiteIconColor) => {
expect(
checkSuiteHandler.iconColor(
createMockSubject({ type: 'CheckSuite', state: checkSuiteStatus }),
),
).toBe(checkSuiteIconColor);
const mockNotification = createPartialMockNotification({
type: 'CheckSuite',
state: checkSuiteStatus,
});

expect(checkSuiteHandler.iconColor(mockNotification)).toBe(
checkSuiteIconColor,
);
});
});

Expand Down
10 changes: 5 additions & 5 deletions src/renderer/utils/notifications/handlers/checkSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class CheckSuiteHandler extends DefaultHandler {
return {};
}

iconType(subject: GitifySubject): FC<OcticonProps> | null {
switch (subject.state as GitifyCheckSuiteStatus) {
iconType(notification: GitifyNotification): FC<OcticonProps> {
switch (notification.subject.state as GitifyCheckSuiteStatus) {
case 'CANCELLED':
return StopIcon;
case 'FAILURE':
Expand All @@ -63,14 +63,14 @@ class CheckSuiteHandler extends DefaultHandler {
}
}

iconColor(subject: GitifySubject): IconColor {
switch (subject.state as GitifyCheckSuiteStatus) {
iconColor(notification: GitifyNotification): IconColor {
switch (notification.subject.state as GitifyCheckSuiteStatus) {
case 'SUCCESS':
return IconColor.GREEN;
case 'FAILURE':
return IconColor.RED;
default:
return defaultHandler.iconColor(subject);
return defaultHandler.iconColor(notification);
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/renderer/utils/notifications/handlers/commit.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import axios from 'axios';
import nock from 'nock';

import {
createMockSubject,
createPartialMockNotification,
} from '../../../__mocks__/notifications-mocks';
import { createPartialMockNotification } from '../../../__mocks__/notifications-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import { createPartialMockUser } from '../../../__mocks__/user-mocks';
import type { GitifyNotification, Link } from '../../../types';
Expand Down Expand Up @@ -99,9 +96,13 @@ describe('renderer/utils/notifications/handlers/commit.ts', () => {
});

it('iconType', () => {
expect(
commitHandler.iconType(createMockSubject({ type: 'Commit' })).displayName,
).toBe('GitCommitIcon');
const mockNotification = createPartialMockNotification({
type: 'Commit',
});

expect(commitHandler.iconType(mockNotification).displayName).toBe(
'GitCommitIcon',
);
});

it('defaultUrl', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/utils/notifications/handlers/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CommitHandler extends DefaultHandler {
};
}

iconType(_subject: GitifySubject): FC<OcticonProps> | null {
iconType(_notification: GitifyNotification): FC<OcticonProps> {
return GitCommitIcon;
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/renderer/utils/notifications/handlers/default.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
createMockSubject,
createPartialMockNotification,
} from '../../../__mocks__/notifications-mocks';
import { createPartialMockNotification } from '../../../__mocks__/notifications-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import type { GitifyNotification } from '../../../types';
import {
Expand Down Expand Up @@ -37,22 +34,27 @@ describe('renderer/utils/notifications/handlers/default.ts', () => {
});

it('iconType', () => {
expect(defaultHandler.iconType(createMockSubject({})).displayName).toBe(
const mockNotification = createPartialMockNotification({});

expect(defaultHandler.iconType(mockNotification).displayName).toBe(
'QuestionIcon',
);
});

describe('iconColor', () => {
it('returns GRAY for any state (fallback behavior)', () => {
it('returns GRAY for any unrecognized state (fallback behavior)', () => {
const states: Array<GitifyNotificationState | null | undefined> = [
'unknown' as GitifyNotificationState,
null,
undefined,
];

states.forEach((state) => {
const subject = createMockSubject({ state });
expect(defaultHandler.iconColor(subject)).toBe(IconColor.GRAY);
const mockNotification = createPartialMockNotification({
state: state,
});

expect(defaultHandler.iconColor(mockNotification)).toBe(IconColor.GRAY);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/utils/notifications/handlers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class DefaultHandler implements NotificationTypeHandler {
return {};
}

iconType(_subject: GitifySubject): FC<OcticonProps> | null {
iconType(_notification: GitifyNotification): FC<OcticonProps> {
return QuestionIcon;
}

iconColor(_subject: GitifySubject): IconColor {
iconColor(_notification: GitifyNotification): IconColor {
return IconColor.GRAY;
}

Expand Down
31 changes: 17 additions & 14 deletions src/renderer/utils/notifications/handlers/discussion.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import axios from 'axios';
import nock from 'nock';

import {
createMockSubject,
createPartialMockNotification,
} from '../../../__mocks__/notifications-mocks';
import { createPartialMockNotification } from '../../../__mocks__/notifications-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import { createMockGraphQLAuthor } from '../../../__mocks__/user-mocks';
import type { GitifyNotification } from '../../../types';
Expand Down Expand Up @@ -308,11 +305,14 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
it.each(
Object.entries(cases) as Array<[GitifyDiscussionState, IconColor]>,
)('iconType for discussion with state %s', (discussionState, discussionIconType) => {
expect(
discussionHandler.iconType(
createMockSubject({ type: 'Discussion', state: discussionState }),
).displayName,
).toBe(discussionIconType);
const mockNotification = createPartialMockNotification({
type: 'Discussion',
state: discussionState,
});

expect(discussionHandler.iconType(mockNotification).displayName).toBe(
discussionIconType,
);
});
});

Expand All @@ -329,11 +329,14 @@ describe('renderer/utils/notifications/handlers/discussion.ts', () => {
it.each(
Object.entries(cases) as Array<[GitifyDiscussionState, IconColor]>,
)('iconColor for discussion with state %s', (discussionState, discussionIconColor) => {
expect(
discussionHandler.iconColor(
createMockSubject({ type: 'Discussion', state: discussionState }),
),
).toBe(discussionIconColor);
const mockNotification = createPartialMockNotification({
type: 'Discussion',
state: discussionState,
});

expect(discussionHandler.iconColor(mockNotification)).toBe(
discussionIconColor,
);
});
});

Expand Down
10 changes: 5 additions & 5 deletions src/renderer/utils/notifications/handlers/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class DiscussionHandler extends DefaultHandler {
};
}

iconType(subject: GitifySubject): FC<OcticonProps> | null {
switch (subject.state as GitifyDiscussionState) {
iconType(notification: GitifyNotification): FC<OcticonProps> {
switch (notification.subject.state as GitifyDiscussionState) {
case 'DUPLICATE':
return DiscussionDuplicateIcon;
case 'OUTDATED':
Expand All @@ -82,14 +82,14 @@ class DiscussionHandler extends DefaultHandler {
}
}

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

Expand Down
29 changes: 15 additions & 14 deletions src/renderer/utils/notifications/handlers/issue.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import axios from 'axios';
import nock from 'nock';

import {
createMockSubject,
createPartialMockNotification,
} from '../../../__mocks__/notifications-mocks';
import { createPartialMockNotification } from '../../../__mocks__/notifications-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import { createMockGraphQLAuthor } from '../../../__mocks__/user-mocks';
import type { GitifyNotification } from '../../../types';
Expand Down Expand Up @@ -248,11 +245,14 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
it.each(
Object.entries(cases) as Array<[GitifyIssueState, IconColor]>,
)('iconType for issue with state %s', (issueState, issueIconType) => {
expect(
issueHandler.iconType(
createMockSubject({ type: 'Issue', state: issueState }),
).displayName,
).toBe(issueIconType);
const mockNotification = createPartialMockNotification({
type: 'Issue',
state: issueState,
});

expect(issueHandler.iconType(mockNotification).displayName).toBe(
issueIconType,
);
});
});

Expand All @@ -269,11 +269,12 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
it.each(
Object.entries(cases) as Array<[GitifyIssueState, IconColor]>,
)('iconColor for issue with state %s', (issueState, issueIconColor) => {
expect(
issueHandler.iconColor(
createMockSubject({ type: 'Issue', state: issueState }),
),
).toBe(issueIconColor);
const mockNotification = createPartialMockNotification({
type: 'Issue',
state: issueState,
});

expect(issueHandler.iconColor(mockNotification)).toBe(issueIconColor);
});
});

Expand Down
10 changes: 5 additions & 5 deletions src/renderer/utils/notifications/handlers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class IssueHandler extends DefaultHandler {
};
}

iconType(subject: GitifySubject): FC<OcticonProps> | null {
switch (subject.state as GitifyIssueState) {
iconType(notification: GitifyNotification): FC<OcticonProps> {
switch (notification.subject.state as GitifyIssueState) {
case 'CLOSED':
case 'COMPLETED':
return IssueClosedIcon;
Expand All @@ -70,8 +70,8 @@ class IssueHandler extends DefaultHandler {
}
}

iconColor(subject: GitifySubject): IconColor {
switch (subject.state as GitifyIssueState) {
iconColor(notification: GitifyNotification): IconColor {
switch (notification.subject.state as GitifyIssueState) {
case 'OPEN':
case 'REOPENED':
return IconColor.GREEN;
Expand All @@ -80,7 +80,7 @@ class IssueHandler extends DefaultHandler {
case 'COMPLETED':
return IconColor.PURPLE;
default:
return defaultHandler.iconColor(subject);
return defaultHandler.iconColor(notification);
}
}

Expand Down
Loading