Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: my quick links #1259

Merged
merged 6 commits into from
Jun 18, 2024
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
44 changes: 44 additions & 0 deletions src/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,50 @@ describe('components/Sidebar.tsx', () => {
);
});

it('opens my github issues page', () => {
const openExternalLinkMock = jest.spyOn(comms, 'openExternalLink');

render(
<AppContext.Provider
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
}}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fireEvent.click(screen.getByLabelText('My Issues'));
expect(openExternalLinkMock).toHaveBeenCalledTimes(1);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/issues',
);
});

it('opens my github pull requests page', () => {
const openExternalLinkMock = jest.spyOn(comms, 'openExternalLink');

render(
<AppContext.Provider
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
}}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fireEvent.click(screen.getByLabelText('My Pull Requests'));
expect(openExternalLinkMock).toHaveBeenCalledTimes(1);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/pulls',
);
});

it('should quit the app', () => {
const quitAppMock = jest.spyOn(comms, 'quitApp');

Expand Down
21 changes: 20 additions & 1 deletion src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
BellIcon,
GearIcon,
GitPullRequestIcon,
IssueOpenedIcon,
SyncIcon,
XCircleIcon,
} from '@primer/octicons-react';
Expand All @@ -9,7 +11,12 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { Logo } from '../components/Logo';
import { AppContext } from '../context/App';
import { quitApp } from '../utils/comms';
import { openGitHubNotifications, openGitifyRepository } from '../utils/links';
import {
openGitHubIssues,
openGitHubNotifications,
openGitHubPulls,
openGitifyRepository,
} from '../utils/links';
import { getNotificationCount } from '../utils/notifications';
import { SidebarButton } from './buttons/SidebarButton';

Expand Down Expand Up @@ -56,6 +63,18 @@ export const Sidebar: FC = () => {
icon={BellIcon}
onClick={() => openGitHubNotifications()}
/>

<SidebarButton
bmulholland marked this conversation as resolved.
Show resolved Hide resolved
title="My Issues"
icon={IssueOpenedIcon}
onClick={() => openGitHubIssues()}
/>

<SidebarButton
title="My Pull Requests"
icon={GitPullRequestIcon}
onClick={() => openGitHubPulls()}
/>
</div>

<div className="px-3 py-4">
Expand Down
180 changes: 180 additions & 0 deletions src/components/__snapshots__/Sidebar.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/utils/links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import * as helpers from './helpers';
import {
openAccountProfile,
openDeveloperSettings,
openGitHubIssues,
openGitHubNotifications,
openGitHubParticipatingDocs,
openGitHubPulls,
openGitifyReleaseNotes,
openGitifyRepository,
openHost,
Expand Down Expand Up @@ -50,6 +52,20 @@ describe('utils/links.ts', () => {
);
});

it('openGitHubIssues', () => {
openGitHubIssues();
expect(comms.openExternalLink).toHaveBeenCalledWith(
'https://github.com/issues',
);
});

it('openGitHubPulls', () => {
openGitHubPulls();
expect(comms.openExternalLink).toHaveBeenCalledWith(
'https://github.com/pulls',
);
});

it('openAccountProfile', () => {
openAccountProfile(mockGitHubCloudAccount);
expect(comms.openExternalLink).toHaveBeenCalledWith(
Expand Down
8 changes: 8 additions & 0 deletions src/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export function openGitHubNotifications() {
openExternalLink('https://github.com/notifications' as Link);
}

export function openGitHubIssues() {
openExternalLink('https://github.com/issues' as Link);
}

export function openGitHubPulls() {
openExternalLink('https://github.com/pulls' as Link);
}

export function openAccountProfile(account: Account) {
const url = new URL(`https://${account.hostname}`);
url.pathname = account.user.login;
Expand Down