diff --git a/src/__mocks__/mockedData.ts b/src/__mocks__/mockedData.ts index 7e05086fe..a5820f612 100644 --- a/src/__mocks__/mockedData.ts +++ b/src/__mocks__/mockedData.ts @@ -299,6 +299,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-20T18:33:39Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -310,6 +311,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-21T03:30:42Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -321,6 +323,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-21T18:26:27Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -330,6 +333,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-23T00:57:58Z', author: { login: 'reply-user', + url: 'https://github.com/reply-user', type: 'User', }, }, @@ -341,6 +345,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-23T00:57:49Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -352,6 +357,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-27T01:22:20Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -361,6 +367,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-05T17:43:52Z', author: { login: 'reply-user', + url: 'https://github.com/reply-user', type: 'User', }, }, @@ -372,6 +379,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-04T20:39:44Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -381,6 +389,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-05T17:41:04Z', author: { login: 'reply-user', + url: 'https://github.com/reply-user', type: 'User', }, }, @@ -392,6 +401,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-05T11:05:42Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -401,6 +411,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-05T17:41:44Z', author: { login: 'reply-user', + url: 'https://github.com/reply-user', type: 'User', }, }, @@ -423,6 +434,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-20T18:33:39Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -434,6 +446,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-21T03:30:42Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -445,6 +458,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-21T18:26:27Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -454,6 +468,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-23T00:57:58Z', author: { login: 'reply-user', + url: 'https://github.com/reply-user', type: 'User', }, }, @@ -465,6 +480,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-23T00:57:49Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -476,6 +492,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-02-27T01:22:20Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -485,6 +502,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-05T17:43:52Z', author: { login: 'reply-user', + url: 'https://github.com/reply-user', type: 'User', }, }, @@ -496,6 +514,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-04T20:39:44Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -505,6 +524,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-05T17:41:04Z', author: { login: 'reply-user', + url: 'https://github.com/reply-user', type: 'User', }, }, @@ -516,6 +536,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-05T11:05:42Z', author: { login: 'comment-user', + url: 'https://github.com/comment-user', type: 'User', }, replies: { @@ -525,6 +546,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { createdAt: '2022-03-05T17:41:44Z', author: { login: 'reply-user', + url: 'https://github.com/reply-user', type: 'User', }, }, diff --git a/src/components/NotificationRow.test.tsx b/src/components/NotificationRow.test.tsx index 9605e5d8b..b92623622 100644 --- a/src/components/NotificationRow.test.tsx +++ b/src/components/NotificationRow.test.tsx @@ -8,6 +8,7 @@ import { AppContext } from '../context/App'; import { mockedSingleNotification } from '../__mocks__/mockedData'; import { NotificationRow } from './NotificationRow'; import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; +import { shell } from 'electron'; describe('components/NotificationRow.tsx', () => { beforeEach(() => { @@ -148,4 +149,35 @@ describe('components/NotificationRow.tsx', () => { fireEvent.click(getByTitle('Unsubscribe')); expect(unsubscribeNotification).toHaveBeenCalledTimes(1); }); + + it('should open notification user profile', () => { + const props = { + notification: { + ...mockedSingleNotification, + subject: { + ...mockedSingleNotification.subject, + user: { + login: 'some-user', + html_url: 'https://github.com/some-user', + type: 'User', + }, + }, + }, + hostname: 'github.com', + }; + + const { getByTitle } = render( + + + , + ); + + fireEvent.click(getByTitle('View User Profile')); + expect(shell.openExternal).toHaveBeenCalledTimes(1); + }); }); diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index 9cf2664a4..d26a31d38 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -10,6 +10,7 @@ import { import { formatForDisplay, openInBrowser } from '../utils/helpers'; import { Notification } from '../typesGithub'; import { AppContext } from '../context/App'; +import { openExternalLink } from '../utils/comms'; interface IProps { hostname: string; @@ -79,13 +80,11 @@ export const NotificationRow: React.FC = ({ -
pressTitle()} - role="main" - > +
pressTitle()} title={notification.subject.title} > {notification.subject.title} @@ -93,7 +92,24 @@ export const NotificationRow: React.FC = ({
{reason.type} -{' '} - {updatedLabel} + + Updated {updatedAt} + {notification.subject.user && ( + <> + {' '} + by{' '} + + openExternalLink(notification.subject.user.html_url) + } + > + {notification.subject.user.login} + + + )} +
diff --git a/src/components/__snapshots__/NotificationRow.test.tsx.snap b/src/components/__snapshots__/NotificationRow.test.tsx.snap index 52d225d96..219fe1bbf 100644 --- a/src/components/__snapshots__/NotificationRow.test.tsx.snap +++ b/src/components/__snapshots__/NotificationRow.test.tsx.snap @@ -35,12 +35,12 @@ exports[`components/NotificationRow.tsx should render itself & its children 1`]
I am a robot and this is a test! @@ -58,7 +58,8 @@ exports[`components/NotificationRow.tsx should render itself & its children 1`] - Updated in over 3 years + Updated + in over 3 years
diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index 549861c74..4b19d4ccf 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -308,12 +308,19 @@ describe('hooks/useNotifications.ts', () => { merged: true, user: { login: 'some-user', + html_url: 'https://github.com/some-user', type: 'User', }, }); nock('https://api.github.com') .get('/3/comments') - .reply(200, { user: { login: 'some-commenter', type: 'User' } }); + .reply(200, { + user: { + login: 'some-commenter', + html_url: 'https://github.com/some-commenter', + type: 'User', + }, + }); nock('https://api.github.com') .get('/4') .reply(200, { @@ -321,12 +328,19 @@ describe('hooks/useNotifications.ts', () => { merged: false, user: { login: 'some-user', + html_url: 'https://github.com/some-user', type: 'User', }, }); nock('https://api.github.com') .get('/4/comments') - .reply(200, { user: { login: 'some-commenter', type: 'User' } }); + .reply(200, { + user: { + login: 'some-commenter', + html_url: 'https://github.com/some-commenter', + type: 'User', + }, + }); const { result } = renderHook(() => useNotifications(true)); diff --git a/src/typesGithub.ts b/src/typesGithub.ts index 01afa62cb..5cb5543ae 100644 --- a/src/typesGithub.ts +++ b/src/typesGithub.ts @@ -137,11 +137,13 @@ export interface User { export interface SubjectUser { login: string; + html_url: string; type: string; } export interface DiscussionAuthor { login: string; + url: string; type: string; } diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index f78324288..b1399501c 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -160,6 +160,7 @@ export async function fetchDiscussion( createdAt author { login + url type } } diff --git a/src/utils/subject.ts b/src/utils/subject.ts index 8fb565b59..0d500afcf 100644 --- a/src/utils/subject.ts +++ b/src/utils/subject.ts @@ -115,13 +115,14 @@ async function getGitifySubjectForDiscussion( if (latestDiscussionComment) { discussionUser = { login: latestDiscussionComment.author.login, + html_url: latestDiscussionComment.author.url, type: latestDiscussionComment.author.type, }; } return { state: discussionState, - user: discussionUser ?? null, + user: discussionUser, }; } @@ -139,6 +140,7 @@ async function getGitifySubjectForIssue( state: issue.state_reason ?? issue.state, user: { login: issueCommentUser?.login ?? issue.user.login, + html_url: issueCommentUser?.html_url ?? issue.user.html_url, type: issueCommentUser?.type ?? issue.user.type, }, }; @@ -165,6 +167,7 @@ async function getGitifySubjectForPullRequest( state: prState, user: { login: prCommentUser?.login ?? pr.user.login, + html_url: prCommentUser?.html_url ?? pr.user.html_url, type: prCommentUser?.type ?? pr.user.type, }, }; @@ -180,6 +183,7 @@ async function getGitifySubjectForRelease( state: null, user: { login: releaseCommentUser.login, + html_url: releaseCommentUser.html_url, type: releaseCommentUser.type, }, };