From 6a4431beac68cccb8d482caab84c1b754d084174 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 10 Jul 2024 06:08:40 -0700 Subject: [PATCH 1/4] feat: add support for RepositoryDependabotAlertsThread --- src/components/notification/NotificationFooter.tsx | 9 +++++++-- src/typesGitHub.ts | 1 + src/utils/helpers.ts | 3 +++ src/utils/icons.ts | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/notification/NotificationFooter.tsx b/src/components/notification/NotificationFooter.tsx index fa883512e..ae075d473 100644 --- a/src/components/notification/NotificationFooter.tsx +++ b/src/components/notification/NotificationFooter.tsx @@ -1,4 +1,4 @@ -import { FeedPersonIcon } from '@primer/octicons-react'; +import { FeedPersonIcon, MarkGithubIcon } from '@primer/octicons-react'; import type { FC, MouseEvent } from 'react'; import { IconColor, Opacity, Size } from '../../types'; import type { Notification } from '../../typesGitHub'; @@ -50,7 +50,12 @@ export const NotificationFooter: FC = ({ ) : (
- + {notification.subject.type === 'RepositoryDependabotAlertsThread' || + notification.subject.type === 'RepositoryVulnerabilityAlert' ? ( + + ) : ( + + )}
)}
{reason.title}
diff --git a/src/typesGitHub.ts b/src/typesGitHub.ts index 39e567236..a9ebf20fc 100644 --- a/src/typesGitHub.ts +++ b/src/typesGitHub.ts @@ -33,6 +33,7 @@ export type SubjectType = | 'Issue' | 'PullRequest' | 'Release' + | 'RepositoryDependabotAlertsThread' | 'RepositoryInvitation' | 'RepositoryVulnerabilityAlert' | 'WorkflowRun'; diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index cab914a54..31f047f0b 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -125,6 +125,9 @@ export async function generateGitHubWebUrl( case 'RepositoryInvitation': url.pathname += '/invitations'; break; + case 'RepositoryDependabotAlertsThread': + url.pathname += '/security/dependabot'; + break; case 'WorkflowRun': url.href = getWorkflowRunUrl(notification); break; diff --git a/src/utils/icons.ts b/src/utils/icons.ts index b85864e2c..f6ae990bd 100644 --- a/src/utils/icons.ts +++ b/src/utils/icons.ts @@ -84,6 +84,8 @@ export function getNotificationTypeIcon(subject: Subject): FC { } case 'Release': return TagIcon; + case 'RepositoryDependabotAlertsThread': + return AlertIcon; case 'RepositoryInvitation': return MailIcon; case 'RepositoryVulnerabilityAlert': From 622f85479b0b1a398019f4ae2d46b8a304cb019f Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 10 Jul 2024 06:20:38 -0700 Subject: [PATCH 2/4] add unit tests --- src/utils/helpers.test.ts | 19 +++++++++++++++++++ src/utils/icons.test.ts | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/src/utils/helpers.test.ts b/src/utils/helpers.test.ts index 2dd653150..49c83bfea 100644 --- a/src/utils/helpers.test.ts +++ b/src/utils/helpers.test.ts @@ -375,6 +375,25 @@ describe('utils/helpers.ts', () => { ); }); + it('Repository Dependabot Alerts Thread url', async () => { + const subject = { + title: 'Your repository has dependencies with security vulnerabilities', + url: null, + latest_comment_url: null, + type: 'RepositoryDependabotAlertsThread' as SubjectType, + }; + + const result = await generateGitHubWebUrl({ + ...mockSingleNotification, + subject: subject, + }); + + expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); + expect(result).toBe( + `https://github.com/gitify-app/notifications-test/security/dependabot?${mockNotificationReferrer}`, + ); + }); + describe('Workflow Run URLs', () => { it('approval requested', async () => { const subject = { diff --git a/src/utils/icons.test.ts b/src/utils/icons.test.ts index 9e991f512..20d9d8aa2 100644 --- a/src/utils/icons.test.ts +++ b/src/utils/icons.test.ts @@ -149,6 +149,13 @@ describe('utils/icons.ts', () => { }), ).displayName, ).toBe('TagIcon'); + expect( + getNotificationTypeIcon( + createSubjectMock({ + type: 'RepositoryDependabotAlertsThread', + }), + ).displayName, + ).toBe('AlertIcon'); expect( getNotificationTypeIcon( createSubjectMock({ From 4377285d9535b831d134eec5d86831740b1a2349 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 10 Jul 2024 06:23:24 -0700 Subject: [PATCH 3/4] add unit tests --- .../notification/NotificationFooter.test.tsx | 44 +- .../NotificationFooter.test.tsx.snap | 418 ++++++++++++++++++ 2 files changed, 461 insertions(+), 1 deletion(-) diff --git a/src/components/notification/NotificationFooter.test.tsx b/src/components/notification/NotificationFooter.test.tsx index 200b919bd..fd01cc043 100644 --- a/src/components/notification/NotificationFooter.test.tsx +++ b/src/components/notification/NotificationFooter.test.tsx @@ -59,7 +59,49 @@ describe('components/notification/NotificationFooter.tsx', () => { expect(tree).toMatchSnapshot(); }); - it('should render itself & its children without avatar', async () => { + describe('security alerts should use github icon for avatar', () => { + it('Repository Dependabot Alerts Thread', async () => { + jest + .spyOn(global.Date, 'now') + .mockImplementation(() => new Date('2024').valueOf()); + + const mockNotification = mockSingleNotification; + mockNotification.subject.type = 'RepositoryDependabotAlertsThread'; + + const props = { + notification: mockNotification, + }; + + const tree = render( + + + , + ); + expect(tree).toMatchSnapshot(); + }); + + it('Repository Vulnerability Alert', async () => { + jest + .spyOn(global.Date, 'now') + .mockImplementation(() => new Date('2024').valueOf()); + + const mockNotification = mockSingleNotification; + mockNotification.subject.type = 'RepositoryVulnerabilityAlert'; + + const props = { + notification: mockNotification, + }; + + const tree = render( + + + , + ); + expect(tree).toMatchSnapshot(); + }); + }); + + it('should default to known avatar if no user found', async () => { jest .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); diff --git a/src/components/notification/__snapshots__/NotificationFooter.test.tsx.snap b/src/components/notification/__snapshots__/NotificationFooter.test.tsx.snap index 5d59c1f55..8429bf33e 100644 --- a/src/components/notification/__snapshots__/NotificationFooter.test.tsx.snap +++ b/src/components/notification/__snapshots__/NotificationFooter.test.tsx.snap @@ -1,5 +1,423 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`components/notification/NotificationFooter.tsx security alerts should use github icon for avatar Repository Dependabot Alerts Thread 1`] = ` +{ + "asFragment": [Function], + "baseElement": +
+
+ +
+ Updated +
+
+ 7 years ago +
+
+ + +
+
+
+ , + "container":
+
+ +
+ Updated +
+
+ 7 years ago +
+
+ + +
+
+
, + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "rerender": [Function], + "unmount": [Function], +} +`; + +exports[`components/notification/NotificationFooter.tsx security alerts should use github icon for avatar Repository Vulnerability Alert 1`] = ` +{ + "asFragment": [Function], + "baseElement": +
+
+ +
+ Updated +
+
+ 7 years ago +
+
+ + +
+
+
+ , + "container":
+
+ +
+ Updated +
+
+ 7 years ago +
+
+ + +
+
+
, + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "rerender": [Function], + "unmount": [Function], +} +`; + exports[`components/notification/NotificationFooter.tsx should render itself & its children 1`] = ` { "asFragment": [Function], From 840556d1bc54c1d17b4ad8da18c4abd71a84d9b5 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 10 Jul 2024 06:23:37 -0700 Subject: [PATCH 4/4] add unit tests --- .../NotificationFooter.test.tsx.snap | 122 +++++++++--------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/src/components/notification/__snapshots__/NotificationFooter.test.tsx.snap b/src/components/notification/__snapshots__/NotificationFooter.test.tsx.snap index 8429bf33e..7d462c36c 100644 --- a/src/components/notification/__snapshots__/NotificationFooter.test.tsx.snap +++ b/src/components/notification/__snapshots__/NotificationFooter.test.tsx.snap @@ -418,7 +418,7 @@ exports[`components/notification/NotificationFooter.tsx security alerts should u } `; -exports[`components/notification/NotificationFooter.tsx should render itself & its children 1`] = ` +exports[`components/notification/NotificationFooter.tsx should default to known avatar if no user found 1`] = ` { "asFragment": [Function], "baseElement": @@ -426,24 +426,29 @@ exports[`components/notification/NotificationFooter.tsx should render itself & i
- +
+ +
Updated
7 years ago
@@ -502,24 +507,29 @@ exports[`components/notification/NotificationFooter.tsx should render itself & i
- +
+ +
Updated
7 years ago
@@ -627,7 +637,7 @@ exports[`components/notification/NotificationFooter.tsx should render itself & i } `; -exports[`components/notification/NotificationFooter.tsx should render itself & its children when last_read_at is null 1`] = ` +exports[`components/notification/NotificationFooter.tsx should render itself & its children 1`] = ` { "asFragment": [Function], "baseElement": @@ -836,7 +846,7 @@ exports[`components/notification/NotificationFooter.tsx should render itself & i } `; -exports[`components/notification/NotificationFooter.tsx should render itself & its children without avatar 1`] = ` +exports[`components/notification/NotificationFooter.tsx should render itself & its children when last_read_at is null 1`] = ` { "asFragment": [Function], "baseElement": @@ -844,29 +854,24 @@ exports[`components/notification/NotificationFooter.tsx should render itself & i
-
- -
+
Updated
7 years ago
@@ -925,29 +930,24 @@ exports[`components/notification/NotificationFooter.tsx should render itself & i
-
- -
+
Updated
7 years ago