Skip to content
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
88 changes: 65 additions & 23 deletions src/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,74 @@ describe('components/Sidebar.tsx', () => {
expect(tree).toMatchSnapshot();
});

it('should refresh the notifications', () => {
render(
<AppContext.Provider
value={{ isLoggedIn: true, notifications: [], fetchNotifications }}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fetchNotifications.mockReset();
fireEvent.click(screen.getByTitle('Refresh Notifications'));
describe('Refresh Notifications', () => {
it('should refresh the notifications when status is not loading', () => {
render(
<AppContext.Provider
value={{
isLoggedIn: true,
notifications: [],
fetchNotifications,
status: 'success',
}}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fetchNotifications.mockReset();
fireEvent.click(screen.getByTitle('Refresh Notifications'));

expect(fetchNotifications).toHaveBeenCalledTimes(1);
});

expect(fetchNotifications).toHaveBeenCalledTimes(1);
it('should not refresh the notifications when status is loading', () => {
render(
<AppContext.Provider
value={{
isLoggedIn: true,
notifications: [],
fetchNotifications,
status: 'loading',
}}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fetchNotifications.mockReset();
fireEvent.click(screen.getByTitle('Refresh Notifications'));

expect(fetchNotifications).not.toHaveBeenCalled();
});
});

it('go to the settings route', () => {
render(
<AppContext.Provider value={{ isLoggedIn: true, notifications: [] }}>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fireEvent.click(screen.getByTitle('Settings'));
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/settings');
describe('Settings', () => {
it('go to the settings route', () => {
render(
<AppContext.Provider value={{ isLoggedIn: true, notifications: [] }}>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fireEvent.click(screen.getByTitle('Settings'));
expect(mockNavigate).toHaveBeenCalledWith('/settings');
});

it('go to the home if settings path already shown', () => {
render(
<AppContext.Provider value={{ isLoggedIn: true, notifications: [] }}>
<MemoryRouter initialEntries={['/settings']}>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fireEvent.click(screen.getByTitle('Settings'));
expect(mockNavigate).toHaveBeenCalledWith('/', { replace: true });
});
});

it('opens github in the notifications page', () => {
Expand Down
16 changes: 9 additions & 7 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export const Sidebar: FC = () => {
ipcRenderer.send('app-quit');
}, []);

const toggleSettings = () => {
if (location.pathname.startsWith('/settings')) {
navigate('/', { replace: true });
} else {
navigate('/settings');
}
};

const notificationsCount = useMemo(() => {
return getNotificationCount(notifications);
}, [notifications]);
Expand Down Expand Up @@ -93,13 +101,7 @@ export const Sidebar: FC = () => {
type="button"
className={sidebarButtonClasses}
title="Settings"
onClick={() => {
if (location.pathname.startsWith('/settings')) {
navigate('/', { replace: true });
} else {
navigate('/settings');
}
}}
onClick={toggleSettings}
>
<GearIcon size={16} aria-label="Settings" />
</button>
Expand Down