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
41 changes: 21 additions & 20 deletions src/renderer/__mocks__/notifications-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Constants } from '../constants';
import type {
AccountNotifications,
GitifyNotification,
GitifyNotificationState,
GitifyRepository,
GitifySubject,
Hostname,
} from '../types';
import type {
Notification,
Repository,
Subject,
Link,
SubjectType,
} from '../typesGitHub';
} from '../types';
import {
mockEnterpriseNotifications,
mockGitHubNotifications,
Expand Down Expand Up @@ -47,21 +46,21 @@ export function createMockSubject(mocks: {
title?: string;
type?: SubjectType;
state?: GitifyNotificationState;
}): Subject {
}): GitifySubject {
return {
title: mocks.title ?? 'Mock Subject',
type: mocks.type ?? ('Unknown' as SubjectType),
state: mocks.state ?? ('Unknown' as GitifyNotificationState),
url: null,
latest_comment_url: null,
latestCommentUrl: null,
};
}

export function createPartialMockNotification(
subject: Partial<Subject>,
repository?: Partial<Repository>,
): Notification {
const mockNotification: Partial<Notification> = {
subject: Partial<GitifySubject>,
repository?: Partial<GitifyRepository>,
): GitifyNotification {
const mockNotification: Partial<GitifyNotification> = {
account: {
method: 'Personal Access Token',
platform: 'GitHub Cloud',
Expand All @@ -70,28 +69,30 @@ export function createPartialMockNotification(
user: mockGitifyUser,
hasRequiredScopes: true,
},
subject: subject as Subject,
subject: subject as GitifySubject,
repository: {
name: 'notifications-test',
full_name: 'gitify-app/notifications-test',
html_url: 'https://github.com/gitify-app/notifications-test',
fullName: 'gitify-app/notifications-test',
htmlUrl: 'https://github.com/gitify-app/notifications-test' as Link,
owner: {
login: 'gitify-app',
avatarUrl: 'https://avatars.githubusercontent.com/u/1' as Link,
type: 'Organization',
},
...repository,
} as Repository,
} as GitifyRepository,
};

return mockNotification as Notification;
return mockNotification as GitifyNotification;
}

export function createMockNotificationForRepoName(
id: string,
repoFullName: string | null,
): Notification {
): GitifyNotification {
return {
id,
repository: repoFullName ? { full_name: repoFullName } : null,
repository: repoFullName ? { fullName: repoFullName } : null,
account: mockGitHubCloudAccount,
} as Notification;
} as GitifyNotification;
}
21 changes: 16 additions & 5 deletions src/renderer/__mocks__/user-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GitifyUser, Link } from '../types';
import type { User } from '../typesGitHub';
import type { GitifyNotificationUser, GitifyUser, Link } from '../types';
import type { RawUser } from '../utils/api/types';

export const mockGitifyUser: GitifyUser = {
login: 'octocat',
Expand All @@ -8,13 +8,24 @@ export const mockGitifyUser: GitifyUser = {
avatar: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
};

export function createPartialMockUser(login: string): User {
const mockUser: Partial<User> = {
export function createPartialMockUser(login: string): RawUser {
const mockUser: Partial<RawUser> = {
login: login,
html_url: `https://github.com/${login}` as Link,
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
type: 'User',
};

return mockUser as User;
return mockUser as RawUser;
}

export function createMockNotificationUser(
login: string,
): GitifyNotificationUser {
return {
login: login,
htmlUrl: `https://github.com/${login}` as Link,
avatarUrl: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
type: 'User',
};
}
3 changes: 1 addition & 2 deletions src/renderer/components/avatars/AvatarWithFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useState } from 'react';

import { Avatar, Stack, Truncate } from '@primer/react';

import { type Link, Size } from '../../types';
import type { UserType } from '../../typesGitHub';
import { type Link, Size, type UserType } from '../../types';
import { getDefaultUserIcon } from '../../utils/icons';
import { isNonHumanUser } from '../../utils/notifications/filters/userType';

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/metrics/MetricGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { renderWithAppContext } from '../../__helpers__/test-utils';
import { mockSettings } from '../../__mocks__/state-mocks';
import type { GitifyMilestone } from '../../types';
import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks';
import type { MilestoneFieldsFragment } from '../../utils/api/graphql/generated/graphql';
import { MetricGroup } from './MetricGroup';

describe('renderer/components/metrics/MetricGroup.tsx', () => {
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
mockNotification.subject.milestone = {
title: 'Milestone 1',
state: 'OPEN',
} as MilestoneFieldsFragment;
} as GitifyMilestone;

const props = {
notification: mockNotification,
Expand All @@ -119,7 +119,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
mockNotification.subject.milestone = {
title: 'Milestone 1',
state: 'CLOSED',
} as MilestoneFieldsFragment;
} as GitifyMilestone;

const props = {
notification: mockNotification,
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/components/metrics/MetricGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import {
} from '@primer/octicons-react';

import { useAppContext } from '../../context/App';
import { IconColor } from '../../types';
import type { Notification } from '../../typesGitHub';
import { type GitifyNotification, IconColor } from '../../types';
import { getPullRequestReviewIcon } from '../../utils/icons';
import { MetricPill } from './MetricPill';

interface MetricGroupProps {
notification: Notification;
notification: GitifyNotification;
}

export const MetricGroup: FC<MetricGroupProps> = ({
Expand Down
10 changes: 7 additions & 3 deletions src/renderer/components/notifications/AccountNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import { GitPullRequestIcon, IssueOpenedIcon } from '@primer/octicons-react';
import { Button, Stack } from '@primer/react';

import { useAppContext } from '../../context/App';
import { type Account, type GitifyError, Size } from '../../types';
import type { Notification } from '../../typesGitHub';
import {
type Account,
type GitifyError,
type GitifyNotification,
Size,
} from '../../types';
import { hasMultipleAccounts } from '../../utils/auth/utils';
import { cn } from '../../utils/cn';
import { getChevronDetails } from '../../utils/helpers';
Expand All @@ -28,7 +32,7 @@ import { RepositoryNotifications } from './RepositoryNotifications';

interface AccountNotificationsProps {
account: Account;
notifications: Notification[];
notifications: GitifyNotification[];
error: GitifyError | null;
showAccountHeader: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import userEvent from '@testing-library/user-event';

import { renderWithAppContext } from '../../__helpers__/test-utils';
import { mockGitHubCloudAccount } from '../../__mocks__/account-mocks';
import type { Link } from '../../types';
import type { UserType } from '../../typesGitHub';
import type { GitifyNotificationUser, Link } from '../../types';
import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks';
import * as comms from '../../utils/comms';
import { NotificationFooter } from './NotificationFooter';
Expand All @@ -28,19 +27,6 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => {
expect(tree).toMatchSnapshot();
});

it('should render itself & its children when last_read_at is null', async () => {
const mockNotification = mockSingleNotification;
mockNotification.last_read_at = null;

const props = {
notification: mockNotification,
};

const tree = renderWithAppContext(<NotificationFooter {...props} />);

expect(tree).toMatchSnapshot();
});

describe('security alerts should use github icon for avatar', () => {
it('Repository Dependabot Alerts Thread', async () => {
const mockNotification = mockSingleNotification;
Expand Down Expand Up @@ -94,10 +80,10 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => {
...mockSingleNotification.subject,
user: {
login: 'some-user',
html_url: 'https://github.com/some-user' as Link,
avatar_url:
htmlUrl: 'https://github.com/some-user' as Link,
avatarUrl:
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
type: 'User' as UserType,
type: 'User' as GitifyNotificationUser['type'],
},
reviews: null,
},
Expand All @@ -111,7 +97,7 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => {

expect(openExternalLinkSpy).toHaveBeenCalledTimes(1);
expect(openExternalLinkSpy).toHaveBeenCalledWith(
props.notification.subject.user.html_url,
props.notification.subject.user.htmlUrl,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import type { FC, MouseEvent } from 'react';

import { RelativeTime, Stack, Text } from '@primer/react';

import { Opacity, Size } from '../../types';
import type { Notification } from '../../typesGitHub';
import { type GitifyNotification, Opacity, Size } from '../../types';
import { cn } from '../../utils/cn';
import { openUserProfile } from '../../utils/links';
import { getReasonDetails } from '../../utils/reason';
import { AvatarWithFallback } from '../avatars/AvatarWithFallback';
import { MetricGroup } from '../metrics/MetricGroup';

interface NotificationFooterProps {
notification: Notification;
notification: GitifyNotification;
}

export const NotificationFooter: FC<NotificationFooterProps> = ({
Expand Down Expand Up @@ -41,7 +40,7 @@ export const NotificationFooter: FC<NotificationFooterProps> = ({
<AvatarWithFallback
alt={notification.subject.user.login}
size={Size.SMALL}
src={notification.subject.user.avatar_url}
src={notification.subject.user.avatarUrl}
userType={notification.subject.user.type}
/>
</button>
Expand All @@ -61,7 +60,7 @@ export const NotificationFooter: FC<NotificationFooterProps> = ({
<Text className="pr-1" title={reason.description}>
{reason.title}
</Text>
<RelativeTime datetime={notification.updated_at} />
<RelativeTime datetime={notification.updatedAt} />
</Stack>

<MetricGroup notification={notification} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('renderer/components/notifications/NotificationHeader.tsx', () => {

expect(openExternalLinkSpy).toHaveBeenCalledTimes(1);
expect(openExternalLinkSpy).toHaveBeenCalledWith(
props.notification.repository.html_url,
props.notification.repository.htmlUrl,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ import type { FC, MouseEvent } from 'react';
import { Stack } from '@primer/react';

import { useAppContext } from '../../context/App';
import { GroupBy, Opacity, Size } from '../../types';
import type { Notification } from '../../typesGitHub';
import { type GitifyNotification, GroupBy, Opacity, Size } from '../../types';
import { cn } from '../../utils/cn';
import { openRepository } from '../../utils/links';
import { AvatarWithFallback } from '../avatars/AvatarWithFallback';

interface NotificationHeaderProps {
notification: Notification;
notification: GitifyNotification;
}

export const NotificationHeader: FC<NotificationHeaderProps> = ({
notification,
}: NotificationHeaderProps) => {
const { settings } = useAppContext();

const repoSlug = notification.repository.full_name;
const repoSlug = notification.repository.fullName;

const notificationNumber = notification.subject?.number
? `#${notification.subject.number}`
Expand All @@ -45,7 +44,7 @@ export const NotificationHeader: FC<NotificationHeaderProps> = ({
alt={repoSlug}
name={repoSlug}
size={Size.SMALL}
src={notification.repository.owner.avatar_url}
src={notification.repository.owner.avatarUrl}
userType={notification.repository.owner.type}
/>
</button>
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/components/notifications/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { BellSlashIcon, CheckIcon, ReadIcon } from '@primer/octicons-react';
import { Stack, Text, Tooltip } from '@primer/react';

import { useAppContext } from '../../context/App';
import { GroupBy, Opacity, Size } from '../../types';
import type { Notification } from '../../typesGitHub';
import { type GitifyNotification, GroupBy, Opacity, Size } from '../../types';
import { cn } from '../../utils/cn';
import { isMarkAsDoneFeatureSupported } from '../../utils/features';
import { openNotification } from '../../utils/links';
Expand All @@ -16,7 +15,7 @@ import { NotificationFooter } from './NotificationFooter';
import { NotificationHeader } from './NotificationHeader';

interface NotificationRowProps {
notification: Notification;
notification: GitifyNotification;
isAnimated?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () =>
});

it('should use default repository icon when avatar is not available', () => {
props.repoNotifications[0].repository.owner.avatar_url = '' as Link;
props.repoNotifications[0].repository.owner.avatarUrl = '' as Link;

const tree = renderWithAppContext(<RepositoryNotifications {...props} />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { CheckIcon, ReadIcon } from '@primer/octicons-react';
import { Button, Stack } from '@primer/react';

import { useAppContext } from '../../context/App';
import { Opacity, Size } from '../../types';
import type { Notification } from '../../typesGitHub';
import { type GitifyNotification, Opacity, Size } from '../../types';
import { cn } from '../../utils/cn';
import { isMarkAsDoneFeatureSupported } from '../../utils/features';
import { getChevronDetails } from '../../utils/helpers';
Expand All @@ -16,7 +15,7 @@ import { HoverGroup } from '../primitives/HoverGroup';
import { NotificationRow } from './NotificationRow';

interface RepositoryNotificationsProps {
repoNotifications: Notification[];
repoNotifications: GitifyNotification[];
repoName: string;
}

Expand All @@ -30,7 +29,7 @@ export const RepositoryNotifications: FC<RepositoryNotificationsProps> = ({
const [showRepositoryNotifications, setShowRepositoryNotifications] =
useState(true);

const avatarUrl = repoNotifications[0].repository.owner.avatar_url;
const avatarUrl = repoNotifications[0].repository.owner.avatarUrl;

const actionMarkAsDone = () => {
setAnimateExit(!settings.delayNotificationState);
Expand Down
Loading