Skip to content

Commit 8429aa9

Browse files
committed
refactor test suites
Signed-off-by: Adam Setch <[email protected]>
1 parent 18524e5 commit 8429aa9

File tree

10 files changed

+478
-892
lines changed

10 files changed

+478
-892
lines changed

src/renderer/utils/api/__mocks__/response-mocks.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
} from '../../../__mocks__/account-mocks';
55
import type { Link } from '../../../types';
66
import type { Notification, Repository, User } from '../../../typesGitHub';
7-
import type { FetchDiscussionByNumberQuery } from '../graphql/generated/graphql';
87

98
export const mockNotificationUser: User = {
109
login: 'octocat',
@@ -368,58 +367,4 @@ export const mockEnterpriseNotifications: Notification[] = [
368367
},
369368
];
370369

371-
export const mockDiscussionByNumberGraphQLResponse: FetchDiscussionByNumberQuery =
372-
{
373-
repository: {
374-
discussion: {
375-
__typename: 'Discussion',
376-
number: 123,
377-
title: '1.16.0',
378-
isAnswered: false,
379-
stateReason: null,
380-
url: 'https://github.com/gitify-app/notifications-test/discussions/612' as Link,
381-
author: {
382-
login: 'comment-user',
383-
html_url: 'https://github.com/comment-user' as Link,
384-
avatar_url:
385-
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
386-
type: 'User',
387-
},
388-
comments: {
389-
totalCount: 2,
390-
nodes: [
391-
{
392-
databaseId: 2258799,
393-
createdAt: '2017-02-20T17:51:57Z',
394-
author: {
395-
login: 'comment-user',
396-
html_url: 'https://github.com/comment-user' as Link,
397-
avatar_url:
398-
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
399-
type: 'User',
400-
},
401-
url: 'https://github.com/gitify-app/notifications-test/discussions/612#discussioncomment-67890',
402-
replies: {
403-
nodes: [
404-
{
405-
databaseId: 2300902,
406-
createdAt: '2017-05-20T17:51:57Z',
407-
author: {
408-
login: 'reply-user',
409-
html_url: 'https://github.com/reply-user' as Link,
410-
avatar_url:
411-
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
412-
type: 'User',
413-
},
414-
url: 'https://github.com/gitify-app/notifications-test/discussions/612#discussioncomment-12345',
415-
},
416-
],
417-
},
418-
},
419-
],
420-
},
421-
},
422-
},
423-
};
424-
425370
export const mockSingleNotification: Notification = mockGitHubNotifications[0];

src/renderer/utils/api/graphql/discussion.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ query FetchDiscussionByNumber(
2323
nodes {
2424
...CommentFields
2525
replies(last: $lastReplies) {
26+
totalCount
2627
nodes {
2728
...CommentFields
2829
}

src/renderer/utils/api/graphql/generated/gql.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import * as types from './graphql';
1616
*/
1717
type Documents = {
1818
"fragment AuthorFields on Actor {\n login\n html_url: url\n avatar_url: avatarUrl\n type: __typename\n}": typeof types.AuthorFieldsFragmentDoc,
19-
"query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n url\n}": typeof types.FetchDiscussionByNumberDocument,
19+
"query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n totalCount\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n url\n}": typeof types.FetchDiscussionByNumberDocument,
2020
"query FetchIssueByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $firstLabels: Int) {\n repository(owner: $owner, name: $name) {\n issue(number: $number) {\n __typename\n number\n title\n url\n state\n stateReason\n milestone {\n ...MilestoneFields\n }\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n url\n author {\n ...AuthorFields\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment MilestoneFields on Milestone {\n state\n title\n}": typeof types.FetchIssueByNumberDocument,
2121
"query FetchPullRequestByNumber($owner: String!, $name: String!, $number: Int!, $firstLabels: Int, $lastComments: Int, $lastReviews: Int, $firstClosingIssues: Int) {\n repository(owner: $owner, name: $name) {\n pullRequest(number: $number) {\n __typename\n number\n title\n url\n state\n merged\n isDraft\n isInMergeQueue\n milestone {\n ...MilestoneFields\n }\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n url\n author {\n ...AuthorFields\n }\n }\n }\n reviews(last: $lastReviews) {\n totalCount\n nodes {\n state\n author {\n login\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n closingIssuesReferences(first: $firstClosingIssues) {\n nodes {\n number\n }\n }\n }\n }\n}\n\nfragment MilestoneFields on Milestone {\n state\n title\n}": typeof types.FetchPullRequestByNumberDocument,
2222
};
2323
const documents: Documents = {
2424
"fragment AuthorFields on Actor {\n login\n html_url: url\n avatar_url: avatarUrl\n type: __typename\n}": types.AuthorFieldsFragmentDoc,
25-
"query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n url\n}": types.FetchDiscussionByNumberDocument,
25+
"query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n totalCount\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n url\n}": types.FetchDiscussionByNumberDocument,
2626
"query FetchIssueByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $firstLabels: Int) {\n repository(owner: $owner, name: $name) {\n issue(number: $number) {\n __typename\n number\n title\n url\n state\n stateReason\n milestone {\n ...MilestoneFields\n }\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n url\n author {\n ...AuthorFields\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment MilestoneFields on Milestone {\n state\n title\n}": types.FetchIssueByNumberDocument,
2727
"query FetchPullRequestByNumber($owner: String!, $name: String!, $number: Int!, $firstLabels: Int, $lastComments: Int, $lastReviews: Int, $firstClosingIssues: Int) {\n repository(owner: $owner, name: $name) {\n pullRequest(number: $number) {\n __typename\n number\n title\n url\n state\n merged\n isDraft\n isInMergeQueue\n milestone {\n ...MilestoneFields\n }\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n url\n author {\n ...AuthorFields\n }\n }\n }\n reviews(last: $lastReviews) {\n totalCount\n nodes {\n state\n author {\n login\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n closingIssuesReferences(first: $firstClosingIssues) {\n nodes {\n number\n }\n }\n }\n }\n}\n\nfragment MilestoneFields on Milestone {\n state\n title\n}": types.FetchPullRequestByNumberDocument,
2828
};
@@ -34,7 +34,7 @@ export function graphql(source: "fragment AuthorFields on Actor {\n login\n ht
3434
/**
3535
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
3636
*/
37-
export function graphql(source: "query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n url\n}"): typeof import('./graphql').FetchDiscussionByNumberDocument;
37+
export function graphql(source: "query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n totalCount\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n url\n}"): typeof import('./graphql').FetchDiscussionByNumberDocument;
3838
/**
3939
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
4040
*/

src/renderer/utils/api/graphql/generated/graphql.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35929,7 +35929,7 @@ export type FetchDiscussionByNumberQuery = { __typename?: 'Query', repository?:
3592935929
| { __typename?: 'Mannequin', login: string, html_url: any, avatar_url: any, type: 'Mannequin' }
3593035930
| { __typename?: 'Organization', login: string, html_url: any, avatar_url: any, type: 'Organization' }
3593135931
| { __typename?: 'User', login: string, html_url: any, avatar_url: any, type: 'User' }
35932-
| null, comments: { __typename?: 'DiscussionCommentConnection', totalCount: number, nodes?: Array<{ __typename?: 'DiscussionComment', databaseId?: number | null, createdAt: any, url: any, replies: { __typename?: 'DiscussionCommentConnection', nodes?: Array<{ __typename?: 'DiscussionComment', databaseId?: number | null, createdAt: any, url: any, author?:
35932+
| null, comments: { __typename?: 'DiscussionCommentConnection', totalCount: number, nodes?: Array<{ __typename?: 'DiscussionComment', databaseId?: number | null, createdAt: any, url: any, replies: { __typename?: 'DiscussionCommentConnection', totalCount: number, nodes?: Array<{ __typename?: 'DiscussionComment', databaseId?: number | null, createdAt: any, url: any, author?:
3593335933
| { __typename?: 'Bot', login: string, html_url: any, avatar_url: any, type: 'Bot' }
3593435934
| { __typename?: 'EnterpriseUserAccount', login: string, html_url: any, avatar_url: any, type: 'EnterpriseUserAccount' }
3593535935
| { __typename?: 'Mannequin', login: string, html_url: any, avatar_url: any, type: 'Mannequin' }
@@ -36072,6 +36072,7 @@ export const FetchDiscussionByNumberDocument = new TypedDocumentString(`
3607236072
nodes {
3607336073
...CommentFields
3607436074
replies(last: $lastReplies) {
36075+
totalCount
3607536076
nodes {
3607636077
...CommentFields
3607736078
}

src/renderer/utils/notifications/handlers/checkSuite.test.ts

Lines changed: 57 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import {
33
createPartialMockNotification,
44
} from '../../../__mocks__/notifications-mocks';
55
import { mockSettings } from '../../../__mocks__/state-mocks';
6-
import { IconColor, type Link } from '../../../types';
6+
import {
7+
type GitifyCheckSuiteStatus,
8+
IconColor,
9+
type Link,
10+
} from '../../../types';
711
import type { Notification } from '../../../typesGitHub';
812
import { checkSuiteHandler, getCheckSuiteAttributes } from './checkSuite';
913

@@ -152,80 +156,60 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
152156
});
153157
});
154158

155-
it('iconType', () => {
156-
expect(
157-
checkSuiteHandler.iconType(
158-
createMockSubject({ type: 'CheckSuite', state: null }),
159-
).displayName,
160-
).toBe('RocketIcon');
161-
162-
expect(
163-
checkSuiteHandler.iconType(
164-
createMockSubject({
165-
type: 'CheckSuite',
166-
state: 'CANCELLED',
167-
}),
168-
).displayName,
169-
).toBe('StopIcon');
170-
171-
expect(
172-
checkSuiteHandler.iconType(
173-
createMockSubject({
174-
type: 'CheckSuite',
175-
state: 'FAILURE',
176-
}),
177-
).displayName,
178-
).toBe('XIcon');
179-
180-
expect(
181-
checkSuiteHandler.iconType(
182-
createMockSubject({
183-
type: 'CheckSuite',
184-
state: 'SKIPPED',
185-
}),
186-
).displayName,
187-
).toBe('SkipIcon');
188-
189-
expect(
190-
checkSuiteHandler.iconType(
191-
createMockSubject({
192-
type: 'CheckSuite',
193-
state: 'SUCCESS',
194-
}),
195-
).displayName,
196-
).toBe('CheckIcon');
159+
describe('iconType', () => {
160+
const cases = {
161+
ACTION_REQUIRED: 'RocketIcon',
162+
CANCELLED: 'StopIcon',
163+
COMPLETED: 'RocketIcon',
164+
FAILURE: 'XIcon',
165+
IN_PROGRESS: 'RocketIcon',
166+
PENDING: 'RocketIcon',
167+
QUEUED: 'RocketIcon',
168+
REQUESTED: 'RocketIcon',
169+
SKIPPED: 'SkipIcon',
170+
STALE: 'RocketIcon',
171+
SUCCESS: 'CheckIcon',
172+
TIMED_OUT: 'RocketIcon',
173+
WAITING: 'RocketIcon',
174+
} satisfies Record<GitifyCheckSuiteStatus, string>;
175+
176+
it.each(
177+
Object.entries(cases) as Array<[GitifyCheckSuiteStatus, IconColor]>,
178+
)('iconType for check suite with status %s', (checkSuiteStatus, checkSuiteIconType) => {
179+
expect(
180+
checkSuiteHandler.iconType(
181+
createMockSubject({ type: 'CheckSuite', state: checkSuiteStatus }),
182+
).displayName,
183+
).toBe(checkSuiteIconType);
184+
});
197185
});
198186

199-
it('iconColor', () => {
200-
expect(
201-
checkSuiteHandler.iconColor(
202-
createMockSubject({ type: 'CheckSuite', state: 'SUCCESS' }),
203-
),
204-
).toBe(IconColor.GREEN);
205-
206-
expect(
207-
checkSuiteHandler.iconColor(
208-
createMockSubject({ type: 'CheckSuite', state: 'FAILURE' }),
209-
),
210-
).toBe(IconColor.RED);
211-
212-
expect(
213-
checkSuiteHandler.iconColor(
214-
createMockSubject({ type: 'CheckSuite', state: 'CANCELLED' }),
215-
),
216-
).toBe(IconColor.GRAY);
217-
218-
expect(
219-
checkSuiteHandler.iconColor(
220-
createMockSubject({ type: 'CheckSuite', state: 'SKIPPED' }),
221-
),
222-
).toBe(IconColor.GRAY);
223-
224-
expect(
225-
checkSuiteHandler.iconColor(
226-
createMockSubject({ type: 'CheckSuite', state: null }),
227-
),
228-
).toBe(IconColor.GRAY);
187+
describe('iconColor', () => {
188+
const cases = {
189+
ACTION_REQUIRED: IconColor.GRAY,
190+
CANCELLED: IconColor.GRAY,
191+
COMPLETED: IconColor.GRAY,
192+
FAILURE: IconColor.RED,
193+
IN_PROGRESS: IconColor.GRAY,
194+
PENDING: IconColor.GRAY,
195+
QUEUED: IconColor.GRAY,
196+
REQUESTED: IconColor.GRAY,
197+
SKIPPED: IconColor.GRAY,
198+
STALE: IconColor.GRAY,
199+
SUCCESS: IconColor.GREEN,
200+
TIMED_OUT: IconColor.GRAY,
201+
WAITING: IconColor.GRAY,
202+
} satisfies Record<GitifyCheckSuiteStatus, IconColor>;
203+
204+
it.each(
205+
Object.entries(cases) as Array<[GitifyCheckSuiteStatus, IconColor]>,
206+
)('iconColor for check suite with status %s', (checkSuiteStatus, checkSuiteIconColor) => {
207+
expect(
208+
checkSuiteHandler.iconColor(
209+
createMockSubject({ type: 'CheckSuite', state: checkSuiteStatus }),
210+
),
211+
).toBe(checkSuiteIconColor);
212+
});
229213
});
230214

231215
it('defaultUrl', () => {

0 commit comments

Comments
 (0)