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
26 changes: 12 additions & 14 deletions src/renderer/__mocks__/account-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import type {
} from '../types';
import { mockGitifyUser } from './user-mocks';

export const mockGitHubAppAccount: Account = {
platform: 'GitHub Cloud',
method: 'GitHub App',
token: 'token-987654321' as Token,
hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
user: mockGitifyUser,
hasRequiredScopes: true,
};

export const mockPersonalAccessTokenAccount: Account = {
platform: 'GitHub Cloud',
method: 'Personal Access Token',
Expand All @@ -20,7 +29,7 @@ export const mockPersonalAccessTokenAccount: Account = {
export const mockOAuthAccount: Account = {
platform: 'GitHub Enterprise Server',
method: 'OAuth App',
token: '1234568790' as Token,
token: 'token-1234568790' as Token,
hostname: 'github.gitify.io' as Hostname,
user: mockGitifyUser,
hasRequiredScopes: true,
Expand All @@ -39,24 +48,13 @@ export const mockGitHubCloudAccount: Account = {
export const mockGitHubEnterpriseServerAccount: Account = {
platform: 'GitHub Enterprise Server',
method: 'Personal Access Token',
token: '1234568790' as Token,
token: 'token-1234568790' as Token,
hostname: 'github.gitify.io' as Hostname,
user: mockGitifyUser,
hasRequiredScopes: true,
};

export const mockGitHubAppAccount: Account = {
platform: 'GitHub Cloud',
method: 'GitHub App',
token: '987654321' as Token,
hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
user: mockGitifyUser,
hasRequiredScopes: true,
};

export function createMockAccountWithError(
error: GitifyError,
): AccountNotifications {
export function mockAccountWithError(error: GitifyError): AccountNotifications {
return {
account: mockGitHubCloudAccount,
notifications: [],
Expand Down
191 changes: 168 additions & 23 deletions src/renderer/__mocks__/notifications-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,209 @@
import { Constants } from '../constants';
import type {
AccountNotifications,
GitifyNotification,
GitifyNotificationUser,
GitifyOwner,
GitifyReason,
GitifyRepository,
GitifySubject,
Hostname,
Link,
} from '../types';
import {
mockEnterpriseNotifications,
mockGitHubNotifications,
mockSingleNotification,
} from '../utils/api/__mocks__/response-mocks';
import {
mockGitHubAppAccount,
mockGitHubCloudAccount,
mockGitHubEnterpriseServerAccount,
} from './account-mocks';
import { mockToken } from './state-mocks';
import { mockGitifyUser } from './user-mocks';

export const mockAccountNotifications: AccountNotifications[] = [
const mockGitHubOwner: GitifyOwner = {
login: 'gitify-app',
avatarUrl:
'https://avatars.githubusercontent.com/u/133795385?s=200&v=4' as Link,
type: 'User',
};

const mockGitHubRepository: GitifyRepository = {
name: 'notifications-test',
fullName: 'gitify-app/notifications-test',
owner: mockGitHubOwner,
htmlUrl: 'https://github.com/gitify-app/notifications-test' as Link,
};

const mockSubjectUser: GitifyNotificationUser = {
login: 'gitify-app',
htmlUrl: 'https://github.com/gitify-app' as Link,
avatarUrl:
'https://avatars.githubusercontent.com/u/133795385?s=200&v=4' as Link,
type: 'User',
};

/**
* Mock Gitify Notifications for GitHub Cloud account
*
* 2 Notifications
* Hostname: 'github.com'
* Repository: 'gitify-app/notifications-test'
*/
export const mockGitHubCloudGitifyNotifications: GitifyNotification[] = [
{
account: mockGitHubCloudAccount,
notifications: mockGitHubNotifications,
order: 0,
id: '138661096',
unread: true,
reason: {
code: 'subscribed',
title: 'Updated',
description: "You're watching the repository.",
},
updatedAt: '2017-05-20T17:51:57Z',
subject: {
title: 'I am a robot and this is a test!',
url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/1' as Link,
latestCommentUrl:
'https://api.github.com/repos/gitify-app/notifications-test/issues/comments/302888448' as Link,
type: 'Issue',
state: 'OPEN',
user: mockSubjectUser,
reviews: [
{
state: 'APPROVED',
users: ['octocat'],
},
{
state: 'CHANGES_REQUESTED',
users: ['gitify-app'],
},
{
state: 'PENDING',
users: ['gitify-user'],
},
],
},
repository: mockGitHubRepository,
},
{
account: mockGitHubCloudAccount,
order: 1,
id: '148827438',
unread: true,
reason: {
code: 'author',
title: 'Authored',
description: 'You created the thread.',
},
updatedAt: '2017-05-20T17:06:34Z',
subject: {
title: 'Improve the UI',
url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/4' as Link,
latestCommentUrl:
'https://api.github.com/repos/gitify-app/notifications-test/issues/comments/302885965' as Link,
type: 'Issue',
reviews: null,
},
repository: mockGitHubRepository,
},
];

const mockEnterpriseOwner: GitifyOwner = {
login: 'myorg',
avatarUrl: 'https://github.gitify.io/avatars/u/4?' as Link,
type: 'Organization',
};

const mockEnterpriseRepository: GitifyRepository = {
name: 'notifications-test',
fullName: 'myorg/notifications-test',
owner: mockEnterpriseOwner,
htmlUrl: 'https://github.gitify.io/myorg/notifications-test' as Link,
};

/**
* Mock Gitify Notifications for GitHub Enterprise account
*
* 2 Notifications
* Hostname: 'github.gitify.io'
* Repository: 'myorg/notifications-test'
*/
export const mockGithubEnterpriseGitifyNotifications: GitifyNotification[] = [
{
account: mockGitHubEnterpriseServerAccount,
order: 0,
id: '3',
unread: true,
reason: {
code: 'subscribed',
title: 'Updated',
description: "You're watching the repository.",
},
updatedAt: '2017-05-20T13:02:48Z',
subject: {
title: 'Release 0.0.1',
url: 'https://github.gitify.io/api/v3/repos/myorg/notifications-test/releases/3' as Link,
latestCommentUrl:
'https://github.gitify.io/api/v3/repos/myorg/notifications-test/releases/3' as Link,
type: 'Release',
reviews: null,
},
repository: mockEnterpriseRepository,
},
{
account: mockGitHubEnterpriseServerAccount,
order: 1,
id: '4',
unread: true,
reason: {
code: 'subscribed',
title: 'Updated',
description: "You're watching the repository.",
},
updatedAt: '2017-05-20T15:52:20Z',
subject: {
title: 'Bump Version',
url: 'https://github.gitify.io/api/v3/repos/myorg/notifications-test/pulls/4' as Link,
latestCommentUrl:
'https://github.gitify.io/api/v3/repos/myorg/notifications-test/issues/comments/21' as Link,
type: 'PullRequest',
reviews: null,
},
repository: mockEnterpriseRepository,
},
];

export const mockGitifyNotification: GitifyNotification =
mockGitHubCloudGitifyNotifications[0];

export const mockMultipleAccountNotifications: AccountNotifications[] = [
{
account: mockGitHubCloudAccount,
notifications: mockGitHubCloudGitifyNotifications,
error: null,
},
{
account: mockGitHubEnterpriseServerAccount,
notifications: mockEnterpriseNotifications,
notifications: mockGithubEnterpriseGitifyNotifications,
error: null,
},
];

export const mockSingleAccountNotifications: AccountNotifications[] = [
{
account: mockGitHubCloudAccount,
notifications: [mockSingleNotification],
notifications: [mockGitifyNotification],
error: null,
},
];

export function createPartialMockNotification(
export function mockPartialGitifyNotification(
subject: Partial<GitifySubject>,
repository?: Partial<GitifyRepository>,
): GitifyNotification {
const mockNotification: Partial<GitifyNotification> = {
account: {
method: 'Personal Access Token',
platform: 'GitHub Cloud',
hostname: Constants.GITHUB_API_BASE_URL as Hostname,
token: mockToken,
user: mockGitifyUser,
hasRequiredScopes: true,
},
account: mockGitHubAppAccount,
reason: {
code: 'subscribed',
title: 'Updated',
description: "You're watching the repository.",
} as GitifyReason,
updatedAt: '2026-01-01T17:00:00Z',
subject: subject as GitifySubject,
repository: {
name: 'notifications-test',
Expand All @@ -76,7 +221,7 @@ export function createPartialMockNotification(
return mockNotification as GitifyNotification;
}

export function createMockNotificationForRepoName(
export function mockGitifyNotificationForRepoName(
id: string,
repoFullName: string | null,
): GitifyNotification {
Expand Down
25 changes: 1 addition & 24 deletions src/renderer/__mocks__/user-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { GitifyNotificationUser, GitifyUser, Link } from '../types';
import type { AuthorFieldsFragment } from '../utils/api/graphql/generated/graphql';
import type { RawUser } from '../utils/api/types';

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

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 RawUser;
}

export function createMockGitifyNotificationUser(
export function mockGitifyNotificationUser(
login: string,
): GitifyNotificationUser {
return {
Expand All @@ -30,13 +17,3 @@ export function createMockGitifyNotificationUser(
type: 'User',
};
}

/**
* Creates a mock author for use in GraphQL response mocks.
*/
export function createMockGraphQLAuthor(login: string): AuthorFieldsFragment {
return {
...createMockGitifyNotificationUser(login),
__typename: 'User',
} as AuthorFieldsFragment;
}
8 changes: 4 additions & 4 deletions src/renderer/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import userEvent from '@testing-library/user-event';
import { MemoryRouter } from 'react-router-dom';

import { renderWithAppContext } from '../__helpers__/test-utils';
import { mockAccountNotifications } from '../__mocks__/notifications-mocks';
import { mockMultipleAccountNotifications } from '../__mocks__/notifications-mocks';
import { mockSettings } from '../__mocks__/state-mocks';
import * as comms from '../utils/comms';
import { Sidebar } from './Sidebar';
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('renderer/components/Sidebar.tsx', () => {
<Sidebar />
</MemoryRouter>,
{
notifications: mockAccountNotifications,
notifications: mockMultipleAccountNotifications,
},
);

Expand Down Expand Up @@ -159,7 +159,7 @@ describe('renderer/components/Sidebar.tsx', () => {
<Sidebar />
</MemoryRouter>,
{
notifications: mockAccountNotifications,
notifications: mockMultipleAccountNotifications,
},
);

Expand All @@ -177,7 +177,7 @@ describe('renderer/components/Sidebar.tsx', () => {
<Sidebar />
</MemoryRouter>,
{
notifications: mockAccountNotifications,
notifications: mockMultipleAccountNotifications,
},
);

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/filters/FilterSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { MarkGithubIcon } from '@primer/octicons-react';

import { renderWithAppContext } from '../../__helpers__/test-utils';
import { mockAccountNotifications } from '../../__mocks__/notifications-mocks';
import { mockMultipleAccountNotifications } from '../../__mocks__/notifications-mocks';
import { mockSettings } from '../../__mocks__/state-mocks';
import { stateFilter } from '../../utils/notifications/filters';
import { FilterSection } from './FilterSection';
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('renderer/components/filters/FilterSection.tsx', () => {
...mockSettings,
detailedNotifications: true,
},
notifications: mockAccountNotifications,
notifications: mockMultipleAccountNotifications,
},
);

Expand All @@ -57,7 +57,7 @@ describe('renderer/components/filters/FilterSection.tsx', () => {
...mockSettings,
detailedNotifications: false,
},
notifications: mockAccountNotifications,
notifications: mockMultipleAccountNotifications,
},
);

Expand Down
Loading