diff --git a/src/components/AccountNotifications.test.tsx b/src/components/AccountNotifications.test.tsx index c3021424d..c8806b2ca 100644 --- a/src/components/AccountNotifications.test.tsx +++ b/src/components/AccountNotifications.test.tsx @@ -49,4 +49,21 @@ describe('components/AccountNotifications.tsx', () => { expect(openAccountProfileMock).toHaveBeenCalledTimes(1); expect(openAccountProfileMock).toHaveBeenCalledWith(mockGitHubCloudAccount); }); + + it('should toggle account notifications visibility', async () => { + const props = { + account: mockGitHubCloudAccount, + notifications: mockGitHubNotifications, + showAccountHostname: true, + }; + + await act(async () => { + render(); + }); + + fireEvent.click(screen.getByTitle('Hide account notifications')); + + const tree = render(); + expect(tree).toMatchSnapshot(); + }); }); diff --git a/src/components/AccountNotifications.tsx b/src/components/AccountNotifications.tsx index 0bda63707..d4a9ebcfd 100644 --- a/src/components/AccountNotifications.tsx +++ b/src/components/AccountNotifications.tsx @@ -1,4 +1,9 @@ -import { ChevronDownIcon, ChevronLeftIcon } from '@primer/octicons-react'; +import { + ChevronDownIcon, + ChevronLeftIcon, + ChevronUpIcon, +} from '@primer/octicons-react'; +import { useState } from 'react'; import type { Account } from '../types'; import type { Notification } from '../typesGitHub'; import { openAccountProfile } from '../utils/links'; @@ -26,7 +31,25 @@ export const AccountNotifications = (props: IProps) => { ), ); - const Chevron = notifications.length > 0 ? ChevronDownIcon : ChevronLeftIcon; + const [showNotifications, setShowNotifications] = useState(true); + + const toggleNotifications = () => { + setShowNotifications(!showNotifications); + }; + + const ChevronIcon = + notifications.length === 0 + ? ChevronLeftIcon + : showNotifications + ? ChevronDownIcon + : ChevronUpIcon; + + const toggleNotificationsLabel = + notifications.length === 0 + ? 'No notifications for account' + : showNotifications + ? 'Hide account notifications' + : 'Show account notifications'; return ( <> @@ -43,23 +66,30 @@ export const AccountNotifications = (props: IProps) => {
- +
)} - {Object.values(groupedNotifications).map((repoNotifications) => { - const repoSlug = repoNotifications[0].repository.full_name; + {showNotifications && + Object.values(groupedNotifications).map((repoNotifications) => { + const repoSlug = repoNotifications[0].repository.full_name; - return ( - - ); - })} + return ( + + ); + })} ); }; diff --git a/src/components/__snapshots__/AccountNotifications.test.tsx.snap b/src/components/__snapshots__/AccountNotifications.test.tsx.snap index 024a22adf..0f1e8f305 100644 --- a/src/components/__snapshots__/AccountNotifications.test.tsx.snap +++ b/src/components/__snapshots__/AccountNotifications.test.tsx.snap @@ -37,20 +37,25 @@ exports[`components/AccountNotifications.tsx should render itself (github.com wi
- + +
@@ -91,20 +96,25 @@ exports[`components/AccountNotifications.tsx should render itself (github.com wi
- + +
@@ -202,6 +212,66 @@ exports[`components/AccountNotifications.tsx should render itself (github.com wi
+ +
+ + + , + "container":
+
+
+ + + + +
+
+ +
+
+
, + "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/AccountNotifications.tsx should toggle account notifications visibility 1`] = ` +{ + "asFragment": [Function], + "baseElement": +
+
+
+ + + + +
+
+
+
+
+
+ + + + +
+
+ +
+
+
+ Repository +
+
, "container":
- + +
+
+ Repository +
, "debug": [Function], "findAllByAltText": [Function],