diff --git a/src/components/AccountNotifications.tsx b/src/components/AccountNotifications.tsx index 188d8aec5..d97b98555 100644 --- a/src/components/AccountNotifications.tsx +++ b/src/components/AccountNotifications.tsx @@ -31,30 +31,31 @@ export const AccountNotifications = (props: IProps) => { ), ); - const [showNotifications, setShowNotifications] = useState(true); + const [showAccountNotifications, setShowAccountNotifications] = + useState(true); - const toggleNotifications = () => { - setShowNotifications(!showNotifications); + const toggleAccountNotifications = () => { + setShowAccountNotifications(!showAccountNotifications); }; const ChevronIcon = notifications.length === 0 ? ChevronLeftIcon - : showNotifications + : showAccountNotifications ? ChevronDownIcon : ChevronUpIcon; - const toggleNotificationsLabel = + const toggleAccountNotificationsLabel = notifications.length === 0 ? 'No notifications for account' - : showNotifications + : showAccountNotifications ? 'Hide account notifications' : 'Show account notifications'; return ( <> {showAccountHostname && ( -
+
-
+
@@ -78,7 +80,7 @@ export const AccountNotifications = (props: IProps) => {
)} - {showNotifications && + {showAccountNotifications && Object.values(groupedNotifications).map((repoNotifications) => { const repoSlug = repoNotifications[0].repository.full_name; diff --git a/src/components/Repository.test.tsx b/src/components/Repository.test.tsx index cf2fa7764..b8b9f3fff 100644 --- a/src/components/Repository.test.tsx +++ b/src/components/Repository.test.tsx @@ -1,4 +1,4 @@ -import { fireEvent, render, screen } from '@testing-library/react'; +import { act, fireEvent, render, screen } from '@testing-library/react'; import { mockGitHubCloudAccount } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import type { Link } from '../types'; @@ -91,4 +91,15 @@ describe('components/Repository.tsx', () => { ); expect(tree).toMatchSnapshot(); }); + + it('should toggle account notifications visibility', async () => { + await act(async () => { + render(); + }); + + fireEvent.click(screen.getByTitle('Hide repository notifications')); + + const tree = render(); + expect(tree).toMatchSnapshot(); + }); }); diff --git a/src/components/Repository.tsx b/src/components/Repository.tsx index b8cdb9bdf..26da6b267 100644 --- a/src/components/Repository.tsx +++ b/src/components/Repository.tsx @@ -1,5 +1,11 @@ -import { CheckIcon, MarkGithubIcon, ReadIcon } from '@primer/octicons-react'; -import { type FC, useCallback, useContext } from 'react'; +import { + CheckIcon, + ChevronDownIcon, + ChevronUpIcon, + MarkGithubIcon, + ReadIcon, +} from '@primer/octicons-react'; +import { type FC, useCallback, useContext, useState } from 'react'; import { AppContext } from '../context/App'; import type { Notification } from '../typesGitHub'; import { openRepository } from '../utils/links'; @@ -28,10 +34,25 @@ export const RepositoryNotifications: FC = ({ const avatarUrl = repoNotifications[0].repository.owner.avatar_url; const repoSlug = repoNotifications[0].repository.full_name; + const [showRepositoryNotifications, setShowRepositoryNotifications] = + useState(true); + + const toggleRepositoryNotifications = () => { + setShowRepositoryNotifications(!showRepositoryNotifications); + }; + + const ChevronIcon = showRepositoryNotifications + ? ChevronDownIcon + : ChevronUpIcon; + + const toggleRepositoryNotificationsLabel = showRepositoryNotifications + ? 'Hide repository notifications' + : 'Show repository notifications'; + return ( <> -
-
+
+
{avatarUrl ? ( = ({
+
- {repoNotifications.map((obj) => ( - - ))} + {showRepositoryNotifications && + repoNotifications.map((obj) => ( + + ))} ); }; diff --git a/src/components/__snapshots__/AccountNotifications.test.tsx.snap b/src/components/__snapshots__/AccountNotifications.test.tsx.snap index d7d8d8798..4c8abbbfd 100644 --- a/src/components/__snapshots__/AccountNotifications.test.tsx.snap +++ b/src/components/__snapshots__/AccountNotifications.test.tsx.snap @@ -6,7 +6,7 @@ exports[`components/AccountNotifications.tsx should render itself (github.com wi "baseElement":
-
+
-
+
+ +
+ +
+
+
+ NotificationRow +
+
+ NotificationRow +
+
, + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "rerender": [Function], + "unmount": [Function], +} +`; + +exports[`components/Repository.tsx should toggle account notifications visibility 1`] = ` +{ + "asFragment": [Function], + "baseElement": +
+
+
+ + + gitify-app/notifications-test + +
+
+ + +
+ +
+
+
+
+
+
+ + + gitify-app/notifications-test + +
+
+ + +
+ +
+
+
+ NotificationRow +
+
+ NotificationRow +
+
+ , + "container":
+
+
+ + + gitify-app/notifications-test + +
+
+