Skip to content

Commit

Permalink
refactor: rename markRepoNotifications to markRepoNotificationsRead
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed Jun 8, 2024
1 parent 665d7a5 commit 8ff06ac
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/components/Repository.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jest.mock('./NotificationRow', () => ({
}));

describe('components/Repository.tsx', () => {
const markRepoNotifications = jest.fn();
const markRepoNotificationsRead = jest.fn();
const markRepoNotificationsDone = jest.fn();

const props = {
Expand All @@ -19,7 +19,7 @@ describe('components/Repository.tsx', () => {
};

beforeEach(() => {
markRepoNotifications.mockReset();
markRepoNotificationsRead.mockReset();

jest.spyOn(shell, 'openExternal');
});
Expand Down Expand Up @@ -50,14 +50,14 @@ describe('components/Repository.tsx', () => {

it('should mark a repo as read', () => {
render(
<AppContext.Provider value={{ markRepoNotifications }}>
<AppContext.Provider value={{ markRepoNotificationsRead }}>
<RepositoryNotifications {...props} />
</AppContext.Provider>,
);

fireEvent.click(screen.getByTitle('Mark Repository as Read'));

expect(markRepoNotifications).toHaveBeenCalledWith(
expect(markRepoNotificationsRead).toHaveBeenCalledWith(
'gitify-app/notifications-test',
'github.com',
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Repository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const RepositoryNotifications: FC<IProps> = ({
repoNotifications,
hostname,
}) => {
const { markRepoNotifications, markRepoNotificationsDone } =
const { markRepoNotificationsRead, markRepoNotificationsDone } =
useContext(AppContext);

const openBrowser = useCallback(() => {
Expand All @@ -27,7 +27,7 @@ export const RepositoryNotifications: FC<IProps> = ({

const markRepoAsRead = useCallback(() => {
const repoSlug = repoNotifications[0].repository.full_name;
markRepoNotifications(repoSlug, hostname);
markRepoNotificationsRead(repoSlug, hostname);
}, [repoNotifications, hostname]);

const markRepoAsDone = useCallback(() => {
Expand Down
16 changes: 8 additions & 8 deletions src/context/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('context/App.tsx', () => {
const markNotificationReadMock = jest.fn();
const markNotificationDoneMock = jest.fn();
const unsubscribeNotificationMock = jest.fn();
const markRepoNotificationsMock = jest.fn();
const markRepoNotificationsReadMock = jest.fn();
const markRepoNotificationsDoneMock = jest.fn();

const mockDefaultState = {
Expand All @@ -59,7 +59,7 @@ describe('context/App.tsx', () => {
markNotificationRead: markNotificationReadMock,
markNotificationDone: markNotificationDoneMock,
unsubscribeNotification: unsubscribeNotificationMock,
markRepoNotifications: markRepoNotificationsMock,
markRepoNotificationsRead: markRepoNotificationsReadMock,
markRepoNotificationsDone: markRepoNotificationsDoneMock,
});
});
Expand Down Expand Up @@ -198,15 +198,15 @@ describe('context/App.tsx', () => {
);
});

it('should call markRepoNotifications', async () => {
it('should call markRepoNotificationsRead', async () => {
const TestComponent = () => {
const { markRepoNotifications } = useContext(AppContext);
const { markRepoNotificationsRead } = useContext(AppContext);

return (
<button
type="button"
onClick={() =>
markRepoNotifications(
markRepoNotificationsRead(
'gitify-app/notifications-test',
'github.com',
)
Expand All @@ -219,12 +219,12 @@ describe('context/App.tsx', () => {

const { getByText } = customRender(<TestComponent />);

markRepoNotificationsMock.mockReset();
markRepoNotificationsReadMock.mockReset();

fireEvent.click(getByText('Test Case'));

expect(markRepoNotificationsMock).toHaveBeenCalledTimes(1);
expect(markRepoNotificationsMock).toHaveBeenCalledWith(
expect(markRepoNotificationsReadMock).toHaveBeenCalledTimes(1);
expect(markRepoNotificationsReadMock).toHaveBeenCalledWith(
mockDefaultState,
'gitify-app/notifications-test',
'github.com',
Expand Down
10 changes: 5 additions & 5 deletions src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ interface AppContextState {
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>;
markRepoNotificationsRead: (id: string, hostname: string) => Promise<void>;
markRepoNotificationsDone: (id: string, hostname: string) => Promise<void>;

settings: SettingsState;
Expand All @@ -103,7 +103,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
markNotificationRead,
markNotificationDone,
unsubscribeNotification,
markRepoNotifications,
markRepoNotificationsRead,
markRepoNotificationsDone,
} = useNotifications();

Expand Down Expand Up @@ -248,9 +248,9 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
[auth, notifications],
);

const markRepoNotificationsWithAccounts = useCallback(
const markRepoNotificationsReadWithAccounts = useCallback(
async (repoSlug: string, hostname: string) =>
await markRepoNotifications({ auth, settings }, repoSlug, hostname),
await markRepoNotificationsRead({ auth, settings }, repoSlug, hostname),
[auth, notifications],
);

Expand Down Expand Up @@ -279,7 +279,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
markNotificationRead: markNotificationReadWithAccounts,
markNotificationDone: markNotificationDoneWithAccounts,
unsubscribeNotification: unsubscribeNotificationWithAccounts,
markRepoNotifications: markRepoNotificationsWithAccounts,
markRepoNotificationsRead: markRepoNotificationsReadWithAccounts,
markRepoNotificationsDone: markRepoNotificationsDoneWithAccounts,

settings,
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ describe('hooks/useNotifications.ts', () => {
});
});

describe('markRepoNotifications', () => {
describe('markRepoNotificationsRead', () => {
const hostname = 'github.com';
const repoSlug = 'gitify-app/notifications-test';

Expand All @@ -479,7 +479,7 @@ describe('hooks/useNotifications.ts', () => {
const { result } = renderHook(() => useNotifications());

act(() => {
result.current.markRepoNotifications(mockState, repoSlug, hostname);
result.current.markRepoNotificationsRead(mockState, repoSlug, hostname);
});

await waitFor(() => {
Expand All @@ -497,7 +497,7 @@ describe('hooks/useNotifications.ts', () => {
const { result } = renderHook(() => useNotifications());

act(() => {
result.current.markRepoNotifications(mockState, repoSlug, hostname);
result.current.markRepoNotificationsRead(mockState, repoSlug, hostname);
});

await waitFor(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface NotificationsState {
id: string,
hostname: string,
) => Promise<void>;
markRepoNotifications: (
markRepoNotificationsRead: (
state: GitifyState,
repoSlug: string,
hostname: string,
Expand Down Expand Up @@ -154,7 +154,7 @@ export const useNotifications = (): NotificationsState => {
[notifications],
);

const markRepoNotifications = useCallback(
const markRepoNotificationsRead = useCallback(
async (state: GitifyState, repoSlug: string, hostname: string) => {
setStatus('loading');

Expand Down Expand Up @@ -251,7 +251,7 @@ export const useNotifications = (): NotificationsState => {
markNotificationRead,
markNotificationDone,
unsubscribeNotification,
markRepoNotifications,
markRepoNotificationsRead,
markRepoNotificationsDone,
};
};

0 comments on commit 8ff06ac

Please sign in to comment.