diff --git a/src/components/Sidebar.test.tsx b/src/components/Sidebar.test.tsx
index 281ea73c0..0dad3f782 100644
--- a/src/components/Sidebar.test.tsx
+++ b/src/components/Sidebar.test.tsx
@@ -57,32 +57,74 @@ describe('components/Sidebar.tsx', () => {
expect(tree).toMatchSnapshot();
});
- it('should refresh the notifications', () => {
- render(
-
-
-
-
- ,
- );
- fetchNotifications.mockReset();
- fireEvent.click(screen.getByTitle('Refresh Notifications'));
+ describe('Refresh Notifications', () => {
+ it('should refresh the notifications when status is not loading', () => {
+ render(
+
+
+
+
+ ,
+ );
+ 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(
+
+
+
+
+ ,
+ );
+ fetchNotifications.mockReset();
+ fireEvent.click(screen.getByTitle('Refresh Notifications'));
+
+ expect(fetchNotifications).not.toHaveBeenCalled();
+ });
});
- it('go to the settings route', () => {
- render(
-
-
-
-
- ,
- );
- fireEvent.click(screen.getByTitle('Settings'));
- expect(mockNavigate).toHaveBeenNthCalledWith(1, '/settings');
+ describe('Settings', () => {
+ it('go to the settings route', () => {
+ render(
+
+
+
+
+ ,
+ );
+ fireEvent.click(screen.getByTitle('Settings'));
+ expect(mockNavigate).toHaveBeenCalledWith('/settings');
+ });
+
+ it('go to the home if settings path already shown', () => {
+ render(
+
+
+
+
+ ,
+ );
+ fireEvent.click(screen.getByTitle('Settings'));
+ expect(mockNavigate).toHaveBeenCalledWith('/', { replace: true });
+ });
});
it('opens github in the notifications page', () => {
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index e47171b0e..7117e193b 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -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]);
@@ -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}
>