Skip to content

Commit c00879a

Browse files
authored
fix: error component height based on accounts (#2375)
fix: error for multiple accounts Signed-off-by: Adam Setch <[email protected]>
1 parent c60d05f commit c00879a

File tree

3 files changed

+582
-19
lines changed

3 files changed

+582
-19
lines changed

src/renderer/components/notifications/AccountNotifications.test.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { act, render, screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33

44
import {
5+
mockAuth,
56
mockGitHubCloudAccount,
67
mockSettings,
78
} from '../../__mocks__/state-mocks';
@@ -80,7 +81,7 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => {
8081
expect(tree).toMatchSnapshot();
8182
});
8283

83-
it('should render itself - account error', async () => {
84+
it('should render itself - account error for single account', async () => {
8485
const props = {
8586
account: mockGitHubCloudAccount,
8687
notifications: [],
@@ -96,7 +97,37 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => {
9697

9798
await act(async () => {
9899
tree = render(
99-
<AppContext.Provider value={{ settings: mockSettings }}>
100+
<AppContext.Provider
101+
value={{
102+
auth: { accounts: [mockGitHubCloudAccount] },
103+
settings: mockSettings,
104+
}}
105+
>
106+
<AccountNotifications {...props} />
107+
</AppContext.Provider>,
108+
);
109+
});
110+
111+
expect(tree).toMatchSnapshot();
112+
});
113+
114+
it('should render itself - account error for multiple accounts', async () => {
115+
const props = {
116+
account: mockGitHubCloudAccount,
117+
notifications: [],
118+
error: {
119+
title: 'Error title',
120+
descriptions: ['Error description'],
121+
emojis: ['🔥'],
122+
},
123+
showAccountHeader: true,
124+
};
125+
126+
let tree: ReturnType<typeof render> | null = null;
127+
128+
await act(async () => {
129+
tree = render(
130+
<AppContext.Provider value={{ auth: mockAuth, settings: mockSettings }}>
100131
<AccountNotifications {...props} />
101132
</AppContext.Provider>,
102133
);

src/renderer/components/notifications/AccountNotifications.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Button, Stack } from '@primer/react';
66
import { AppContext } from '../../context/App';
77
import { type Account, type GitifyError, Size } from '../../types';
88
import type { Notification } from '../../typesGitHub';
9+
import { hasMultipleAccounts } from '../../utils/auth/utils';
910
import { cn } from '../../utils/cn';
1011
import { getChevronDetails } from '../../utils/helpers';
1112
import {
@@ -37,7 +38,7 @@ export const AccountNotifications: FC<IAccountNotifications> = (
3738
) => {
3839
const { account, showAccountHeader, notifications } = props;
3940

40-
const { settings } = useContext(AppContext);
41+
const { auth, settings } = useContext(AppContext);
4142

4243
const [showAccountNotifications, setShowAccountNotifications] =
4344
useState(true);
@@ -126,7 +127,9 @@ export const AccountNotifications: FC<IAccountNotifications> = (
126127

127128
{showAccountNotifications && (
128129
<>
129-
{props.error && <Oops error={props.error} fullHeight={false} />}
130+
{props.error && (
131+
<Oops error={props.error} fullHeight={!hasMultipleAccounts(auth)} />
132+
)}
130133

131134
{!hasNotifications && !props.error && <AllRead fullHeight={false} />}
132135

0 commit comments

Comments
 (0)