Skip to content
Open
1 change: 1 addition & 0 deletions src/renderer/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const mockNotificationSettings: NotificationSettingsState = {
showPills: true,
showNumber: true,
participating: false,
fetchReadNotifications: false,
markAsDoneOnOpen: false,
markAsDoneOnUnsubscribe: false,
delayNotificationState: false,
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const Sidebar: FC = () => {
status,
settings,
auth,
unreadNotificationCount,
notificationCount,
hasUnreadNotifications,
} = useAppContext();

Expand Down Expand Up @@ -91,7 +91,7 @@ export const Sidebar: FC = () => {
<IconButton
aria-label="Notifications"
data-testid="sidebar-notifications"
description={`${unreadNotificationCount} unread notifications ↗`}
description={`${notificationCount} ${settings.fetchReadNotifications ? 'notifications' : 'unread notifications'} ↗`}
icon={BellIcon}
onClick={() => openGitHubNotifications(primaryAccountHostname)}
size="small"
Expand Down
18 changes: 18 additions & 0 deletions src/renderer/components/notifications/NotificationRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => {
expect(markNotificationsAsReadMock).toHaveBeenCalledTimes(1);
});

it('should hide mark as read button when notification is already read', async () => {
const readNotification = {
...mockSingleNotification,
unread: false,
};

const props = {
notification: readNotification,
account: mockGitHubCloudAccount,
};

renderWithAppContext(<NotificationRow {...props} />);

expect(
screen.queryByTestId('notification-mark-as-read'),
).not.toBeInTheDocument();
});

it('should mark notifications as done', async () => {
const markNotificationsAsDoneMock = jest.fn();

Expand Down
15 changes: 8 additions & 7 deletions src/renderer/components/notifications/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ export const NotificationRow: FC<NotificationRowProps> = ({

{!animateExit && (
<HoverGroup bgColor="group-hover:bg-gitify-notification-hover">
<HoverButton
action={actionMarkAsRead}
enabled={!isNotificationRead}
icon={ReadIcon}
label="Mark as read"
testid="notification-mark-as-read"
/>

<HoverButton
action={actionMarkAsDone}
enabled={isMarkAsDoneFeatureSupported(notification.account)}
Expand All @@ -146,13 +154,6 @@ export const NotificationRow: FC<NotificationRowProps> = ({
testid="notification-mark-as-done"
/>

<HoverButton
action={actionMarkAsRead}
icon={ReadIcon}
label="Mark as read"
testid="notification-mark-as-read"
/>

<HoverButton
action={actionUnsubscribeFromThread}
icon={BellSlashIcon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () =>
repoNotifications: mockGitHubNotifications,
};

beforeEach(() => {
// Reset mock notification state between tests since it's mutated
for (const n of mockGitHubNotifications) {
n.unread = true;
}
});

afterEach(() => {
jest.clearAllMocks();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export const RepositoryNotifications: FC<RepositoryNotificationsProps> = ({

{!animateExit && (
<HoverGroup bgColor="group-hover:bg-gitify-repository">
<HoverButton
action={actionMarkAsRead}
enabled={!areAllRepoNotificationsRead}
icon={ReadIcon}
label="Mark repository as read"
testid="repository-mark-as-read"
/>

<HoverButton
action={actionMarkAsDone}
enabled={isMarkAsDoneFeatureSupported(
Expand All @@ -101,13 +109,6 @@ export const RepositoryNotifications: FC<RepositoryNotificationsProps> = ({
testid="repository-mark-as-done"
/>

<HoverButton
action={actionMarkAsRead}
icon={ReadIcon}
label="Mark repository as read"
testid="repository-mark-as-read"
/>

<HoverButton
action={actionToggleRepositoryNotifications}
icon={Chevron.icon}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading