Repository: gitify-app/gitify
Pull request #959 (2024-04-03 12:25:59)

refactor: rename markNotification to markNotificationRead


Patch:
diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx
index d26a31d3..b72faac6 100644
--- a/src/components/NotificationRow.tsx
+++ b/src/components/NotificationRow.tsx
@@ -25,7 +25,7 @@ export const NotificationRow: React.FC<IProps> = ({
     settings,
     accounts,
     removeNotificationFromState,
-    markNotification,
+    markNotificationRead,
     markNotificationDone,
     unsubscribeNotification,
   } = useContext(AppContext);
@@ -133,7 +133,7 @@ export const NotificationRow: React.FC<IProps> = ({
         <button
           className="focus:outline-none h-full hover:text-green-500"
           title="Mark as Read"
-          onClick={() => markNotification(notification.id, hostname)}
+          onClick={() => markNotificationRead(notification.id, hostname)}
         >
           <ReadIcon size={14} aria-label="Mark as Read" />
         </button>
diff --git a/src/context/App.tsx b/src/context/App.tsx
index 8d7907a0..b600889d 100644
--- a/src/context/App.tsx
+++ b/src/context/App.tsx
@@ -56,7 +56,7 @@ interface AppContextState {
   requestFailed: boolean;
   removeNotificationFromState: (id: string, hostname: string) => void;
   fetchNotifications: () => Promise<void>;
-  markNotification: (id: string, hostname: string) => Promise<void>;
+  markNotificationRead: (id: string, hostname: string) => Promise<void>;
   markNotificationDone: (id: string, hostname: string) => Promise<void>;
   unsubscribeNotification: (id: string, hostname: string) => Promise<void>;
   markRepoNotifications: (id: string, hostname: string) => Promise<void>;
@@ -77,7 +77,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
     requestFailed,
     isFetching,
     removeNotificationFromState,
-    markNotification,
+    markNotificationRead,
     markNotificationDone,
     unsubscribeNotification,
     markRepoNotifications,
@@ -190,9 +190,9 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
     [accounts, settings, notifications],
   );
 
-  const markNotificationWithAccounts = useCallback(
+  const markNotificationReadWithAccounts = useCallback(
     async (id: string, hostname: string) =>
-      await markNotification(accounts, id, hostname),
+      await markNotificationRead(accounts, id, hostname),
     [accounts, notifications],
   );
 
@@ -235,7 +235,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
         requestFailed,
         removeNotificationFromState,
         fetchNotifications: fetchNotificationsWithAccounts,
-        markNotification: markNotificationWithAccounts,
+        markNotificationRead: markNotificationReadWithAccounts,
         markNotificationDone: markNotificationDoneWithAccounts,
         unsubscribeNotification: unsubscribeNotificationWithAccounts,
         markRepoNotifications: markRepoNotificationsWithAccounts,
diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts
index c9959bb5..48c811d3 100644
--- a/src/hooks/useNotifications.ts
+++ b/src/hooks/useNotifications.ts
@@ -26,7 +26,7 @@ interface NotificationsState {
     accounts: AuthState,
     settings: SettingsState,
   ) => Promise<void>;
-  markNotification: (
+  markNotificationRead: (
     accounts: AuthState,
     id: string,
     hostname: string,
@@ -202,7 +202,7 @@ export const useNotifications = (colors: boolean): NotificationsState => {
     [notifications],
   );
 
-  const markNotification = useCallback(
+  const markNotificationRead = useCallback(
     async (accounts, id, hostname) => {
       setIsFetching(true);
 
@@ -286,7 +286,7 @@ export const useNotifications = (colors: boolean): NotificationsState => {
           token,
           { ignored: true },
         );
-        await markNotification(accounts, id, hostname);
+        await markNotificationRead(accounts, id, hostname);
       } catch (err) {
         setIsFetching(false);
       }
@@ -391,7 +391,7 @@ export const useNotifications = (colors: boolean): NotificationsState => {
 
     removeNotificationFromState,
     fetchNotifications,
-    markNotification,
+    markNotificationRead,
     markNotificationDone,
     unsubscribeNotification,
     markRepoNotifications,


Test patch:
diff --git a/src/components/NotificationRow.test.tsx b/src/components/NotificationRow.test.tsx
index 42293a0c..22909b1c 100644
--- a/src/components/NotificationRow.test.tsx
+++ b/src/components/NotificationRow.test.tsx
@@ -82,7 +82,7 @@ describe('components/NotificationRow.tsx', () => {
   });
 
   it('should mark a notification as read', () => {
-    const markNotification = jest.fn();
+    const markNotificationRead = jest.fn();
 
     const props = {
       notification: mockedSingleNotification,
@@ -96,14 +96,14 @@ describe('components/NotificationRow.tsx', () => {
           accounts: mockAccounts,
         }}
       >
-        <AppContext.Provider value={{ markNotification }}>
+        <AppContext.Provider value={{ markNotificationRead }}>
           <NotificationRow {...props} />
         </AppContext.Provider>
       </AppContext.Provider>,
     );
 
     fireEvent.click(getByTitle('Mark as Read'));
-    expect(markNotification).toHaveBeenCalledTimes(1);
+    expect(markNotificationRead).toHaveBeenCalledTimes(1);
   });
 
   it('should mark a notification as done', () => {
diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx
index 00a5acdc..24ca1f09 100644
--- a/src/context/App.test.tsx
+++ b/src/context/App.test.tsx
@@ -43,7 +43,7 @@ describe('context/App.tsx', () => {
     getNotificationCountMock.mockReturnValue(1);
 
     const fetchNotificationsMock = jest.fn();
-    const markNotificationMock = jest.fn();
+    const markNotificationReadMock = jest.fn();
     const markNotificationDoneMock = jest.fn();
     const unsubscribeNotificationMock = jest.fn();
     const markRepoNotificationsMock = jest.fn();
@@ -51,7 +51,7 @@ describe('context/App.tsx', () => {
     beforeEach(() => {
       (useNotifications as jest.Mock).mockReturnValue({
         fetchNotifications: fetchNotificationsMock,
-        markNotification: markNotificationMock,
+        markNotificationRead: markNotificationReadMock,
         markNotificationDone: markNotificationDoneMock,
         unsubscribeNotification: unsubscribeNotificationMock,
         markRepoNotifications: markRepoNotificationsMock,
@@ -104,12 +104,12 @@ describe('context/App.tsx', () => {
       expect(fetchNotificationsMock).toHaveBeenCalledTimes(1);
     });
 
-    it('should call markNotification', async () => {
+    it('should call markNotificationRead', async () => {
       const TestComponent = () => {
-        const { markNotification } = useContext(AppContext);
+        const { markNotificationRead } = useContext(AppContext);
 
         return (
-          <button onClick={() => markNotification('123-456', 'github.com')}>
+          <button onClick={() => markNotificationRead('123-456', 'github.com')}>
             Test Case
           </button>
         );
@@ -117,12 +117,12 @@ describe('context/App.tsx', () => {
 
       const { getByText } = customRender(<TestComponent />);
 
-      markNotificationMock.mockReset();
+      markNotificationReadMock.mockReset();
 
       fireEvent.click(getByText('Test Case'));
 
-      expect(markNotificationMock).toHaveBeenCalledTimes(1);
-      expect(markNotificationMock).toHaveBeenCalledWith(
+      expect(markNotificationReadMock).toHaveBeenCalledTimes(1);
+      expect(markNotificationReadMock).toHaveBeenCalledWith(
         { enterpriseAccounts: [], token: null, user: null },
         '123-456',
         'github.com',
diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts
index bbcc64eb..b5ca27b1 100644
--- a/src/hooks/useNotifications.test.ts
+++ b/src/hooks/useNotifications.test.ts
@@ -477,7 +477,7 @@ describe('hooks/useNotifications.ts', () => {
     });
   });
 
-  describe('markNotification', () => {
+  describe('markNotificationRead', () => {
     const id = 'notification-123';
 
     describe('github.com', () => {
@@ -492,7 +492,7 @@ describe('hooks/useNotifications.ts', () => {
         const { result } = renderHook(() => useNotifications(false));
 
         act(() => {
-          result.current.markNotification(accounts, id, hostname);
+          result.current.markNotificationRead(accounts, id, hostname);
         });
 
         await waitFor(() => {
@@ -510,7 +510,7 @@ describe('hooks/useNotifications.ts', () => {
         const { result } = renderHook(() => useNotifications(false));
 
         act(() => {
-          result.current.markNotification(accounts, id, hostname);
+          result.current.markNotificationRead(accounts, id, hostname);
         });
 
         await waitFor(() => {
@@ -533,7 +533,7 @@ describe('hooks/useNotifications.ts', () => {
         const { result } = renderHook(() => useNotifications(false));
 
         act(() => {
-          result.current.markNotification(accounts, id, hostname);
+          result.current.markNotificationRead(accounts, id, hostname);
         });
 
         await waitFor(() => {
@@ -551,7 +551,7 @@ describe('hooks/useNotifications.ts', () => {
         const { result } = renderHook(() => useNotifications(false));
 
         act(() => {
-          result.current.markNotification(accounts, id, hostname);
+          result.current.markNotificationRead(accounts, id, hostname);
         });
 
         await waitFor(() => {