Skip to content

Commit

Permalink
chore: improve tests for sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsojramos committed Jun 5, 2023
1 parent 710d9ac commit 6ba4f34
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ const LIGHT_GRADIENT_END = '#FFFFFF';
const DARK_GRADIENT_START = '#22283B';
const DARK_GRADIENT_END = '#555B6E';

export const Logo = ({ isDark, onClick, className = '' }: IProps) => (
export const Logo = ({ isDark, onClick, className = '', ...props }: IProps) => (
<svg
className={className}
onClick={() => onClick && onClick()}
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
viewBox="0 0 500 500"
role="logo"
{...props}
>
<defs>
<linearGradient
Expand Down
30 changes: 29 additions & 1 deletion src/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fireEvent, render } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import * as React from 'react';
import { Router } from 'react-router';
Expand Down Expand Up @@ -102,6 +102,34 @@ describe('components/Sidebar.tsx', () => {
);
});

it('should quit the app', () => {
const { getByLabelText } = render(
<AppContext.Provider value={{ isLoggedIn: false, notifications: [] }}>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>
);
fireEvent.click(getByLabelText('Quit App'));
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
expect(ipcRenderer.send).toHaveBeenCalledWith('app-quit');
});

it('should open the gitify repository', () => {
render(
<AppContext.Provider value={{ isLoggedIn: false, notifications: [] }}>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>
);
fireEvent.click(screen.getByTestId('gitify-logo'));
expect(shell.openExternal).toHaveBeenCalledTimes(1);
expect(shell.openExternal).toHaveBeenCalledWith(
'https://github.com/gitify-app/gitify'
);
});

describe('should render the notifications icon', () => {
it('when there are 0 notifications', () => {
const { getByLabelText } = render(
Expand Down
1 change: 1 addition & 0 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const Sidebar: React.FC = () => {
<div className="flex flex-col flex-1 items-center py-4">
<Logo
className="w-5 my-3 mx-auto cursor-pointer"
data-testid="gitify-logo"
onClick={onOpenBrowser}
/>

Expand Down
2 changes: 2 additions & 0 deletions src/components/__snapshots__/Sidebar.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`components/Sidebar.tsx should render itself & its children (logged in)
>
<svg
className="w-5 my-3 mx-auto cursor-pointer"
data-testid="gitify-logo"
onClick={[Function]}
role="logo"
viewBox="0 0 500 500"
Expand Down Expand Up @@ -127,6 +128,7 @@ exports[`components/Sidebar.tsx should render itself & its children (logged out)
>
<svg
className="w-5 my-3 mx-auto cursor-pointer"
data-testid="gitify-logo"
onClick={[Function]}
role="logo"
viewBox="0 0 500 500"
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const Constants = {
clientSecret: process.env.OAUTH_CLIENT_SECRET,
},

REPO_SLUG: 'manosim/gitify',
REPO_SLUG: 'gitify-app/gitify',

// Storage
STORAGE_KEY: 'gitify-storage',
Expand Down

0 comments on commit 6ba4f34

Please sign in to comment.