Skip to content

Commit

Permalink
refactor: extract sidebar button into component
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed Jun 18, 2024
1 parent dc674f1 commit 23a11de
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 268 deletions.
44 changes: 0 additions & 44 deletions src/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,50 +146,6 @@ 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: 1 addition & 20 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
BellIcon,
GearIcon,
GitPullRequestIcon,
IssueOpenedIcon,
SyncIcon,
XCircleIcon,
} from '@primer/octicons-react';
Expand All @@ -11,12 +9,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { Logo } from '../components/Logo';
import { AppContext } from '../context/App';
import { quitApp } from '../utils/comms';
import {
openGitHubIssues,
openGitHubNotifications,
openGitHubPulls,
openGitifyRepository,
} from '../utils/links';
import { openGitHubNotifications, openGitifyRepository } from '../utils/links';
import { getNotificationCount } from '../utils/notifications';
import { SidebarButton } from './buttons/SidebarButton';

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

<SidebarButton
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: 0 additions & 180 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: 0 additions & 16 deletions src/utils/links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import * as helpers from './helpers';
import {
openAccountProfile,
openDeveloperSettings,
openGitHubIssues,
openGitHubNotifications,
openGitHubParticipatingDocs,
openGitHubPulls,
openGitifyReleaseNotes,
openGitifyRepository,
openHost,
Expand Down Expand Up @@ -52,20 +50,6 @@ 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: 0 additions & 8 deletions src/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ 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

0 comments on commit 23a11de

Please sign in to comment.