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
6 changes: 6 additions & 0 deletions src/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type Account,
type AuthState,
type GitifyState,
type GitifyUser,
type SettingsState,
Theme,
Expand Down Expand Up @@ -81,3 +82,8 @@ export const mockSettings: SettingsState = {
delayNotificationState: false,
showPills: true,
};

export const mockState: GitifyState = {
auth: mockAuth,
settings: mockSettings,
};
33 changes: 18 additions & 15 deletions src/context/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ describe('context/App.tsx', () => {
const markRepoNotificationsMock = jest.fn();
const markRepoNotificationsDoneMock = jest.fn();

const mockDefaultState = {
auth: { accounts: [], enterpriseAccounts: [], token: null, user: null },
settings: mockSettings,
};

beforeEach(() => {
(useNotifications as jest.Mock).mockReturnValue({
fetchNotifications: fetchNotificationsMock,
Expand Down Expand Up @@ -131,13 +136,7 @@ describe('context/App.tsx', () => {

expect(markNotificationReadMock).toHaveBeenCalledTimes(1);
expect(markNotificationReadMock).toHaveBeenCalledWith(
{
accounts: [],
enterpriseAccounts: [],
token: null,
user: null,
},
mockSettings,
mockDefaultState,
'123-456',
'github.com',
);
Expand Down Expand Up @@ -165,8 +164,7 @@ describe('context/App.tsx', () => {

expect(markNotificationDoneMock).toHaveBeenCalledTimes(1);
expect(markNotificationDoneMock).toHaveBeenCalledWith(
{ accounts: [], enterpriseAccounts: [], token: null, user: null },
mockSettings,
mockDefaultState,
'123-456',
'github.com',
);
Expand Down Expand Up @@ -194,8 +192,7 @@ describe('context/App.tsx', () => {

expect(unsubscribeNotificationMock).toHaveBeenCalledTimes(1);
expect(unsubscribeNotificationMock).toHaveBeenCalledWith(
{ accounts: [], enterpriseAccounts: [], token: null, user: null },
mockSettings,
mockDefaultState,
'123-456',
'github.com',
);
Expand Down Expand Up @@ -228,8 +225,7 @@ describe('context/App.tsx', () => {

expect(markRepoNotificationsMock).toHaveBeenCalledTimes(1);
expect(markRepoNotificationsMock).toHaveBeenCalledWith(
{ accounts: [], enterpriseAccounts: [], token: null, user: null },
mockSettings,
mockDefaultState,
'gitify-app/notifications-test',
'github.com',
);
Expand Down Expand Up @@ -262,8 +258,15 @@ describe('context/App.tsx', () => {

expect(markRepoNotificationsDoneMock).toHaveBeenCalledTimes(1);
expect(markRepoNotificationsDoneMock).toHaveBeenCalledWith(
{ accounts: [], enterpriseAccounts: [], token: null, user: null },
mockSettings,
{
auth: {
accounts: [],
enterpriseAccounts: [],
token: null,
user: null,
},
settings: mockSettings,
},
'gitify-app/notifications-test',
'github.com',
);
Expand Down
16 changes: 8 additions & 8 deletions src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {

// biome-ignore lint/correctness/useExhaustiveDependencies: We only want fetchNotifications to be called for certain account or setting changes.
useEffect(() => {
fetchNotifications(auth, settings);
fetchNotifications({ auth, settings });
}, [
settings.participating,
settings.showBots,
Expand All @@ -126,7 +126,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
]);

useInterval(() => {
fetchNotifications(auth, settings);
fetchNotifications({ auth, settings });
}, Constants.FETCH_INTERVAL);

// biome-ignore lint/correctness/useExhaustiveDependencies: We need to update tray title when settings or notifications changes.
Expand Down Expand Up @@ -226,37 +226,37 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
}, []);

const fetchNotificationsWithAccounts = useCallback(
async () => await fetchNotifications(auth, settings),
async () => await fetchNotifications({ auth, settings }),
[auth, settings, notifications],
);

const markNotificationReadWithAccounts = useCallback(
async (id: string, hostname: string) =>
await markNotificationRead(auth, settings, id, hostname),
await markNotificationRead({ auth, settings }, id, hostname),
[auth, notifications],
);

const markNotificationDoneWithAccounts = useCallback(
async (id: string, hostname: string) =>
await markNotificationDone(auth, settings, id, hostname),
await markNotificationDone({ auth, settings }, id, hostname),
[auth, notifications],
);

const unsubscribeNotificationWithAccounts = useCallback(
async (id: string, hostname: string) =>
await unsubscribeNotification(auth, settings, id, hostname),
await unsubscribeNotification({ auth, settings }, id, hostname),
[auth, notifications],
);

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

const markRepoNotificationsDoneWithAccounts = useCallback(
async (repoSlug: string, hostname: string) =>
await markRepoNotificationsDone(auth, settings, repoSlug, hostname),
await markRepoNotificationsDone({ auth, settings }, repoSlug, hostname),
[auth, notifications],
);

Expand Down
Loading